From 39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Tue, 30 Oct 2018 14:34:14 +0800 Subject: 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 --- core/test/governance_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'core/test/governance_test.go') 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)) } -- cgit v1.2.3