diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-10 17:59:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-10 17:59:17 +0800 |
commit | 4345050093710739c9e417956bc3a8339e7d99a6 (patch) | |
tree | 24fe4e21b95605f8854f6be073a762ece294d479 /core/blockchain_test.go | |
parent | ac3187e706bc11f1b36e32015a6e51a96cc8cfe9 (diff) | |
download | tangerine-consensus-4345050093710739c9e417956bc3a8339e7d99a6.tar.gz tangerine-consensus-4345050093710739c9e417956bc3a8339e7d99a6.tar.zst tangerine-consensus-4345050093710739c9e417956bc3a8339e7d99a6.zip |
core: reduce blockrandomness message (#477)
* core: reduce blockchain randomness msg
* add test
Diffstat (limited to 'core/blockchain_test.go')
-rw-r--r-- | core/blockchain_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 991dc94..46e7630 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -495,6 +495,31 @@ func (s *BlockChainTestSuite) TestAddEmptyBlockDirectly() { s.Require().NotNil(rec.block) } +func (s *BlockChainTestSuite) TestShouldAddRandomness() { + initBlock := s.newRoundOneInitBlock() + bc := s.newBlockChain(initBlock, 10) + blocks := s.newBlocks(2, initBlock) + b0, b1 := blocks[0], blocks[1] + r0 := s.newRandomnessFromBlock(b0) + r1 := s.newRandomnessFromBlock(b1) + + // If a block is extracted, the randomness should not be added. + s.Require().NoError(bc.addBlock(b0)) + s.True(bc.shouldAddRandomness(r0)) + s.Require().NoError(bc.addRandomness(r0)) + s.False(bc.shouldAddRandomness(r0)) + s.Require().Len(bc.extractBlocks(), 1) + s.Require().Equal(b0.Hash, bc.lastDelivered.Hash) + + // If a block has already have randomness, it should not be added. + s.True(bc.shouldAddRandomness(r1)) + s.Require().NoError(bc.addRandomness(r1)) + s.Require().Len(bc.pendingRandomnesses, 1) + s.False(bc.shouldAddRandomness(r1)) + s.Require().NoError(bc.addBlock(b1)) + s.False(bc.shouldAddRandomness(r1)) +} + func TestBlockChain(t *testing.T) { suite.Run(t, new(BlockChainTestSuite)) } |