aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-11-20 13:57:24 +0800
committerGitHub <noreply@github.com>2018-11-20 13:57:24 +0800
commit6d95559bf7eb62e6c114ca4d4040c44ffd553629 (patch)
tree5c62252e4cfe59c318ef3bb67b6c55891a58a4d3 /core/test
parente5891f7ca08737c3f3bc37fd523537cb243f8b0d (diff)
downloadtangerine-consensus-6d95559bf7eb62e6c114ca4d4040c44ffd553629.tar.gz
tangerine-consensus-6d95559bf7eb62e6c114ca4d4040c44ffd553629.tar.zst
tangerine-consensus-6d95559bf7eb62e6c114ca4d4040c44ffd553629.zip
core: support NumChains change for BA modules (#339)
Diffstat (limited to 'core/test')
-rw-r--r--core/test/app.go3
-rw-r--r--core/test/governance.go12
-rw-r--r--core/test/governance_test.go6
3 files changed, 17 insertions, 4 deletions
diff --git a/core/test/app.go b/core/test/app.go
index a5d0270..e67d5c9 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -198,6 +198,9 @@ func (app *App) GetLatestDeliveredPosition() types.Position {
defer app.deliveredLock.RUnlock()
app.blocksLock.RLock()
defer app.blocksLock.RUnlock()
+ if len(app.DeliverSequence) == 0 {
+ return types.Position{}
+ }
return app.blocks[app.DeliverSequence[len(app.DeliverSequence)-1]].Position
}
diff --git a/core/test/governance.go b/core/test/governance.go
index f96e9e7..14c8177 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -33,6 +33,9 @@ import (
typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg"
)
+// TODO(mission): add a method to compare config/crs between governance
+// instances.
+
// Governance is an implementation of Goverance for testing purpose.
type Governance struct {
roundShift uint64
@@ -105,6 +108,13 @@ func (g *Governance) NotifyRoundHeight(round, height uint64) {
func() {
g.lock.Lock()
defer g.lock.Unlock()
+ // Check if there is any pending changes for previous rounds.
+ for r := range g.pendingConfigChanges {
+ if r < shiftedRound+1 {
+ panic(fmt.Errorf("pending change no longer applied: %v, now: %v",
+ r, shiftedRound+1))
+ }
+ }
for t, v := range g.pendingConfigChanges[shiftedRound+1] {
if err := g.stateModule.RequestChange(t, v); err != nil {
panic(err)
@@ -346,7 +356,7 @@ func (g *Governance) RegisterConfigChange(
}
g.lock.Lock()
defer g.lock.Unlock()
- if round <= uint64(len(g.configs)) {
+ if round < uint64(len(g.configs)) {
return errors.New(
"attempt to register state change for prepared rounds")
}
diff --git a/core/test/governance_test.go b/core/test/governance_test.go
index 07b0d46..01993f9 100644
--- a/core/test/governance_test.go
+++ b/core/test/governance_test.go
@@ -77,13 +77,13 @@ func (s *GovernanceTestSuite) TestRegisterChange() {
req.Equal(g.Configuration(4).NumChains, uint32(20))
// Unable to register change for prepared round.
req.Error(g.RegisterConfigChange(4, StateChangeNumChains, uint32(32)))
- // Unable to register change for next notified round.
- req.Error(g.RegisterConfigChange(5, StateChangeNumChains, uint32(32)))
// It's ok to make some change when condition is met.
+ req.NoError(g.RegisterConfigChange(5, StateChangeNumChains, uint32(32)))
req.NoError(g.RegisterConfigChange(6, StateChangeNumChains, uint32(32)))
req.NoError(g.RegisterConfigChange(7, StateChangeNumChains, uint32(40)))
// In local mode, state for round 6 would be ready after notified with
- // round 5.
+ // round 2.
+ g.NotifyRoundHeight(2, 0)
g.NotifyRoundHeight(3, 0)
// In local mode, state for round 7 would be ready after notified with
// round 6.