From 4f4f880c892511eeb0a42b0e139665e58da6115f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Fri, 18 Aug 2023 13:20:20 +0800 Subject: [PATCH] fix test --- miner/worker_test.go | 91 ++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/miner/worker_test.go b/miner/worker_test.go index 183e4e0f2a01..66f3f87a1520 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -1035,47 +1035,54 @@ func TestSkippedL1MessageDatabaseEntries(t *testing.T) { {QueueIndex: 1, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}}, } - l1MessageTest(t, msgs, false, func(_i int, block *types.Block, db ethdb.Database) bool { - // skip #0, include #1 - assert.Equal(1, len(block.Transactions())) - - assert.True(block.Transactions()[0].IsL1MessageTx()) - assert.Equal(uint64(1), block.Transactions()[0].AsL1MessageTx().QueueIndex) - - // db is updated correctly - queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(db, block.Hash()) - assert.NotNil(queueIndex) - - assert.Equal(uint64(2), *queueIndex) - - l1msg := rawdb.ReadL1Message(db, 0) - assert.NotNil(l1msg) - hash := types.NewTx(l1msg).Hash() - - stx := rawdb.ReadSkippedTransaction(db, hash) - assert.NotNil(stx) - assert.True(stx.Tx.IsL1MessageTx()) - assert.Equal(uint64(0), stx.Tx.AsL1MessageTx().QueueIndex) - assert.Equal("gas limit exceeded", stx.Reason) - assert.Equal(block.NumberU64(), stx.BlockNumber) - assert.Nil(stx.BlockHash) - - numSkipped := rawdb.ReadNumSkippedL1Messages(db) - assert.Equal(uint64(1), numSkipped) - - hash2 := rawdb.ReadSkippedL1MessageHash(db, 0) - assert.NotNil(hash2) - assert.Equal(&hash, hash2) - - // iterator API - it := rawdb.IterateSkippedTransactionsFrom(db, 0) - hasMore := it.Next() - assert.True(hasMore) - assert.Equal(uint64(0), it.Index()) - hash3 := it.TransactionHash() - assert.Equal(hash, hash3) - hasMore = it.Next() - assert.False(hasMore) - return true + l1MessageTest(t, msgs, false, func(blockNum int, block *types.Block, db ethdb.Database, w *worker) bool { + switch blockNum { + case 0: + return false + case 1: + // skip #0, include #1 + assert.Equal(1, len(block.Transactions())) + + assert.True(block.Transactions()[0].IsL1MessageTx()) + assert.Equal(uint64(1), block.Transactions()[0].AsL1MessageTx().QueueIndex) + + // db is updated correctly + queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(db, block.Hash()) + assert.NotNil(queueIndex) + + assert.Equal(uint64(2), *queueIndex) + + l1msg := rawdb.ReadL1Message(db, 0) + assert.NotNil(l1msg) + hash := types.NewTx(l1msg).Hash() + + stx := rawdb.ReadSkippedTransaction(db, hash) + assert.NotNil(stx) + assert.True(stx.Tx.IsL1MessageTx()) + assert.Equal(uint64(0), stx.Tx.AsL1MessageTx().QueueIndex) + assert.Equal("gas limit exceeded", stx.Reason) + assert.Equal(block.NumberU64(), stx.BlockNumber) + assert.Nil(stx.BlockHash) + + numSkipped := rawdb.ReadNumSkippedL1Messages(db) + assert.Equal(uint64(1), numSkipped) + + hash2 := rawdb.ReadSkippedL1MessageHash(db, 0) + assert.NotNil(hash2) + assert.Equal(&hash, hash2) + + // iterator API + it := rawdb.IterateSkippedTransactionsFrom(db, 0) + hasMore := it.Next() + assert.True(hasMore) + assert.Equal(uint64(0), it.Index()) + hash3 := it.TransactionHash() + assert.Equal(hash, hash3) + hasMore = it.Next() + assert.False(hasMore) + return true + default: + return true + } }) }