aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go4
-rw-r--r--rpc/args.go9
-rw-r--r--rpc/args_test.go40
3 files changed, 35 insertions, 18 deletions
diff --git a/rpc/api.go b/rpc/api.go
index ff166264b..bde24847f 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -297,10 +297,6 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if err := json.Unmarshal(req.Params, &args); err != nil {
return err
}
- if err := args.requirements(); err != nil {
- return err
- }
-
id := api.xeth().NewFilterString(args.Word)
*reply = common.ToHex(big.NewInt(int64(id)).Bytes())
case "eth_uninstallFilter":
diff --git a/rpc/args.go b/rpc/args.go
index 459c6546b..96188d02e 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -649,18 +649,13 @@ func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) {
if !ok {
return NewInvalidTypeError("filter", "not a string")
}
- args.Word = argstr
-
- return nil
-}
-
-func (args *FilterStringArgs) requirements() error {
- switch args.Word {
+ switch argstr {
case "latest", "pending":
break
default:
return NewValidationError("Word", "Must be `latest` or `pending`")
}
+ args.Word = argstr
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 90b283891..9325b1c9b 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -1106,10 +1106,6 @@ func TestFilterStringArgs(t *testing.T) {
t.Error(err)
}
- if err := args.requirements(); err != nil {
- t.Error(err)
- }
-
if expected.Word != args.Word {
t.Errorf("Word shoud be %#v but is %#v", expected.Word, args.Word)
}
@@ -1119,9 +1115,39 @@ func TestFilterStringEmptyArgs(t *testing.T) {
input := `[]`
args := new(FilterStringArgs)
- err := json.Unmarshal([]byte(input), &args)
- if err == nil {
- t.Error("Expected error but didn't get one")
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
+func TestFilterStringInvalidArgs(t *testing.T) {
+ input := `{}`
+
+ args := new(FilterStringArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
+func TestFilterStringWordInt(t *testing.T) {
+ input := `[7]`
+
+ args := new(FilterStringArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
+ }
+}
+
+func TestFilterStringWordWrong(t *testing.T) {
+ input := `["foo"]`
+
+ args := new(FilterStringArgs)
+ str := ExpectValidationError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Errorf(str)
}
}