accounts/abi/bind/base,accounts/abi/bind/bind_test,accounts/abi/bind/template: Removing accessor for Address as it is redundent (address is required even in the generated code), Adding test for new methods, fixing issue with call to .Normalized.Name and not Original.Name and moving GetABI to the combined binding implementation insead of the raw (Note: it might be nice to use generics here to clean up the template and bindings).

This commit is contained in:
ulmentflam 2023-09-11 13:51:32 -04:00
parent 0f65144fc0
commit 9fa47c28fe
No known key found for this signature in database
3 changed files with 45 additions and 11 deletions

View file

@ -149,11 +149,6 @@ func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend Co
return c.address, tx, c, nil
}
// Address returns the contract deployment address.
func (c *BoundContract) Address() common.Address {
return c.address
}
// GetABI returns the contract ABI Object of the BoundContract.
func (c *BoundContract) GetABI() abi.ABI {
return c.abi

View file

@ -2061,6 +2061,45 @@ var bindTests = []struct {
t.Fatalf("combined binding (%v) nil or error (%v) not nil", b, nil)
}
`,
}, {
name: "BindConvenienceMethods",
contract: `
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
contract BindConvenienceMethods {
event Bar(address _bar);
function foo() public {}
}
`,
bytecode: []string{"6080604052348015600f57600080fd5b50606d80601d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c298557814602d575b600080fd5b60336035565b005b56fea2646970667358221220bd57c6759dcde310f52ee8c78b3e0708958ebe0e84df4e9d02acaf3692be89b964736f6c63430008040033"},
abi: []string{"[\n\t{\n\t\t\"anonymous\": false,\n\t\t\"inputs\": [\n\t\t\t{\n\t\t\t\t\"indexed\": false,\n\t\t\t\t\"internalType\": \"address\",\n\t\t\t\t\"name\": \"_bar\",\n\t\t\t\t\"type\": \"address\"\n\t\t\t}\n\t\t],\n\t\t\"name\": \"Bar\",\n\t\t\"type\": \"event\"\n\t},\n\t{\n\t\t\"inputs\": [],\n\t\t\"name\": \"foo\",\n\t\t\"outputs\": [],\n\t\t\"stateMutability\": \"nonpayable\",\n\t\t\"type\": \"function\"\n\t}\n]"},
imports: `
"github.com/ethereum/go-ethereum/common"
`,
tester: `
b, err := NewBindConvenienceMethods(common.Address{}, nil)
if b == nil || err != nil {
t.Fatalf("combined binding (%v) nil or error (%v) not nil", b, err)
}
_, err = b.BarEvent()
if err != nil {
t.Fatalf("binding (%v) failed to get event (%v)", b, err)
}
_, err = b.FooMethod()
if err != nil {
t.Fatalf("binding (%v) failed to get method (%v)", b, err)
}
_, err = b.FooRawCalldata()
if err != nil {
t.Fatalf("binding (%v) failed to get raw calldata (%v)", b, err)
}
_ = b.GetABI() // Validate GetABI()-method exists
`,
},
}

View file

@ -276,8 +276,8 @@ var (
}
// GetABI is a convenience that returns the parsed ABI of the bound contract.
func (_{{$contract.Type}} *{{$contract.Type}}Raw) GetABI() abi.ABI {
return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.GetABI()
func (_{{$contract.Type}} *{{$contract.Type}}) GetABI() abi.ABI {
return _{{$contract.Type}}.{{$contract.Type}}Caller.contract.GetABI()
}
// Call invokes the (constant) contract method with params as input values and
@ -323,7 +323,7 @@ var (
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}Caller) {{.Normalized.Name}}Method() (*abi.Method, error) {
return _{{$contract.Type}}.contract.Method("{{.Normalized.Name}}")
return _{{$contract.Type}}.contract.Method("{{.Original.Name}}")
}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
@ -372,7 +372,7 @@ var (
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}Method() (*abi.Method, error) {
return _{{$contract.Type}}.contract.Method("{{.Normalized.Name}}")
return _{{$contract.Type}}.contract.Method("{{.Original.Name}}")
}
// {{.Normalized.Name}}RawCalldata is the abi packed data binding the contract method 0x{{printf "%x" .Original.ID}}.
@ -525,7 +525,7 @@ var (
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}Filterer) {{.Normalized.Name}}Event() (*abi.Event, error) {
return _{{$contract.Type}}.contract.Event("{{.Normalized.Name}}")
return _{{$contract.Type}}.contract.Event("{{.Original.Name}}")
}
// Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.ID}}.