From d0c33f5bafdeac62f356fd7ab81fd83cd5710261 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 13 May 2025 14:08:55 +0800 Subject: [PATCH] test(raw_db): add more `L1Origin` tests (#427) --- core/rawdb/taiko_l1_origin.go | 3 ++- core/rawdb/taiko_l1_origin_test.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/rawdb/taiko_l1_origin.go b/core/rawdb/taiko_l1_origin.go index c0cfb52d97..83d6c181e3 100644 --- a/core/rawdb/taiko_l1_origin.go +++ b/core/rawdb/taiko_l1_origin.go @@ -50,8 +50,9 @@ type l1OriginMarshaling struct { } // IsPreconfBlock returns true if the L1Origin is for a preconfirmation block. +// A preconfirmation block is defined as one where the L1BlockHeight is either nil or zero. func (l *L1Origin) IsPreconfBlock() bool { - return l.L1BlockHeight == nil + return l.L1BlockHeight == nil || l.L1BlockHeight.Cmp(common.Big0) == 0 } // WriteL1Origin stores a L1Origin into the database. diff --git a/core/rawdb/taiko_l1_origin_test.go b/core/rawdb/taiko_l1_origin_test.go index dae37a354f..7bffa2f6a9 100644 --- a/core/rawdb/taiko_l1_origin_test.go +++ b/core/rawdb/taiko_l1_origin_test.go @@ -33,10 +33,12 @@ func randomHash() common.Hash { func TestL1Origin(t *testing.T) { db := NewMemoryDatabase() testL1Origin := &L1Origin{ - BlockID: randomBigInt(), - L2BlockHash: randomHash(), - L1BlockHeight: randomBigInt(), - L1BlockHash: randomHash(), + BlockID: randomBigInt(), + L2BlockHash: randomHash(), + // L1BlockHeight is intentionally set to nil to represent a value of zero for legacy behavior. + L1BlockHeight: nil, + L1BlockHash: randomHash(), + BuildPayloadArgsID: [8]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}, } WriteL1Origin(db, testL1Origin.BlockID, testL1Origin) l1Origin, err := ReadL1Origin(db, testL1Origin.BlockID) @@ -44,8 +46,9 @@ func TestL1Origin(t *testing.T) { require.NotNil(t, l1Origin) assert.Equal(t, testL1Origin.BlockID, l1Origin.BlockID) assert.Equal(t, testL1Origin.L2BlockHash, l1Origin.L2BlockHash) - assert.Equal(t, testL1Origin.L1BlockHeight, l1Origin.L1BlockHeight) + assert.True(t, l1Origin.L1BlockHeight.Cmp(common.Big0) == 0) assert.Equal(t, testL1Origin.L1BlockHash, l1Origin.L1BlockHash) + assert.Equal(t, testL1Origin.BuildPayloadArgsID, l1Origin.BuildPayloadArgsID) } func TestHeadL1Origin(t *testing.T) {