Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thegaram committed Aug 18, 2023
1 parent c0e9f03 commit 4f4f880
Showing 1 changed file with 49 additions and 42 deletions.
91 changes: 49 additions & 42 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}

0 comments on commit 4f4f880

Please sign in to comment.