Commit bf4989f2 authored by refcell's avatar refcell Committed by GitHub

fix(op-e2e): Dogfood E2E Wait Utilities (#9336)

* fix(op-e2e): wait receipt with status dogfooding

* fix import error

---------
Co-authored-by: default avatarMatthew Slipper <me@matthewslipper.com>
parent 8b873b91
...@@ -176,6 +176,9 @@ func TestSystemE2EDencunAtGenesis(t *testing.T) { ...@@ -176,6 +176,9 @@ func TestSystemE2EDencunAtGenesis(t *testing.T) {
// TestSystemE2EDencunAtGenesis tests if L2 finalizes when blobs are present on L1 // TestSystemE2EDencunAtGenesis tests if L2 finalizes when blobs are present on L1
func TestSystemE2EDencunAtGenesisWithBlobs(t *testing.T) { func TestSystemE2EDencunAtGenesisWithBlobs(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
InitParallel(t) InitParallel(t)
cfg := DefaultSystemConfig(t) cfg := DefaultSystemConfig(t)
...@@ -199,7 +202,7 @@ func TestSystemE2EDencunAtGenesisWithBlobs(t *testing.T) { ...@@ -199,7 +202,7 @@ func TestSystemE2EDencunAtGenesisWithBlobs(t *testing.T) {
err = l1Client.SendTransaction(sendCtx, tx) err = l1Client.SendTransaction(sendCtx, tx)
require.NoError(t, err, "Sending L1 empty blob tx") require.NoError(t, err, "Sending L1 empty blob tx")
// Wait for transaction on L1 // Wait for transaction on L1
blockContainsBlob, err := geth.WaitForTransaction(tx.Hash(), l1Client, 30*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second) blockContainsBlob, err := wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "Waiting for blob tx on L1") require.Nil(t, err, "Waiting for blob tx on L1")
// end sending blob-containing txns on l1 // end sending blob-containing txns on l1
l2Client := sys.Clients["sequencer"] l2Client := sys.Clients["sequencer"]
......
...@@ -33,6 +33,9 @@ import ( ...@@ -33,6 +33,9 @@ import (
// TestGasPriceOracleFeeUpdates checks that the gas price oracle cannot be locked by mis-configuring parameters. // TestGasPriceOracleFeeUpdates checks that the gas price oracle cannot be locked by mis-configuring parameters.
func TestGasPriceOracleFeeUpdates(t *testing.T) { func TestGasPriceOracleFeeUpdates(t *testing.T) {
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
InitParallel(t) InitParallel(t)
// Define our values to set in the GasPriceOracle (we set them high to see if it can lock L2 or stop bindings // Define our values to set in the GasPriceOracle (we set them high to see if it can lock L2 or stop bindings
// from updating the prices once again. // from updating the prices once again.
...@@ -66,14 +69,13 @@ func TestGasPriceOracleFeeUpdates(t *testing.T) { ...@@ -66,14 +69,13 @@ func TestGasPriceOracleFeeUpdates(t *testing.T) {
txTimeoutDuration := 10 * time.Duration(cfg.DeployConfig.L1BlockTime) * time.Second txTimeoutDuration := 10 * time.Duration(cfg.DeployConfig.L1BlockTime) * time.Second
// Update the gas config, wait for it to show up on L2, & verify that it was set as intended // Update the gas config, wait for it to show up on L2, & verify that it was set as intended
opts.Context, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) opts.Context, cancel = context.WithTimeout(ctx, txTimeoutDuration)
tx, err := sysconfig.SetGasConfig(opts, overheadValue, scalarValue) tx, err := sysconfig.SetGasConfig(opts, overheadValue, scalarValue)
cancel() cancel()
require.Nil(t, err, "sending overhead update tx") require.Nil(t, err, "sending overhead update tx")
receipt, err := geth.WaitForTransaction(tx.Hash(), l1Client, txTimeoutDuration) receipt, err := wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "waiting for sysconfig set gas config update tx") require.Nil(t, err, "Waiting for sysconfig set gas config update tx")
require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful, "transaction failed")
_, err = geth.WaitForL1OriginOnL2(sys.RollupConfig, receipt.BlockNumber.Uint64(), l2Seq, txTimeoutDuration) _, err = geth.WaitForL1OriginOnL2(sys.RollupConfig, receipt.BlockNumber.Uint64(), l2Seq, txTimeoutDuration)
require.NoError(t, err, "waiting for L2 block to include the sysconfig update") require.NoError(t, err, "waiting for L2 block to include the sysconfig update")
...@@ -98,9 +100,8 @@ func TestGasPriceOracleFeeUpdates(t *testing.T) { ...@@ -98,9 +100,8 @@ func TestGasPriceOracleFeeUpdates(t *testing.T) {
cancel() cancel()
require.Nil(t, err, "sending overhead update tx") require.Nil(t, err, "sending overhead update tx")
receipt, err = geth.WaitForTransaction(tx.Hash(), l1Client, txTimeoutDuration) receipt, err = wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "waiting for sysconfig set gas config update tx") require.Nil(t, err, "Waiting for sysconfig set gas config update tx")
require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful, "transaction failed")
_, err = geth.WaitForL1OriginOnL2(sys.RollupConfig, receipt.BlockNumber.Uint64(), l2Seq, txTimeoutDuration) _, err = geth.WaitForL1OriginOnL2(sys.RollupConfig, receipt.BlockNumber.Uint64(), l2Seq, txTimeoutDuration)
require.NoError(t, err, "waiting for L2 block to include the sysconfig update") require.NoError(t, err, "waiting for L2 block to include the sysconfig update")
...@@ -394,6 +395,9 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -394,6 +395,9 @@ func TestMixedWithdrawalValidity(t *testing.T) {
for i := 0; i <= 8; i++ { for i := 0; i <= 8; i++ {
i := i // avoid loop var capture i := i // avoid loop var capture
t.Run(fmt.Sprintf("withdrawal test#%d", i+1), func(t *testing.T) { t.Run(fmt.Sprintf("withdrawal test#%d", i+1), func(t *testing.T) {
ctx, bgCancel := context.WithCancel(context.Background())
defer bgCancel()
InitParallel(t) InitParallel(t)
// Create our system configuration, funding all accounts we created for L1/L2, and start it // Create our system configuration, funding all accounts we created for L1/L2, and start it
...@@ -470,15 +474,15 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -470,15 +474,15 @@ func TestMixedWithdrawalValidity(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Obtain the transactor's starting balance on L1. // Obtain the transactor's starting balance on L1.
ctx, cancel := context.WithTimeout(context.Background(), txTimeoutDuration) txCtx, txCancel := context.WithTimeout(context.Background(), txTimeoutDuration)
transactor.ExpectedL1Balance, err = l1Client.BalanceAt(ctx, transactor.Account.L1Opts.From, nil) transactor.ExpectedL1Balance, err = l1Client.BalanceAt(txCtx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the transactor's starting balance on L2. // Obtain the transactor's starting balance on L2.
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) txCtx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
transactor.ExpectedL2Balance, err = l2Verif.BalanceAt(ctx, transactor.Account.L2Opts.From, nil) transactor.ExpectedL2Balance, err = l2Verif.BalanceAt(txCtx, transactor.Account.L2Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Bind to the L2-L1 message passer // Bind to the L2-L1 message passer
...@@ -505,23 +509,20 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -505,23 +509,20 @@ func TestMixedWithdrawalValidity(t *testing.T) {
require.Nil(t, err, "sending initiate withdraw tx") require.Nil(t, err, "sending initiate withdraw tx")
t.Logf("Waiting for tx %s to be in sequencer", tx.Hash().Hex()) t.Logf("Waiting for tx %s to be in sequencer", tx.Hash().Hex())
receiptSeq, err := geth.WaitForTransaction(tx.Hash(), l2Seq, txTimeoutDuration) receiptSeq, err := wait.ForReceiptOK(ctx, l2Seq, tx.Hash())
require.Nil(t, err, "withdrawal initiated on L2 sequencer") require.Nil(t, err, "withdrawal initiated on L2 sequencer")
require.Equal(t, receiptSeq.Status, types.ReceiptStatusSuccessful, "transaction failed")
verifierTip, err := l2Verif.BlockByNumber(context.Background(), nil) verifierTip, err := l2Verif.BlockByNumber(context.Background(), nil)
require.Nil(t, err) require.Nil(t, err)
t.Logf("Waiting for tx %s to be in verifier. Verifier tip is %s:%d. Included in sequencer in block %s:%d", tx.Hash().Hex(), verifierTip.Hash().Hex(), verifierTip.NumberU64(), receiptSeq.BlockHash.Hex(), receiptSeq.BlockNumber) t.Logf("Waiting for tx %s to be in verifier. Verifier tip is %s:%d. Included in sequencer in block %s:%d", tx.Hash().Hex(), verifierTip.Hash().Hex(), verifierTip.NumberU64(), receiptSeq.BlockHash.Hex(), receiptSeq.BlockNumber)
// Wait for the transaction to appear in L2 verifier receipt, err := wait.ForReceiptOK(ctx, l2Verif, tx.Hash())
receipt, err := geth.WaitForTransaction(tx.Hash(), l2Verif, txTimeoutDuration)
require.Nilf(t, err, "withdrawal tx %s not found in verifier. included in block %s:%d", tx.Hash().Hex(), receiptSeq.BlockHash.Hex(), receiptSeq.BlockNumber) require.Nilf(t, err, "withdrawal tx %s not found in verifier. included in block %s:%d", tx.Hash().Hex(), receiptSeq.BlockHash.Hex(), receiptSeq.BlockNumber)
require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful, "transaction failed")
// Obtain the header for the block containing the transaction (used to calculate gas fees) // Obtain the header for the block containing the transaction (used to calculate gas fees)
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) txCtx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
header, err := l2Verif.HeaderByNumber(ctx, receipt.BlockNumber) header, err := l2Verif.HeaderByNumber(txCtx, receipt.BlockNumber)
cancel() txCancel()
require.Nil(t, err) require.Nil(t, err)
// Calculate gas fees for the withdrawal in L2 to later adjust our balance. // Calculate gas fees for the withdrawal in L2 to later adjust our balance.
...@@ -534,15 +535,15 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -534,15 +535,15 @@ func TestMixedWithdrawalValidity(t *testing.T) {
transactor.ExpectedL2Nonce = transactor.ExpectedL2Nonce + 1 transactor.ExpectedL2Nonce = transactor.ExpectedL2Nonce + 1
// Wait for the finalization period, then we can finalize this withdrawal. // Wait for the finalization period, then we can finalize this withdrawal.
ctx, cancel = context.WithTimeout(context.Background(), 40*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second) ctx, withdaralCancel := context.WithTimeout(context.Background(), 40*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second)
require.NotEqual(t, cfg.L1Deployments.L2OutputOracleProxy, common.Address{}) require.NotEqual(t, cfg.L1Deployments.L2OutputOracleProxy, common.Address{})
blockNumber, err := wait.ForOutputRootPublished(ctx, l1Client, cfg.L1Deployments.L2OutputOracleProxy, receipt.BlockNumber) blockNumber, err := wait.ForOutputRootPublished(ctx, l1Client, cfg.L1Deployments.L2OutputOracleProxy, receipt.BlockNumber)
cancel() withdaralCancel()
require.Nil(t, err) require.Nil(t, err)
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
header, err = l2Verif.HeaderByNumber(ctx, new(big.Int).SetUint64(blockNumber)) header, err = l2Verif.HeaderByNumber(ctx, new(big.Int).SetUint64(blockNumber))
cancel() txCancel()
require.Nil(t, err) require.Nil(t, err)
rpcClient, err := rpc.Dial(sys.EthInstances["verifier"].WSEndpoint()) rpcClient, err := rpc.Dial(sys.EthInstances["verifier"].WSEndpoint())
...@@ -639,14 +640,13 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -639,14 +640,13 @@ func TestMixedWithdrawalValidity(t *testing.T) {
} else { } else {
require.NoError(t, err) require.NoError(t, err)
receipt, err = geth.WaitForTransaction(tx.Hash(), l1Client, txTimeoutDuration) receipt, err = wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "finalize withdrawal") require.Nil(t, err, "finalize withdrawal")
require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)
// Verify balance after withdrawal // Verify balance after withdrawal
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
header, err = l1Client.HeaderByNumber(ctx, receipt.BlockNumber) header, err = l1Client.HeaderByNumber(ctx, receipt.BlockNumber)
cancel() txCancel()
require.Nil(t, err) require.Nil(t, err)
// Ensure that withdrawal - gas fees are added to the L1 balance // Ensure that withdrawal - gas fees are added to the L1 balance
...@@ -657,13 +657,12 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -657,13 +657,12 @@ func TestMixedWithdrawalValidity(t *testing.T) {
transactor.ExpectedL1Nonce++ transactor.ExpectedL1Nonce++
// Ensure that our withdrawal was proved successfully // Ensure that our withdrawal was proved successfully
proveReceipt, err := geth.WaitForTransaction(tx.Hash(), l1Client, 3*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second) _, err := wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "prove withdrawal") require.Nil(t, err, "prove withdrawal")
require.Equal(t, types.ReceiptStatusSuccessful, proveReceipt.Status)
// Wait for finalization and then create the Finalized Withdrawal Transaction // Wait for finalization and then create the Finalized Withdrawal Transaction
ctx, cancel = context.WithTimeout(context.Background(), 45*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second) ctx, withdrawalCancel := context.WithTimeout(context.Background(), 45*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second)
defer cancel() defer withdrawalCancel()
err = wait.ForFinalizationPeriod(ctx, l1Client, header.Number, cfg.L1Deployments.L2OutputOracleProxy) err = wait.ForFinalizationPeriod(ctx, l1Client, header.Number, cfg.L1Deployments.L2OutputOracleProxy)
require.Nil(t, err) require.Nil(t, err)
...@@ -678,39 +677,39 @@ func TestMixedWithdrawalValidity(t *testing.T) { ...@@ -678,39 +677,39 @@ func TestMixedWithdrawalValidity(t *testing.T) {
// At the end, assert our account balance/nonce states. // At the end, assert our account balance/nonce states.
// Obtain the L2 sequencer account balance // Obtain the L2 sequencer account balance
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL1Balance, err := l1Client.BalanceAt(ctx, transactor.Account.L1Opts.From, nil) endL1Balance, err := l1Client.BalanceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the L1 account nonce // Obtain the L1 account nonce
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL1Nonce, err := l1Client.NonceAt(ctx, transactor.Account.L1Opts.From, nil) endL1Nonce, err := l1Client.NonceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the L2 sequencer account balance // Obtain the L2 sequencer account balance
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL2SeqBalance, err := l2Seq.BalanceAt(ctx, transactor.Account.L1Opts.From, nil) endL2SeqBalance, err := l2Seq.BalanceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the L2 sequencer account nonce // Obtain the L2 sequencer account nonce
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL2SeqNonce, err := l2Seq.NonceAt(ctx, transactor.Account.L1Opts.From, nil) endL2SeqNonce, err := l2Seq.NonceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the L2 verifier account balance // Obtain the L2 verifier account balance
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL2VerifBalance, err := l2Verif.BalanceAt(ctx, transactor.Account.L1Opts.From, nil) endL2VerifBalance, err := l2Verif.BalanceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// Obtain the L2 verifier account nonce // Obtain the L2 verifier account nonce
ctx, cancel = context.WithTimeout(context.Background(), txTimeoutDuration) ctx, txCancel = context.WithTimeout(context.Background(), txTimeoutDuration)
endL2VerifNonce, err := l2Verif.NonceAt(ctx, transactor.Account.L1Opts.From, nil) endL2VerifNonce, err := l2Verif.NonceAt(ctx, transactor.Account.L1Opts.From, nil)
cancel() txCancel()
require.NoError(t, err) require.NoError(t, err)
// TODO: Check L1 balance as well here. We avoided this due to time constraints as it seems L1 fees // TODO: Check L1 balance as well here. We avoided this due to time constraints as it seems L1 fees
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" "github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
...@@ -42,18 +41,17 @@ func SendDepositTx(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client, l ...@@ -42,18 +41,17 @@ func SendDepositTx(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client, l
require.Nil(t, err, "with deposit tx") require.Nil(t, err, "with deposit tx")
// Wait for transaction on L1 // Wait for transaction on L1
l1Receipt, err := geth.WaitForTransaction(tx.Hash(), l1Client, 10*time.Duration(cfg.DeployConfig.L1BlockTime)*time.Second) ctx, cancel := context.WithCancel(context.Background())
defer cancel()
l1Receipt, err := wait.ForReceiptOK(ctx, l1Client, tx.Hash())
require.Nil(t, err, "Waiting for deposit tx on L1") require.Nil(t, err, "Waiting for deposit tx on L1")
// Wait for transaction to be included on L2 // Wait for transaction to be included on L2
reconstructedDep, err := derive.UnmarshalDepositLogEvent(l1Receipt.Logs[0]) reconstructedDep, err := derive.UnmarshalDepositLogEvent(l1Receipt.Logs[0])
require.NoError(t, err, "Could not reconstruct L2 Deposit") require.NoError(t, err, "Could not reconstruct L2 Deposit")
tx = types.NewTx(reconstructedDep) tx = types.NewTx(reconstructedDep)
// Use a long wait because the l2Client may not be configured to receive gossip from the sequencer l2Receipt, err := wait.ForReceipt(ctx, l2Client, tx.Hash(), l2Opts.ExpectedStatus)
// so has to wait for the batcher to submit and then import those blocks from L1. require.NoError(t, err, "Waiting for deposit tx on L2")
l2Receipt, err := geth.WaitForTransaction(tx.Hash(), l2Client, 60*time.Second)
require.NoError(t, err)
require.Equal(t, l2Opts.ExpectedStatus, l2Receipt.Status, "l2 transaction status")
return l2Receipt return l2Receipt
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment