aboutsummaryrefslogtreecommitdiffstats
path: root/core/nonblocking_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-16 10:06:47 +0800
committerGitHub <noreply@github.com>2018-10-16 10:06:47 +0800
commit4ec958aad80f02086f87bf300ce7ba676618d5fc (patch)
treee99f2c47bb77cafd1b65ca1634dede59c0a5995b /core/nonblocking_test.go
parent781ce54993568ea7661642bb2ac7fc61eacb1f44 (diff)
downloaddexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar.gz
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar.bz2
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar.lz
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar.xz
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.tar.zst
dexon-consensus-4ec958aad80f02086f87bf300ce7ba676618d5fc.zip
core: fix block confirmed is not called when Debug is not implemented. (#208)
Diffstat (limited to 'core/nonblocking_test.go')
-rw-r--r--core/nonblocking_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go
index 50f580a..cad7def 100644
--- a/core/nonblocking_test.go
+++ b/core/nonblocking_test.go
@@ -27,6 +27,7 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
+// slowApp is an Application instance slow things down in every method.
type slowApp struct {
sleep time.Duration
blockConfirmed map[common.Hash]struct{}
@@ -80,6 +81,41 @@ func (app *slowApp) BlockDelivered(
app.blockDelivered[blockHash] = struct{}{}
}
+// noDebugApp is to make sure nonBlocking works when Debug interface
+// is not implemented by the provided Application instance.
+type noDebugApp struct {
+ blockConfirmed map[common.Hash]struct{}
+ blockDelivered map[common.Hash]struct{}
+}
+
+func newNoDebugApp() *noDebugApp {
+ return &noDebugApp{
+ blockConfirmed: make(map[common.Hash]struct{}),
+ blockDelivered: make(map[common.Hash]struct{}),
+ }
+}
+
+func (app *noDebugApp) PreparePayload(_ types.Position) ([]byte, error) {
+ panic("test")
+}
+
+func (app *noDebugApp) PrepareWitness(_ uint64) (types.Witness, error) {
+ panic("test")
+}
+
+func (app *noDebugApp) VerifyBlock(_ *types.Block) bool {
+ panic("test")
+}
+
+func (app *noDebugApp) BlockConfirmed(block types.Block) {
+ app.blockConfirmed[block.Hash] = struct{}{}
+}
+
+func (app *noDebugApp) BlockDelivered(
+ blockHash common.Hash, _ types.FinalizationResult) {
+ app.blockDelivered[blockHash] = struct{}{}
+}
+
type NonBlockingTestSuite struct {
suite.Suite
}
@@ -118,6 +154,23 @@ func (s *NonBlockingTestSuite) TestNonBlocking() {
}
}
+func (s *NonBlockingTestSuite) TestNoDebug() {
+ app := newNoDebugApp()
+ nbModule := newNonBlocking(app, nil)
+ hash := common.NewRandomHash()
+ // Test BlockConfirmed.
+ nbModule.BlockConfirmed(types.Block{Hash: hash})
+ // Test BlockDelivered
+ nbModule.BlockDelivered(hash, types.FinalizationResult{})
+ nbModule.wait()
+ s.Contains(app.blockConfirmed, hash)
+ s.Contains(app.blockDelivered, hash)
+ // Test other synchronous methods.
+ s.Panics(func() { nbModule.PreparePayload(types.Position{}) })
+ s.Panics(func() { nbModule.PrepareWitness(0) })
+ s.Panics(func() { nbModule.VerifyBlock(nil) })
+}
+
func TestNonBlocking(t *testing.T) {
suite.Run(t, new(NonBlockingTestSuite))
}