Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 19, 2024
1 parent c364fbb commit 722da75
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions sequencesender/sequencesender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"testing"

"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sequencesender/txbuilder"
"github.com/0xPolygon/cdk/state"
"github.com/0xPolygon/cdk/state/datastream"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -71,3 +74,44 @@ func TestStreamTx(t *testing.T) {

printBatch(decodedBatch, true, true)
}

func TestAddNewBatchL2Block(t *testing.T) {
logger := log.GetDefaultLogger()
txBuilder := txbuilder.NewTxBuilderBananaZKEVM(logger, nil, nil, bind.TransactOpts{}, 100, nil, nil, nil)
sut := SequenceSender{
logger: logger,
cfg: Config{},
ethTransactions: make(map[common.Hash]*ethTxData),
ethTxData: make(map[common.Hash][]byte),
sequenceData: make(map[uint64]*sequenceData),
validStream: false,
latestStreamBatch: 0,
seqSendingStopped: false,
TxBuilder: txBuilder,
}

l2Block := datastream.L2Block{
Number: 1,
BatchNumber: 1,
L1InfotreeIndex: 1,
}
sut.addNewSequenceBatch(&l2Block)
l2Block = datastream.L2Block{
Number: 2,
BatchNumber: 1,
L1InfotreeIndex: 0,
}
sut.addNewBatchL2Block(&l2Block)
data := sut.sequenceData[sut.wipBatch]
// L1InfotreeIndex 0 is ignored
require.Equal(t, uint32(1), data.batch.L1InfoTreeIndex(), "new block have index=0 and is ignored")

l2Block = datastream.L2Block{
Number: 2,
BatchNumber: 1,
L1InfotreeIndex: 5,
}
sut.addNewBatchL2Block(&l2Block)
data = sut.sequenceData[sut.wipBatch]
require.Equal(t, uint32(5), data.batch.L1InfoTreeIndex(), "new block have index=5 and is set")
}

0 comments on commit 722da75

Please sign in to comment.