diff options
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/governance_test.go | 6 | ||||
-rw-r--r-- | core/test/network_test.go | 2 | ||||
-rw-r--r-- | core/test/state.go | 8 | ||||
-rw-r--r-- | core/test/state_test.go | 31 |
4 files changed, 22 insertions, 25 deletions
diff --git a/core/test/governance_test.go b/core/test/governance_test.go index e0a2365..af2b5c5 100644 --- a/core/test/governance_test.go +++ b/core/test/governance_test.go @@ -35,11 +35,11 @@ func (s *GovernanceTestSuite) TestEqual() { _, genesisNodes, err := NewKeys(20) req.NoError(err) g1, err := NewGovernance(NewState( - genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) // Create a governance with different lambda. g2, err := NewGovernance(NewState( - genesisNodes, 50*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 50*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) req.False(g1.Equal(g2, true)) // Create configs for 3 rounds for g1. @@ -72,7 +72,7 @@ func (s *GovernanceTestSuite) TestRegisterChange() { _, genesisNodes, err := NewKeys(20) req.NoError(err) g, err := NewGovernance(NewState( - genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) // Unable to register change for genesis round. req.Error(g.RegisterConfigChange(0, StateChangeDKGSetSize, uint32(32))) diff --git a/core/test/network_test.go b/core/test/network_test.go index 22c31a8..3e9b557 100644 --- a/core/test/network_test.go +++ b/core/test/network_test.go @@ -248,7 +248,7 @@ func (s *NetworkTestSuite) TestBroadcastToSet() { _, pubKeys, err := NewKeys(peerCount) req.NoError(err) gov, err := NewGovernance(NewState( - pubKeys, time.Second, &common.NullLogger{}, true), 2) + 1, pubKeys, time.Second, &common.NullLogger{}, true), 2) req.NoError(err) req.NoError(gov.State().RequestChange(StateChangeDKGSetSize, uint32(1))) req.NoError(gov.State().RequestChange(StateChangeNotarySetSize, uint32(1))) diff --git a/core/test/state.go b/core/test/state.go index f1cf365..fbf4505 100644 --- a/core/test/state.go +++ b/core/test/state.go @@ -117,6 +117,7 @@ type State struct { // - node set // - crs func NewState( + dkgDelayRound uint64, nodePubKeys []crypto.PublicKey, lambda time.Duration, logger common.Logger, @@ -126,6 +127,11 @@ func NewState( nodes[types.NewNodeID(key)] = key } genesisCRS := crypto.Keccak256Hash([]byte("__ DEXON")) + crs := make([]common.Hash, dkgDelayRound+1) + for i := range crs { + crs[i] = genesisCRS + genesisCRS = crypto.Keccak256Hash(genesisCRS[:]) + } return &State{ local: local, logger: logger, @@ -133,7 +139,7 @@ func NewState( lambdaDKG: lambda * 10, roundInterval: 1000, minBlockInterval: 4 * lambda, - crs: []common.Hash{genesisCRS}, + crs: crs, nodes: nodes, notarySetSize: uint32(len(nodes)), dkgSetSize: uint32(len(nodes)), diff --git a/core/test/state_test.go b/core/test/state_test.go index ad3a1d6..8d2b2a2 100644 --- a/core/test/state_test.go +++ b/core/test/state_test.go @@ -160,10 +160,10 @@ func (s *StateTestSuite) TestEqual() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) req.NoError(st.Equal(st)) // One node is missing. - st1 := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st1 := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) for nID := range st1.nodes { delete(st1.nodes, nID) break @@ -174,7 +174,6 @@ func (s *StateTestSuite) TestEqual() { req.NoError(st.Equal(st2)) s.makeConfigChanges(st) req.Equal(st.Equal(st2), ErrStateConfigNotEqual) - req.NoError(st.ProposeCRS(1, common.NewRandomHash())) req.NoError(st.ProposeCRS(2, common.NewRandomHash())) req.NoError(st.RequestChange(StateResetDKG, common.NewRandomHash())) masterPubKey := s.newDKGMasterPublicKey(2) @@ -230,12 +229,12 @@ func (s *StateTestSuite) TestPendingChangesEqual() { // Setup a non-local mode State instance. _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) req.NoError(st.Equal(st)) // Apply some changes. s.makeConfigChanges(st) crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) + req.NoError(st.ProposeCRS(2, crs)) masterPubKey := s.newDKGMasterPublicKey(2) ready := s.newDKGMPKReady(2) comp := s.newDKGComplaint(2) @@ -251,7 +250,7 @@ func (s *StateTestSuite) TestLocalMode() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) config1, nodes1 := st.Snapshot() req.True(s.compareNodes(genesisNodes, nodes1)) // Check settings of config1 affected by genesisNodes and lambda. @@ -274,9 +273,6 @@ func (s *StateTestSuite) TestLocalMode() { req.True(s.findNode(newNodes, pubKey)) // Test adding CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) - req.Equal(st.CRS(1), crs) - crs = common.NewRandomHash() req.NoError(st.ProposeCRS(2, crs)) req.Equal(st.CRS(2), crs) // Test adding node set, DKG complaints, final, master public key. @@ -335,16 +331,11 @@ func (s *StateTestSuite) TestPacking() { // Make config changes. _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) s.makeConfigChanges(st) // Add new CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) - packAndApply(st) - // Check if CRS is added. - req.Equal(st.CRS(1), crs) - crs2 := common.NewRandomHash() - req.NoError(st.ProposeCRS(2, crs2)) + req.NoError(st.ProposeCRS(2, crs)) // Add new node. prvKey, err := ecdsa.NewPrivateKey() req.NoError(err) @@ -366,7 +357,7 @@ func (s *StateTestSuite) TestPacking() { config, nodes := st.Snapshot() s.checkConfigChanges(config) // Check if CRS is added. - req.Equal(st.CRS(2), crs2) + req.Equal(st.CRS(2), crs) // Check if new node is added. req.True(s.findNode(nodes, pubKey)) // Check DKGMasterPublicKeys. @@ -409,14 +400,14 @@ func (s *StateTestSuite) TestRequestBroadcastAndPack() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) - st1 := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) + st1 := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) req.NoError(st.Equal(st1)) // Make configuration changes. s.makeConfigChanges(st) // Add new CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) + req.NoError(st.ProposeCRS(2, crs)) // Add new node. prvKey, err := ecdsa.NewPrivateKey() req.NoError(err) |