FilterStringArgs tests

pull/579/head
Taylor Gerring 10 years ago
parent e21ce9a9b4
commit 62ebf999bf
  1. 4
      rpc/api.go
  2. 9
      rpc/args.go
  3. 40
      rpc/args_test.go

@ -297,10 +297,6 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if err := json.Unmarshal(req.Params, &args); err != nil { if err := json.Unmarshal(req.Params, &args); err != nil {
return err return err
} }
if err := args.requirements(); err != nil {
return err
}
id := api.xeth().NewFilterString(args.Word) id := api.xeth().NewFilterString(args.Word)
*reply = common.ToHex(big.NewInt(int64(id)).Bytes()) *reply = common.ToHex(big.NewInt(int64(id)).Bytes())
case "eth_uninstallFilter": case "eth_uninstallFilter":

@ -649,18 +649,13 @@ func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) {
if !ok { if !ok {
return NewInvalidTypeError("filter", "not a string") return NewInvalidTypeError("filter", "not a string")
} }
args.Word = argstr switch argstr {
return nil
}
func (args *FilterStringArgs) requirements() error {
switch args.Word {
case "latest", "pending": case "latest", "pending":
break break
default: default:
return NewValidationError("Word", "Must be `latest` or `pending`") return NewValidationError("Word", "Must be `latest` or `pending`")
} }
args.Word = argstr
return nil return nil
} }

@ -1106,10 +1106,6 @@ func TestFilterStringArgs(t *testing.T) {
t.Error(err) t.Error(err)
} }
if err := args.requirements(); err != nil {
t.Error(err)
}
if expected.Word != args.Word { if expected.Word != args.Word {
t.Errorf("Word shoud be %#v but is %#v", 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 := `[]` input := `[]`
args := new(FilterStringArgs) args := new(FilterStringArgs)
err := json.Unmarshal([]byte(input), &args) str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
if err == nil { if len(str) > 0 {
t.Error("Expected error but didn't get one") 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)
} }
} }

Loading…
Cancel
Save