aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 02:39:40 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 02:39:40 +0800
commite21ce9a9b48a651a704a92369712c17113d92ad6 (patch)
tree8de7d6fd44e085f87cd173e894f8c3d30138a4de
parentf68ca2b6e6b3dafb9f40f5c73ecca3168eb5a090 (diff)
downloadgo-tangerine-e21ce9a9b48a651a704a92369712c17113d92ad6.tar.gz
go-tangerine-e21ce9a9b48a651a704a92369712c17113d92ad6.tar.zst
go-tangerine-e21ce9a9b48a651a704a92369712c17113d92ad6.zip
DbHexArgs tests
-rw-r--r--rpc/args.go4
-rw-r--r--rpc/args_test.go78
2 files changed, 80 insertions, 2 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 78e60c1f4..459c6546b 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -567,10 +567,10 @@ func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) {
func (a *DbHexArgs) requirements() error {
if len(a.Database) == 0 {
- return NewInvalidTypeError("Database", "cannot be blank")
+ return NewValidationError("Database", "cannot be blank")
}
if len(a.Key) == 0 {
- return NewInvalidTypeError("Key", "cannot be blank")
+ return NewValidationError("Key", "cannot be blank")
}
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index f28bdbbd3..90b283891 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -919,6 +919,84 @@ func TestDbHexArgs(t *testing.T) {
}
}
+func TestDbHexArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(DbHexArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(DbHexArgs)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsDatabaseType(t *testing.T) {
+ input := `[true, "keyval", "valval"]`
+
+ args := new(DbHexArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsKeyType(t *testing.T) {
+ input := `["dbval", 3, "valval"]`
+
+ args := new(DbHexArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsValType(t *testing.T) {
+ input := `["dbval", "keyval", {}]`
+
+ args := new(DbHexArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsDatabaseEmpty(t *testing.T) {
+ input := `["", "keyval", "valval"]`
+
+ args := new(DbHexArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err.Error())
+ }
+
+ str := ExpectValidationError(args.requirements())
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestDbHexArgsKeyEmpty(t *testing.T) {
+ input := `["dbval", "", "valval"]`
+
+ args := new(DbHexArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err.Error())
+ }
+
+ str := ExpectValidationError(args.requirements())
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestWhisperMessageArgs(t *testing.T) {
input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
"topics": ["0x68656c6c6f20776f726c64"],