@@ -71,12 +71,12 @@ func TestEventId(t *testing.T) {
71
71
}{
72
72
{
73
73
definition : `[
74
- { "type" : "event", "name" : "balance ", "inputs": [{ "name" : "in", "type": "uint256" }] },
75
- { "type" : "event", "name" : "check ", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
74
+ { "type" : "event", "name" : "Balance ", "inputs": [{ "name" : "in", "type": "uint256" }] },
75
+ { "type" : "event", "name" : "Check ", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
76
76
]` ,
77
77
expectations : map [string ]common.Hash {
78
- "balance " : crypto .Keccak256Hash ([]byte ("balance (uint256)" )),
79
- "check " : crypto .Keccak256Hash ([]byte ("check (address,uint256)" )),
78
+ "Balance " : crypto .Keccak256Hash ([]byte ("Balance (uint256)" )),
79
+ "Check " : crypto .Keccak256Hash ([]byte ("Check (address,uint256)" )),
80
80
},
81
81
},
82
82
}
@@ -95,6 +95,39 @@ func TestEventId(t *testing.T) {
95
95
}
96
96
}
97
97
98
+ func TestEventString (t * testing.T ) {
99
+ var table = []struct {
100
+ definition string
101
+ expectations map [string ]string
102
+ }{
103
+ {
104
+ definition : `[
105
+ { "type" : "event", "name" : "Balance", "inputs": [{ "name" : "in", "type": "uint256" }] },
106
+ { "type" : "event", "name" : "Check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] },
107
+ { "type" : "event", "name" : "Transfer", "inputs": [{ "name": "from", "type": "address", "indexed": true }, { "name": "to", "type": "address", "indexed": true }, { "name": "value", "type": "uint256" }] }
108
+ ]` ,
109
+ expectations : map [string ]string {
110
+ "Balance" : "event Balance(uint256 in)" ,
111
+ "Check" : "event Check(address t, uint256 b)" ,
112
+ "Transfer" : "event Transfer(address indexed from, address indexed to, uint256 value)" ,
113
+ },
114
+ },
115
+ }
116
+
117
+ for _ , test := range table {
118
+ abi , err := JSON (strings .NewReader (test .definition ))
119
+ if err != nil {
120
+ t .Fatal (err )
121
+ }
122
+
123
+ for name , event := range abi .Events {
124
+ if event .String () != test .expectations [name ] {
125
+ t .Errorf ("expected string to be %s, got %s" , test .expectations [name ], event .String ())
126
+ }
127
+ }
128
+ }
129
+ }
130
+
98
131
// TestEventMultiValueWithArrayUnpack verifies that array fields will be counted after parsing array.
99
132
func TestEventMultiValueWithArrayUnpack (t * testing.T ) {
100
133
definition := `[{"name": "test", "type": "event", "inputs": [{"indexed": false, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`
0 commit comments