Skip to content

Commit

Permalink
b.helper()
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 30, 2023
1 parent 52feef8 commit ba108c6
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ issues:
- goimports
- govet
- stylecheck
max-same-issues: 50
max-same-issues: 500

linters-settings:
dogsled:
Expand Down
2 changes: 2 additions & 0 deletions internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3094,12 +3094,14 @@ func signAddPrecommitWithExtension(
extension []byte,
stub *validatorStub,
) {
t.Helper()
v, err := stub.signVote(types.PrecommitType, hash, header, extension, true)
require.NoError(t, err, "failed to sign vote")
addVotes(cs, v)
}

func findBlockSizeLimit(t *testing.T, height, maxBytes int64, cs *State, partSize uint32, oversized bool) (*types.Block, *types.PartSet) {
t.Helper()
var offset int64
if !oversized {
offset = -2
Expand Down
2 changes: 2 additions & 0 deletions internal/consensus/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"os"
"path/filepath"

// "sync".
"testing"
"time"
Expand Down Expand Up @@ -237,6 +238,7 @@ func nBytes(n int) []byte {
}

func benchmarkWalDecode(b *testing.B, n int) {
b.Helper()
// registerInterfacesOnce()

buf := new(bytes.Buffer)
Expand Down
1 change: 1 addition & 0 deletions internal/rand/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func BenchmarkRandBytes1MiB(b *testing.B) {
}

func benchmarkRandBytes(b *testing.B, n int) {
b.Helper()
for i := 0; i < b.N; i++ {
_ = Bytes(n)
}
Expand Down
3 changes: 3 additions & 0 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func ensureNoFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
}

func ensureFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
t.Helper()
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
select {
case <-ch:
Expand All @@ -97,6 +98,7 @@ func ensureFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {

// Call CheckTx on a given mempool on each transaction in the list.
func callCheckTx(t *testing.T, mp Mempool, txs types.Txs) {
t.Helper()
for i, tx := range txs {
if _, err := mp.CheckTx(tx); err != nil {
// Skip invalid txs.
Expand All @@ -123,6 +125,7 @@ func NewRandomTxs(numTxs int, txLen int) types.Txs {
// Generate a list of random transactions of a given size and call CheckTx on
// each of them.
func checkTxs(t *testing.T, mp Mempool, count int) types.Txs {
t.Helper()
txs := NewRandomTxs(count, 20)
callCheckTx(t, mp, txs)
return txs
Expand Down
6 changes: 6 additions & 0 deletions mempool/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ func TestMempoolReactorMaxActiveOutboundConnectionsStar(t *testing.T) {
// Check that the mempool has exactly the given list of txs and, if it's not the
// first reactor (reactorIndex == 0), then each tx has a non-empty list of senders.
func checkTxsInMempoolAndSenders(t *testing.T, r *Reactor, txs types.Txs, reactorIndex int) {
t.Helper()
r.txSendersMtx.Lock()
defer r.txSendersMtx.Unlock()

Expand Down Expand Up @@ -602,6 +603,7 @@ func newUniqueTxs(n int) types.Txs {
// Wait for all reactors to finish applying a testing function to a list of
// transactions.
func waitForReactors(t *testing.T, txs types.Txs, reactors []*Reactor, testFunc func(*testing.T, types.Txs, *Reactor, int)) {
t.Helper()
wg := new(sync.WaitGroup)
for i, reactor := range reactors {
wg.Add(1)
Expand Down Expand Up @@ -635,6 +637,7 @@ func waitForNumTxsInMempool(numTxs int, mempool Mempool) {
// Wait until all txs are in the mempool and check that the number of txs in the
// mempool is as expected.
func checkTxsInMempool(t *testing.T, txs types.Txs, reactor *Reactor, _ int) {
t.Helper()
waitForNumTxsInMempool(len(txs), reactor.mempool)

reapedTxs := reactor.mempool.ReapMaxTxs(len(txs))
Expand All @@ -645,6 +648,7 @@ func checkTxsInMempool(t *testing.T, txs types.Txs, reactor *Reactor, _ int) {
// Wait until all txs are in the mempool and check that they are in the same
// order as given.
func checkTxsInOrder(t *testing.T, txs types.Txs, reactor *Reactor, reactorIndex int) {
t.Helper()
waitForNumTxsInMempool(len(txs), reactor.mempool)

// Check that all transactions in the mempool are in the same order as txs.
Expand All @@ -656,6 +660,7 @@ func checkTxsInOrder(t *testing.T, txs types.Txs, reactor *Reactor, reactorIndex
}

func updateMempool(t *testing.T, mp Mempool, validTxs types.Txs, invalidTxs types.Txs) {
t.Helper()
allTxs := append(validTxs, invalidTxs...)

validTxResponses := abciResponses(len(validTxs), abci.CodeTypeOK)
Expand All @@ -671,6 +676,7 @@ func updateMempool(t *testing.T, mp Mempool, validTxs types.Txs, invalidTxs type

// ensure no txs on reactor after some timeout.
func ensureNoTxs(t *testing.T, reactor *Reactor, timeout time.Duration) {
t.Helper()
time.Sleep(timeout) // wait for the txs in all mempools
assert.Zero(t, reactor.mempool.Size())
}
Expand Down
1 change: 1 addition & 0 deletions p2p/conn/secret_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ func makeKVStoreConnPair() (fooConn, barConn kvstoreConn) {
}

func makeSecretConnPair(tb testing.TB) (fooSecConn, barSecConn *SecretConnection) {
tb.Helper()
var (
fooConn, barConn = makeKVStoreConnPair()
fooPrvKey = ed25519.GenPrivKey()
Expand Down
1 change: 1 addition & 0 deletions types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestEvidenceList(t *testing.T) {
}

func randomDuplicateVoteEvidence(t *testing.T) *DuplicateVoteEvidence {
t.Helper()
val := NewMockPV()
blockID := makeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := makeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))
Expand Down
2 changes: 2 additions & 0 deletions types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestTxProofUnchangable(t *testing.T) {
}

func testTxProofUnchangable(t *testing.T) {
t.Helper()
// make some proof
txs := makeTxs(randInt(2, 100), randInt(16, 128))
root := txs.Hash()
Expand All @@ -124,6 +125,7 @@ func testTxProofUnchangable(t *testing.T) {

// assertBadProof makes sure that the proof doesn't deserialize into something valid.
func assertBadProof(t *testing.T, root []byte, bad []byte, good TxProof) {
t.Helper()
var (
proof TxProof
pbProof cmtproto.TxProof
Expand Down
1 change: 1 addition & 0 deletions types/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
tc := tc
countAllSignatures := false
f := func(t *testing.T) {
t.Helper()
_, valSet, vals := randVoteSet(tc.height, round, PrecommitType, tc.valSize, 10, false)
totalVotes := tc.blockVotes + tc.absentVotes + tc.nilVotes
sigs := make([]CommitSig, totalVotes)
Expand Down
4 changes: 4 additions & 0 deletions types/validator_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ func valSetTotalProposerPriority(valSet *ValidatorSet) int64 {
}

func verifyValidatorSet(t *testing.T, valSet *ValidatorSet) {
t.Helper()
// verify that the capacity and length of validators is the same
assert.Equal(t, len(valSet.Validators), cap(valSet.Validators))

Expand Down Expand Up @@ -839,6 +840,7 @@ type valSetErrTestCase struct {
}

func executeValSetErrTestCase(t *testing.T, idx int, tt valSetErrTestCase) {
t.Helper()
// create a new set and apply updates, keeping copies for the checks
valSet := createNewValidatorSet(tt.startVals)
valSetCopy := valSet.Copy()
Expand Down Expand Up @@ -1226,6 +1228,7 @@ func randTestVSetCfg(nBase, nAddMax int) testVSetCfg {
}

func applyChangesToValSet(t *testing.T, expErr error, valSet *ValidatorSet, valsLists ...[]testVal) {
t.Helper()
changes := make([]testVal, 0)
for _, valsList := range valsLists {
changes = append(changes, valsList...)
Expand Down Expand Up @@ -1290,6 +1293,7 @@ func TestValSetUpdatePriorityOrderTests(t *testing.T) {
}

func verifyValSetUpdatePriorityOrder(t *testing.T, valSet *ValidatorSet, cfg testVSetCfg, nMaxElections int32) {
t.Helper()
// Run election up to nMaxElections times, sort validators by priorities
valSet.IncrementProposerPriority(cmtrand.Int31()%nMaxElections + 1)

Expand Down

0 comments on commit ba108c6

Please sign in to comment.