Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,14 @@ var bindTests = []struct {
`Tupler`,
`
contract Tupler {
function tuple() constant returns (string a, int b, bytes32 c) {
return ("Hi", 1, sha3(""));
function tuple(bool reverts) public view returns (string memory a, int b, bytes32 c) {
require(!reverts, "reverts");
return ("Hi", 1, keccak256(""));
}
}
`,
[]string{`606060405260dc8060106000396000f3606060405260e060020a60003504633175aae28114601a575b005b600060605260c0604052600260809081527f486900000000000000000000000000000000000000000000000000000000000060a05260017fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060e0829052610100819052606060c0908152600261012081905281906101409060a09080838184600060046012f1505081517fffff000000000000000000000000000000000000000000000000000000000000169091525050604051610160819003945092505050f3`},
[]string{`[{"constant":true,"inputs":[],"name":"tuple","outputs":[{"name":"a","type":"string"},{"name":"b","type":"int256"},{"name":"c","type":"bytes32"}],"type":"function"}]`},
[]string{`608060405234801561001057600080fd5b506101f1806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063ea8ca60414610030575b600080fd5b61005e6004803603602081101561004657600080fd5b810190808035151590602001909291905050506100e7565b6040518080602001848152602001838152602001828103825285818151815260200191508051906020019080838360005b838110156100aa57808201518184015260208101905061008f565b50505050905090810190601f1680156100d75780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b60606000808315610160576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260078152602001807f726576657274730000000000000000000000000000000000000000000000000081525060200191505060405180910390fd5b600160405180600001905060405180910390206040518060400160405280600281526020017f48690000000000000000000000000000000000000000000000000000000000008152509190819150925092509250919390925056fea264697066735822122048d43e3751e084a632f01cfb2b6b539e749c343d884f27f1611a8ec758c2dcd464736f6c634300060a0033`},
[]string{`[{"inputs":[{"internalType":"bool","name":"reverts","type":"bool"}],"name":"tuple","outputs":[{"internalType":"string","name":"a","type":"string"},{"internalType":"int256","name":"b","type":"int256"},{"internalType":"bytes32","name":"c","type":"bytes32"}],"stateMutability":"view","type":"function"}]`},
`
"math/big"

Expand All @@ -409,11 +410,15 @@ var bindTests = []struct {
}
sim.Commit()

if res, err := tupler.Tuple(nil); err != nil {
if res, err := tupler.Tuple(nil, false); err != nil {
t.Fatalf("Failed to call structure retriever: %v", err)
} else if res.A != "Hi" || res.B.Cmp(big.NewInt(1)) != 0 {
t.Fatalf("Retrieved value mismatch: have %v/%v, want %v/%v", res.A, res.B, "Hi", 1)
}

if _, err := tupler.Tuple(nil, true); err == nil {
t.Fatal("Expected err calling Tuple with revert")
}
`,
nil,
nil,
Expand Down
6 changes: 5 additions & 1 deletion accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,14 @@ var (
err := _{{$contract.Type}}.contract.Call(opts, &out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
{{if .Structured}}
outstruct := new(struct{ {{range .Normalized.Outputs}} {{.Name}} {{bindtype .Type $structs}}; {{end}} })
if err != nil {
return *outstruct, err
}

{{range $i, $t := .Normalized.Outputs}}
outstruct.{{.Name}} = out[{{$i}}].({{bindtype .Type $structs}}){{end}}

return *outstruct, err
return *outstruct, nil
{{else}}
if err != nil {
return {{range $i, $_ := .Normalized.Outputs}}*new({{bindtype .Type $structs}}), {{end}} err
Expand Down