mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +00:00
This commit is contained in:
parent
0c306686bb
commit
f5d921bad2
1 changed files with 43 additions and 22 deletions
|
|
@ -106,27 +106,33 @@ func TestWaitDeployed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWaitDeployedCornerCases(t *testing.T) {
|
func TestWaitDeployedCornerCases(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
config := *params.TestXDPoSMockChainConfig
|
config := *params.TestXDPoSMockChainConfig
|
||||||
config.Eip1559Block = big.NewInt(0)
|
config.Eip1559Block = big.NewInt(0)
|
||||||
backend := backends.NewXDCSimulatedBackend(
|
var (
|
||||||
types.GenesisAlloc{
|
backend = backends.NewXDCSimulatedBackend(
|
||||||
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(100000000000000000)},
|
types.GenesisAlloc{
|
||||||
},
|
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(100000000000000000)},
|
||||||
10000000,
|
},
|
||||||
&config,
|
10000000,
|
||||||
|
&config,
|
||||||
|
)
|
||||||
|
head, _ = backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
||||||
|
gasPrice = new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
||||||
|
signer = types.LatestSigner(&config)
|
||||||
|
code = common.FromHex("6060604052600a8060106000396000f360606040526008565b00")
|
||||||
|
ctx, cancel = context.WithCancel(t.Context())
|
||||||
)
|
)
|
||||||
defer backend.Close()
|
defer backend.Close()
|
||||||
|
|
||||||
head, _ := backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
|
// 1. WaitDeploy on a transaction that does not deploy a contract, verify it
|
||||||
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
|
// returns an error.
|
||||||
|
tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{
|
||||||
// Create a transaction to an account.
|
Nonce: 0,
|
||||||
code := "6060604052600a8060106000396000f360606040526008565b00"
|
To: &common.Address{0x01},
|
||||||
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
|
Gas: 300000,
|
||||||
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
|
GasPrice: gasPrice,
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
Data: code,
|
||||||
defer cancel()
|
})
|
||||||
if err := backend.SendTransaction(ctx, tx); err != nil {
|
if err := backend.SendTransaction(ctx, tx); err != nil {
|
||||||
t.Errorf("failed to send transaction: %q", err)
|
t.Errorf("failed to send transaction: %q", err)
|
||||||
}
|
}
|
||||||
|
|
@ -135,14 +141,22 @@ func TestWaitDeployedCornerCases(t *testing.T) {
|
||||||
t.Errorf("error mismatch: want %q, got %q, ", bind.ErrNoAddressInReceipt, err)
|
t.Errorf("error mismatch: want %q, got %q, ", bind.ErrNoAddressInReceipt, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a transaction that is not mined.
|
// 2. Create a contract, but cancel the WaitDeploy before it is mined.
|
||||||
tx = types.NewContractCreation(1, big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
|
tx = types.MustSignNewTx(testKey, signer, &types.LegacyTx{
|
||||||
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
|
Nonce: 1,
|
||||||
|
Gas: 300000,
|
||||||
|
GasPrice: gasPrice,
|
||||||
|
Data: code,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Wait in another thread so that we can quickly cancel it after submitting
|
||||||
|
// the transaction.
|
||||||
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
contextCanceled := errors.New("context canceled")
|
defer close(done)
|
||||||
if _, err := bind.WaitDeployed(ctx, backend, tx.Hash()); err.Error() != contextCanceled.Error() {
|
_, err := bind.WaitDeployed(ctx, backend, tx.Hash())
|
||||||
t.Errorf("error mismatch: want %q, got %q, ", contextCanceled, err)
|
if !errors.Is(err, context.Canceled) {
|
||||||
|
t.Errorf("error mismatch: want %v, got %v", context.Canceled, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -150,4 +164,11 @@ func TestWaitDeployedCornerCases(t *testing.T) {
|
||||||
t.Errorf("failed to send transaction: %q", err)
|
t.Errorf("failed to send transaction: %q", err)
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
|
// Wait for goroutine to exit or for a timeout.
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second * 2):
|
||||||
|
t.Fatalf("failed to cancel wait deploy")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue