test(raw_db): add more L1Origin tests (#427)

This commit is contained in:
David 2025-05-13 14:08:55 +08:00 committed by GitHub
parent 187f85d772
commit d0c33f5baf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View file

@ -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.

View file

@ -35,8 +35,10 @@ func TestL1Origin(t *testing.T) {
testL1Origin := &L1Origin{
BlockID: randomBigInt(),
L2BlockHash: randomHash(),
L1BlockHeight: randomBigInt(),
// 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) {