From d444a71ec78e27e7aa7d4a55d0667770e248b5e7 Mon Sep 17 00:00:00 2001 From: Anca Zamfir Date: Tue, 21 Dec 2021 20:39:11 +0100 Subject: [PATCH] Fix pbts tests (#7413) * Allow nil block ID check in ensureProposalWithTimout * William's suggestion to get the proposal from the proposer instead of generating it. * Remove error check on service stop --- internal/consensus/common_test.go | 11 +++++++---- internal/consensus/pbts_test.go | 13 +++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 3407010fe..6baf8d638 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -656,11 +656,11 @@ func ensureRelock(t *testing.T, relockCh <-chan tmpubsub.Message, height int64, } func ensureProposal(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) { - ensureProposalWithTimeout(t, proposalCh, height, round, propID, ensureTimeout) + ensureProposalWithTimeout(t, proposalCh, height, round, &propID, ensureTimeout) } // nolint: lll -func ensureProposalWithTimeout(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID, timeout time.Duration) { +func ensureProposalWithTimeout(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID *types.BlockID, timeout time.Duration) { t.Helper() msg := ensureMessageBeforeTimeout(t, proposalCh, timeout) proposalEvent, ok := msg.Data().(types.EventDataCompleteProposal) @@ -668,9 +668,12 @@ func ensureProposalWithTimeout(t *testing.T, proposalCh <-chan tmpubsub.Message, msg.Data()) require.Equal(t, height, proposalEvent.Height) require.Equal(t, round, proposalEvent.Round) - require.True(t, proposalEvent.BlockID.Equals(propID), - "Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID) + if propID != nil { + require.True(t, proposalEvent.BlockID.Equals(*propID), + "Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID) + } } + func ensurePrecommit(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32) { t.Helper() ensureVote(t, voteCh, height, round, tmproto.PrecommitType) diff --git a/internal/consensus/pbts_test.go b/internal/consensus/pbts_test.go index 2d2ec331f..05888b62a 100644 --- a/internal/consensus/pbts_test.go +++ b/internal/consensus/pbts_test.go @@ -146,12 +146,12 @@ func (p *pbtsTestHarness) observedValidatorProposerHeight(previousBlockTime time p.validatorClock.On("Now").Return(p.height2ProposedBlockTime).Times(6) ensureNewRound(p.t, p.roundCh, p.currentHeight, p.currentRound) - propBlock, partSet, err := p.observedState.createProposalBlock() - require.NoError(p.t, err) - bid := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: partSet.Header()} timeout := time.Until(previousBlockTime.Add(ensureTimeout)) - ensureProposalWithTimeout(p.t, p.ensureProposalCh, p.currentHeight, p.currentRound, bid, timeout) + ensureProposalWithTimeout(p.t, p.ensureProposalCh, p.currentHeight, p.currentRound, nil, timeout) + + rs := p.observedState.GetRoundState() + bid := types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()} ensurePrevote(p.t, p.ensureVoteCh, p.currentHeight, p.currentRound) signAddVotes(p.ctx, p.t, p.observedState, tmproto.PrevoteType, p.chainID, bid, p.otherValidators...) @@ -299,8 +299,7 @@ func (p *pbtsTestHarness) run() resultSet { r2 := p.height2() p.intermediateHeights() r5 := p.height5() - err := p.observedState.Stop() - require.NoError(p.t, err) + _ = p.observedState.Stop() return resultSet{ genesisHeight: r1, height2: r2, @@ -328,7 +327,6 @@ func (hr heightResult) isComplete() bool { // until after the genesis time has passed. The test sets the genesis time in the // future and then ensures that the observed validator waits to propose a block. func TestProposerWaitsForGenesisTime(t *testing.T) { - t.Skip() ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -359,7 +357,6 @@ func TestProposerWaitsForGenesisTime(t *testing.T) { // and then verifies that the observed validator waits until after the block time // of height 4 to propose a block at height 5. func TestProposerWaitsForPreviousBlock(t *testing.T) { - t.Skip() ctx, cancel := context.WithCancel(context.Background()) defer cancel() initialTime := time.Now().Add(time.Millisecond * 50)