|
|
|
@ -45,8 +45,6 @@ func TestPhaseSwitching(t *testing.T) { |
|
|
|
|
|
|
|
|
|
assert.Equal(t, FBFTAnnounce, consensus.phase) // It's a new consensus, we should be at the FBFTAnnounce phase
|
|
|
|
|
|
|
|
|
|
override := false |
|
|
|
|
|
|
|
|
|
switches := []phaseSwitch{ |
|
|
|
|
{start: FBFTAnnounce, end: FBFTPrepare}, |
|
|
|
|
{start: FBFTPrepare, end: FBFTCommit}, |
|
|
|
@ -54,13 +52,11 @@ func TestPhaseSwitching(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, sw := range switches { |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end, override) |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override = true |
|
|
|
|
|
|
|
|
|
for _, sw := range switches { |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end, override) |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switches = []phaseSwitch{ |
|
|
|
@ -70,16 +66,13 @@ func TestPhaseSwitching(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, sw := range switches { |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end, override) |
|
|
|
|
testPhaseGroupSwitching(t, consensus, phases, sw.start, sw.end) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPhaseGroupSwitching(t *testing.T, consensus *Consensus, phases []FBFTPhase, startPhase FBFTPhase, desiredPhase FBFTPhase, override bool) { |
|
|
|
|
phaseMapping := make(map[FBFTPhase]bool) |
|
|
|
|
|
|
|
|
|
if override { |
|
|
|
|
func testPhaseGroupSwitching(t *testing.T, consensus *Consensus, phases []FBFTPhase, startPhase FBFTPhase, desiredPhase FBFTPhase) { |
|
|
|
|
for range phases { |
|
|
|
|
consensus.switchPhase("test", desiredPhase, override) |
|
|
|
|
consensus.switchPhase("test", desiredPhase) |
|
|
|
|
assert.Equal(t, desiredPhase, consensus.phase) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -88,23 +81,6 @@ func testPhaseGroupSwitching(t *testing.T, consensus *Consensus, phases []FBFTPh |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
phaseMapping[FBFTAnnounce] = false |
|
|
|
|
phaseMapping[FBFTPrepare] = false |
|
|
|
|
phaseMapping[FBFTCommit] = false |
|
|
|
|
phaseMapping[startPhase] = false |
|
|
|
|
phaseMapping[desiredPhase] = true |
|
|
|
|
|
|
|
|
|
assert.Equal(t, startPhase, consensus.phase) |
|
|
|
|
|
|
|
|
|
for _, phase := range phases { |
|
|
|
|
consensus.switchPhase("test", desiredPhase, override) |
|
|
|
|
expected := phaseMapping[phase] |
|
|
|
|
assert.Equal(t, expected, (phase == consensus.phase)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert.Equal(t, desiredPhase, consensus.phase) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetNextLeaderKeyShouldFailForStandardGeneratedConsensus(t *testing.T) { |
|
|
|
|
_, _, consensus, _, err := GenerateConsensusForTesting() |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|