aboutsummaryrefslogtreecommitdiffstats
path: root/integration_test/consensus_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'integration_test/consensus_test.go')
-rw-r--r--integration_test/consensus_test.go92
1 files changed, 90 insertions, 2 deletions
diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go
index 6bc6c4b..8fd3fa4 100644
--- a/integration_test/consensus_test.go
+++ b/integration_test/consensus_test.go
@@ -95,6 +95,18 @@ func (s *ConsensusTestSuite) setupNodes(
return nodes
}
+func (s *ConsensusTestSuite) verifyNodes(nodes map[types.NodeID]*node) {
+ for ID, node := range nodes {
+ s.Require().NoError(node.app.Verify())
+ for otherID, otherNode := range nodes {
+ if ID == otherID {
+ continue
+ }
+ s.Require().NoError(node.app.Compare(otherNode.app))
+ }
+ }
+}
+
func (s *ConsensusTestSuite) TestSimple() {
// The simplest test case:
// - Node set is equals to DKG set and notary set for each chain in each
@@ -108,15 +120,18 @@ func (s *ConsensusTestSuite) TestSimple() {
dMoment = time.Now().UTC()
untilRound = uint64(5)
)
+ if testing.Short() {
+ untilRound = 2
+ }
prvKeys, pubKeys, err := test.NewKeys(peerCount)
req.NoError(err)
// Setup seed governance instance. Give a short latency to make this test
// run faster.
seedGov, err := test.NewGovernance(
- pubKeys, 30*time.Millisecond, core.ConfigRoundShift)
+ pubKeys, 100*time.Millisecond, core.ConfigRoundShift)
req.NoError(err)
req.NoError(seedGov.State().RequestChange(
- test.StateChangeRoundInterval, 25*time.Second))
+ test.StateChangeRoundInterval, 50*time.Second))
// A short round interval.
nodes := s.setupNodes(dMoment, prvKeys, seedGov)
for _, n := range nodes {
@@ -136,6 +151,79 @@ Loop:
// Oh ya.
break
}
+ s.verifyNodes(nodes)
+}
+
+func (s *ConsensusTestSuite) TestNumChainsChange() {
+ var (
+ req = s.Require()
+ peerCount = 4
+ dMoment = time.Now().UTC()
+ untilRound = uint64(6)
+ )
+ if testing.Short() {
+ // Short test won't test configuration change packed as payload of
+ // blocks and applied when delivered.
+ untilRound = 5
+ }
+ prvKeys, pubKeys, err := test.NewKeys(peerCount)
+ req.NoError(err)
+ // Setup seed governance instance.
+ seedGov, err := test.NewGovernance(
+ pubKeys, 100*time.Millisecond, core.ConfigRoundShift)
+ req.NoError(err)
+ // Setup configuration for round 0 and round 1.
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeRoundInterval, 45*time.Second))
+ seedGov.CatchUpWithRound(1)
+ // Setup configuration for round 2.
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeNumChains, uint32(5)))
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeRoundInterval, 55*time.Second))
+ seedGov.CatchUpWithRound(2)
+ // Setup configuration for round 3.
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeNumChains, uint32(6)))
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeRoundInterval, 75*time.Second))
+ seedGov.CatchUpWithRound(3)
+ // Setup nodes.
+ nodes := s.setupNodes(dMoment, prvKeys, seedGov)
+ // Pick master node, and register changes on it.
+ var pickedNode *node
+ for _, pickedNode = range nodes {
+ break
+ }
+ // Register configuration changes for round 4.
+ req.NoError(pickedNode.gov.RegisterConfigChange(
+ 4, test.StateChangeNumChains, uint32(4)))
+ req.NoError(pickedNode.gov.RegisterConfigChange(
+ 4, test.StateChangeRoundInterval, 45*time.Second))
+ // Register configuration changes for round 5.
+ req.NoError(pickedNode.gov.RegisterConfigChange(
+ 5, test.StateChangeNumChains, uint32(5)))
+ req.NoError(pickedNode.gov.RegisterConfigChange(
+ 5, test.StateChangeRoundInterval, 55*time.Second))
+ // Run test.
+ for _, n := range nodes {
+ go n.con.Run(&types.Block{})
+ }
+Loop:
+ for {
+ <-time.After(5 * time.Second)
+ s.T().Log("check latest position delivered by each node")
+ for _, n := range nodes {
+ latestPos := n.app.GetLatestDeliveredPosition()
+ s.T().Log("latestPos", n.con.ID, &latestPos)
+ if latestPos.Round < untilRound {
+ continue Loop
+ }
+ }
+ // Oh ya.
+ break
+ }
+ s.verifyNodes(nodes)
}
func TestConsensus(t *testing.T) {