aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/args_test.go')
-rw-r--r--rpc/args_test.go229
1 files changed, 214 insertions, 15 deletions
diff --git a/rpc/args_test.go b/rpc/args_test.go
index b88bab280..cfe6c0c45 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -8,6 +8,61 @@ import (
"testing"
)
+func TestBlockheightInvalidString(t *testing.T) {
+ v := "foo"
+ var num int64
+
+ str := ExpectInvalidTypeError(blockHeight(v, &num))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockheightEarliest(t *testing.T) {
+ v := "earliest"
+ e := int64(0)
+ var num int64
+
+ err := blockHeight(v, &num)
+ if err != nil {
+ t.Error(err)
+ }
+
+ if num != e {
+ t.Errorf("Expected %s but got %s", e, num)
+ }
+}
+
+func TestBlockheightLatest(t *testing.T) {
+ v := "latest"
+ e := int64(-1)
+ var num int64
+
+ err := blockHeight(v, &num)
+ if err != nil {
+ t.Error(err)
+ }
+
+ if num != e {
+ t.Errorf("Expected %s but got %s", e, num)
+ }
+}
+
+func TestBlockheightPending(t *testing.T) {
+ v := "pending"
+ e := int64(-2)
+ var num int64
+
+ err := blockHeight(v, &num)
+ if err != nil {
+ t.Error(err)
+ }
+
+ if num != e {
+ t.Errorf("Expected %s but got %s", e, num)
+ }
+}
+
func ExpectValidationError(err error) string {
var str string
switch err.(type) {
@@ -121,6 +176,26 @@ func TestGetBalanceArgs(t *testing.T) {
}
}
+func TestGetBalanceArgsBlocknumMissing(t *testing.T) {
+ input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
+ expected := new(GetBalanceArgs)
+ expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
+ expected.BlockNumber = -1
+
+ args := new(GetBalanceArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if args.Address != expected.Address {
+ t.Errorf("Address should be %v but is %v", expected.Address, args.Address)
+ }
+
+ if args.BlockNumber != expected.BlockNumber {
+ t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestGetBalanceArgsLatest(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected := new(GetBalanceArgs)
@@ -231,6 +306,16 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
}
}
+func TestGetBlockByHashArgsHashBool(t *testing.T) {
+ input := `[false, true]`
+
+ args := new(GetBlockByHashArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestGetBlockByNumberArgsBlockNum(t *testing.T) {
input := `[436, false]`
expected := new(GetBlockByNumberArgs)
@@ -586,10 +671,6 @@ func TestCallArgs(t *testing.T) {
t.Error(err)
}
- if expected.From != args.From {
- t.Errorf("From shoud be %#v but is %#v", expected.From, args.From)
- }
-
if expected.To != args.To {
t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
}
@@ -810,19 +891,8 @@ func TestCallArgsNotStrings(t *testing.T) {
}
}
-func TestCallArgsFromEmpty(t *testing.T) {
- input := `[{"to": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
-
- args := new(CallArgs)
- str := ExpectValidationError(json.Unmarshal([]byte(input), &args))
- if len(str) > 0 {
- t.Error(str)
- }
-}
-
func TestCallArgsToEmpty(t *testing.T) {
input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
-
args := new(CallArgs)
str := ExpectValidationError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
@@ -850,6 +920,26 @@ func TestGetStorageArgs(t *testing.T) {
}
}
+func TestGetStorageArgsMissingBlocknum(t *testing.T) {
+ input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
+ expected := new(GetStorageArgs)
+ expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
+ expected.BlockNumber = -1
+
+ args := new(GetStorageArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Address != args.Address {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestGetStorageInvalidArgs(t *testing.T) {
input := `{}`
@@ -915,6 +1005,31 @@ func TestGetStorageAtArgs(t *testing.T) {
}
}
+func TestGetStorageAtArgsMissingBlocknum(t *testing.T) {
+ input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0"]`
+ expected := new(GetStorageAtArgs)
+ expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
+ expected.Key = "0x0"
+ expected.BlockNumber = -1
+
+ args := new(GetStorageAtArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Address != args.Address {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.Key != args.Key {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestGetStorageAtEmptyArgs(t *testing.T) {
input := `[]`
@@ -1015,6 +1130,26 @@ func TestGetTxCountAddressNotString(t *testing.T) {
}
}
+func TestGetTxCountBlockheightMissing(t *testing.T) {
+ input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
+ expected := new(GetTxCountArgs)
+ expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
+ expected.BlockNumber = -1
+
+ args := new(GetTxCountArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Address != args.Address {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestGetTxCountBlockheightInvalid(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
@@ -1045,6 +1180,26 @@ func TestGetDataArgs(t *testing.T) {
}
}
+func TestGetDataArgsBlocknumMissing(t *testing.T) {
+ input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"]`
+ expected := new(GetDataArgs)
+ expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
+ expected.BlockNumber = -1
+
+ args := new(GetDataArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Address != args.Address {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestGetDataArgsEmpty(t *testing.T) {
input := `[]`
@@ -1995,6 +2150,50 @@ func TestWhisperIdentityArgsInt(t *testing.T) {
}
}
+func TestBlockNumArgs(t *testing.T) {
+ input := `["0x29a"]`
+ expected := new(BlockNumIndexArgs)
+ expected.BlockNumber = 666
+
+ args := new(BlockNumArg)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
+func TestBlockNumArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(BlockNumArg)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockNumArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(BlockNumArg)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+func TestBlockNumArgsBool(t *testing.T) {
+ input := `[true]`
+
+ args := new(BlockNumArg)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestBlockNumIndexArgs(t *testing.T) {
input := `["0x29a", "0x0"]`
expected := new(BlockNumIndexArgs)