aboutsummaryrefslogtreecommitdiffstats
path: root/core/total-ordering_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-08-08 19:32:20 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-08-08 19:32:20 +0800
commit295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785 (patch)
treebdb93aaa638ec890596a18490505a45204dc2cc7 /core/total-ordering_test.go
parenta418ea95c0f5afb50cbb78aedecc68373353d06e (diff)
downloaddexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.gz
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.bz2
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.lz
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.xz
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.zst
dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.zip
core: Add Consensus to replace core.Blocklattice (#35)
* Make Sequencer return slice of blocks. * Fix naming issue The function 'getHeightVecto' would return ackingStatusVector. * Fix comment error. * Add methods to collect info when proposing blocks. * Add test.App * Add test.Gov * Move this type to core.types to avoid cyclic import. * Add core.Consensus * Move getMedianTime, interpoTime to util These functions are not depending on members of core.consensusTimestamp and is required when testing core.Consensus. * Make sure types.Block.Clone would copy critical fields. * Remove core.blocklattice * Define 'infinity' in core/total-ordering This definition is defined in core/blocklattice originally. * Fix a bug when processing the same block twice. * Integrate simulation with core.Consensus core.Consensus is a replacement of core.Blocklattice * Fix the comment to use sigular form. * Move lock mechanism to sub modules. * phi should be 2*fmax+1 * Fixup: should aborting when the validator is added * Fix for new block fields * Fix the bug that the total ordering sequence is wrong.
Diffstat (limited to 'core/total-ordering_test.go')
-rw-r--r--core/total-ordering_test.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/core/total-ordering_test.go b/core/total-ordering_test.go
index 11e253a..b4fe13c 100644
--- a/core/total-ordering_test.go
+++ b/core/total-ordering_test.go
@@ -59,12 +59,19 @@ func (s *TotalOrderingTestSuite) genRootBlock(
}
func (s *TotalOrderingTestSuite) checkNotDeliver(to *totalOrdering, b *types.Block) {
- hashes, eqrly, err := to.processBlock(b)
- s.Empty(hashes)
+ blocks, eqrly, err := to.processBlock(b)
+ s.Empty(blocks)
s.False(eqrly)
s.Nil(err)
}
+func (s *TotalOrderingTestSuite) checkHashSequence(blocks []*types.Block, hashes common.Hashes) {
+ sort.Sort(hashes)
+ for i, h := range hashes {
+ s.Equal(blocks[i].Hash, h)
+ }
+}
+
func (s *TotalOrderingTestSuite) checkNotInWorkingSet(
to *totalOrdering, b *types.Block) {
@@ -407,11 +414,11 @@ func (s *TotalOrderingTestSuite) TestEarlyDeliver() {
s.Equal(vec[validators[3]].minHeight, b30.Height)
s.Equal(vec[validators[3]].count, uint64(2))
- hashes, early, err := to.processBlock(b32)
- s.Require().Len(hashes, 1)
+ blocks, early, err := to.processBlock(b32)
+ s.Require().Len(blocks, 1)
s.True(early)
s.Nil(err)
- s.Equal(hashes[0], b00.Hash)
+ s.checkHashSequence(blocks, common.Hashes{b00.Hash})
// Check the internal state after delivered.
s.Len(to.candidateAckingStatusVectors, 4) // b01, b10, b20, b30 are candidates.
@@ -663,12 +670,10 @@ func (s *TotalOrderingTestSuite) TestBasicCaseForK2() {
s.Equal(vec[validators[3]].count, uint64(3))
// Check the first deliver.
- hashes, early, err := to.processBlock(b02)
+ blocks, early, err := to.processBlock(b02)
s.True(early)
s.Nil(err)
- expected := common.Hashes{b00.Hash, b10.Hash}
- sort.Sort(expected)
- s.Equal(hashes, expected)
+ s.checkHashSequence(blocks, common.Hashes{b00.Hash, b10.Hash})
// Make sure b00, b10 are removed from current working set.
s.checkNotInWorkingSet(to, b00)
@@ -706,12 +711,10 @@ func (s *TotalOrderingTestSuite) TestBasicCaseForK2() {
s.checkNotDeliver(to, b13)
// Check the second deliver.
- hashes, early, err = to.processBlock(b03)
+ blocks, early, err = to.processBlock(b03)
s.True(early)
s.Nil(err)
- expected = common.Hashes{b11.Hash, b20.Hash}
- sort.Sort(expected)
- s.Equal(hashes, expected)
+ s.checkHashSequence(blocks, common.Hashes{b11.Hash, b20.Hash})
// Make sure b11, b20 are removed from current working set.
s.checkNotInWorkingSet(to, b11)
@@ -760,12 +763,10 @@ func (s *TotalOrderingTestSuite) TestBasicCaseForK2() {
// Make 'Acking Node Set' contains blocks from all validators,
// this should trigger not-early deliver.
- hashes, early, err = to.processBlock(b23)
+ blocks, early, err = to.processBlock(b23)
s.False(early)
s.Nil(err)
- expected = common.Hashes{b01.Hash, b30.Hash}
- sort.Sort(expected)
- s.Equal(expected, hashes)
+ s.checkHashSequence(blocks, common.Hashes{b01.Hash, b30.Hash})
// Make sure b01, b30 not in working set
s.checkNotInWorkingSet(to, b01)
@@ -874,12 +875,10 @@ func (s *TotalOrderingTestSuite) TestBasicCaseForK0() {
s.Equal(vec[validators[3]].count, uint64(2))
// This new block should trigger non-early deliver.
- hashes, early, err := to.processBlock(b40)
+ blocks, early, err := to.processBlock(b40)
s.False(early)
s.Nil(err)
- expected := common.Hashes{b20.Hash}
- sort.Sort(expected)
- s.Equal(expected, hashes)
+ s.checkHashSequence(blocks, common.Hashes{b20.Hash})
// Make sure b20 is no long existing in working set.
s.checkNotInWorkingSet(to, b20)