aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args_test.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 18:07:14 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 18:07:14 +0800
commit493e0d7be883bb1acd3b8588b0e3d641ce06c73b (patch)
treec7f54a7bf73d735674d5a7684104cb615a7522bf /rpc/args_test.go
parent93af30a6f6308fe4e59b3a96f65ef535f1855865 (diff)
downloadgo-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar.gz
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar.bz2
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar.lz
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar.xz
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.tar.zst
go-tangerine-493e0d7be883bb1acd3b8588b0e3d641ce06c73b.zip
improved GetBlockByNumber tests
Diffstat (limited to 'rpc/args_test.go')
-rw-r--r--rpc/args_test.go60
1 files changed, 57 insertions, 3 deletions
diff --git a/rpc/args_test.go b/rpc/args_test.go
index b6d592a09..b9a68d8bc 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -145,7 +145,27 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
}
}
-func TestGetBlockByNumberArgs(t *testing.T) {
+func TestGetBlockByNumberArgsBlockNum(t *testing.T) {
+ input := `[436, false]`
+ expected := new(GetBlockByNumberArgs)
+ expected.BlockNumber = 436
+ expected.IncludeTxs = false
+
+ args := new(GetBlockByNumberArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if args.BlockNumber != expected.BlockNumber {
+ t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
+ }
+
+ if args.IncludeTxs != expected.IncludeTxs {
+ t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
+ }
+}
+
+func TestGetBlockByNumberArgsBlockHex(t *testing.T) {
input := `["0x1b4", false]`
expected := new(GetBlockByNumberArgs)
expected.BlockNumber = 436
@@ -157,7 +177,7 @@ func TestGetBlockByNumberArgs(t *testing.T) {
}
if args.BlockNumber != expected.BlockNumber {
- t.Errorf("BlockHash should be %v but is %v", expected.BlockNumber, args.BlockNumber)
+ t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
}
if args.IncludeTxs != expected.IncludeTxs {
@@ -170,8 +190,42 @@ func TestGetBlockByNumberEmpty(t *testing.T) {
args := new(GetBlockByNumberArgs)
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 TestGetBlockByNumberBool(t *testing.T) {
+ input := `[true, true]`
+
+ args := new(GetBlockByNumberArgs)
+ 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 TestGetBlockByNumberBlockObject(t *testing.T) {
+ input := `{}`
+
+ args := new(GetBlockByNumberArgs)
+ 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())
}
}