From 93af30a6f6308fe4e59b3a96f65ef535f1855865 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 26 Mar 2015 11:06:45 +0100 Subject: [PATCH] improved GetBlockByHashArgs tests --- rpc/args_test.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/rpc/args_test.go b/rpc/args_test.go index 20930a3d8..b6d592a09 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -100,13 +100,48 @@ func TestGetBlockByHashArgs(t *testing.T) { } } -func TestGetBlockByHashEmpty(t *testing.T) { +func TestGetBlockByHashArgsEmpty(t *testing.T) { input := `[]` args := new(GetBlockByHashArgs) 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 TestGetBlockByHashArgsInvalid(t *testing.T) { + input := `{}` + + args := new(GetBlockByHashArgs) + 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 TestGetBlockByHashArgsHashInt(t *testing.T) { + input := `[8]` + + args := new(GetBlockByHashArgs) + 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()) } }