@ -832,9 +832,6 @@ func TestUnpackIntoMapNamingConflict(t *testing.T) {
if err = abi . UnpackIntoMap ( receivedMap , "received" , data ) ; err != nil {
t . Error ( "naming conflict between two events; no error expected" )
}
if len ( receivedMap ) != 1 {
t . Error ( "naming conflict between two events; event defined latest in the abi expected to be used" )
}
// Method and event have the same name
abiJSON = ` [ { "constant":false,"inputs":[ { "name":"memo","type":"bytes"}],"name":"received","outputs":[],"payable":true,"stateMutability":"payable","type":"function"}, { "anonymous":false,"inputs":[ { "indexed":false,"name":"sender","type":"address"}, { "indexed":false,"name":"amount","type":"uint256"}, { "indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"}, { "anonymous":false,"inputs":[ { "indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}] `
@ -999,3 +996,45 @@ func TestABI_EventById(t *testing.T) {
}
}
}
func TestDuplicateMethodNames ( t * testing . T ) {
abiJSON := ` [ { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}],"name":"transfer","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}, { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}, { "name":"data","type":"bytes"}],"name":"transfer","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}, { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}, { "name":"data","type":"bytes"}, { "name":"customFallback","type":"string"}],"name":"transfer","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] `
contractAbi , err := JSON ( strings . NewReader ( abiJSON ) )
if err != nil {
t . Fatal ( err )
}
if _ , ok := contractAbi . Methods [ "transfer" ] ; ! ok {
t . Fatalf ( "Could not find original method" )
}
if _ , ok := contractAbi . Methods [ "transfer0" ] ; ! ok {
t . Fatalf ( "Could not find duplicate method" )
}
if _ , ok := contractAbi . Methods [ "transfer1" ] ; ! ok {
t . Fatalf ( "Could not find duplicate method" )
}
if _ , ok := contractAbi . Methods [ "transfer2" ] ; ok {
t . Fatalf ( "Should not have found extra method" )
}
}
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
// conflict and that the second transfer method will be renamed transfer1.
func TestDoubleDuplicateMethodNames ( t * testing . T ) {
abiJSON := ` [ { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}],"name":"transfer","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}, { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}, { "name":"data","type":"bytes"}],"name":"transfer0","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}, { "constant":false,"inputs":[ { "name":"to","type":"address"}, { "name":"value","type":"uint256"}, { "name":"data","type":"bytes"}, { "name":"customFallback","type":"string"}],"name":"transfer","outputs":[ { "name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] `
contractAbi , err := JSON ( strings . NewReader ( abiJSON ) )
if err != nil {
t . Fatal ( err )
}
if _ , ok := contractAbi . Methods [ "transfer" ] ; ! ok {
t . Fatalf ( "Could not find original method" )
}
if _ , ok := contractAbi . Methods [ "transfer0" ] ; ! ok {
t . Fatalf ( "Could not find duplicate method" )
}
if _ , ok := contractAbi . Methods [ "transfer1" ] ; ! ok {
t . Fatalf ( "Could not find duplicate method" )
}
if _ , ok := contractAbi . Methods [ "transfer2" ] ; ok {
t . Fatalf ( "Should not have found extra method" )
}
}