aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 03:52:09 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 03:52:09 +0800
commit9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8 (patch)
treee15cd955e22f97a2094086c1d98c5e270f65f5f8 /rpc
parent81f36df910533de63dc5ac66f38b5481961cc0c8 (diff)
downloaddexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar.gz
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar.bz2
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar.lz
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar.xz
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.tar.zst
dexon-9ca87afd0ba043043a3d2b4919d72b7f7a39ffe8.zip
WhisperFilterArgs
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go2
-rw-r--r--rpc/args.go24
-rw-r--r--rpc/args_test.go47
3 files changed, 60 insertions, 13 deletions
diff --git a/rpc/api.go b/rpc/api.go
index bde24847f..ad48b8607 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -417,7 +417,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
opts := new(xeth.Options)
- opts.From = args.From
+ // opts.From = args.From
opts.To = args.To
opts.Topics = args.Topics
id := api.xeth().NewWhisperFilter(opts)
diff --git a/rpc/args.go b/rpc/args.go
index 0169ece58..5ad971ced 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -720,9 +720,8 @@ type WhisperFilterArgs struct {
func (args *WhisperFilterArgs) UnmarshalJSON(b []byte) (err error) {
var obj []struct {
- To string
- From string
- Topics []string
+ To interface{}
+ Topics []interface{}
}
if err = json.Unmarshal(b, &obj); err != nil {
@@ -733,9 +732,22 @@ func (args *WhisperFilterArgs) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 1)
}
- args.To = obj[0].To
- args.From = obj[0].From
- args.Topics = obj[0].Topics
+ var argstr string
+ argstr, ok := obj[0].To.(string)
+ if !ok {
+ return NewInvalidTypeError("to", "is not a string")
+ }
+ args.To = argstr
+
+ t := make([]string, len(obj[0].Topics))
+ for i, j := range obj[0].Topics {
+ argstr, ok := j.(string)
+ if !ok {
+ return NewInvalidTypeError("topics["+string(i)+"]", "is not a string")
+ }
+ t[i] = argstr
+ }
+ args.Topics = t
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 7cb63b67e..f668dfdd4 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -1086,10 +1086,9 @@ func TestFilterIdArgsBool(t *testing.T) {
}
}
-func TestWhsiperFilterArgs(t *testing.T) {
+func TestWhisperFilterArgs(t *testing.T) {
input := `[{"topics": ["0x68656c6c6f20776f726c64"], "to": "0x34ag445g3455b34"}]`
expected := new(WhisperFilterArgs)
- expected.From = ""
expected.To = "0x34ag445g3455b34"
expected.Topics = []string{"0x68656c6c6f20776f726c64"}
@@ -1098,10 +1097,6 @@ func TestWhsiperFilterArgs(t *testing.T) {
t.Error(err)
}
- if expected.From != args.From {
- t.Errorf("From shoud be %#v but is %#v", expected.From, args.From)
- }
-
if expected.To != args.To {
t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
}
@@ -1111,6 +1106,46 @@ func TestWhsiperFilterArgs(t *testing.T) {
// }
}
+func TestWhisperFilterArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(WhisperFilterArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperFilterArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(WhisperFilterArgs)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperFilterArgsToBool(t *testing.T) {
+ input := `[{"topics": ["0x68656c6c6f20776f726c64"], "to": false}]`
+
+ args := new(WhisperFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperFilterArgsTopicInt(t *testing.T) {
+ input := `[{"topics": [6], "to": "0x34ag445g3455b34"}]`
+
+ args := new(WhisperFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestCompileArgs(t *testing.T) {
input := `["contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"]`
expected := new(CompileArgs)