From 1f1e98f96b57c0c5c7a9350129f67d425a4c6af4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 26 Mar 2015 20:10:31 +0100 Subject: [PATCH] FilterIdArgs --- rpc/args.go | 11 +++++++---- rpc/args_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index 96188d02eb..921d8e98cc 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -664,9 +664,8 @@ type FilterIdArgs struct { } func (args *FilterIdArgs) UnmarshalJSON(b []byte) (err error) { - var obj []string - r := bytes.NewReader(b) - if err := json.NewDecoder(r).Decode(&obj); err != nil { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { return NewDecodeParamError(err.Error()) } @@ -674,7 +673,11 @@ func (args *FilterIdArgs) UnmarshalJSON(b []byte) (err error) { return NewInsufficientParamsError(len(obj), 1) } - args.Id = int(common.Big(obj[0]).Int64()) + var num int64 + if err := numString(obj[0], &num); err != nil { + return err + } + args.Id = int(num) return nil } diff --git a/rpc/args_test.go b/rpc/args_test.go index 9325b1c9b5..7bbf729f22 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -1056,6 +1056,36 @@ func TestFilterIdArgs(t *testing.T) { } } +func TestFilterIdArgsInvalid(t *testing.T) { + input := `{}` + + args := new(FilterIdArgs) + str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args)) + if len(str) > 0 { + t.Errorf(str) + } +} + +func TestFilterIdArgsEmpty(t *testing.T) { + input := `[]` + + args := new(FilterIdArgs) + str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args)) + if len(str) > 0 { + t.Errorf(str) + } +} + +func TestFilterIdArgsBool(t *testing.T) { + input := `[true]` + + args := new(FilterIdArgs) + str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args)) + if len(str) > 0 { + t.Errorf(str) + } +} + func TestWhsiperFilterArgs(t *testing.T) { input := `[{"topics": ["0x68656c6c6f20776f726c64"], "to": "0x34ag445g3455b34"}]` expected := new(WhisperFilterArgs)