aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args_test.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 22:54:54 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 22:54:54 +0800
commit9f84c78eb5cceb5f413fbdeafe63786f1b958e83 (patch)
tree0766de9a36167eff00b7acc831638d7103800a00 /rpc/args_test.go
parent2788fb4ce51be646946c9dd66a607ab26b2bd6b3 (diff)
downloaddexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar.gz
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar.bz2
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar.lz
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar.xz
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.tar.zst
dexon-9f84c78eb5cceb5f413fbdeafe63786f1b958e83.zip
BlockFilterArgs
Diffstat (limited to 'rpc/args_test.go')
-rw-r--r--rpc/args_test.go214
1 files changed, 204 insertions, 10 deletions
diff --git a/rpc/args_test.go b/rpc/args_test.go
index cb1d1904b..602631b67 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -804,14 +804,23 @@ func TestBlockFilterArgs(t *testing.T) {
"limit": "0x3",
"offset": "0x0",
"address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
- "topics": ["0x12341234"]}]`
+ "topics":
+ [
+ ["0xAA", "0xBB"],
+ ["0xCC", "0xDD"]
+ ]
+ }]`
+
expected := new(BlockFilterArgs)
expected.Earliest = 1
expected.Latest = 2
expected.Max = 3
expected.Skip = 0
- expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
- // expected.Topics = []string{"0x12341234"}
+ expected.Address = []string{"0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"}
+ expected.Topics = [][]string{
+ []string{"0xAA", "0xBB"},
+ []string{"0xCC", "0xDD"},
+ }
args := new(BlockFilterArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
@@ -834,17 +843,73 @@ func TestBlockFilterArgs(t *testing.T) {
t.Errorf("Skip shoud be %#v but is %#v", expected.Skip, args.Skip)
}
- if expected.Address != args.Address {
+ if expected.Address[0] != args.Address[0] {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
- // if expected.Topics != args.Topics {
- // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic)
- // }
+ if expected.Topics[0][0] != args.Topics[0][0] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
+ if expected.Topics[0][1] != args.Topics[0][1] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
+ if expected.Topics[1][0] != args.Topics[1][0] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
+ if expected.Topics[1][1] != args.Topics[1][1] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
+
+}
+
+func TestBlockFilterArgsDefaults(t *testing.T) {
+ input := `[{
+ "address": ["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"],
+ "topics": ["0xAA","0xBB"]
+ }]`
+ expected := new(BlockFilterArgs)
+ expected.Earliest = -1
+ expected.Latest = -1
+ expected.Max = 100
+ expected.Skip = 0
+ expected.Address = []string{"0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"}
+ expected.Topics = [][]string{[]string{"0xAA"}, []string{"0xBB"}}
+
+ args := new(BlockFilterArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Earliest != args.Earliest {
+ t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
+ }
+
+ if expected.Latest != args.Latest {
+ t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
+ }
+
+ if expected.Max != args.Max {
+ t.Errorf("Max shoud be %#v but is %#v", expected.Max, args.Max)
+ }
+
+ if expected.Skip != args.Skip {
+ t.Errorf("Skip shoud be %#v but is %#v", expected.Skip, args.Skip)
+ }
+
+ if expected.Address[0] != args.Address[0] {
+ t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
+ }
+
+ if expected.Topics[0][0] != args.Topics[0][0] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
+
+ if expected.Topics[1][0] != args.Topics[1][0] {
+ t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
+ }
}
func TestBlockFilterArgsWords(t *testing.T) {
- t.Skip()
input := `[{
"fromBlock": "latest",
"toBlock": "pending"
@@ -867,10 +932,33 @@ func TestBlockFilterArgsWords(t *testing.T) {
}
}
-func TestBlockFilterArgsBool(t *testing.T) {
+func TestBlockFilterArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(BlockFilterArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsFromBool(t *testing.T) {
input := `[{
"fromBlock": true,
- "toBlock": false
+ "toBlock": "pending"
+ }]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsToBool(t *testing.T) {
+ input := `[{
+ "fromBlock": "pending",
+ "toBlock": true
}]`
args := new(BlockFilterArgs)
@@ -890,6 +978,112 @@ func TestBlockFilterArgsEmptyArgs(t *testing.T) {
}
}
+func TestBlockFilterArgsLimitInvalid(t *testing.T) {
+ input := `[{"limit": false}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsOffsetInvalid(t *testing.T) {
+ input := `[{"offset": true}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsAddressInt(t *testing.T) {
+ input := `[{
+ "address": 1,
+ "topics": "0x12341234"}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsAddressSliceInt(t *testing.T) {
+ input := `[{
+ "address": [1],
+ "topics": "0x12341234"}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsTopicInt(t *testing.T) {
+ input := `[{
+ "address": ["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"],
+ "topics": 1}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsTopicSliceInt(t *testing.T) {
+ input := `[{
+ "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
+ "topics": [1]}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsTopicSliceInt2(t *testing.T) {
+ input := `[{
+ "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
+ "topics": ["0xAA", [1]]}]`
+
+ args := new(BlockFilterArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestBlockFilterArgsTopicComplex(t *testing.T) {
+ input := `[{
+ "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
+ "topics": ["0xAA", ["0xBB", "0xCC"]]
+ }]`
+
+ args := new(BlockFilterArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ fmt.Printf("%v\n", args)
+ return
+ }
+
+ if args.Topics[0][0] != "0xAA" {
+ t.Errorf("Topic should be %s but is %s", "0xAA", args.Topics[0][0])
+ }
+
+ if args.Topics[1][0] != "0xBB" {
+ t.Errorf("Topic should be %s but is %s", "0xBB", args.Topics[0][0])
+ }
+
+ if args.Topics[1][1] != "0xCC" {
+ t.Errorf("Topic should be %s but is %s", "0xCC", args.Topics[0][0])
+ }
+}
+
func TestDbArgs(t *testing.T) {
input := `["testDB","myKey","0xbeef"]`
expected := new(DbArgs)