mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
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:
parent
0f65144fc0
commit
9fa47c28fe
3 changed files with 45 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2060,7 +2060,46 @@ var bindTests = []struct {
|
|||
if b, err := NewNumericMethodName(common.Address{}, nil); b == nil || err != nil {
|
||||
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
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}}.
|
||||
|
|
|
|||
Loading…
Reference in a new issue