aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-09-25 14:10:16 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-09-25 14:10:16 +0800
commit6c8d26d2e797e8420fc3de4b15e4c556f968aba0 (patch)
tree22beecc01da7a9ce5cac36135a89010d6d4ed4f2 /core/test
parentca935bdbac190766f29fb73433a82ee5806bc8f9 (diff)
downloadtangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.gz
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.bz2
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.lz
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.xz
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.tar.zst
tangerine-consensus-6c8d26d2e797e8420fc3de4b15e4c556f968aba0.zip
core: add debug (#133)
* Split interface * Rename nonblocking-application to nonblocking Parts needs nonblocking gets more. * Implement core.nonBlocking based on interface split * Fix: the witness parent hash could be parent on compaction chain. * Rename Application.DeliverBlock to BlockDeliver To sync with naming of other methods. * Change methods' fingerprint - BlockConfirmed provides block hash only. - BlockDeliver provde a whole block.
Diffstat (limited to 'core/test')
-rw-r--r--core/test/app.go12
-rw-r--r--core/test/app_test.go21
-rw-r--r--core/test/stopper_test.go4
3 files changed, 24 insertions, 13 deletions
diff --git a/core/test/app.go b/core/test/app.go
index 617bc38..7a0ad97 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -115,7 +115,7 @@ func (app *App) VerifyPayloads(payloads []byte) bool {
}
// BlockConfirmed implements Application interface.
-func (app *App) BlockConfirmed(block *types.Block) {
+func (app *App) BlockConfirmed(_ common.Hash) {
}
// StronglyAcked implements Application interface.
@@ -145,16 +145,16 @@ func (app *App) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
}
}
-// DeliverBlock implements Application interface.
-func (app *App) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
+// BlockDeliver implements Application interface.
+func (app *App) BlockDeliver(block types.Block) {
app.deliveredLock.Lock()
defer app.deliveredLock.Unlock()
- app.Delivered[blockHash] = &AppDeliveredRecord{
- ConsensusTime: timestamp,
+ app.Delivered[block.Hash] = &AppDeliveredRecord{
+ ConsensusTime: block.Witness.Timestamp,
When: time.Now().UTC(),
}
- app.DeliverSequence = append(app.DeliverSequence, blockHash)
+ app.DeliverSequence = append(app.DeliverSequence, block.Hash)
}
// BlockProcessedChan returns a channel to receive the block hashes that have
diff --git a/core/test/app_test.go b/core/test/app_test.go
index 0003852..649ccbe 100644
--- a/core/test/app_test.go
+++ b/core/test/app_test.go
@@ -73,9 +73,18 @@ func (s *AppTestSuite) setupAppByTotalOrderDeliver(
func (s *AppTestSuite) deliverBlockWithTimeFromSequenceLength(
app *App, hash common.Hash) {
- app.DeliverBlock(
- hash,
- time.Time{}.Add(time.Duration(len(app.DeliverSequence))*time.Second))
+ s.deliverBlock(app, hash, time.Time{}.Add(
+ time.Duration(len(app.DeliverSequence))*time.Second))
+}
+
+func (s *AppTestSuite) deliverBlock(
+ app *App, hash common.Hash, timestamp time.Time) {
+
+ app.BlockDeliver(types.Block{
+ Hash: hash,
+ Witness: types.Witness{
+ Timestamp: timestamp,
+ }})
}
func (s *AppTestSuite) TestCompare() {
@@ -105,7 +114,7 @@ func (s *AppTestSuite) TestCompare() {
wrongTime := time.Time{}.Add(
time.Duration(len(app3.DeliverSequence)) * time.Second)
wrongTime = wrongTime.Add(1 * time.Second)
- app3.DeliverBlock(s.to3.BlockHashes[0], wrongTime)
+ s.deliverBlock(app3, s.to3.BlockHashes[0], wrongTime)
req.Equal(ErrMismatchConsensusTime, app1.Compare(app3))
req.Equal(ErrMismatchConsensusTime, app3.Compare(app1))
// An App without any delivered blocks.
@@ -124,7 +133,7 @@ func (s *AppTestSuite) TestVerify() {
s.setupAppByTotalOrderDeliver(app1, s.to3)
req.Nil(app1.Verify())
// A delivered block without strongly ack
- app1.DeliverBlock(common.NewRandomHash(), time.Time{})
+ s.deliverBlock(app1, common.NewRandomHash(), time.Time{})
req.Equal(ErrDeliveredBlockNotAcked, app1.Verify())
// The consensus time is out of order.
app2 := NewApp()
@@ -133,7 +142,7 @@ func (s *AppTestSuite) TestVerify() {
app2.StronglyAcked(h)
}
app2.TotalOrderingDeliver(s.to2.BlockHashes, s.to2.Early)
- app2.DeliverBlock(s.to2.BlockHashes[0], time.Time{})
+ s.deliverBlock(app2, s.to2.BlockHashes[0], time.Time{})
req.Equal(ErrConsensusTimestampOutOfOrder, app2.Verify())
// A delivered block is not found in total ordering delivers.
app3 := NewApp()
diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go
index 262e178..cb52032 100644
--- a/core/test/stopper_test.go
+++ b/core/test/stopper_test.go
@@ -61,7 +61,9 @@ func (s *StopperTestSuite) TestStopByConfirmedBlocks() {
}
app.TotalOrderingDeliver(hashes, false)
for _, h := range hashes {
- app.DeliverBlock(h, time.Time{})
+ app.BlockDeliver(types.Block{
+ Hash: h,
+ Witness: types.Witness{Timestamp: time.Time{}}})
}
}
}