mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +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()
|
defer sim.Close()
|
||||||
// 1.
|
// 1.
|
||||||
parent := sim.blockchain.CurrentBlock()
|
parent := sim.blockchain.CurrentBlock()
|
||||||
|
|
||||||
// 2.
|
// 2.
|
||||||
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
||||||
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
||||||
|
|
||||||
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
||||||
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
tx, err := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
||||||
sim.SendTransaction(context.Background(), tx)
|
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()
|
sim.Commit()
|
||||||
|
|
||||||
// 3.
|
// 3.
|
||||||
receipt, _ := sim.TransactionReceipt(context.Background(), tx.Hash())
|
receipt, _ := sim.TransactionReceipt(context.Background(), tx.Hash())
|
||||||
if h := receipt.BlockNumber.Uint64(); h != 1 {
|
if h := receipt.BlockNumber.Uint64(); h != 1 {
|
||||||
t.Errorf("TX included in wrong block: %d", h)
|
t.Errorf("TX included in wrong block: %d", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4.
|
// 4.
|
||||||
if err := sim.Fork(context.Background(), parent.Hash()); err != nil {
|
if err := sim.Fork(context.Background(), parent.Hash()); err != nil {
|
||||||
t.Errorf("forking: %v", err)
|
t.Errorf("forking: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5.
|
// 5.
|
||||||
sim.Commit()
|
sim.Commit()
|
||||||
if err := sim.SendTransaction(context.Background(), tx); err != nil {
|
if err := sim.SendTransaction(context.Background(), tx); err != nil {
|
||||||
t.Errorf("sending transaction: %v", err)
|
t.Errorf("sending transaction: %v", err)
|
||||||
}
|
}
|
||||||
sim.Commit()
|
sim.Commit()
|
||||||
|
|
||||||
// 6.
|
// 6.
|
||||||
receipt, _ = sim.TransactionReceipt(context.Background(), tx.Hash())
|
receipt, _ = sim.TransactionReceipt(context.Background(), tx.Hash())
|
||||||
if h := receipt.BlockNumber.Uint64(); h != 2 {
|
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))
|
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
||||||
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
|
||||||
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
|
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()
|
h2 := sim.Commit()
|
||||||
|
|
||||||
// Create another block in the original chain
|
// Create another block in the original chain
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,9 @@ func TestWaitDeployed(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Send and mine the transaction.
|
// 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()
|
backend.Commit()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
@ -125,7 +127,9 @@ func TestWaitDeployedCornerCases(t *testing.T) {
|
||||||
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
|
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
backend.SendTransaction(ctx, tx)
|
if err := backend.SendTransaction(ctx, tx); err != nil {
|
||||||
|
t.Errorf("failed to send transaction: %q", err)
|
||||||
|
}
|
||||||
backend.Commit()
|
backend.Commit()
|
||||||
notContractCreation := errors.New("tx is not contract creation")
|
notContractCreation := errors.New("tx is not contract creation")
|
||||||
if _, err := bind.WaitDeployed(ctx, backend, tx); err.Error() != notContractCreation.Error() {
|
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()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue