Skip to content

Commit 1da872b

Browse files
committed
accounts/abi/bind: check SendTransaction error in tests (ethereum#30349)
In few tests the returned error from `SendTransaction` is not being checked. This PR checks the returned err in tests. Returning errors also revealed tx in `TestCommitReturnValue` is not actually being sent, and returns err ` only replay-protected (EIP-155) transactions allowed over RPC`. Fixed the transaction by using the `testTx` function.
1 parent da88de9 commit 1da872b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

accounts/abi/bind/backends/simulated_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,29 +1376,38 @@ func TestForkResendTx(t *testing.T) {
13761376
defer sim.Close()
13771377
// 1.
13781378
parent := sim.blockchain.CurrentBlock()
1379+
13791380
// 2.
13801381
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
13811382
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
1382-
13831383
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
1384-
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
1385-
sim.SendTransaction(context.Background(), tx)
1384+
tx, err := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
1385+
if err != nil {
1386+
t.Fatalf("could not sign transaction: %v", err)
1387+
}
1388+
if err = sim.SendTransaction(context.Background(), tx); err != nil {
1389+
t.Fatalf("sending transaction: %v", err)
1390+
}
13861391
sim.Commit()
1392+
13871393
// 3.
13881394
receipt, _ := sim.TransactionReceipt(context.Background(), tx.Hash())
13891395
if h := receipt.BlockNumber.Uint64(); h != 1 {
13901396
t.Errorf("TX included in wrong block: %d", h)
13911397
}
1398+
13921399
// 4.
13931400
if err := sim.Fork(context.Background(), parent.Hash()); err != nil {
13941401
t.Errorf("forking: %v", err)
13951402
}
1403+
13961404
// 5.
13971405
sim.Commit()
13981406
if err := sim.SendTransaction(context.Background(), tx); err != nil {
13991407
t.Errorf("sending transaction: %v", err)
14001408
}
14011409
sim.Commit()
1410+
14021411
// 6.
14031412
receipt, _ = sim.TransactionReceipt(context.Background(), tx.Hash())
14041413
if h := receipt.BlockNumber.Uint64(); h != 2 {
@@ -1425,7 +1434,10 @@ func TestCommitReturnValue(t *testing.T) {
14251434
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
14261435
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
14271436
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
1428-
sim.SendTransaction(context.Background(), tx)
1437+
if err := sim.SendTransaction(context.Background(), tx); err != nil {
1438+
t.Errorf("sending transaction: %v", err)
1439+
}
1440+
14291441
h2 := sim.Commit()
14301442

14311443
// Create another block in the original chain

accounts/abi/bind/util_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func TestWaitDeployed(t *testing.T) {
8686
}()
8787

8888
// Send and mine the transaction.
89-
backend.SendTransaction(ctx, tx)
89+
if err := backend.SendTransaction(ctx, tx); err != nil {
90+
t.Errorf("test %q: failed to send transaction: %v", name, err)
91+
}
9092
backend.Commit()
9193

9294
select {
@@ -125,7 +127,9 @@ func TestWaitDeployedCornerCases(t *testing.T) {
125127
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
126128
ctx, cancel := context.WithCancel(context.Background())
127129
defer cancel()
128-
backend.SendTransaction(ctx, tx)
130+
if err := backend.SendTransaction(ctx, tx); err != nil {
131+
t.Errorf("failed to send transaction: %q", err)
132+
}
129133
backend.Commit()
130134
notContractCreation := errors.New("tx is not contract creation")
131135
if _, err := bind.WaitDeployed(ctx, backend, tx); err.Error() != notContractCreation.Error() {
@@ -143,6 +147,8 @@ func TestWaitDeployedCornerCases(t *testing.T) {
143147
}
144148
}()
145149

146-
backend.SendTransaction(ctx, tx)
150+
if err := backend.SendTransaction(ctx, tx); err != nil {
151+
t.Errorf("failed to send transaction: %q", err)
152+
}
147153
cancel()
148154
}

0 commit comments

Comments
 (0)