@@ -87,12 +87,12 @@ func TestEventId(t *testing.T) {
87
87
}{
88
88
{
89
89
definition : `[
90
- { "type" : "event", "name" : "balance ", "inputs": [{ "name" : "in", "type": "uint256" }] },
91
- { "type" : "event", "name" : "check ", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
90
+ { "type" : "event", "name" : "Balance ", "inputs": [{ "name" : "in", "type": "uint256" }] },
91
+ { "type" : "event", "name" : "Check ", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
92
92
]` ,
93
93
expectations : map [string ]common.Hash {
94
- "balance " : crypto .Keccak256Hash ([]byte ("balance (uint256)" )),
95
- "check " : crypto .Keccak256Hash ([]byte ("check (address,uint256)" )),
94
+ "Balance " : crypto .Keccak256Hash ([]byte ("Balance (uint256)" )),
95
+ "Check " : crypto .Keccak256Hash ([]byte ("Check (address,uint256)" )),
96
96
},
97
97
},
98
98
}
@@ -111,6 +111,39 @@ func TestEventId(t *testing.T) {
111
111
}
112
112
}
113
113
114
+ func TestEventString (t * testing.T ) {
115
+ var table = []struct {
116
+ definition string
117
+ expectations map [string ]string
118
+ }{
119
+ {
120
+ definition : `[
121
+ { "type" : "event", "name" : "Balance", "inputs": [{ "name" : "in", "type": "uint256" }] },
122
+ { "type" : "event", "name" : "Check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] },
123
+ { "type" : "event", "name" : "Transfer", "inputs": [{ "name": "from", "type": "address", "indexed": true }, { "name": "to", "type": "address", "indexed": true }, { "name": "value", "type": "uint256" }] }
124
+ ]` ,
125
+ expectations : map [string ]string {
126
+ "Balance" : "event Balance(uint256 in)" ,
127
+ "Check" : "event Check(address t, uint256 b)" ,
128
+ "Transfer" : "event Transfer(address indexed from, address indexed to, uint256 value)" ,
129
+ },
130
+ },
131
+ }
132
+
133
+ for _ , test := range table {
134
+ abi , err := JSON (strings .NewReader (test .definition ))
135
+ if err != nil {
136
+ t .Fatal (err )
137
+ }
138
+
139
+ for name , event := range abi .Events {
140
+ if event .String () != test .expectations [name ] {
141
+ t .Errorf ("expected string to be %s, got %s" , test .expectations [name ], event .String ())
142
+ }
143
+ }
144
+ }
145
+ }
146
+
114
147
// TestEventMultiValueWithArrayUnpack verifies that array fields will be counted after parsing array.
115
148
func TestEventMultiValueWithArrayUnpack (t * testing.T ) {
116
149
definition := `[{"name": "test", "type": "event", "inputs": [{"indexed": false, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`
0 commit comments