Skip to content
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mock-gen:
mockery --output test/mocks --srcpkg github.com/cometbft/cometbft/rpc/client --name Client
mockery --output test/mocks --srcpkg github.com/cometbft/cometbft/abci/types --name Application
mockery --output test/mocks --srcpkg github.com/rollkit/go-da --name DA
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/store --name Store
Comment thread
MSevey marked this conversation as resolved.
.PHONY: mock-gen


Expand Down
93 changes: 93 additions & 0 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/store"
test "github.com/rollkit/rollkit/test/log"
"github.com/rollkit/rollkit/test/mocks"
"github.com/rollkit/rollkit/types"
)

Expand Down Expand Up @@ -240,6 +241,20 @@ func TestSubmitBlocksToDA(t *testing.T) {
isErrExpected: true,
expectedPendingBlocksLength: 1,
},
{
name: "B is too big on its own. So A gets submitted but, B and C never get submitted",
blocks: func() []*types.Block {
numBlocks, numTxs := 3, 5
blocks := make([]*types.Block, numBlocks)
blocks[0] = types.GetRandomBlock(uint64(1), numTxs)
blocks[1], err = getBlockBiggerThan(2, maxDABlobSizeLimit)
require.NoError(err)
blocks[2] = types.GetRandomBlock(uint64(3), numTxs)
return blocks
Comment thread
arhamj marked this conversation as resolved.
}(),
isErrExpected: true,
expectedPendingBlocksLength: 2,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -282,6 +297,84 @@ func getTempKVStore(t *testing.T) ds.TxnDatastore {
return kvStore
}

// Test_submitBlocksToDA_BlockMarshalErrorCase1: A itself has a marshalling error. So A, B and C never get submitted.
func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
Comment thread
MSevey marked this conversation as resolved.
assert := assert.New(t)
require := require.New(t)
ctx := context.Background()

m := getManager(t, goDATest.NewDummyDA())

block1 := types.GetRandomBlock(uint64(0), 5)
block2 := types.GetRandomBlock(uint64(1), 5)
block3 := types.GetRandomBlock(uint64(2), 5)

store := mocks.NewStore(t)
invalidateBlockHeader(block1)
store.On("GetMetadata", ctx, LastSubmittedHeightKey).Return(nil, ds.ErrNotFound)
store.On("GetBlock", ctx, uint64(1)).Return(block1, nil)
store.On("GetBlock", ctx, uint64(2)).Return(block2, nil)
store.On("GetBlock", ctx, uint64(3)).Return(block3, nil)
store.On("Height").Return(uint64(3))

m.store = store

var err error
m.pendingBlocks, err = NewPendingBlocks(store, m.logger)
require.NoError(err)

err = m.submitBlocksToDA(ctx)
assert.ErrorContains(err, "failed to submit all blocks to DA layer")
blocks, err := m.pendingBlocks.getPendingBlocks(ctx)
assert.NoError(err)
assert.Equal(3, len(blocks))
}

// Test_submitBlocksToDA_BlockMarshalErrorCase2: A and B are fair blocks, but C has a marshalling error. None of the blocks get submitted to DA layer.
func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ctx := context.Background()

m := getManager(t, goDATest.NewDummyDA())

block1 := types.GetRandomBlock(uint64(0), 5)
block2 := types.GetRandomBlock(uint64(1), 5)
block3 := types.GetRandomBlock(uint64(2), 5)

store := mocks.NewStore(t)
invalidateBlockHeader(block3)
store.On("GetMetadata", ctx, LastSubmittedHeightKey).Return(nil, ds.ErrNotFound)
store.On("GetBlock", ctx, uint64(1)).Return(block1, nil)
store.On("GetBlock", ctx, uint64(2)).Return(block2, nil)
store.On("GetBlock", ctx, uint64(3)).Return(block3, nil)
store.On("Height").Return(uint64(3))

m.store = store

var err error
m.pendingBlocks, err = NewPendingBlocks(store, m.logger)
require.NoError(err)

err = m.submitBlocksToDA(ctx)
assert.ErrorContains(err, "failed to submit all blocks to DA layer")
blocks, err := m.pendingBlocks.getPendingBlocks(ctx)
assert.NoError(err)
assert.Equal(3, len(blocks))
}

// invalidateBlockHeader results in a block header that produces a marshalling error
func invalidateBlockHeader(block *types.Block) {
Comment thread
MSevey marked this conversation as resolved.
for i := range block.SignedHeader.Validators.Validators {
block.SignedHeader.Validators.Validators[i] = &cmtypes.Validator{
Address: []byte(""),
PubKey: nil,
VotingPower: -1,
ProposerPriority: 0,
}
}
}
Comment thread
arhamj marked this conversation as resolved.

func Test_isProposer(t *testing.T) {
require := require.New(t)

Expand Down
Loading