consensus: fix round advances in state test

This commit is contained in:
William Banfield
2022-01-20 14:59:25 -05:00
parent c8e8a62084
commit 0ce3805a4b
2 changed files with 30 additions and 4 deletions
+25
View File
@@ -686,7 +686,32 @@ func ensurePrevote(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, r
t.Helper()
ensureVote(t, voteCh, height, round, tmproto.PrevoteType)
}
func ensurePrevoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte) {
t.Helper()
ensureVoteMatch(t, voteCh, height, round, hash, tmproto.PrevoteType)
}
func ensureVoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte, voteType tmproto.SignedMsgType) {
t.Helper()
select {
case <-time.After(ensureTimeout):
t.Fatal("Timeout expired while waiting for NewVote event")
case msg := <-voteCh:
voteEvent, ok := msg.Data().(types.EventDataVote)
require.True(t, ok, "expected a EventDataVote, got %T. Wrong subscription channel?",
msg.Data())
vote := voteEvent.Vote
require.Equal(t, height, vote.Height)
require.Equal(t, round, vote.Round)
require.Equal(t, voteType, vote.Type)
if hash == nil {
require.Nil(t, vote.BlockID.Hash, "Expected prevote to be for nil, got %X", vote.BlockID.Hash)
} else {
require.True(t, bytes.Equal(vote.BlockID.Hash, hash), "Expected prevote to be for %X, got %X", hash, vote.BlockID.Hash)
}
}
}
func ensureVote(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, voteType tmproto.SignedMsgType) {
t.Helper()
select {
+5 -4
View File
@@ -353,7 +353,7 @@ func TestStateOversizedBlock(t *testing.T) {
// propose, prevote, and precommit a block
func TestStateFullRound1(t *testing.T) {
config := configSetup(t)
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -372,7 +372,9 @@ func TestStateFullRound1(t *testing.T) {
t.Error(err)
}
voteCh := subscribe(ctx, t, cs.eventBus, types.EventQueryVote)
pv, err := cs.privValidator.GetPubKey(ctx)
require.NoError(t, err)
voteCh := subscribeToVoter(ctx, t, cs, pv.Address())
propCh := subscribe(ctx, t, cs.eventBus, types.EventQueryCompleteProposal)
newRoundCh := subscribe(ctx, t, cs.eventBus, types.EventQueryNewRound)
@@ -384,8 +386,7 @@ func TestStateFullRound1(t *testing.T) {
ensureNewProposal(t, propCh, height, round)
propBlockHash := cs.GetRoundState().ProposalBlock.Hash()
ensurePrevote(t, voteCh, height, round) // wait for prevote
validatePrevote(ctx, t, cs, round, vss[0], propBlockHash)
ensurePrevoteMatch(t, voteCh, height, round, propBlockHash) // wait for prevote
ensurePrecommit(t, voteCh, height, round) // wait for precommit