aboutsummaryrefslogtreecommitdiffstats
path: root/core/compaction-chain_test.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-15 10:33:17 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-10-15 10:33:17 +0800
commitc636088a657b81b2baff6fa5cc72eaaeb2b817e2 (patch)
tree8e20c75cbd749118456c0ade8208b52ae3b401ef /core/compaction-chain_test.go
parent26bea95ae8a63e7bee4983e85d00a6ff6ca82f7c (diff)
downloaddexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar.gz
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar.bz2
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar.lz
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar.xz
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.tar.zst
dexon-consensus-c636088a657b81b2baff6fa5cc72eaaeb2b817e2.zip
core: No randomness for round 0 (#198)
* No randomness for round 0 * Ignore round 0 randomness
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))
}