aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args_test.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-04-05 00:58:23 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-04-05 00:58:23 +0800
commit5c988c8ea0be0c100f315f15a91d86e28f22125b (patch)
tree5a7219a51de77bd5dcb4b3296899785d041be943 /rpc/args_test.go
parent435378e953212813ec90b639d8d22b1d602447ea (diff)
downloadgo-tangerine-5c988c8ea0be0c100f315f15a91d86e28f22125b.tar.gz
go-tangerine-5c988c8ea0be0c100f315f15a91d86e28f22125b.tar.zst
go-tangerine-5c988c8ea0be0c100f315f15a91d86e28f22125b.zip
Increased test coverage for args
Diffstat (limited to 'rpc/args_test.go')
-rw-r--r--rpc/args_test.go214
1 files changed, 214 insertions, 0 deletions
diff --git a/rpc/args_test.go b/rpc/args_test.go
index b88bab280..050f8e472 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)
@@ -850,6 +935,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 +1020,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 +1145,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 +1195,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 +2165,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)