@@ -61,10 +61,10 @@ func TestReader(t *testing.T) {
61
61
exp := ABI {
62
62
Methods : map [string ]Method {
63
63
"balance" : {
64
- "balance" , true , nil , nil ,
64
+ "balance" , "balance" , true , nil , nil ,
65
65
},
66
66
"send" : {
67
- "send" , false , []Argument {
67
+ "send" , "send" , false , []Argument {
68
68
{"amount" , Uint256 , false },
69
69
}, nil ,
70
70
},
@@ -162,32 +162,30 @@ func TestTestSlice(t *testing.T) {
162
162
if err != nil {
163
163
t .Fatal (err )
164
164
}
165
-
166
165
slice := make ([]uint64 , 2 )
167
166
if _ , err := abi .Pack ("uint64[2]" , slice ); err != nil {
168
167
t .Error (err )
169
168
}
170
-
171
169
if _ , err := abi .Pack ("uint64[]" , slice ); err != nil {
172
170
t .Error (err )
173
171
}
174
172
}
175
173
176
174
func TestMethodSignature (t * testing.T ) {
177
175
String , _ := NewType ("string" , nil )
178
- m := Method {"foo" , false , []Argument {{"bar" , String , false }, {"baz" , String , false }}, nil }
176
+ m := Method {"foo" , "foo" , false , []Argument {{"bar" , String , false }, {"baz" , String , false }}, nil }
179
177
exp := "foo(string,string)"
180
178
if m .Sig () != exp {
181
179
t .Error ("signature mismatch" , exp , "!=" , m .Sig ())
182
180
}
183
181
184
182
idexp := crypto .Keccak256 ([]byte (exp ))[:4 ]
185
- if ! bytes .Equal (m .Id (), idexp ) {
186
- t .Errorf ("expected ids to match %x != %x" , m .Id (), idexp )
183
+ if ! bytes .Equal (m .ID (), idexp ) {
184
+ t .Errorf ("expected ids to match %x != %x" , m .ID (), idexp )
187
185
}
188
186
189
187
uintt , _ := NewType ("uint256" , nil )
190
- m = Method {"foo" , false , []Argument {{"bar" , uintt , false }}, nil }
188
+ m = Method {"foo" , "foo" , false , []Argument {{"bar" , uintt , false }}, nil }
191
189
exp = "foo(uint256)"
192
190
if m .Sig () != exp {
193
191
t .Error ("signature mismatch" , exp , "!=" , m .Sig ())
@@ -206,13 +204,36 @@ func TestMethodSignature(t *testing.T) {
206
204
{Name : "y" , Type : "int256" },
207
205
}},
208
206
})
209
- m = Method {"foo" , false , []Argument {{"s" , s , false }, {"bar" , String , false }}, nil }
207
+ m = Method {"foo" , "foo" , false , []Argument {{"s" , s , false }, {"bar" , String , false }}, nil }
210
208
exp = "foo((int256,int256[],(int256,int256)[],(int256,int256)[2]),string)"
211
209
if m .Sig () != exp {
212
210
t .Error ("signature mismatch" , exp , "!=" , m .Sig ())
213
211
}
214
212
}
215
213
214
+ func TestOverloadedMethodSignature (t * testing.T ) {
215
+ json := `[{"constant":true,"inputs":[{"name":"i","type":"uint256"},{"name":"j","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"i","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"}],"name":"bar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"},{"indexed":false,"name":"j","type":"uint256"}],"name":"bar","type":"event"}]`
216
+ abi , err := JSON (strings .NewReader (json ))
217
+ if err != nil {
218
+ t .Fatal (err )
219
+ }
220
+ check := func (name string , expect string , method bool ) {
221
+ if method {
222
+ if abi .Methods [name ].Sig () != expect {
223
+ t .Fatalf ("The signature of overloaded method mismatch, want %s, have %s" , expect , abi .Methods [name ].Sig ())
224
+ }
225
+ } else {
226
+ if abi .Events [name ].Sig () != expect {
227
+ t .Fatalf ("The signature of overloaded event mismatch, want %s, have %s" , expect , abi .Events [name ].Sig ())
228
+ }
229
+ }
230
+ }
231
+ check ("foo" , "foo(uint256,uint256)" , true )
232
+ check ("foo0" , "foo(uint256)" , true )
233
+ check ("bar" , "bar(uint256)" , false )
234
+ check ("bar0" , "bar(uint256,uint256)" , false )
235
+ }
236
+
216
237
func TestMultiPack (t * testing.T ) {
217
238
abi , err := JSON (strings .NewReader (jsondata2 ))
218
239
if err != nil {
@@ -900,13 +921,13 @@ func TestABI_MethodById(t *testing.T) {
900
921
}
901
922
for name , m := range abi .Methods {
902
923
a := fmt .Sprintf ("%v" , m )
903
- m2 , err := abi .MethodById (m .Id ())
924
+ m2 , err := abi .MethodById (m .ID ())
904
925
if err != nil {
905
926
t .Fatalf ("Failed to look up ABI method: %v" , err )
906
927
}
907
928
b := fmt .Sprintf ("%v" , m2 )
908
929
if a != b {
909
- t .Errorf ("Method %v (id %v) not 'findable' by id in ABI" , name , common .ToHex (m .Id ()))
930
+ t .Errorf ("Method %v (id %v) not 'findable' by id in ABI" , name , common .ToHex (m .ID ()))
910
931
}
911
932
}
912
933
// Also test empty
@@ -974,8 +995,8 @@ func TestABI_EventById(t *testing.T) {
974
995
t .Errorf ("We should find a event for topic %s, test #%d" , topicID .Hex (), testnum )
975
996
}
976
997
977
- if event .Id () != topicID {
978
- t .Errorf ("Event id %s does not match topic %s, test #%d" , event .Id ().Hex (), topicID .Hex (), testnum )
998
+ if event .ID () != topicID {
999
+ t .Errorf ("Event id %s does not match topic %s, test #%d" , event .ID ().Hex (), topicID .Hex (), testnum )
979
1000
}
980
1001
981
1002
unknowntopicID := crypto .Keccak256Hash ([]byte ("unknownEvent" ))
0 commit comments