aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 03:20:43 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 03:20:43 +0800
commitb414a1303f33aef26b606367ac68163f9b6c87c8 (patch)
tree2d7d9ad091472ef9ccfd44b84f3cfaa752789afd
parent1f1e98f96b57c0c5c7a9350129f67d425a4c6af4 (diff)
downloaddexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar.gz
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar.bz2
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar.lz
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar.xz
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.tar.zst
dexon-b414a1303f33aef26b606367ac68163f9b6c87c8.zip
WhisperIdentityArgs
-rw-r--r--rpc/args.go14
-rw-r--r--rpc/args_test.go30
2 files changed, 40 insertions, 4 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 921d8e98c..c11ffa3cc 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -687,9 +687,8 @@ type WhisperIdentityArgs struct {
}
func (args *WhisperIdentityArgs) 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())
}
@@ -697,7 +696,14 @@ func (args *WhisperIdentityArgs) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 1)
}
- args.Identity = obj[0]
+ argstr, ok := obj[0].(string)
+ if !ok {
+ return NewInvalidTypeError("arg0", "not a string")
+ }
+ // if !common.IsHex(argstr) {
+ // return NewValidationError("arg0", "not a hexstring")
+ // }
+ args.Identity = argstr
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 7bbf729f2..b3df3ba38 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -1196,6 +1196,36 @@ func TestWhisperIdentityArgs(t *testing.T) {
}
}
+func TestWhisperIdentityArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(WhisperIdentityArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
+func TestWhisperIdentityArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(WhisperIdentityArgs)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
+func TestWhisperIdentityArgsInt(t *testing.T) {
+ input := `[4]`
+
+ args := new(WhisperIdentityArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
func TestBlockNumIndexArgs(t *testing.T) {
input := `["0x29a", "0x0"]`
expected := new(BlockNumIndexArgs)