aboutsummaryrefslogtreecommitdiffstats
path: root/core/compaction-chain_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/compaction-chain_test.go')
-rw-r--r--core/compaction-chain_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go
index 3366d5f..f91f1a1 100644
--- a/core/compaction-chain_test.go
+++ b/core/compaction-chain_test.go
@@ -84,6 +84,9 @@ func (s *CompactionChainTestSuite) TestExtractBlocks() {
for idx := range blocks {
blocks[idx] = &types.Block{
Hash: common.NewRandomHash(),
+ Position: types.Position{
+ Round: 1,
+ },
}
s.Require().False(cc.blockRegistered(blocks[idx].Hash))
cc.registerBlock(blocks[idx])
@@ -155,6 +158,40 @@ func (s *CompactionChainTestSuite) TestExtractBlocks() {
}
}
+func (s *CompactionChainTestSuite) TestExtractBlocksRound0() {
+ cc := s.newCompactionChain()
+ blocks := make([]*types.Block, 10)
+ for idx := range blocks {
+ blocks[idx] = &types.Block{
+ Hash: common.NewRandomHash(),
+ Position: types.Position{
+ Round: 0,
+ },
+ }
+ s.Require().False(cc.blockRegistered(blocks[idx].Hash))
+ cc.registerBlock(blocks[idx])
+ s.Require().True(cc.blockRegistered(blocks[idx].Hash))
+ }
+ // Round 0 should be able to be extracted without randomness.
+ for i := 0; i < 3; i++ {
+ s.Require().NoError(cc.processBlock(blocks[i]))
+ }
+ delivered := cc.extractBlocks()
+ s.Require().Len(delivered, 3)
+
+ // Round 0 should be able to be extracted without randomness.
+ for i := 3; i < 10; i++ {
+ s.Require().NoError(cc.processBlock(blocks[i]))
+ }
+ delivered = append(delivered, cc.extractBlocks()...)
+ s.Require().Len(delivered, 10)
+
+ // The delivered order should be the same as processing order.
+ for i, block := range delivered {
+ s.Equal(block.Hash, blocks[i].Hash)
+ }
+}
+
func TestCompactionChain(t *testing.T) {
suite.Run(t, new(CompactionChainTestSuite))
}