aboutsummaryrefslogtreecommitdiffstats
path: root/core/lattice-data_test.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-01-15 16:06:21 +0800
committerGitHub <noreply@github.com>2019-01-15 16:06:21 +0800
commit8e1b6161f346993b74558124758cfb650465cf05 (patch)
treec5b60eae90c3358e6faf43cee9d3ffc3b9945dd1 /core/lattice-data_test.go
parent809e8def862fdfa792061a448f952747f1af4d3c (diff)
downloadtangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar.gz
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar.bz2
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar.lz
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar.xz
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.tar.zst
tangerine-consensus-8e1b6161f346993b74558124758cfb650465cf05.zip
core: Fix BA3.0 (#420)
* Add Restart to Ticker * Change pre allocated size * Return NextTime from lattice * Few hacky fixes for BA * PullVote in FastRollback state * Add shallowBlock for agreementResult * Extend period * Fixup
Diffstat (limited to 'core/lattice-data_test.go')
-rw-r--r--core/lattice-data_test.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/core/lattice-data_test.go b/core/lattice-data_test.go
index 8252361..2e6d684 100644
--- a/core/lattice-data_test.go
+++ b/core/lattice-data_test.go
@@ -193,7 +193,7 @@ func (s *LatticeDataTestSuite) TestSanityCheck() {
)
check := func(expectedErr error, b *types.Block) {
s.hashBlock(b)
- err := data.sanityCheck(b)
+ err := data.sanityCheck(b, false)
req.NotNil(err)
req.IsType(expectedErr, err)
}
@@ -323,7 +323,7 @@ func (s *LatticeDataTestSuite) TestSanityCheck() {
Timestamp: time.Now().UTC().Add(500 * time.Second),
}
s.hashBlock(b11)
- req.NoError(data.sanityCheck(b11))
+ req.NoError(data.sanityCheck(b11, false))
_, err := data.addBlock(b11)
req.NoError(err)
// A block didn't perform round switching.
@@ -340,7 +340,7 @@ func (s *LatticeDataTestSuite) TestSanityCheck() {
// A block with expected new round ID should be OK.
b12.Position.Round = 1
s.hashBlock(b12)
- req.NoError(data.sanityCheck(b12))
+ req.NoError(data.sanityCheck(b12, false))
}
func (s *LatticeDataTestSuite) TestRandomlyGeneratedBlocks() {
@@ -404,7 +404,7 @@ func (s *LatticeDataTestSuite) TestRandomlyGeneratedBlocks() {
req.NoError(err)
revealedHashes = append(revealedHashes, b.Hash)
// Pass blocks to lattice.
- req.NoError(data.sanityCheck(&b))
+ req.NoError(data.sanityCheck(&b, false))
delivered, err = data.addBlock(&b)
req.NoError(err)
for _, b := range delivered {
@@ -550,12 +550,14 @@ func (s *LatticeDataTestSuite) TestPrepareBlock() {
req.Equal(b01.Position.Height, uint64(1))
}
-func (s *LatticeDataTestSuite) TestNextHeight() {
- // Test 'NextHeight' method when lattice is ready.
- data, _ := s.genTestCase1()
- h, err := data.nextHeight(0, 0)
+func (s *LatticeDataTestSuite) TestNextBlock() {
+ // Test 'NextBlock' method when lattice is ready.
+ data, blocks := s.genTestCase1()
+ h, ts, err := data.nextBlock(0, 0)
s.Require().NoError(err)
- s.Require().Equal(h, uint64(4))
+ s.Require().Equal(uint64(4), h)
+ // 2ns of minBlockTime is defined in genTestCase1().
+ s.Require().Equal(blocks[0][3].Timestamp.Add(2*time.Nanosecond), ts)
// Test 'NextHeight' method when lattice is empty.
// Setup a configuration that no restriction on block interval and
// round cutting.
@@ -564,10 +566,12 @@ func (s *LatticeDataTestSuite) TestNextHeight() {
NumChains: 4,
MinBlockInterval: 1 * time.Second,
}
- data = newLatticeData(nil, time.Now().UTC(), 0, genesisConfig)
- h, err = data.nextHeight(0, 0)
+ now := time.Now().UTC()
+ data = newLatticeData(nil, now, 0, genesisConfig)
+ h, ts, err = data.nextBlock(0, 0)
s.Require().NoError(err)
- s.Require().Equal(h, uint64(0))
+ s.Require().Equal(now, ts)
+ s.Require().Equal(uint64(0), h)
}
func (s *LatticeDataTestSuite) TestPrepareEmptyBlock() {
@@ -666,7 +670,7 @@ func (s *LatticeDataTestSuite) TestNumChainsChange() {
req.NoError(err)
s.hashBlock(b)
// Do the actual lattice usage.
- req.NoError(lattice.sanityCheck(b))
+ req.NoError(lattice.sanityCheck(b, false))
d, err := lattice.addBlock(b)
req.NoError(err)
delivered = append(delivered, d...)