aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/governance_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-30 14:34:14 +0800
committerGitHub <noreply@github.com>2018-10-30 14:34:14 +0800
commit39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732 (patch)
treea87c5f90957d88d49c6255259efad5d2299d95be /core/test/governance_test.go
parent9c08b810e12f0a828e1de47b40b4e5de30c1c929 (diff)
downloaddexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.gz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.bz2
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.lz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.xz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.zst
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.zip
test: integrate state to gov (#275)
* Fix dummy error * Check validity before apply state changes. * Add RegisterConfigChange method to test.Governance * Add SwitchToRemoteMode method to test.State
Diffstat (limited to 'core/test/governance_test.go')
-rw-r--r--core/test/governance_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/test/governance_test.go b/core/test/governance_test.go
index 16de2a1..fe0dde7 100644
--- a/core/test/governance_test.go
+++ b/core/test/governance_test.go
@@ -59,6 +59,36 @@ func (s *GovernanceTestSuite) TestEqual() {
req.False(g1.Equal(g4, true))
}
+func (s *GovernanceTestSuite) TestRegisterChange() {
+ req := s.Require()
+ _, genesisNodes, err := NewKeys(20)
+ req.NoError(err)
+ g, err := NewGovernance(genesisNodes, 100*time.Millisecond)
+ req.NoError(err)
+ // Unable to register change for genesis round.
+ req.Error(g.RegisterConfigChange(0, StateChangeNumChains, uint32(32)))
+ // Make some round prepared.
+ g.CatchUpWithRound(4)
+ 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(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.
+ g.NotifyRoundHeight(5, 0)
+ // In local mode, state for round 7 would be ready after notified with
+ // round 6.
+ g.NotifyRoundHeight(6, 0)
+ // Notify governance to take a snapshot for round 7's configuration.
+ g.NotifyRoundHeight(7, 0)
+ req.Equal(g.Configuration(6).NumChains, uint32(32))
+ req.Equal(g.Configuration(7).NumChains, uint32(40))
+}
+
func TestGovernance(t *testing.T) {
suite.Run(t, new(GovernanceTestSuite))
}