Skip to content

Commit 573fd7b

Browse files
ceyonurmask-pp
authored andcommitted
accounts/abi/bind, ethclient/simulated: 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 750519d commit 573fd7b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

accounts/abi/bind/util_test.go

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

8484
// Send and mine the transaction.
85-
backend.Client().SendTransaction(ctx, tx)
85+
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
86+
t.Errorf("test %q: failed to send transaction: %v", name, err)
87+
}
8688
backend.Commit()
8789

8890
select {
@@ -116,7 +118,9 @@ func TestWaitDeployedCornerCases(t *testing.T) {
116118
tx, _ = types.SignTx(tx, types.LatestSigner(params.AllDevChainProtocolChanges), testKey)
117119
ctx, cancel := context.WithCancel(context.Background())
118120
defer cancel()
119-
backend.Client().SendTransaction(ctx, tx)
121+
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
122+
t.Errorf("failed to send transaction: %q", err)
123+
}
120124
backend.Commit()
121125
notContractCreation := errors.New("tx is not contract creation")
122126
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != notContractCreation.Error() {
@@ -134,6 +138,8 @@ func TestWaitDeployedCornerCases(t *testing.T) {
134138
}
135139
}()
136140

137-
backend.Client().SendTransaction(ctx, tx)
141+
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
142+
t.Errorf("failed to send transaction: %q", err)
143+
}
138144
cancel()
139145
}

ethclient/simulated/backend_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ func TestForkResendTx(t *testing.T) {
213213
if err != nil {
214214
t.Fatalf("could not create transaction: %v", err)
215215
}
216-
client.SendTransaction(ctx, tx)
216+
if err := client.SendTransaction(ctx, tx); err != nil {
217+
t.Fatalf("sending transaction: %v", err)
218+
}
217219
sim.Commit()
218220

219221
// 3.
@@ -256,11 +258,10 @@ func TestCommitReturnValue(t *testing.T) {
256258
}
257259

258260
// Create a block in the original chain (containing a transaction to force different block hashes)
259-
head, _ := client.HeaderByNumber(ctx, nil) // Should be child's, good enough
260-
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
261-
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
262-
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
263-
client.SendTransaction(ctx, tx)
261+
tx, _ := newTx(sim, testKey)
262+
if err := client.SendTransaction(ctx, tx); err != nil {
263+
t.Errorf("sending transaction: %v", err)
264+
}
264265

265266
h2 := sim.Commit()
266267

0 commit comments

Comments
 (0)