aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/abi_test.go
diff options
context:
space:
mode:
authorbas-vk <bas-vk@users.noreply.github.com>2016-12-22 08:51:20 +0800
committerFelix Lange <fjl@users.noreply.github.com>2016-12-22 08:51:20 +0800
commit6d15d00ac4b5f162737a27dfa6f8e9976383776e (patch)
tree59fd8d8ae13451b7e830b79e84fb0083e150c3d2 /accounts/abi/abi_test.go
parentbdaa43510b294bf49bbac1392d5518611c06eedc (diff)
downloadgo-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar.gz
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar.bz2
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar.lz
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar.xz
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.tar.zst
go-tangerine-6d15d00ac4b5f162737a27dfa6f8e9976383776e.zip
accounts/abi: add support for "anonymous" and "indexed" for events (#3464)
Diffstat (limited to 'accounts/abi/abi_test.go')
-rw-r--r--accounts/abi/abi_test.go53
1 files changed, 44 insertions, 9 deletions
diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go
index 85e25f9ea..99c46df0d 100644
--- a/accounts/abi/abi_test.go
+++ b/accounts/abi/abi_test.go
@@ -752,23 +752,58 @@ func TestDefaultFunctionParsing(t *testing.T) {
func TestBareEvents(t *testing.T) {
const definition = `[
{ "type" : "event", "name" : "balance" },
- { "type" : "event", "name" : "name" }]`
+ { "type" : "event", "name" : "anon", "anonymous" : true},
+ { "type" : "event", "name" : "args", "inputs" : [{ "indexed":false, "name":"arg0", "type":"uint256" }, { "indexed":true, "name":"arg1", "type":"address" }] }
+ ]`
+
+ arg0, _ := NewType("uint256")
+ arg1, _ := NewType("address")
+
+ expectedEvents := map[string]struct {
+ Anonymous bool
+ Args []Argument
+ }{
+ "balance": {false, nil},
+ "anon": {true, nil},
+ "args": {false, []Argument{
+ Argument{Name: "arg0", Type: arg0, Indexed: false},
+ Argument{Name: "arg1", Type: arg1, Indexed: true},
+ }},
+ }
abi, err := JSON(strings.NewReader(definition))
if err != nil {
t.Fatal(err)
}
- if len(abi.Events) != 2 {
- t.Error("expected 2 events")
- }
-
- if _, ok := abi.Events["balance"]; !ok {
- t.Error("expected 'balance' event to be present")
+ if len(abi.Events) != len(expectedEvents) {
+ t.Fatalf("invalid number of events after parsing, want %d, got %d", len(expectedEvents), len(abi.Events))
}
- if _, ok := abi.Events["name"]; !ok {
- t.Error("expected 'name' event to be present")
+ for name, exp := range expectedEvents {
+ got, ok := abi.Events[name]
+ if !ok {
+ t.Errorf("could not found event %s", name)
+ continue
+ }
+ if got.Anonymous != exp.Anonymous {
+ t.Errorf("invalid anonymous indication for event %s, want %v, got %v", name, exp.Anonymous, got.Anonymous)
+ }
+ if len(got.Inputs) != len(exp.Args) {
+ t.Errorf("invalid number of args, want %d, got %d", len(exp.Args), len(got.Inputs))
+ continue
+ }
+ for i, arg := range exp.Args {
+ if arg.Name != got.Inputs[i].Name {
+ t.Errorf("events[%s].Input[%d] has an invalid name, want %s, got %s", name, i, arg.Name, got.Inputs[i].Name)
+ }
+ if arg.Indexed != got.Inputs[i].Indexed {
+ t.Errorf("events[%s].Input[%d] has an invalid indexed indication, want %v, got %v", name, i, arg.Indexed, got.Inputs[i].Indexed)
+ }
+ if arg.Type.T != got.Inputs[i].Type.T {
+ t.Errorf("events[%s].Input[%d] has an invalid type, want %x, got %x", name, i, arg.Type.T, got.Inputs[i].Type.T)
+ }
+ }
}
}