accounts/abi: enable struct golang binding generation (#18491)
* accounts/abi, cmd/abigen: support tuple accounts/abi/bind, cmd/abigen: add objc back accounts/abi/bind: use byte[24] as function indicator accounts/abi/bind: resolve struct slice or array accounts/abi/bind: remove sort logic accounts: fix issues in abi * accounts/abi: address comment
This commit is contained in:
committed by
Guillaume Ballet
parent
ca6c8c2af4
commit
5f5de49cd9
@ -23,9 +23,13 @@ import (
|
||||
|
||||
const methoddata = `
|
||||
[
|
||||
{ "type" : "function", "name" : "balance", "constant" : true },
|
||||
{ "type" : "function", "name" : "send", "constant" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
|
||||
{ "type" : "function", "name" : "transfer", "constant" : false, "inputs" : [ { "name" : "from", "type" : "address" }, { "name" : "to", "type" : "address" }, { "name" : "value", "type" : "uint256" } ], "outputs" : [ { "name" : "success", "type" : "bool" } ] }
|
||||
{"type": "function", "name": "balance", "constant": true },
|
||||
{"type": "function", "name": "send", "constant": false, "inputs": [{ "name": "amount", "type": "uint256" }]},
|
||||
{"type": "function", "name": "transfer", "constant": false, "inputs": [{"name": "from", "type": "address"}, {"name": "to", "type": "address"}, {"name": "value", "type": "uint256"}], "outputs": [{"name": "success", "type": "bool"}]},
|
||||
{"constant":false,"inputs":[{"components":[{"name":"x","type":"uint256"},{"name":"y","type":"uint256"}],"name":"a","type":"tuple"}],"name":"tuple","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
|
||||
{"constant":false,"inputs":[{"components":[{"name":"x","type":"uint256"},{"name":"y","type":"uint256"}],"name":"a","type":"tuple[]"}],"name":"tupleSlice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
|
||||
{"constant":false,"inputs":[{"components":[{"name":"x","type":"uint256"},{"name":"y","type":"uint256"}],"name":"a","type":"tuple[5]"}],"name":"tupleArray","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},
|
||||
{"constant":false,"inputs":[{"components":[{"name":"x","type":"uint256"},{"name":"y","type":"uint256"}],"name":"a","type":"tuple[5][]"}],"name":"complexTuple","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}
|
||||
]`
|
||||
|
||||
func TestMethodString(t *testing.T) {
|
||||
@ -45,6 +49,22 @@ func TestMethodString(t *testing.T) {
|
||||
method: "transfer",
|
||||
expectation: "function transfer(address from, address to, uint256 value) returns(bool success)",
|
||||
},
|
||||
{
|
||||
method: "tuple",
|
||||
expectation: "function tuple((uint256,uint256) a) returns()",
|
||||
},
|
||||
{
|
||||
method: "tupleArray",
|
||||
expectation: "function tupleArray((uint256,uint256)[5] a) returns()",
|
||||
},
|
||||
{
|
||||
method: "tupleSlice",
|
||||
expectation: "function tupleSlice((uint256,uint256)[] a) returns()",
|
||||
},
|
||||
{
|
||||
method: "complexTuple",
|
||||
expectation: "function complexTuple((uint256,uint256)[5][] a) returns()",
|
||||
},
|
||||
}
|
||||
|
||||
abi, err := JSON(strings.NewReader(methoddata))
|
||||
@ -59,3 +79,50 @@ func TestMethodString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMethodSig(t *testing.T) {
|
||||
var cases = []struct {
|
||||
method string
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
method: "balance",
|
||||
expect: "balance()",
|
||||
},
|
||||
{
|
||||
method: "send",
|
||||
expect: "send(uint256)",
|
||||
},
|
||||
{
|
||||
method: "transfer",
|
||||
expect: "transfer(address,address,uint256)",
|
||||
},
|
||||
{
|
||||
method: "tuple",
|
||||
expect: "tuple((uint256,uint256))",
|
||||
},
|
||||
{
|
||||
method: "tupleArray",
|
||||
expect: "tupleArray((uint256,uint256)[5])",
|
||||
},
|
||||
{
|
||||
method: "tupleSlice",
|
||||
expect: "tupleSlice((uint256,uint256)[])",
|
||||
},
|
||||
{
|
||||
method: "complexTuple",
|
||||
expect: "complexTuple((uint256,uint256)[5][])",
|
||||
},
|
||||
}
|
||||
abi, err := JSON(strings.NewReader(methoddata))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
got := abi.Methods[test.method].Sig()
|
||||
if got != test.expect {
|
||||
t.Errorf("expected string to be %s, got %s", test.expect, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user