diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-12 00:40:29 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-08-12 00:40:29 +0800 |
commit | a57a1c2392f6f150d2127cc28236ca74f338dd7e (patch) | |
tree | 1d295e5d43688b3346504068b2f0038faf574dd1 /core/consensus_test.go | |
parent | 08c208c21f93d55bf3275610cbaf3ee6a545956a (diff) | |
download | dexon-consensus-a57a1c2392f6f150d2127cc28236ca74f338dd7e.tar.gz dexon-consensus-a57a1c2392f6f150d2127cc28236ca74f338dd7e.tar.zst dexon-consensus-a57a1c2392f6f150d2127cc28236ca74f338dd7e.zip |
core: Hash block in Consensus.PrepareBlock. (#46)
* Add hash to block
* Check block hash in Consensus.sanityCheck
* Add hashBlockFn in block generator.go
Diffstat (limited to 'core/consensus_test.go')
-rw-r--r-- | core/consensus_test.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/consensus_test.go b/core/consensus_test.go index 84542fd..c26e7e8 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -37,11 +37,9 @@ func (s *ConsensusTestSuite) prepareGenesisBlock( proposerID types.ValidatorID, gov Governance) *types.Block { - hash := common.NewRandomHash() block := &types.Block{ ProposerID: proposerID, ParentHash: common.Hash{}, - Hash: hash, Height: 0, Acks: make(map[common.Hash]struct{}), Timestamps: make(map[types.ValidatorID]time.Time), @@ -50,6 +48,9 @@ func (s *ConsensusTestSuite) prepareGenesisBlock( block.Timestamps[vID] = time.Time{} } block.Timestamps[proposerID] = time.Now().UTC() + var err error + block.Hash, err = hashBlock(block) + s.Require().Nil(err) return block } @@ -121,8 +122,10 @@ func (s *ConsensusTestSuite) TestSimpleDeliverBlock() { time.Sleep(minInterval) b11 := &types.Block{ ProposerID: validators[1], - Hash: common.NewRandomHash(), } + var err error + b11.Hash, err = hashBlock(b11) + s.Require().Nil(err) req.Nil(objs[validators[1]].con.PrepareBlock(b11, time.Now().UTC())) req.Len(b11.Acks, 4) req.Contains(b11.Acks, b00.Hash) @@ -280,8 +283,10 @@ func (s *ConsensusTestSuite) TestPrepareBlock() { req.Nil(con.ProcessBlock(b30)) b11 := &types.Block{ ProposerID: validators[1], - Hash: common.NewRandomHash(), } + var err error + b11.Hash, err = hashBlock(b11) + s.Require().Nil(err) // Sleep to make sure 'now' is slower than b10's timestamp. time.Sleep(100 * time.Millisecond) req.Nil(con.PrepareBlock(b11, time.Now().UTC())) @@ -293,8 +298,9 @@ func (s *ConsensusTestSuite) TestPrepareBlock() { req.Nil(con.ProcessBlock(b11)) b12 := &types.Block{ ProposerID: validators[1], - Hash: common.NewRandomHash(), } + b12.Hash, err = hashBlock(b12) + s.Require().Nil(err) req.Nil(con.PrepareBlock(b12, time.Now().UTC())) req.Len(b12.Acks, 1) req.Contains(b12.Acks, b11.Hash) |