mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
accounts/abi/bind: check SendTransaction error in tests (#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.
This commit is contained in:
parent
11d3afd849
commit
ced65923db
2 changed files with 25 additions and 7 deletions
|
|
@ -1376,29 +1376,38 @@ func TestForkResendTx(t *testing.T) {
|
|||
defer sim.Close()
|
||||
// 1.
|
||||
parent := sim.blockchain.CurrentBlock()
|
||||
|
||||
// 2.
|
||||
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
||||
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
||||
|
||||
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
||||
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
||||
sim.SendTransaction(context.Background(), tx)
|
||||
tx, err := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
||||
if err != nil {
|
||||
t.Fatalf("could not sign transaction: %v", err)
|
||||
}
|
||||
if err = sim.SendTransaction(context.Background(), tx); err != nil {
|
||||
t.Fatalf("sending transaction: %v", err)
|
||||
}
|
||||
sim.Commit()
|
||||
|
||||
// 3.
|
||||
receipt, _ := sim.TransactionReceipt(context.Background(), tx.Hash())
|
||||
if h := receipt.BlockNumber.Uint64(); h != 1 {
|
||||
t.Errorf("TX included in wrong block: %d", h)
|
||||
}
|
||||
|
||||
// 4.
|
||||
if err := sim.Fork(context.Background(), parent.Hash()); err != nil {
|
||||
t.Errorf("forking: %v", err)
|
||||
}
|
||||
|
||||
// 5.
|
||||
sim.Commit()
|
||||
if err := sim.SendTransaction(context.Background(), tx); err != nil {
|
||||
t.Errorf("sending transaction: %v", err)
|
||||
}
|
||||
sim.Commit()
|
||||
|
||||
// 6.
|
||||
receipt, _ = sim.TransactionReceipt(context.Background(), tx.Hash())
|
||||
if h := receipt.BlockNumber.Uint64(); h != 2 {
|
||||
|
|
@ -1425,7 +1434,10 @@ func TestCommitReturnValue(t *testing.T) {
|
|||
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
||||
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
||||
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
||||
sim.SendTransaction(context.Background(), tx)
|
||||
if err := sim.SendTransaction(context.Background(), tx); err != nil {
|
||||
t.Errorf("sending transaction: %v", err)
|
||||
}
|
||||
|
||||
h2 := sim.Commit()
|
||||
|
||||
// Create another block in the original chain
|
||||
|
|
|
|||
|
|
@ -86,7 +86,9 @@ func TestWaitDeployed(t *testing.T) {
|
|||
}()
|
||||
|
||||
// Send and mine the transaction.
|
||||
backend.SendTransaction(ctx, tx)
|
||||
if err := backend.SendTransaction(ctx, tx); err != nil {
|
||||
t.Errorf("test %q: failed to send transaction: %v", name, err)
|
||||
}
|
||||
backend.Commit()
|
||||
|
||||
select {
|
||||
|
|
@ -125,7 +127,9 @@ func TestWaitDeployedCornerCases(t *testing.T) {
|
|||
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
backend.SendTransaction(ctx, tx)
|
||||
if err := backend.SendTransaction(ctx, tx); err != nil {
|
||||
t.Errorf("failed to send transaction: %q", err)
|
||||
}
|
||||
backend.Commit()
|
||||
notContractCreation := errors.New("tx is not contract creation")
|
||||
if _, err := bind.WaitDeployed(ctx, backend, tx); err.Error() != notContractCreation.Error() {
|
||||
|
|
@ -143,6 +147,8 @@ func TestWaitDeployedCornerCases(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
backend.SendTransaction(ctx, tx)
|
||||
if err := backend.SendTransaction(ctx, tx); err != nil {
|
||||
t.Errorf("failed to send transaction: %q", err)
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue