From c636088a657b81b2baff6fa5cc72eaaeb2b817e2 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 15 Oct 2018 10:33:17 +0800 Subject: core: No randomness for round 0 (#198) * No randomness for round 0 * Ignore round 0 randomness --- core/compaction-chain_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'core/compaction-chain_test.go') 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)) } -- cgit v1.2.3