GetTxCountArgs

This commit is contained in:
Taylor Gerring
2015-03-26 12:47:00 +01:00
parent 9c4504dc41
commit 4523a00b91
3 changed files with 57 additions and 23 deletions

View File

@ -559,20 +559,16 @@ func TestGetStorageAtArgsValueNotString(t *testing.T) {
}
func TestGetTxCountArgs(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "pending"]`
expected := new(GetTxCountArgs)
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected.BlockNumber = -1
expected.Address = common.HexToAddress("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
expected.BlockNumber = -2
args := new(GetTxCountArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if err := args.requirements(); err != nil {
t.Error(err)
}
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
@ -587,8 +583,58 @@ func TestGetTxCountEmptyArgs(t *testing.T) {
args := new(GetTxCountArgs)
err := json.Unmarshal([]byte(input), &args)
if err == nil {
switch err.(type) {
case nil:
t.Error("Expected error but didn't get one")
case *InsufficientParamsError:
break
default:
t.Errorf("Expected *rpc.InsufficientParamsError but got %T with message `%s`", err, err.Error())
}
}
func TestGetTxCountEmptyArgsInvalid(t *testing.T) {
input := `false`
args := new(GetTxCountArgs)
err := json.Unmarshal([]byte(input), &args)
switch err.(type) {
case nil:
t.Error("Expected error but didn't get one")
case *DecodeParamError:
break
default:
t.Errorf("Expected *rpc.DecodeParamError but got %T with message `%s`", err, err.Error())
}
}
func TestGetTxCountAddressNotString(t *testing.T) {
input := `[false, "pending"]`
args := new(GetTxCountArgs)
err := json.Unmarshal([]byte(input), &args)
switch err.(type) {
case nil:
t.Error("Expected error but didn't get one")
case *DecodeParamError:
break
default:
t.Errorf("Expected *rpc.DecodeParamError but got %T with message `%s`", err, err.Error())
}
}
func TestGetTxCountBlockheightInvalid(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
args := new(GetTxCountArgs)
err := json.Unmarshal([]byte(input), &args)
switch err.(type) {
case nil:
t.Error("Expected error but didn't get one")
case *DecodeParamError:
break
default:
t.Errorf("Expected *rpc.DecodeParamError but got %T with message `%s`", err, err.Error())
}
}