Skip to content

Commit 326da99

Browse files
committed
wip (just committing so that I can rebase off master to use ethclient.RevertErrorData)
1 parent 3f758c3 commit 326da99

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

accounts/abi/bind/bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func isKeyWord(arg string) bool {
7171
}
7272

7373
func add(val1, val2 int) int {
74-
return val1 + val1
74+
return val1 + val2
7575
}
7676

7777
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant

accounts/abi/bind/v2/internal/solc_errors/bindings.go

Lines changed: 33 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"contracts":{"contract.sol:C":{"abi":[{"inputs":[{"internalType":"uint256","name":"arg1","type":"uint256"},{"internalType":"uint256","name":"arg2","type":"uint256"},{"internalType":"uint256","name":"arg3","type":"uint256"},{"internalType":"bool","name":"arg4","type":"bool"}],"name":"BadThing","type":"error"},{"inputs":[],"name":"Foo","outputs":[],"stateMutability":"pure","type":"function"}],"bin":"6080604052348015600e575f80fd5b506101148061001c5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c8063bfb4ebcf14602a575b5f80fd5b60306032565b005b5f600160025f6040517fbb6a82f1000000000000000000000000000000000000000000000000000000008152600401606c949392919060a3565b60405180910390fd5b5f819050919050565b6085816075565b82525050565b5f8115159050919050565b609d81608b565b82525050565b5f60808201905060b45f830187607e565b60bf6020830186607e565b60ca6040830185607e565b60d560608301846096565b9594505050505056fea26469706673582212205ce065ab1cfe16beba2b766e14009fc67ac66c214872149c889f0589720b870a64736f6c634300081a0033"}},"version":"0.8.26+commit.8a97fa7a.Darwin.appleclang"}
1+
{"contracts":{"contract.sol:C":{"abi":[{"inputs":[{"internalType":"uint256","name":"arg1","type":"uint256"},{"internalType":"uint256","name":"arg2","type":"uint256"},{"internalType":"uint256","name":"arg3","type":"uint256"},{"internalType":"bool","name":"arg4","type":"bool"}],"name":"BadThing","type":"error"},{"inputs":[{"internalType":"uint256","name":"arg1","type":"uint256"},{"internalType":"uint256","name":"arg2","type":"uint256"},{"internalType":"uint256","name":"arg3","type":"uint256"},{"internalType":"uint256","name":"arg4","type":"uint256"}],"name":"BadThing2","type":"error"},{"inputs":[],"name":"Bar","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"Foo","outputs":[],"stateMutability":"pure","type":"function"}],"bin":"6080604052348015600e575f80fd5b506101c58061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063b0a378b014610038578063bfb4ebcf14610042575b5f80fd5b61004061004c565b005b61004a610092565b005b5f6001600260036040517fd233a24f00000000000000000000000000000000000000000000000000000000815260040161008994939291906100ef565b60405180910390fd5b5f600160025f6040517fbb6a82f10000000000000000000000000000000000000000000000000000000081526004016100ce949392919061014c565b60405180910390fd5b5f819050919050565b6100e9816100d7565b82525050565b5f6080820190506101025f8301876100e0565b61010f60208301866100e0565b61011c60408301856100e0565b61012960608301846100e0565b95945050505050565b5f8115159050919050565b61014681610132565b82525050565b5f60808201905061015f5f8301876100e0565b61016c60208301866100e0565b61017960408301856100e0565b610186606083018461013d565b9594505050505056fea26469706673582212203f89da086f6d7e52e75f82a20ebbf7337f166a6dbae309180c8bb95e1a157e6e64736f6c634300081a0033"}},"version":"0.8.26+commit.8a97fa7a.Darwin.appleclang"}

accounts/abi/bind/v2/internal/solc_errors/contract.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.26;
33

44
error BadThing(uint256 arg1, uint256 arg2, uint256 arg3, bool arg4);
5+
error BadThing2(uint256 arg1, uint256 arg2, uint256 arg3, uint256 arg4);
56

67
contract C {
78
function Foo() public pure {
@@ -12,4 +13,12 @@ contract C {
1213
arg4: false
1314
});
1415
}
16+
function Bar() public pure {
17+
revert BadThing2({
18+
arg1: uint256(0),
19+
arg2: uint256(1),
20+
arg3: uint256(2),
21+
arg4: uint256(3)
22+
});
23+
}
1524
}

accounts/abi/bind/v2/lib_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
2626
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/events"
2727
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/nested_libraries"
28+
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/solc_errors"
2829
"github.com/ethereum/go-ethereum/cmd/utils"
2930
"github.com/ethereum/go-ethereum/common"
3031
"github.com/ethereum/go-ethereum/common/compiler"
@@ -263,6 +264,7 @@ func TestDeploymentWithOverrides(t *testing.T) {
263264
t.Fatalf("expected internal call count of 6. got %d.", internalCallCount.Uint64())
264265
}
265266
}
267+
266268
func TestEvents(t *testing.T) {
267269
// test watch/filter logs method on a contract that emits various kinds of events (struct-containing, etc.)
268270
txAuth, backend, err := testSetup()
@@ -373,6 +375,39 @@ done:
373375
}
374376
}
375377

378+
func TestErrors(t *testing.T) {
379+
// test watch/filter logs method on a contract that emits various kinds of events (struct-containing, etc.)
380+
txAuth, backend, err := testSetup()
381+
if err != nil {
382+
t.Fatalf("error setting up testing env: %v", err)
383+
}
384+
385+
deploymentParams := DeploymentParams{
386+
Contracts: []*bind.MetaData{solc_errors.CMetaData},
387+
}
388+
389+
res, err := LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
390+
if err != nil {
391+
t.Fatalf("error deploying contract for testing: %v", err)
392+
}
393+
394+
backend.Commit()
395+
if _, err := bind.WaitDeployed(context.Background(), backend, res.Txs[solc_errors.CMetaData.Pattern]); err != nil {
396+
t.Fatalf("WaitDeployed failed %v", err)
397+
}
398+
399+
var packedInput []byte
400+
opts := &bind.CallOpts{
401+
From: res.Addrs[solc_errors.CMetaData.Pattern],
402+
}
403+
instance := ContractInstance{res.Addrs[solc_errors.CMetaData.Pattern], backend}
404+
_, err := Call[struct{}](&instance, opts, packedInput, func(packed []byte) (*struct{}, error) { return nil, nil })
405+
if err == nil {
406+
t.Fatalf("expected call to fail")
407+
}
408+
409+
}
410+
376411
func TestBindingGeneration(t *testing.T) {
377412
matches, _ := filepath.Glob("internal/*")
378413
var dirs []string

0 commit comments

Comments
 (0)