From 966e0ff4fe979284626f99e449667b3321010a62 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Feb 2025 18:19:29 +0800 Subject: [PATCH] test(taiko-client): add multi-blobs tests for porposer --- .../taiko-client/internal/testutils/helper.go | 1 + .../internal/testutils/memory_blob_server.go | 2 +- .../taiko-client/proposer/proposer_test.go | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/taiko-client/internal/testutils/helper.go b/packages/taiko-client/internal/testutils/helper.go index c0aa99f366b..54308b4a1f5 100644 --- a/packages/taiko-client/internal/testutils/helper.go +++ b/packages/taiko-client/internal/testutils/helper.go @@ -271,6 +271,7 @@ func SignatureFromRSV(r, s string, v byte) []byte { return append(append(hexutil.MustDecode(r), hexutil.MustDecode(s)...), v) } +// AssembleTestTx assembles a test transaction. func AssembleTestTx( client *rpc.EthClient, priv *ecdsa.PrivateKey, diff --git a/packages/taiko-client/internal/testutils/memory_blob_server.go b/packages/taiko-client/internal/testutils/memory_blob_server.go index 0820400db19..78f94f49030 100644 --- a/packages/taiko-client/internal/testutils/memory_blob_server.go +++ b/packages/taiko-client/internal/testutils/memory_blob_server.go @@ -119,6 +119,7 @@ func NewMemoryBlobServer() *MemoryBlobServer { } w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) if err := json.NewEncoder(w).Encode(&rpc.BlobServerResponse{ Commitment: blobInfo.Commitment, Data: blobInfo.Data, @@ -128,7 +129,6 @@ func NewMemoryBlobServer() *MemoryBlobServer { w.WriteHeader(http.StatusInternalServerError) return } - w.WriteHeader(http.StatusOK) })), } } diff --git a/packages/taiko-client/proposer/proposer_test.go b/packages/taiko-client/proposer/proposer_test.go index ad62c476761..12ddabd9d09 100644 --- a/packages/taiko-client/proposer/proposer_test.go +++ b/packages/taiko-client/proposer/proposer_test.go @@ -358,6 +358,55 @@ func (s *ProposerTestSuite) TestUpdateProposingTicker() { s.NotPanics(s.p.updateProposingTicker) } +func (s *ProposerTestSuite) TestProposeMultiBlobsInOneBatch() { + // Propose valid L2 blocks to make the L2 fork into Pacaya fork. + for i := 0; i < int(s.RPCClient.PacayaClients.ForkHeight); i++ { + s.ProposeAndInsertValidBlock(s.p, s.s) + } + l2Head1, err := s.RPCClient.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + s.NotZero(l2Head1.Number.Uint64()) + + // Propose a batch which contains two blobs. + var ( + batchSize = 2 + txNumInBatch = 500 + txsBatch = make([]types.Transactions, 2) + ) + testAddrNonce, err := s.RPCClient.L2.NonceAt(context.Background(), s.TestAddr, l2Head1.Number) + s.Nil(err) + + for i := 0; i < batchSize; i++ { + for j := 0; j < txNumInBatch; j++ { + to := common.BytesToAddress(testutils.RandomBytes(32)) + + tx, err := testutils.AssembleTestTx( + s.RPCClient.L2, + s.TestAddrPrivKey, + uint64(i*txNumInBatch+int(testAddrNonce)+j), + &to, + common.Big1, + []byte{1}, + ) + s.Nil(err) + txsBatch[i] = append(txsBatch[i], tx) + } + } + + s.Nil(s.p.ProposeTxListPacaya(context.Background(), txsBatch)) + s.Nil(s.s.ProcessL1Blocks(context.Background())) + + l2Head2, err := s.RPCClient.L2.BlockByNumber(context.Background(), nil) + s.Nil(err) + s.Equal(l2Head1.Number.Uint64()+uint64(batchSize), l2Head2.Number().Uint64()) + s.Equal(txNumInBatch+1, l2Head2.Transactions().Len()) + + l2Head3, err := s.RPCClient.L2.BlockByHash(context.Background(), l2Head2.ParentHash()) + s.Nil(err) + s.Equal(l2Head1.Number.Uint64()+uint64(batchSize-1), l2Head3.Number().Uint64()) + s.Equal(txNumInBatch+1, l2Head3.Transactions().Len()) +} + func (s *ProposerTestSuite) TestStartClose() { s.Nil(s.p.Start()) s.cancel()