Skip to content

Commit 99e3da9

Browse files
Update static epoch test to use same testing flow (#2761)
* update static epoch test to use same testing flow * updated bft-tests.yml for debugging TestEpochStaticTransition/TestStaticEpochTransition * added scheduled run every hour * kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition #1 * kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition #2 * #3 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #4 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #5 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #6 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #7 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #8 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #9 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * #10 kick off another CI test run for TestEpochStaticTransition/TestStaticEpochTransition * remove sleep * Dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * dummy commit * 7699 dummy commit * 3651 dummy commit * 21538 dummy commit * 7108 dummy commit * 7186 dummy commit * 1772 dummy commit * 30464 dummy commit * 15633 dummy commit * 11129 dummy commit * 15839 dummy commit * remove dummy file * remove dummy file Co-authored-by: gomisha <[email protected]>
1 parent b0e1827 commit 99e3da9

File tree

4 files changed

+58
-105
lines changed

4 files changed

+58
-105
lines changed

.github/workflows/bft-tests.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ name: BFT Tests
66
# this workflow should be disabled in Github when not needed: https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow
77

88
on:
9+
schedule:
10+
- cron: '0 */1 * * *' # every 1 hour
911
push:
1012
branches:
11-
- '**/*bft*'
13+
- '**/*6313*'
1214

1315
env:
1416
GO_VERSION: 1.18
@@ -46,7 +48,7 @@ jobs:
4648
fail-fast: false
4749
matrix:
4850
test-category:
49-
- integration-bft
51+
- integration-epochs
5052
env:
5153
TEST_CATEGORY: ${{ matrix.test-category }}
5254
runs-on: ubuntu-latest

integration/tests/epochs/epoch_join_and_leave_an_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package epochs
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/suite"
7+
68
"github.com/onflow/flow-go/model/flow"
79
"github.com/onflow/flow-go/utils/unittest"
8-
"github.com/stretchr/testify/suite"
910
)
1011

