Commit 84442b17 authored by Jason Yellick's avatar Jason Yellick

op-e2e: make TestBatcherMultiTx more resilient

TestBatcherMultiTx disables the batch submitter at the beginning of the
test, then starts it later to ensure that it catches up and
appropriately submits the transactions.

However, currently it does this by checking the block number before
starting the batcher, then waiting for 3 blocks before checking for the
transactions.  Because there is no synchronization, it's possible that
the block number advances before the batcher starts, which can lead to
the test flaking.

This commit changes the approach to fetching each of the next 10 blocks,
and succeeding once the transactions are found, or failing if none are
found within the next 10 blocks.
parent ad28267b
...@@ -1351,22 +1351,21 @@ func TestBatcherMultiTx(t *testing.T) { ...@@ -1351,22 +1351,21 @@ func TestBatcherMultiTx(t *testing.T) {
err = sys.BatchSubmitter.Start() err = sys.BatchSubmitter.Start()
require.Nil(t, err) require.Nil(t, err)
// wait for 3 L1 blocks
_, err = waitForBlock(big.NewInt(int64(l1Number)+3), l1Client, time.Duration(cfg.DeployConfig.L1BlockTime*5)*time.Second)
require.Nil(t, err, "Waiting for l1 blocks")
// count the number of transactions submitted to L1 in the last 3 blocks
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
totalTxCount := 0 totalTxCount := 0
for i := int64(0); i < 3; i++ { // wait for up to 10 L1 blocks, usually only 3 is required, but it's
block, err := l1Client.BlockByNumber(ctx, big.NewInt(int64(l1Number)+i+1)) // possible additional L1 blocks will be created before the batcher starts,
require.Nil(t, err) // so we wait additional blocks.
for i := int64(0); i < 10; i++ {
block, err := waitForBlock(big.NewInt(int64(l1Number)+i), l1Client, time.Duration(cfg.DeployConfig.L1BlockTime*5)*time.Second)
require.Nil(t, err, "Waiting for l1 blocks")
totalTxCount += len(block.Transactions()) totalTxCount += len(block.Transactions())
if totalTxCount >= 10 {
return
}
} }
// expect at least 10 batcher transactions, given 10 L2 blocks were generated above t.Fatal("Expected at least 10 transactions from the batcher")
require.GreaterOrEqual(t, totalTxCount, 10)
} }
func safeAddBig(a *big.Int, b *big.Int) *big.Int { func safeAddBig(a *big.Int, b *big.Int) *big.Int {
......
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