Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(taiko-client): add multi-blobs tests for proposer #18881

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/taiko-client/internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -128,7 +129,6 @@ func NewMemoryBlobServer() *MemoryBlobServer {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
})),
}
}
Expand Down
49 changes: 49 additions & 0 deletions packages/taiko-client/proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down