Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: enable staticcheck for test code and fix issues #5401

Merged
merged 3 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ issues:
# - nilerr
- nolintlint
# - revive
- staticcheck
# - staticcheck
- typecheck
- path: _test\.go
linters:
- staticcheck
text: "SA4006: this value" # of X is never used
# Ignore missing parallel tests in existing packages
- path: ^agreement.*_test\.go
linters:
Expand Down
4 changes: 2 additions & 2 deletions crypto/stateproof/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func BenchmarkBuildVerify(b *testing.B) {
data := testMessage("hello world").IntoStateProofMessageHash()

var parts []basics.Participant
var partkeys []*merklesignature.Secrets
//var partkeys []*merklesignature.Secrets
var sigs []merklesignature.Signature
for i := 0; i < npart; i++ {
signer := generateTestSigner(0, stateProofIntervalForTests+1, stateProofIntervalForTests, a)
Expand All @@ -662,7 +662,7 @@ func BenchmarkBuildVerify(b *testing.B) {
sig, err := signerInRound.SignBytes(data[:])
require.NoError(b, err, "failed to create keys")

partkeys = append(partkeys, signer)
//partkeys = append(partkeys, signer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not completely remove this line?

sigs = append(sigs, sig)
parts = append(parts, part)
}
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/verify/txnBatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func TestStreamToBatchCtxCancelPoolQueue(t *testing.T) { //nolint:paralleltest /
// cancel the ctx as the sig is not yet sent to the exec pool
// the test might sporadically fail if between sending the txn above
// and the cancelation, 2 x waitForNextTxnDuration elapses (10ms)
time.Sleep(12)
time.Sleep(12 * time.Millisecond)
jannotti marked this conversation as resolved.
Show resolved Hide resolved
go func() {
// wait a bit before releasing the tasks, so that the verificationPool ctx first gets canceled
time.Sleep(20 * time.Millisecond)
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/verify/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func TestPaysetGroups(t *testing.T) {

func BenchmarkPaysetGroups(b *testing.B) {
if b.N < 2000 {
b.N = 2000
b.N = 2000 //nolint:staticcheck // intentionally setting b.N
}
_, signedTxn, secrets, addrs := generateTestObjects(b.N, 20, 0, 50)
blkHdr := createDummyBlockHeader()
Expand Down Expand Up @@ -1056,7 +1056,7 @@ func verifyGroup(t *testing.T, txnGroups [][]transactions.SignedTxn, blkHdr *boo

func BenchmarkTxn(b *testing.B) {
if b.N < 2000 {
b.N = 2000
b.N = 2000 //nolint:staticcheck // intentionally setting b.N
}
_, signedTxn, secrets, addrs := generateTestObjects(b.N, 20, 0, 50)
blk := bookkeeping.Block{BlockHeader: createDummyBlockHeader()}
Expand Down
3 changes: 2 additions & 1 deletion ledger/acctdeltas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ func benchmarkWriteCatchpointStagingBalancesSub(b *testing.B, ascendingOrder boo
b.ReportMetric(float64(b.N)/float64((time.Since(accountsWritingStarted)-accountsGenerationDuration).Seconds()), "accounts/sec")
}

//nolint:staticcheck // intentionally setting b.N
func BenchmarkWriteCatchpointStagingBalances(b *testing.B) {
benchSizes := []int{1024 * 100, 1024 * 200, 1024 * 400}
for _, size := range benchSizes {
Expand Down Expand Up @@ -1131,10 +1132,10 @@ func TestKVStoreNilBlobConversion(t *testing.T) {

err = dbs.Wdb.Atomic(func(ctx context.Context, tx *sql.Tx) (err0 error) {
writer, err0 := sqlitedriver.MakeAccountsSQLWriter(tx, false, false, true, false)
defer writer.Close()
if err0 != nil {
return
}
defer writer.Close()
for i := 0; i < len(kvPairDBPrepareSet); i++ {
err0 = writer.UpsertKvPair(string(kvPairDBPrepareSet[i].key), nil)
if err0 != nil {
Expand Down
2 changes: 1 addition & 1 deletion ledger/eval/cow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (ml *mockLedger) BlockHdr(rnd basics.Round) (bookkeeping.BlockHeader, error
}

func (ml *mockLedger) blockHdrCached(rnd basics.Round) (bookkeeping.BlockHeader, error) {
return ml.blockHdrCached(rnd)
return ml.BlockHdr(rnd)
}

func (ml *mockLedger) GetStateProofVerificationContext(rnd basics.Round) (*ledgercore.StateProofVerificationContext, error) {
Expand Down
4 changes: 2 additions & 2 deletions ledger/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ func (ledger *evalTestLedger) BlockHdr(rnd basics.Round) (bookkeeping.BlockHeade
}

func (ledger *evalTestLedger) BlockHdrCached(rnd basics.Round) (bookkeeping.BlockHeader, error) {
return ledger.BlockHdrCached(rnd)
return ledger.BlockHdr(rnd)
}

func (ledger *evalTestLedger) VotersForStateProof(rnd basics.Round) (*ledgercore.VotersForRound, error) {
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func (l *testCowBaseLedger) BlockHdr(basics.Round) (bookkeeping.BlockHeader, err
}

func (l *testCowBaseLedger) BlockHdrCached(rnd basics.Round) (bookkeeping.BlockHeader, error) {
return l.BlockHdrCached(rnd)
return l.BlockHdr(rnd)
}

func (l *testCowBaseLedger) CheckDup(config.ConsensusParams, basics.Round, basics.Round, basics.Round, transactions.Txid, ledgercore.Txlease) error {
Expand Down
2 changes: 1 addition & 1 deletion ledger/evalbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func BenchmarkBlockEvaluatorDiskAppCalls(b *testing.B) {
// the setup time for this test is 1.5 minutes long. By setting the b.N = 2, we
// set up for success on the first iteration, and preventing a second iteration.
if b.N < 2 {
b.N = 2
b.N = 2 //nolint:staticcheck // intentionally setting b.N
}
// program sets all 16 available keys of len 64 bytes to same values of 64 bytes
source := `#pragma version 5
Expand Down
2 changes: 1 addition & 1 deletion ledger/onlineaccountscache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func benchmarkOnlineAccountsCacheRead(b *testing.B, historyLength int) {
// preparation stage above non-negligible.
minN := 100
if b.N < minN {
b.N = minN
b.N = minN //nolint:staticcheck // intentionally setting b.N
}

var r cachedOnlineAccount
Expand Down