1112
func TestEpochJoinAndLeaveAN(t *testing.T) {

integration/tests/epochs/epoch_static_transition_test.go

+28-98
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ package epochs
33
import (
44
"testing"
55

6-
"github.com/stretchr/testify/assert"
76
"github.com/stretchr/testify/require"
87
"github.com/stretchr/testify/suite"
98

10-
"github.com/onflow/flow-go/integration/testnet"
119
"github.com/onflow/flow-go/model/flow"
12-
"github.com/onflow/flow-go/state/protocol"
1310
)
1411

1512
func TestEpochStaticTransition(t *testing.T) {
@@ -33,107 +30,40 @@ func (s *StaticEpochTransitionSuite) SetupTest() {
3330
s.Suite.SetupTest()
3431
}
3532

36-
// TestStaticEpochTransition asserts epoch state transitions over two full epochs
37-
// without any nodes joining or leaving.
33+
// TestStaticEpochTransition asserts epoch state transitions over full epoch
34+
// without any nodes joining or leaving. In particular, we assert that we enter
35+
// the EpochSetup phase, then successfully enter the second epoch (implying a
36+
// successful DKG).
37+
// This is equivalent to runTestEpochJoinAndLeave, without any committee changes.
3838
func (s *StaticEpochTransitionSuite) TestStaticEpochTransition() {
3939

40-
// phaseCheck is a utility struct that contains information about the
41-
// final view of each epoch/phase.
42-
type phaseCheck struct {
43-
epoch uint64
44-
phase flow.EpochPhase
45-
finalView uint64 // the final view of the phase as defined by the EpochSetup
46-
}
40+
s.TimedLogf("waiting for EpochSetup phase of first epoch to begin")
41+
s.WaitForPhase(s.ctx, flow.EpochPhaseSetup)
42+
s.TimedLogf("successfully reached EpochSetup phase of first epoch")
4743

48-
phaseChecks := []*phaseCheck{}
49-
// iterate through two epochs and populate a list of phase checks
50-
for counter := 0; counter < 2; counter++ {
44+
snapshot, err := s.client.GetLatestProtocolSnapshot(s.ctx)
45+
require.NoError(s.T(), err)
5146

52-
// wait until the access node reaches the desired epoch
53-
var epoch protocol.Epoch
54-
var epochCounter uint64
55-
for epoch == nil || epochCounter != uint64(counter) {
56-
snapshot, err := s.client.GetLatestProtocolSnapshot(s.ctx)
57-
require.NoError(s.T(), err)
58-
epoch = snapshot.Epochs().Current()
59-
epochCounter, err = epoch.Counter()
60-
require.NoError(s.T(), err)
61-
}
47+
header, err := snapshot.Head()
48+
require.NoError(s.T(), err)
49+
s.TimedLogf("retrieved header after entering EpochSetup phase: height=%d, view=%d", header.Height, header.View)
6250

63-
epochFirstView, err := epoch.FirstView()
64-
require.NoError(s.T(), err)
65-
epochDKGPhase1Final, err := epoch.DKGPhase1FinalView()
66-
require.NoError(s.T(), err)
67-
epochDKGPhase2Final, err := epoch.DKGPhase2FinalView()
68-
require.NoError(s.T(), err)
69-
epochDKGPhase3Final, err := epoch.DKGPhase3FinalView()
70-
require.NoError(s.T(), err)
71-
epochFinal, err := epoch.FinalView()
72-
require.NoError(s.T(), err)
51+
epoch1FinalView, err := snapshot.Epochs().Current().FinalView()
52+
require.NoError(s.T(), err)
53+
epoch1Counter, err := snapshot.Epochs().Current().Counter()
54+
require.NoError(s.T(), err)
7355

74-
epochViews := []*phaseCheck{
75-
{epoch: epochCounter, phase: flow.EpochPhaseStaking, finalView: epochFirstView},
76-
{epoch: epochCounter, phase: flow.EpochPhaseSetup, finalView: epochDKGPhase1Final},
77-
{epoch: epochCounter, phase: flow.EpochPhaseSetup, finalView: epochDKGPhase2Final},
78-
{epoch: epochCounter, phase: flow.EpochPhaseSetup, finalView: epochDKGPhase3Final},
79-
{epoch: epochCounter, phase: flow.EpochPhaseCommitted, finalView: epochFinal},
80-
}
56+
// wait for the final view of the first epoch
57+
s.TimedLogf("waiting for the final view (%d) of epoch %d", epoch1FinalView, epoch1Counter)
58+
s.BlockState.WaitForSealedView(s.T(), epoch1FinalView+5)
59+
s.TimedLogf("sealed final view (%d) of epoch %d", epoch1FinalView, epoch1Counter)
8160

82-
for _, v := range epochViews {
83-
s.BlockState.WaitForSealedView(s.T(), v.finalView)
84-
}
61+
// assert transition to second epoch happened as expected
62+
// if counter is still 0, epoch emergency fallback was triggered and we can fail early
63+
s.assertEpochCounter(s.ctx, 1)
8564

86-
phaseChecks = append(phaseChecks, epochViews...)
87-
}
88-
89-
s.net.StopContainers()
90-
91-
consensusContainers := make([]*testnet.Container, 0)
92-
for _, c := range s.net.Containers {
93-
if c.Config.Role == flow.RoleConsensus {
94-
consensusContainers = append(consensusContainers, c)
95-
}
96-
}
97-
98-
for _, c := range consensusContainers {
99-
containerState, err := c.OpenState()
100-
require.NoError(s.T(), err)
101-
102-
// create a map of [view] => {epoch-counter, phase}
103-
lookup := map[uint64]struct {
104-
epochCounter uint64
105-
phase flow.EpochPhase
106-
}{}
107-
108-
final, err := containerState.Final().Head()
109-
require.NoError(s.T(), err)
110-
111-
var h uint64
112-
for h = 0; h <= final.Height; h++ {
113-
snapshot := containerState.AtHeight(h)
114-
115-
head, err := snapshot.Head()
116-
require.NoError(s.T(), err)
117-
118-
epoch := snapshot.Epochs().Current()
119-
currentEpochCounter, err := epoch.Counter()
120-
require.NoError(s.T(), err)
121-
currentPhase, err := snapshot.Phase()
122-
require.NoError(s.T(), err)
123-
124-
lookup[head.View] = struct {
125-
epochCounter uint64
126-
phase flow.EpochPhase
127-
}{
128-
currentEpochCounter,
129-
currentPhase,
130-
}
131-
}
132-
133-
for _, v := range phaseChecks {
134-
item := lookup[v.finalView]
135-
assert.Equal(s.T(), v.epoch, item.epochCounter, "wrong epoch at view %d", v.finalView)
136-
assert.Equal(s.T(), v.phase, item.phase, "wrong phase at view %d", v.finalView)
137-
}
138-
}
65+
// submit a smoke test transaction to verify the network can seal a transaction
66+
s.TimedLogf("sending smoke test transaction in second epoch")
67+
s.submitSmokeTestTransaction(s.ctx)
68+
s.TimedLogf("successfully submitted and observed sealing of smoke test transaction")
13969
}

integration/tests/epochs/suite.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ func (s *Suite) Ghost() *client.GhostClient {
129129
return client
130130
}
131131

132+
// TimedLogf logs the message using t.Log, but prefixes the current time.
133+
func (s *Suite) TimedLogf(msg string, args ...interface{}) {
134+
args = append([]interface{}{time.Now().String()}, args...)
135+
s.T().Logf("%s - "+msg, args...)
136+
}
137+
132138
func (s *Suite) TearDownTest() {
133139
s.log.Info().Msg("================> Start TearDownTest")
134140
s.net.Remove()
@@ -762,27 +768,39 @@ func (s *Suite) runTestEpochJoinAndLeave(role flow.Role, checkNetworkHealth node
762768
}
763769

764770
// staking our new node and add get the corresponding container for that node
771+
s.TimedLogf("staking joining node with role %s", role.String())
765772
info, testContainer := s.StakeNewNode(s.ctx, env, role)
773+
s.TimedLogf("successfully staked joining node: %s", info.NodeID)
766774

767775
// use admin transaction to remove node, this simulates a node leaving the network
776+
s.TimedLogf("removing node %s with role %s", containerToReplace.Config.NodeID, role.String())
768777
s.removeNodeFromProtocol(s.ctx, env, containerToReplace.Config.NodeID)
778+
s.TimedLogf("successfully removed node: %s", containerToReplace.Config.NodeID)
769779

770780
// wait for epoch setup phase before we start our container and pause the old container
781+
s.TimedLogf("waiting for EpochSetup phase of first epoch to begin")
771782
s.WaitForPhase(s.ctx, flow.EpochPhaseSetup)
783+
s.TimedLogf("successfully reached EpochSetup phase of first epoch")
772784

773785
// get latest snapshot and start new container
774786
snapshot, err := s.client.GetLatestProtocolSnapshot(s.ctx)
775787
require.NoError(s.T(), err)
776788
testContainer.WriteRootSnapshot(snapshot)
777789
testContainer.Container.Start(s.ctx)
778790

779-
currentEpochFinalView, err := snapshot.Epochs().Current().FinalView()
791+
header, err := snapshot.Head()
792+
require.NoError(s.T(), err)
793+
s.TimedLogf("retrieved header after entering EpochSetup phase: height=%d, view=%d", header.Height, header.View)
794+
795+
epoch1FinalView, err := snapshot.Epochs().Current().FinalView()
780796
require.NoError(s.T(), err)
781797

782798
// wait for 5 views after the start of the next epoch before we pause our container to replace
783-
s.BlockState.WaitForSealedView(s.T(), currentEpochFinalView+5)
799+
s.TimedLogf("waiting for sealed view %d before pausing container", epoch1FinalView+5)
800+
s.BlockState.WaitForSealedView(s.T(), epoch1FinalView+5)
801+
s.TimedLogf("observed sealed view %d -> pausing container", epoch1FinalView+5)
784802

785-
//make sure container to replace removed from smart contract state
803+
// make sure container to replace removed from smart contract state
786804
s.assertNodeNotApprovedOrProposed(s.ctx, env, containerToReplace.Config.NodeID)
787805

788806
// assert transition to second epoch happened as expected
@@ -793,7 +811,9 @@ func (s *Suite) runTestEpochJoinAndLeave(role flow.Role, checkNetworkHealth node
793811
require.NoError(s.T(), err)
794812

795813
// wait for 5 views after pausing our container to replace before we assert healthy network
796-
s.BlockState.WaitForSealedView(s.T(), currentEpochFinalView+10)
814+
s.TimedLogf("waiting for sealed view %d before asserting network health", epoch1FinalView+10)
815+
s.BlockState.WaitForSealedView(s.T(), epoch1FinalView+10)
816+
s.TimedLogf("observed sealed view %d -> asserting network health", epoch1FinalView+10)
797817

798818
// make sure the network is healthy after adding new node
799819
checkNetworkHealth(s.ctx, env, snapshot, info)

0 commit comments

Comments
 (0)