Skip to content

Commit

Permalink
test(taiko-client): improve tests for blob sync (#18764)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Jan 14, 2025
1 parent 70942ea commit 4df3edc
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions packages/taiko-client/driver/chain_syncer/blob/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import (
"time"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/taiko"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
Expand Down Expand Up @@ -53,6 +56,99 @@ func (s *BlobSyncerTestSuite) SetupTest() {
s.initProposer()
}

func (s *BlobSyncerTestSuite) TestBlobSyncRobustness() {
ctx := context.Background()

meta := s.ProposeAndInsertValidBlock(s.p, s.s)

block, err := s.RPCClient.L2.BlockByNumber(ctx, meta.GetBlockID())
s.Nil(err)

lastVerifiedBlockInfo, err := s.s.rpc.GetLastVerifiedBlock(ctx)
s.Nil(err)

txListBytes, err := rlp.EncodeToBytes(block.Transactions())
s.Nil(err)

parent, err := s.RPCClient.L2ParentByBlockID(context.Background(), meta.GetBlockID())
s.Nil(err)

// Reset l2 chain.
s.Nil(rpc.SetHead(ctx, s.RPCClient.L2, common.Big0))

attributes := &engine.PayloadAttributes{
Timestamp: meta.GetTimestamp(),
Random: meta.GetDifficulty(),
SuggestedFeeRecipient: meta.GetCoinbase(),
Withdrawals: make([]*types.Withdrawal, 0),
BlockMetadata: &engine.BlockMetadata{
Beneficiary: meta.GetCoinbase(),
GasLimit: uint64(meta.GetGasLimit()) + taiko.AnchorGasLimit,
Timestamp: meta.GetTimestamp(),
TxList: txListBytes,
MixHash: meta.GetDifficulty(),
ExtraData: meta.GetExtraData(),
},
BaseFeePerGas: block.BaseFee(),
L1Origin: &rawdb.L1Origin{
BlockID: meta.GetBlockID(),
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
L1BlockHeight: meta.GetRawBlockHeight(),
L1BlockHash: meta.GetRawBlockHash(),
},
}

step0 := func() *engine.ForkChoiceResponse {
fcRes, err := s.RPCClient.L2Engine.ForkchoiceUpdate(
ctx,
&engine.ForkchoiceStateV1{HeadBlockHash: parent.Hash()},
attributes,
)
s.Nil(err)
s.Equal(engine.VALID, fcRes.PayloadStatus.Status)
s.True(true, fcRes.PayloadID != nil)
return fcRes
}

step1 := func(fcRes *engine.ForkChoiceResponse) *engine.ExecutableData {
payload, err := s.RPCClient.L2Engine.GetPayload(ctx, fcRes.PayloadID)
s.Nil(err)
return payload
}

step2 := func(payload *engine.ExecutableData) *engine.ExecutableData {
execStatus, err := s.RPCClient.L2Engine.NewPayload(ctx, payload)
s.Nil(err)
s.Equal(engine.VALID, execStatus.Status)
return payload
}

step3 := func(payload *engine.ExecutableData) {
fcRes, err := s.RPCClient.L2Engine.ForkchoiceUpdate(ctx, &engine.ForkchoiceStateV1{
HeadBlockHash: payload.BlockHash,
SafeBlockHash: lastVerifiedBlockInfo.BlockHash,
FinalizedBlockHash: lastVerifiedBlockInfo.BlockHash,
}, nil)
s.Nil(err)
s.Equal(engine.VALID, fcRes.PayloadStatus.Status)
}

loopSize := 10
for i := 0; i < loopSize; i++ {
step0()
}

for i := 0; i < loopSize; i++ {
step1(step0())
}

for i := 0; i < loopSize; i++ {
step2(step1(step0()))
}

step3(step2(step1(step0())))
}

func (s *BlobSyncerTestSuite) TestProcessL1Blocks() {
s.Nil(s.s.ProcessL1Blocks(context.Background()))
}
Expand Down

0 comments on commit 4df3edc

Please sign in to comment.