From 765e1e313cf16696f9b9790e0dca9516a0bfbba6 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Wed, 22 Sep 2021 08:56:42 -0400 Subject: [PATCH] consensus: remove panics from test helper functions (#6969) --- internal/consensus/byzantine_test.go | 2 +- internal/consensus/common_test.go | 221 ++++++++------- internal/consensus/mempool_test.go | 32 +-- internal/consensus/reactor_test.go | 3 +- internal/consensus/replay_test.go | 31 +- internal/consensus/state_test.go | 404 +++++++++++++-------------- 6 files changed, 360 insertions(+), 333 deletions(-) diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index d9e5e46b8..8ddc0c4b4 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -59,7 +59,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { defer os.RemoveAll(thisConfig.RootDir) - ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal + ensureDir(t, path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal app := appFunc() vals := types.TM2PB.ValidatorUpdates(state.Validators) app.InitChain(abci.RequestInitChain{Validators: vals}) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index bcbbe7c88..06e645882 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -52,7 +52,7 @@ func configSetup(t *testing.T) *config.Config { cfg, err := ResetConfig("consensus_reactor_test") require.NoError(t, err) - t.Cleanup(func() { os.RemoveAll(cfg.RootDir) }) + t.Cleanup(func() { os.RemoveAll(config.RootDir) }) consensusReplayConfig, err := ResetConfig("consensus_replay_test") require.NoError(t, err) @@ -73,9 +73,10 @@ func configSetup(t *testing.T) *config.Config { return cfg } -func ensureDir(dir string, mode os.FileMode) { +func ensureDir(t *testing.T, dir string, mode os.FileMode) { + t.Helper() if err := tmos.EnsureDir(dir, mode); err != nil { - panic(err) + t.Fatalf("error opening directory: %s", err) } } @@ -231,18 +232,20 @@ func startTestRound(ctx context.Context, cs *State, height int64, round int32) { // Create proposal block from cs1 but sign it with vs. func decideProposal( ctx context.Context, + t *testing.T, cs1 *State, vs *validatorStub, height int64, round int32, ) (proposal *types.Proposal, block *types.Block) { + t.Helper() cs1.mtx.Lock() block, blockParts := cs1.createProposalBlock() validRound := cs1.ValidRound chainID := cs1.state.ChainID cs1.mtx.Unlock() if block == nil { - panic("Failed to createProposalBlock. Did you forget to add commit for previous block?") + t.Fatal("Failed to createProposalBlock. Did you forget to add commit for previous block?") } // Make proposal @@ -250,7 +253,7 @@ func decideProposal( proposal = types.NewProposal(height, round, polRound, propBlockID) p := proposal.ToProto() if err := vs.SignProposal(ctx, chainID, p); err != nil { - panic(err) + t.Fatalf("error signing proposal: %s", err) } proposal.Signature = p.Signature @@ -276,44 +279,39 @@ func signAddVotes( addVotes(to, signVotes(ctx, cfg, voteType, hash, header, vss...)...) } -func validatePrevote( - ctx context.Context, - t *testing.T, - cs *State, - round int32, - privVal *validatorStub, - blockHash []byte, -) { +func validatePrevote(ctx context.Context, t *testing.T, cs *State, round int32, privVal *validatorStub, blockHash []byte) { + t.Helper() prevotes := cs.Votes.Prevotes(round) pubKey, err := privVal.GetPubKey(ctx) require.NoError(t, err) address := pubKey.Address() var vote *types.Vote if vote = prevotes.GetByAddress(address); vote == nil { - panic("Failed to find prevote from validator") + t.Fatalf("Failed to find prevote from validator") } if blockHash == nil { if vote.BlockID.Hash != nil { - panic(fmt.Sprintf("Expected prevote to be for nil, got %X", vote.BlockID.Hash)) + t.Fatalf("Expected prevote to be for nil, got %X", vote.BlockID.Hash) } } else { if !bytes.Equal(vote.BlockID.Hash, blockHash) { - panic(fmt.Sprintf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash)) + t.Fatalf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash) } } } func validateLastPrecommit(ctx context.Context, t *testing.T, cs *State, privVal *validatorStub, blockHash []byte) { + t.Helper() votes := cs.LastCommit pv, err := privVal.GetPubKey(ctx) require.NoError(t, err) address := pv.Address() var vote *types.Vote if vote = votes.GetByAddress(address); vote == nil { - panic("Failed to find precommit from validator") + t.Fatalf("Failed to find precommit from validator") } if !bytes.Equal(vote.BlockID.Hash, blockHash) { - panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash)) + t.Fatalf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash) } } @@ -327,41 +325,42 @@ func validatePrecommit( votedBlockHash, lockedBlockHash []byte, ) { + t.Helper() precommits := cs.Votes.Precommits(thisRound) pv, err := privVal.GetPubKey(ctx) require.NoError(t, err) address := pv.Address() var vote *types.Vote if vote = precommits.GetByAddress(address); vote == nil { - panic("Failed to find precommit from validator") + t.Fatalf("Failed to find precommit from validator") } if votedBlockHash == nil { if vote.BlockID.Hash != nil { - panic("Expected precommit to be for nil") + t.Fatalf("Expected precommit to be for nil") } } else { if !bytes.Equal(vote.BlockID.Hash, votedBlockHash) { - panic("Expected precommit to be for proposal block") + t.Fatalf("Expected precommit to be for proposal block") } } if lockedBlockHash == nil { if cs.LockedRound != lockRound || cs.LockedBlock != nil { - panic(fmt.Sprintf( + t.Fatalf( "Expected to be locked on nil at round %d. Got locked at round %d with block %v", lockRound, cs.LockedRound, - cs.LockedBlock)) + cs.LockedBlock) } } else { if cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash) { - panic(fmt.Sprintf( + t.Fatalf( "Expected block to be locked on round %d, got %d. Got locked block %X, expected %X", lockRound, cs.LockedRound, cs.LockedBlock.Hash(), - lockedBlockHash)) + lockedBlockHash) } } } @@ -376,6 +375,7 @@ func validatePrevoteAndPrecommit( votedBlockHash, lockedBlockHash []byte, ) { + t.Helper() // verify the prevote validatePrevote(ctx, t, cs, thisRound, privVal, votedBlockHash) // verify precommit @@ -479,13 +479,14 @@ func newStateWithConfigAndBlockStore( return cs } -func loadPrivValidator(cfg *config.Config) *privval.FilePV { - privValidatorKeyFile := cfg.PrivValidator.KeyFile() - ensureDir(filepath.Dir(privValidatorKeyFile), 0700) - privValidatorStateFile := cfg.PrivValidator.StateFile() +func loadPrivValidator(t *testing.T, config *config.Config) *privval.FilePV { + t.Helper() + privValidatorKeyFile := config.PrivValidator.KeyFile() + ensureDir(t, filepath.Dir(privValidatorKeyFile), 0700) + privValidatorStateFile := config.PrivValidator.StateFile() privValidator, err := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile) if err != nil { - panic(err) + t.Fatalf("error generating validator file: %s", err) } privValidator.Reset() return privValidator @@ -518,220 +519,241 @@ func randState( //------------------------------------------------------------------------------- -func ensureNoNewEvent(ch <-chan tmpubsub.Message, timeout time.Duration, +func ensureNoNewEvent(t *testing.T, ch <-chan tmpubsub.Message, timeout time.Duration, errorMessage string) { + t.Helper() select { case <-time.After(timeout): break case <-ch: - panic(errorMessage) + t.Fatalf("unexpected event: %s", errorMessage) } } -func ensureNoNewEventOnChannel(ch <-chan tmpubsub.Message) { +func ensureNoNewEventOnChannel(t *testing.T, ch <-chan tmpubsub.Message) { + t.Helper() ensureNoNewEvent( + t, ch, ensureTimeout, "We should be stuck waiting, not receiving new event on the channel") } -func ensureNoNewRoundStep(stepCh <-chan tmpubsub.Message) { +func ensureNoNewRoundStep(t *testing.T, stepCh <-chan tmpubsub.Message) { + t.Helper() ensureNoNewEvent( + t, stepCh, ensureTimeout, "We should be stuck waiting, not receiving NewRoundStep event") } -func ensureNoNewUnlock(unlockCh <-chan tmpubsub.Message) { +func ensureNoNewUnlock(t *testing.T, unlockCh <-chan tmpubsub.Message) { + t.Helper() ensureNoNewEvent( + t, unlockCh, ensureTimeout, "We should be stuck waiting, not receiving Unlock event") } -func ensureNoNewTimeout(stepCh <-chan tmpubsub.Message, timeout int64) { +func ensureNoNewTimeout(t *testing.T, stepCh <-chan tmpubsub.Message, timeout int64) { + t.Helper() timeoutDuration := time.Duration(timeout*10) * time.Nanosecond ensureNoNewEvent( + t, stepCh, timeoutDuration, "We should be stuck waiting, not receiving NewTimeout event") } -func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int32, timeout time.Duration, errorMessage string) { +func ensureNewEvent(t *testing.T, ch <-chan tmpubsub.Message, height int64, round int32, timeout time.Duration, errorMessage string) { //nolint: lll + t.Helper() select { case <-time.After(timeout): - panic(errorMessage) + t.Fatalf("timed out waiting for new event: %s", errorMessage) case msg := <-ch: roundStateEvent, ok := msg.Data().(types.EventDataRoundState) if !ok { - panic(fmt.Sprintf("expected a EventDataRoundState, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataRoundState, got %T. Wrong subscription channel?", msg.Data()) } if roundStateEvent.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, roundStateEvent.Height)) + t.Fatalf("expected height %v, got %v", height, roundStateEvent.Height) } if roundStateEvent.Round != round { - panic(fmt.Sprintf("expected round %v, got %v", round, roundStateEvent.Round)) + t.Fatalf("expected round %v, got %v", round, roundStateEvent.Round) } // TODO: We could check also for a step at this point! } } -func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewRound(t *testing.T, roundCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewRound event") + t.Fatal("Timeout expired while waiting for NewRound event") case msg := <-roundCh: newRoundEvent, ok := msg.Data().(types.EventDataNewRound) if !ok { - panic(fmt.Sprintf("expected a EventDataNewRound, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataNewRound, got %T. Wrong subscription channel?", msg.Data()) } if newRoundEvent.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, newRoundEvent.Height)) + t.Fatalf("expected height %v, got %v", height, newRoundEvent.Height) } if newRoundEvent.Round != round { - panic(fmt.Sprintf("expected round %v, got %v", round, newRoundEvent.Round)) + t.Fatalf("expected round %v, got %v", round, newRoundEvent.Round) } } } -func ensureNewTimeout(timeoutCh <-chan tmpubsub.Message, height int64, round int32, timeout int64) { +func ensureNewTimeout(t *testing.T, timeoutCh <-chan tmpubsub.Message, height int64, round int32, timeout int64) { + t.Helper() timeoutDuration := time.Duration(timeout*10) * time.Nanosecond - ensureNewEvent(timeoutCh, height, round, timeoutDuration, + ensureNewEvent(t, timeoutCh, height, round, timeoutDuration, "Timeout expired while waiting for NewTimeout event") } -func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewProposal(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewProposal event") + t.Fatalf("Timeout expired while waiting for NewProposal event") case msg := <-proposalCh: proposalEvent, ok := msg.Data().(types.EventDataCompleteProposal) if !ok { - panic(fmt.Sprintf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", + msg.Data()) } if proposalEvent.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, proposalEvent.Height)) + t.Fatalf("expected height %v, got %v", height, proposalEvent.Height) } if proposalEvent.Round != round { - panic(fmt.Sprintf("expected round %v, got %v", round, proposalEvent.Round)) + t.Fatalf("expected round %v, got %v", round, proposalEvent.Round) } } } -func ensureNewValidBlock(validBlockCh <-chan tmpubsub.Message, height int64, round int32) { - ensureNewEvent(validBlockCh, height, round, ensureTimeout, +func ensureNewValidBlock(t *testing.T, validBlockCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() + ensureNewEvent(t, validBlockCh, height, round, ensureTimeout, "Timeout expired while waiting for NewValidBlock event") } -func ensureNewBlock(blockCh <-chan tmpubsub.Message, height int64) { +func ensureNewBlock(t *testing.T, blockCh <-chan tmpubsub.Message, height int64) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewBlock event") + t.Fatalf("Timeout expired while waiting for NewBlock event") case msg := <-blockCh: blockEvent, ok := msg.Data().(types.EventDataNewBlock) if !ok { - panic(fmt.Sprintf("expected a EventDataNewBlock, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataNewBlock, got %T. Wrong subscription channel?", + msg.Data()) } if blockEvent.Block.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, blockEvent.Block.Height)) + t.Fatalf("expected height %v, got %v", height, blockEvent.Block.Height) } } } -func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash tmbytes.HexBytes) { +func ensureNewBlockHeader(t *testing.T, blockCh <-chan tmpubsub.Message, height int64, blockHash tmbytes.HexBytes) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewBlockHeader event") + t.Fatalf("Timeout expired while waiting for NewBlockHeader event") case msg := <-blockCh: blockHeaderEvent, ok := msg.Data().(types.EventDataNewBlockHeader) if !ok { - panic(fmt.Sprintf("expected a EventDataNewBlockHeader, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataNewBlockHeader, got %T. Wrong subscription channel?", + msg.Data()) } if blockHeaderEvent.Header.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, blockHeaderEvent.Header.Height)) + t.Fatalf("expected height %v, got %v", height, blockHeaderEvent.Header.Height) } if !bytes.Equal(blockHeaderEvent.Header.Hash(), blockHash) { - panic(fmt.Sprintf("expected header %X, got %X", blockHash, blockHeaderEvent.Header.Hash())) + t.Fatalf("expected header %X, got %X", blockHash, blockHeaderEvent.Header.Hash()) } } } -func ensureNewUnlock(unlockCh <-chan tmpubsub.Message, height int64, round int32) { - ensureNewEvent(unlockCh, height, round, ensureTimeout, +func ensureNewUnlock(t *testing.T, unlockCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() + ensureNewEvent(t, unlockCh, height, round, ensureTimeout, "Timeout expired while waiting for NewUnlock event") } -func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) { +func ensureProposal(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewProposal event") + t.Fatalf("Timeout expired while waiting for NewProposal event") case msg := <-proposalCh: proposalEvent, ok := msg.Data().(types.EventDataCompleteProposal) if !ok { - panic(fmt.Sprintf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", + msg.Data()) } if proposalEvent.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, proposalEvent.Height)) + t.Fatalf("expected height %v, got %v", height, proposalEvent.Height) } if proposalEvent.Round != round { - panic(fmt.Sprintf("expected round %v, got %v", round, proposalEvent.Round)) + t.Fatalf("expected round %v, got %v", round, proposalEvent.Round) } if !proposalEvent.BlockID.Equals(propID) { - panic(fmt.Sprintf("Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID)) + t.Fatalf("Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID) } } } -func ensurePrecommit(voteCh <-chan tmpubsub.Message, height int64, round int32) { - ensureVote(voteCh, height, round, tmproto.PrecommitType) +func ensurePrecommit(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() + ensureVote(t, voteCh, height, round, tmproto.PrecommitType) } -func ensurePrevote(voteCh <-chan tmpubsub.Message, height int64, round int32) { - ensureVote(voteCh, height, round, tmproto.PrevoteType) +func ensurePrevote(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32) { + t.Helper() + ensureVote(t, voteCh, height, round, tmproto.PrevoteType) } -func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int32, +func ensureVote(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, voteType tmproto.SignedMsgType) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for NewVote event") + t.Fatalf("Timeout expired while waiting for NewVote event") case msg := <-voteCh: voteEvent, ok := msg.Data().(types.EventDataVote) if !ok { - panic(fmt.Sprintf("expected a EventDataVote, got %T. Wrong subscription channel?", - msg.Data())) + t.Fatalf("expected a EventDataVote, got %T. Wrong subscription channel?", + msg.Data()) } vote := voteEvent.Vote if vote.Height != height { - panic(fmt.Sprintf("expected height %v, got %v", height, vote.Height)) + t.Fatalf("expected height %v, got %v", height, vote.Height) } if vote.Round != round { - panic(fmt.Sprintf("expected round %v, got %v", round, vote.Round)) + t.Fatalf("expected round %v, got %v", round, vote.Round) } if vote.Type != voteType { - panic(fmt.Sprintf("expected type %v, got %v", voteType, vote.Type)) + t.Fatalf("expected type %v, got %v", voteType, vote.Type) } } } -func ensurePrecommitTimeout(ch <-chan tmpubsub.Message) { +func ensurePrecommitTimeout(t *testing.T, ch <-chan tmpubsub.Message) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for the Precommit to Timeout") + t.Fatalf("Timeout expired while waiting for the Precommit to Timeout") case <-ch: } } -func ensureNewEventOnChannel(ch <-chan tmpubsub.Message) { +func ensureNewEventOnChannel(t *testing.T, ch <-chan tmpubsub.Message) { + t.Helper() select { case <-time.After(ensureTimeout): - panic("Timeout expired while waiting for new activity on the channel") + t.Fatalf("Timeout expired while waiting for new activity on the channel") case <-ch: } } @@ -755,6 +777,7 @@ func randConsensusState( appFunc func() abci.Application, configOpts ...func(*config.Config), ) ([]*State, cleanupFunc) { + t.Helper() genDoc, privVals := factory.RandGenesisDoc(cfg, nValidators, false, 30) css := make([]*State, nValidators) @@ -777,7 +800,7 @@ func randConsensusState( opt(thisConfig) } - ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal + ensureDir(t, filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal app := appFunc() @@ -806,6 +829,7 @@ func randConsensusState( // nPeers = nValidators + nNotValidator func randConsensusNetWithPeers( ctx context.Context, + t *testing.T, cfg *config.Config, nValidators, nPeers int, @@ -815,6 +839,7 @@ func randConsensusNetWithPeers( ) ([]*State, *types.GenesisDoc, *config.Config, cleanupFunc) { genDoc, privVals := factory.RandGenesisDoc(cfg, nValidators, false, testMinPower) css := make([]*State, nPeers) + t.Helper() logger := consensusLogger() var peer0Config *config.Config @@ -827,7 +852,7 @@ func randConsensusNetWithPeers( } configRootDirs = append(configRootDirs, thisConfig.RootDir) - ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal + ensureDir(t, filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal if i == 0 { peer0Config = thisConfig } @@ -837,16 +862,16 @@ func randConsensusNetWithPeers( } else { tempKeyFile, err := os.CreateTemp("", "priv_validator_key_") if err != nil { - panic(err) + t.Fatalf("error creating temp file for validator key: %s", err) } tempStateFile, err := os.CreateTemp("", "priv_validator_state_") if err != nil { - panic(err) + t.Fatalf("error loading validator state: %s", err) } privVal, err = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "") if err != nil { - panic(err) + t.Fatalf("error generating validator key: %s", err) } } diff --git a/internal/consensus/mempool_test.go b/internal/consensus/mempool_test.go index e24cb1160..4282bae94 100644 --- a/internal/consensus/mempool_test.go +++ b/internal/consensus/mempool_test.go @@ -44,12 +44,12 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) { newBlockCh := subscribe(ctx, t, cs.eventBus, types.EventQueryNewBlock) startTestRound(ctx, cs, height, round) - ensureNewEventOnChannel(newBlockCh) // first block gets committed - ensureNoNewEventOnChannel(newBlockCh) + ensureNewEventOnChannel(t, newBlockCh) // first block gets committed + ensureNoNewEventOnChannel(t, newBlockCh) deliverTxsRange(ctx, cs, 0, 1) - ensureNewEventOnChannel(newBlockCh) // commit txs - ensureNewEventOnChannel(newBlockCh) // commit updated app hash - ensureNoNewEventOnChannel(newBlockCh) + ensureNewEventOnChannel(t, newBlockCh) // commit txs + ensureNewEventOnChannel(t, newBlockCh) // commit updated app hash + ensureNoNewEventOnChannel(t, newBlockCh) } func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { @@ -70,9 +70,9 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { newBlockCh := subscribe(ctx, t, cs.eventBus, types.EventQueryNewBlock) startTestRound(ctx, cs, cs.Height, cs.Round) - ensureNewEventOnChannel(newBlockCh) // first block gets committed - ensureNoNewEventOnChannel(newBlockCh) // then we dont make a block ... - ensureNewEventOnChannel(newBlockCh) // until the CreateEmptyBlocksInterval has passed + ensureNewEventOnChannel(t, newBlockCh) // first block gets committed + ensureNoNewEventOnChannel(t, newBlockCh) // then we dont make a block ... + ensureNewEventOnChannel(t, newBlockCh) // until the CreateEmptyBlocksInterval has passed } func TestMempoolProgressInHigherRound(t *testing.T) { @@ -103,19 +103,19 @@ func TestMempoolProgressInHigherRound(t *testing.T) { } startTestRound(ctx, cs, height, round) - ensureNewRound(newRoundCh, height, round) // first round at first height - ensureNewEventOnChannel(newBlockCh) // first block gets committed + ensureNewRound(t, newRoundCh, height, round) // first round at first height + ensureNewEventOnChannel(t, newBlockCh) // first block gets committed height++ // moving to the next height round = 0 - ensureNewRound(newRoundCh, height, round) // first round at next height - deliverTxsRange(ctx, cs, 0, 1) // we deliver txs, but dont set a proposal so we get the next round - ensureNewTimeout(timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds()) + ensureNewRound(t, newRoundCh, height, round) // first round at next height + deliverTxsRange(ctx, cs, 0, 1) // we deliver txs, but dont set a proposal so we get the next round + ensureNewTimeout(t, timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds()) - round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) // wait for the next round - ensureNewEventOnChannel(newBlockCh) // now we can commit the block + round++ // moving to the next round + ensureNewRound(t, newRoundCh, height, round) // wait for the next round + ensureNewEventOnChannel(t, newBlockCh) // now we can commit the block } func deliverTxsRange(ctx context.Context, cs *State, start, end int) { diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index de6465f23..190aa9a30 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -382,7 +382,7 @@ func TestReactorWithEvidence(t *testing.T) { defer os.RemoveAll(thisConfig.RootDir) - ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal + ensureDir(t, path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal app := appFunc() vals := types.TM2PB.ValidatorUpdates(state.Validators) app.InitChain(abci.RequestInitChain{Validators: vals}) @@ -703,6 +703,7 @@ func TestReactorValidatorSetChanges(t *testing.T) { nVals := 4 states, _, _, cleanup := randConsensusNetWithPeers( ctx, + t, cfg, nVals, nPeers, diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index bf1927742..566f849dc 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -61,7 +61,7 @@ func startNewStateAndWaitForBlock(ctx context.Context, t *testing.T, consensusRe logger := log.TestingLogger() state, err := sm.MakeGenesisStateFromFile(consensusReplayConfig.GenesisFile()) require.NoError(t, err) - privValidator := loadPrivValidator(consensusReplayConfig) + privValidator := loadPrivValidator(t, consensusReplayConfig) blockStore := store.NewBlockStore(dbm.NewMemDB()) cs := newStateWithConfigAndBlockStore( ctx, @@ -166,7 +166,7 @@ LOOP: blockStore := store.NewBlockStore(blockDB) state, err := sm.MakeGenesisStateFromFile(consensusReplayConfig.GenesisFile()) require.NoError(t, err) - privValidator := loadPrivValidator(consensusReplayConfig) + privValidator := loadPrivValidator(t, consensusReplayConfig) cs := newStateWithConfigAndBlockStore( ctx, logger, @@ -335,6 +335,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { css, genDoc, cfg, cleanup := randConsensusNetWithPeers( ctx, + t, cfg, nVals, nPeers, @@ -359,15 +360,15 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { // start the machine startTestRound(ctx, css[0], height, round) incrementHeight(vss...) - ensureNewRound(newRoundCh, height, 0) - ensureNewProposal(proposalCh, height, round) + ensureNewRound(t, newRoundCh, height, 0) + ensureNewProposal(t, proposalCh, height, round) rs := css[0].GetRoundState() signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) // HEIGHT 2 height++ @@ -394,12 +395,12 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) // HEIGHT 3 height++ @@ -426,12 +427,12 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) // HEIGHT 4 height++ @@ -485,7 +486,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0) err = assertMempool(css[0].txNotifier).CheckTx(ctx, removeValidatorTx2, nil, mempool.TxInfo{}) @@ -501,7 +502,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { rs.ProposalBlockParts.Header(), newVss[i]) } - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) // HEIGHT 5 height++ @@ -511,7 +512,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { newVss[newVssIdx].VotingPower = 25 sort.Sort(ValidatorStubsByPower(newVss)) selfIndex = valIndexFn(0) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() for i := 0; i < nVals+1; i++ { if i == selfIndex { @@ -521,7 +522,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) } - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) // HEIGHT 6 height++ @@ -548,7 +549,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() for i := 0; i < nVals+3; i++ { if i == selfIndex { @@ -558,7 +559,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) } - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) sim.Chain = make([]*types.Block, 0) sim.Commits = make([]*types.Commit, 0) diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index 9216577d5..aa2b35cca 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -71,7 +71,7 @@ func TestStateProposerSelection0(t *testing.T) { startTestRound(ctx, cs1, height, round) // Wait for new round so proposer is set. - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) // Commit a block and ensure proposer for the next height is correct. prop := cs1.GetRoundState().Validators.GetProposer() @@ -83,7 +83,7 @@ func TestStateProposerSelection0(t *testing.T) { } // Wait for complete proposal. - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() signAddVotes( @@ -97,7 +97,7 @@ func TestStateProposerSelection0(t *testing.T) { ) // Wait for new round so next validator is set. - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) prop = cs1.GetRoundState().Validators.GetProposer() pv1, err := vss[1].GetPubKey(ctx) @@ -128,7 +128,7 @@ func TestStateProposerSelection2(t *testing.T) { var round int32 = 2 startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) // wait for the new round + ensureNewRound(t, newRoundCh, height, round) // wait for the new round // everyone just votes nil. we get a new proposer each round for i := int32(0); int(i) < len(vss); i++ { @@ -146,7 +146,7 @@ func TestStateProposerSelection2(t *testing.T) { rs := cs1.GetRoundState() signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...) - ensureNewRound(newRoundCh, height, i+round+1) // wait for the new round event each round + ensureNewRound(t, newRoundCh, height, i+round+1) // wait for the new round event each round incrementRound(vss[1:]...) } @@ -169,7 +169,7 @@ func TestStateEnterProposeNoPrivValidator(t *testing.T) { startTestRound(ctx, cs, height, round) // if we're not a validator, EnterPropose should timeout - ensureNewTimeout(timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds()) + ensureNewTimeout(t, timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds()) if cs.GetRoundState().Proposal != nil { t.Error("Expected to make no proposal, since no privValidator") @@ -194,7 +194,7 @@ func TestStateEnterProposeYesPrivValidator(t *testing.T) { cs.enterNewRound(height, round) cs.startRoutines(ctx, 3) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) // Check that Proposal, ProposalBlock, ProposalBlockParts are set. rs := cs.GetRoundState() @@ -209,7 +209,7 @@ func TestStateEnterProposeYesPrivValidator(t *testing.T) { } // if we're a validator, enterPropose should not timeout - ensureNoNewTimeout(timeoutCh, cs.config.TimeoutPropose.Nanoseconds()) + ensureNoNewTimeout(t, timeoutCh, cs.config.TimeoutPropose.Nanoseconds()) } func TestStateBadProposal(t *testing.T) { @@ -259,18 +259,18 @@ func TestStateBadProposal(t *testing.T) { startTestRound(ctx, cs1, height, round) // wait for proposal - ensureProposal(proposalCh, height, round, blockID) + ensureProposal(t, proposalCh, height, round, blockID) // wait for prevote - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) // add bad prevote from vs2 and wait for it signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) // wait for precommit - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) } @@ -325,15 +325,15 @@ func TestStateOversizedBlock(t *testing.T) { // c1 should log an error with the block part message as it exceeds the consensus params. The // block is not added to cs.ProposalBlock so the node timeouts. - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) // and then should send nil prevote and precommit regardless of whether other validators prevote and // precommit on it - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) - ensurePrevote(voteCh, height, round) - ensurePrecommit(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) } @@ -371,18 +371,18 @@ func TestStateFullRound1(t *testing.T) { // Maybe it would be better to call explicitly startRoutines(4) startTestRound(ctx, cs, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(propCh, height, round) + ensureNewProposal(t, propCh, height, round) propBlockHash := cs.GetRoundState().ProposalBlock.Hash() - ensurePrevote(voteCh, height, round) // wait for prevote + ensurePrevote(t, voteCh, height, round) // wait for prevote validatePrevote(ctx, t, cs, round, vss[0], propBlockHash) - ensurePrecommit(voteCh, height, round) // wait for precommit + ensurePrecommit(t, voteCh, height, round) // wait for precommit // we're going to roll right into new height - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) validateLastPrecommit(ctx, t, cs, vss[0], propBlockHash) } @@ -402,8 +402,8 @@ func TestStateFullRoundNil(t *testing.T) { cs.enterPrevote(height, round) cs.startRoutines(ctx, 4) - ensurePrevote(voteCh, height, round) // prevote - ensurePrecommit(voteCh, height, round) // precommit + ensurePrevote(t, voteCh, height, round) // prevote + ensurePrecommit(t, voteCh, height, round) // precommit // should prevote and precommit nil validatePrevoteAndPrecommit(ctx, t, cs, round, -1, vss[0], nil, nil) @@ -427,7 +427,7 @@ func TestStateFullRound2(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote // we should be stuck in limbo waiting for more prevotes rs := cs1.GetRoundState() @@ -435,9 +435,9 @@ func TestStateFullRound2(t *testing.T) { // prevote arrives from vs2: signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propPartSetHeader, vs2) - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote - ensurePrecommit(voteCh, height, round) // precommit + ensurePrecommit(t, voteCh, height, round) // precommit // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, 0, 0, vss[0], propBlockHash, propBlockHash) @@ -445,10 +445,10 @@ func TestStateFullRound2(t *testing.T) { // precommit arrives from vs2: signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propPartSetHeader, vs2) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // wait to finish commit, propose in next height - ensureNewBlock(newBlockCh, height) + ensureNewBlock(t, newBlockCh, height) } //------------------------------------------------------------------------------------------ @@ -482,21 +482,21 @@ func TestStateLockNoPOL(t *testing.T) { cs1.enterNewRound(height, round) cs1.startRoutines(ctx, 0) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) roundState := cs1.GetRoundState() theBlockHash := roundState.ProposalBlock.Hash() thePartSetHeader := roundState.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote // we should now be stuck in limbo forever, waiting for more prevotes // prevote arrives from vs2: signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, thePartSetHeader, vs2) - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote - ensurePrecommit(voteCh, height, round) // precommit + ensurePrecommit(t, voteCh, height, round) // precommit // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) @@ -506,16 +506,16 @@ func TestStateLockNoPOL(t *testing.T) { copy(hash, theBlockHash) hash[0] = (hash[0] + 1) % 255 signAddVotes(ctx, config, cs1, tmproto.PrecommitType, hash, thePartSetHeader, vs2) - ensurePrecommit(voteCh, height, round) // precommit + ensurePrecommit(t, voteCh, height, round) // precommit // (note we're entering precommit for a second time this round) // but with invalid args. then we enterPrecommitWait, and the timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) /// round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("#### ONTO ROUND 1") /* Round2 (cs1, B) // B B2 @@ -524,7 +524,7 @@ func TestStateLockNoPOL(t *testing.T) { incrementRound(vs2) // now we're on a new round and not the proposer, so wait for timeout - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) rs := cs1.GetRoundState() @@ -533,33 +533,33 @@ func TestStateLockNoPOL(t *testing.T) { } // wait to finish prevote - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) // we should have prevoted our locked block validatePrevote(ctx, t, cs1, round, vss[0], rs.LockedBlock.Hash()) // add a conflicting prevote from the other validator signAddVotes(ctx, config, cs1, tmproto.PrevoteType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) // now we're going to enter prevote again, but with invalid args // and then prevote wait, which should timeout. then wait for precommit - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) - ensurePrecommit(voteCh, height, round) // precommit + ensurePrecommit(t, voteCh, height, round) // precommit // the proposed block should still be locked and our precommit added // we should precommit nil and be locked on the proposal validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) // add conflicting precommit from vs2 signAddVotes(ctx, config, cs1, tmproto.PrecommitType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // (note we're entering precommit for a second time this round, but with invalid args // then we enterPrecommitWait and timeout into NewRound - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // entering new round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("#### ONTO ROUND 2") /* Round3 (vs2, _) // B, B2 @@ -567,7 +567,7 @@ func TestStateLockNoPOL(t *testing.T) { incrementRound(vs2) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = cs1.GetRoundState() // now we're on a new round and are the proposer @@ -578,14 +578,14 @@ func TestStateLockNoPOL(t *testing.T) { rs.LockedBlock)) } - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote validatePrevote(ctx, t, cs1, round, vss[0], rs.LockedBlock.Hash()) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) - ensurePrecommit(voteCh, height, round) // precommit + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) + ensurePrecommit(t, voteCh, height, round) // precommit validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but be locked on proposal @@ -597,15 +597,15 @@ func TestStateLockNoPOL(t *testing.T) { hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) // needed so generated block is different than locked block cs2, _, err := randState(ctx, config, log.TestingLogger(), 2) require.NoError(t, err) // before we time out into new round, set next proposal block - prop, propBlock := decideProposal(ctx, cs2, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } @@ -613,7 +613,7 @@ func TestStateLockNoPOL(t *testing.T) { incrementRound(vs2) round++ // entering new round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("#### ONTO ROUND 3") /* Round4 (vs2, C) // B C // B C @@ -625,17 +625,17 @@ func TestStateLockNoPOL(t *testing.T) { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) - ensurePrevote(voteCh, height, round) // prevote + ensureNewProposal(t, proposalCh, height, round) + ensurePrevote(t, voteCh, height, round) // prevote // prevote for locked block (not proposal) validatePrevote(ctx, t, cs1, 3, vss[0], cs1.LockedBlock.Hash()) // prevote for proposed block signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) - ensurePrecommit(voteCh, height, round) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but locked on proposal signAddVotes( @@ -646,7 +646,7 @@ func TestStateLockNoPOL(t *testing.T) { propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) } // 4 vals in two rounds, @@ -687,17 +687,17 @@ func TestStateLockPOLRelock(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewRound(t, newRoundCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) // our precommit + ensurePrecommit(t, voteCh, height, round) // our precommit // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) @@ -708,7 +708,7 @@ func TestStateLockPOLRelock(t *testing.T) { cs2, err := newState(ctx, logger, cs1.state, vs2, kvstore.NewApplication()) require.NoError(t, err) - prop, propBlock := decideProposal(ctx, cs2, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } @@ -719,7 +719,7 @@ func TestStateLockPOLRelock(t *testing.T) { incrementRound(vs2, vs3, vs4) // timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round //XXX: this isnt guaranteed to get there before the timeoutPropose ... @@ -727,7 +727,7 @@ func TestStateLockPOLRelock(t *testing.T) { t.Fatal(err) } - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 1") /* @@ -738,24 +738,24 @@ func TestStateLockPOLRelock(t *testing.T) { // now we're on a new round and not the proposer // but we should receive the proposal - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) // go to prevote, node should prevote for locked block (not the new proposal) - this is relocking - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) // now lets add prevotes from everyone else for the new block signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have unlocked and locked on the new block, sending a precommit for this new block validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash, propBlockHash) // more prevote creating a majority on the new block and this is then committed signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3) - ensureNewBlockHeader(newBlockCh, height, propBlockHash) + ensureNewBlockHeader(t, newBlockCh, height, propBlockHash) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) } // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka @@ -789,19 +789,19 @@ func TestStateLockPOLUnlock(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) @@ -810,18 +810,18 @@ func TestStateLockPOLUnlock(t *testing.T) { signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) // before we time out into new round, set next proposal block - prop, propBlock := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) propBlockParts := propBlock.MakePartSet(partSize) // timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) rs = cs1.GetRoundState() lockedBlockHash := rs.LockedBlock.Hash() incrementRound(vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("#### ONTO ROUND 1") /* Round2 (vs2, C) // B nil nil nil // nil nil nil _ @@ -832,24 +832,24 @@ func TestStateLockPOLUnlock(t *testing.T) { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) // go to prevote, prevote for locked block (not proposal) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], lockedBlockHash) // now lets add prevotes from everyone else for nil (a polka!) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // the polka makes us unlock and precommit nil - ensureNewUnlock(unlockCh, height, round) - ensurePrecommit(voteCh, height, round) + ensureNewUnlock(t, unlockCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have unlocked and committed nil // NOTE: since we don't relock on nil, the lock round is -1 validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3) - ensureNewRound(newRoundCh, height, round+1) + ensureNewRound(t, newRoundCh, height, round+1) } // 4 vals, v1 locks on proposed block in the first round but the other validators only prevote @@ -885,17 +885,17 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewRound(t, newRoundCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() firstBlockHash := rs.ProposalBlock.Hash() firstBlockParts := rs.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) // prevote + ensurePrevote(t, voteCh, height, round) // prevote signAddVotes(ctx, config, cs1, tmproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) // our precommit + ensurePrecommit(t, voteCh, height, round) // our precommit // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], firstBlockHash, firstBlockHash) @@ -905,7 +905,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { // before we timeout to the new round set the new proposal cs2, err := newState(ctx, logger, cs1.state, vs2, kvstore.NewApplication()) require.NoError(t, err) - prop, propBlock := decideProposal(ctx, cs2, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } @@ -916,11 +916,11 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { incrementRound(vs2, vs3, vs4) // timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 1") /* @@ -930,13 +930,13 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { // now we're on a new round but v1 misses the proposal // go to prevote, node should prevote for locked block (not the new proposal) - this is relocking - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], firstBlockHash) // now lets add prevotes from everyone else for the new block signAddVotes(ctx, config, cs1, tmproto.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have unlocked and locked on the new block, sending a precommit for this new block validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) @@ -950,7 +950,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { // before we timeout to the new round set the new proposal cs3, err := newState(ctx, logger, cs1.state, vs3, kvstore.NewApplication()) require.NoError(t, err) - prop, propBlock = decideProposal(ctx, cs3, vs3, vs3.Height, vs3.Round+1) + prop, propBlock = decideProposal(ctx, t, cs3, vs3, vs3.Height, vs3.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } @@ -961,10 +961,10 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { incrementRound(vs2, vs3, vs4) // timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 2") /* @@ -975,13 +975,13 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { t.Fatal(err) } - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) // we are no longer locked to the first block so we should be able to prevote validatePrevote(ctx, t, cs1, round, vss[0], thirdPropBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, thirdPropBlockHash, thirdPropBlockParts.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we have a majority, now vs1 can change lock to the third block validatePrecommit(ctx, t, cs1, round, round, vss[0], thirdPropBlockHash, thirdPropBlockHash) } @@ -1013,13 +1013,13 @@ func TestStateLockPOLSafety1(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlock.Hash()) // the others sign a polka but we don't see it @@ -1033,19 +1033,19 @@ func TestStateLockPOLSafety1(t *testing.T) { signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // cs1 precommit nil - ensurePrecommit(voteCh, height, round) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensurePrecommit(t, voteCh, height, round) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) t.Log("### ONTO ROUND 1") - prop, propBlock := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) incrementRound(vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) //XXX: this isnt guaranteed to get there before the timeoutPropose ... if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil { @@ -1056,7 +1056,7 @@ func TestStateLockPOLSafety1(t *testing.T) { // a polka happened but we didn't see it! */ - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = cs1.GetRoundState() @@ -1066,24 +1066,24 @@ func TestStateLockPOLSafety1(t *testing.T) { t.Logf("new prop hash %v", fmt.Sprintf("%X", propBlockHash)) // go to prevote, prevote for proposal block - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) // now we see the others prevote for it, so we should lock on it signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have precommitted validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash, propBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) incrementRound(vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 2") /*Round3 @@ -1091,10 +1091,10 @@ func TestStateLockPOLSafety1(t *testing.T) { */ // timeout of propose - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) // finish prevote - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) // we should prevote what we're locked on validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) @@ -1106,7 +1106,7 @@ func TestStateLockPOLSafety1(t *testing.T) { t.Log("Done adding prevotes!") - ensureNoNewRoundStep(newStepCh) + ensureNoNewRoundStep(t, newStepCh) } // 4 vals. @@ -1139,7 +1139,7 @@ func TestStateLockPOLSafety2(t *testing.T) { // the block for R0: gets polkad but we miss it // (even though we signed it, shhh) - _, propBlock0 := decideProposal(ctx, cs1, vss[0], height, round) + _, propBlock0 := decideProposal(ctx, t, cs1, vss[0], height, round) propBlockHash0 := propBlock0.Hash() propBlockParts0 := propBlock0.MakePartSet(partSize) propBlockID0 := types.BlockID{Hash: propBlockHash0, PartSetHeader: propBlockParts0.Header()} @@ -1148,7 +1148,7 @@ func TestStateLockPOLSafety2(t *testing.T) { prevotes := signVotes(ctx, config, tmproto.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4) // the block for round 1 - prop1, propBlock1 := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round+1) + prop1, propBlock1 := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) propBlockHash1 := propBlock1.Hash() propBlockParts1 := propBlock1.MakePartSet(partSize) @@ -1158,19 +1158,19 @@ func TestStateLockPOLSafety2(t *testing.T) { t.Log("### ONTO Round 1") // jump in at round 1 startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) if err := cs1.SetProposalAndBlock(prop1, propBlock1, propBlockParts1, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash1) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1) @@ -1181,7 +1181,7 @@ func TestStateLockPOLSafety2(t *testing.T) { incrementRound(vs2, vs3, vs4) // timeout of precommit wait to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round // in round 2 we see the polkad block from round 0 @@ -1200,15 +1200,15 @@ func TestStateLockPOLSafety2(t *testing.T) { // Add the pol votes addVotes(cs1, prevotes...) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO Round 2") /*Round2 // now we see the polka from round 1, but we shouldnt unlock */ - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) - ensureNoNewUnlock(unlockCh) - ensurePrevote(voteCh, height, round) + ensureNoNewUnlock(t, unlockCh) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash1) } @@ -1242,14 +1242,14 @@ func TestProposeValidBlock(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock propBlockHash := propBlock.Hash() - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) // the others sign a polka @@ -1257,32 +1257,32 @@ func TestProposeValidBlock(t *testing.T) { propBlockHash, propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have precommitted validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash, propBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) incrementRound(vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 2") // timeout of propose - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) - ensureNewUnlock(unlockCh, height, round) + ensureNewUnlock(t, unlockCh, height, round) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have precommitted validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) @@ -1293,18 +1293,18 @@ func TestProposeValidBlock(t *testing.T) { round += 2 // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 3") - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) t.Log("### ONTO ROUND 4") - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs = cs1.GetRoundState() assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), propBlockHash)) @@ -1338,15 +1338,15 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) // vs2 send prevote for propBlock @@ -1355,9 +1355,9 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { // vs3 send prevote nil signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs3) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // we should have precommitted validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) @@ -1370,7 +1370,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { // vs2 send (delayed) prevote for propBlock signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs4) - ensureNewValidBlock(validBlockCh, height, round) + ensureNewValidBlock(t, validBlockCh, height, round) rs = cs1.GetRoundState() @@ -1408,31 +1408,31 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) { incrementRound(vs2, vs3, vs4) startTestRound(ctx, cs1, cs1.Height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) - prop, propBlock := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round+1) + prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) // vs2, vs3 and vs4 send prevote for propBlock signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) - ensureNewValidBlock(validBlockCh, height, round) + ensureNewValidBlock(t, validBlockCh, height, round) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash)) @@ -1459,12 +1459,12 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) { // start round startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) - ensureNewRound(newRoundCh, height, round+1) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewRound(t, newRoundCh, height, round+1) } // 4 vals, 3 Prevotes for nil from the higher round. @@ -1489,22 +1489,22 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) { // start round startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) incrementRound(vss[1:]...) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) rs := cs1.GetRoundState() assert.True(t, rs.Step == cstypes.RoundStepPropose) // P0 does not prevote before timeoutPropose expires - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Propose(round).Nanoseconds()) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) } @@ -1530,23 +1530,23 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) { // start round startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) incrementRound(vss[1:]...) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) } // 4 vals, 3 Prevotes for nil in the current round. @@ -1571,14 +1571,14 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) { // start round in which PO is not proposer startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) incrementRound(vss[1:]...) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) - ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) } @@ -1601,17 +1601,17 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) { newRoundCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryNewRound) validBlockCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryValidBlock) - _, propBlock := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round) + _, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round) propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) // start round in which PO is not proposer startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) - ensureNewValidBlock(validBlockCh, height, round) + ensureNewValidBlock(t, validBlockCh, height, round) rs := cs1.GetRoundState() assert.True(t, rs.Step == cstypes.RoundStepCommit) @@ -1639,18 +1639,18 @@ func TestCommitFromPreviousRound(t *testing.T) { validBlockCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryValidBlock) proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) - prop, propBlock := decideProposal(ctx, cs1, vs2, vs2.Height, vs2.Round) + prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round) propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) // start round in which PO is not proposer startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock for the previous round signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) - ensureNewValidBlock(validBlockCh, height, round) + ensureNewValidBlock(t, validBlockCh, height, round) rs := cs1.GetRoundState() assert.True(t, rs.Step == cstypes.RoundStepCommit) @@ -1662,8 +1662,8 @@ func TestCommitFromPreviousRound(t *testing.T) { t.Fatal(err) } - ensureNewProposal(proposalCh, height, round) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewProposal(t, proposalCh, height, round) + ensureNewRound(t, newRoundCh, height+1, 0) } type fakeTxNotifier struct { @@ -1707,19 +1707,19 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) @@ -1728,18 +1728,18 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) // wait till timeout occurs - ensurePrecommitTimeout(precommitTimeoutCh) + ensurePrecommitTimeout(t, precommitTimeoutCh) - ensureNewRound(newRoundCh, height, round+1) + ensureNewRound(t, newRoundCh, height, round+1) // majority is now reached signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) - ensureNewBlockHeader(newBlockHeader, height, theBlockHash) + ensureNewBlockHeader(t, newBlockHeader, height, theBlockHash) cs1.txNotifier.(*fakeTxNotifier).Notify() - ensureNewTimeout(timeoutProposeCh, height+1, round, cs1.config.Propose(round).Nanoseconds()) + ensureNewTimeout(t, timeoutProposeCh, height+1, round, cs1.config.Propose(round).Nanoseconds()) rs = cs1.GetRoundState() assert.False( t, @@ -1772,19 +1772,19 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts.Header() - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) // add precommits @@ -1792,15 +1792,15 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) { signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) - ensureNewBlockHeader(newBlockHeader, height, theBlockHash) + ensureNewBlockHeader(t, newBlockHeader, height, theBlockHash) - prop, propBlock := decideProposal(ctx, cs1, vs2, height+1, 0) + prop, propBlock := decideProposal(ctx, t, cs1, vs2, height+1, 0) propBlockParts := propBlock.MakePartSet(partSize) if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil { t.Fatal(err) } - ensureNewProposal(proposalCh, height+1, 0) + ensureNewProposal(t, proposalCh, height+1, 0) rs = cs1.GetRoundState() assert.False( @@ -1825,7 +1825,7 @@ func TestStateSlashingPrevotes(t *testing.T) { voteCh := subscribeToVoter(ctx, t, cs1, cs1.privValidator.GetAddress()) // start round and wait for propose and prevote - startTestRound(cs1, cs1.Height, 0) + startTestRound(ctx, cs1, cs1.Height, 0) <-newRoundCh re := <-proposalCh <-voteCh // prevote @@ -1860,7 +1860,7 @@ func TestStateSlashingPrecommits(t *testing.T) { voteCh := subscribeToVoter(ctx, t, cs1, cs1.privValidator.GetAddress()) // start round and wait for propose and prevote - startTestRound(cs1, cs1.Height, 0) + startTestRound(ctx, cs1, cs1.Height, 0) <-newRoundCh re := <-proposalCh <-voteCh // prevote @@ -1916,18 +1916,18 @@ func TestStateHalt1(t *testing.T) { // start round and wait for propose and prevote startTestRound(ctx, cs1, height, round) - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) - ensureNewProposal(proposalCh, height, round) + ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock propBlockParts := propBlock.MakePartSet(partSize) - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4) - ensurePrecommit(voteCh, height, round) + ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash()) @@ -1940,11 +1940,11 @@ func TestStateHalt1(t *testing.T) { incrementRound(vs2, vs3, vs4) // timeout to new round - ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) + ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) round++ // moving to the next round - ensureNewRound(newRoundCh, height, round) + ensureNewRound(t, newRoundCh, height, round) rs = cs1.GetRoundState() t.Log("### ONTO ROUND 1") @@ -1954,16 +1954,16 @@ func TestStateHalt1(t *testing.T) { */ // go to prevote, prevote for locked block - ensurePrevote(voteCh, height, round) + ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], rs.LockedBlock.Hash()) // now we receive the precommit from the previous round addVotes(cs1, precommit4) // receiving that precommit should take us straight to commit - ensureNewBlock(newBlockCh, height) + ensureNewBlock(t, newBlockCh, height) - ensureNewRound(newRoundCh, height+1, 0) + ensureNewRound(t, newRoundCh, height+1, 0) } func TestStateOutputsBlockPartsStats(t *testing.T) {