aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/args.go17
-rw-r--r--rpc/args_test.go92
2 files changed, 104 insertions, 5 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 5ad971ced..3637aff66 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -590,8 +590,8 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
To string
From string
Topics []string
- Priority string
- Ttl string
+ Priority interface{}
+ Ttl interface{}
}
if err = json.Unmarshal(b, &obj); err != nil {
@@ -605,8 +605,17 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
args.To = obj[0].To
args.From = obj[0].From
args.Topics = obj[0].Topics
- args.Priority = uint32(common.Big(obj[0].Priority).Int64())
- args.Ttl = uint32(common.Big(obj[0].Ttl).Int64())
+
+ var num int64
+ if err := numString(obj[0].Priority, &num); err != nil {
+ return err
+ }
+ args.Priority = uint32(num)
+
+ if err := numString(obj[0].Ttl, &num); err != nil {
+ return err
+ }
+ args.Ttl = uint32(num)
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index f668dfdd4..da98071e9 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -1009,7 +1009,7 @@ func TestWhisperMessageArgs(t *testing.T) {
expected.Payload = "0x68656c6c6f20776f726c64"
expected.Priority = 100
expected.Ttl = 100
- expected.Topics = []string{"0x68656c6c6f20776f726c64"}
+ // expected.Topics = []string{"0x68656c6c6f20776f726c64"}
args := new(WhisperMessageArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
@@ -1041,6 +1041,96 @@ func TestWhisperMessageArgs(t *testing.T) {
// }
}
+func TestWhisperMessageArgsInt(t *testing.T) {
+ input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
+ "topics": ["0x68656c6c6f20776f726c64"],
+ "payload":"0x68656c6c6f20776f726c64",
+ "ttl": 12,
+ "priority": 16}]`
+ expected := new(WhisperMessageArgs)
+ expected.From = "0xc931d93e97ab07fe42d923478ba2465f2"
+ expected.To = ""
+ expected.Payload = "0x68656c6c6f20776f726c64"
+ expected.Priority = 16
+ expected.Ttl = 12
+ // expected.Topics = []string{"0x68656c6c6f20776f726c64"}
+
+ args := new(WhisperMessageArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ 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)
+ }
+
+ if expected.Payload != args.Payload {
+ t.Errorf("Value shoud be %#v but is %#v", expected.Payload, args.Payload)
+ }
+
+ if expected.Ttl != args.Ttl {
+ t.Errorf("Ttl shoud be %v but is %v", expected.Ttl, args.Ttl)
+ }
+
+ if expected.Priority != args.Priority {
+ t.Errorf("Priority shoud be %v but is %v", expected.Priority, args.Priority)
+ }
+
+ // if expected.Topics != args.Topics {
+ // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic)
+ // }
+}
+
+func TestWhisperMessageArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(WhisperMessageArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperMessageArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(WhisperMessageArgs)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperMessageArgsTtlBool(t *testing.T) {
+ input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
+ "topics": ["0x68656c6c6f20776f726c64"],
+ "payload":"0x68656c6c6f20776f726c64",
+ "ttl": true,
+ "priority": "0x64"}]`
+ args := new(WhisperMessageArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestWhisperMessageArgsPriorityBool(t *testing.T) {
+ input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
+ "topics": ["0x68656c6c6f20776f726c64"],
+ "payload":"0x68656c6c6f20776f726c64",
+ "ttl": "0x12",
+ "priority": true}]`
+ args := new(WhisperMessageArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestFilterIdArgs(t *testing.T) {
input := `["0x7"]`
expected := new(FilterIdArgs)