Skip to content

Commit 011e246

Browse files
no gosec in test files
1 parent 5040a65 commit 011e246

File tree

12 files changed

+35
-25
lines changed

12 files changed

+35
-25
lines changed

.avalanche-golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,12 @@ linters:
244244
- common-false-positives
245245
- legacy
246246
- std-error-handling
247+
rules:
248+
# Exclude some linters from running on test files.
249+
# 1. Exclude the top level tests/ directory.
250+
# 2. Exclude any file prefixed with test_ in any directory.
251+
# 3. Exclude any directory suffixed with test.
252+
# 4. Exclude any file suffixed with _test.go.
253+
- path: "(^tests/)|(^(.*/)*test_[^/]*\\.go$)|(.*test/.*)|(.*_test\\.go$)"
254+
linters:
255+
- gosec

core/extstate/database_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (fs *fuzzState) deleteStorage(accountIndex int, storageIndexInput uint64) {
311311
func FuzzTree(f *testing.F) {
312312
f.Fuzz(func(t *testing.T, randSeed int64, byteSteps []byte) {
313313
fuzzState := newFuzzState(t)
314-
rand := rand.New(rand.NewSource(randSeed)) //nolint:gosec // this isn't a good fuzz test, but it is reproducible.
314+
rand := rand.New(rand.NewSource(randSeed)) // this isn't a good fuzz test, but it is reproducible.
315315

316316
for range 10 {
317317
fuzzState.createAccount()

network/peer_tracker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ func (p *peerTracker) GetAnyPeer(minVersion *version.Application) (ids.NodeID, b
123123
averager safemath.Averager
124124
)
125125
randomValue, err := rand.SecureFloat64()
126-
if err != nil {
126+
switch {
127+
case err != nil:
127128
log.Error("failed to generate secure random number for peer selection", "err", err)
128129
// Fallback to deterministic behavior - use bandwidth heap
129130
nodeID, averager, ok = p.bandwidthHeap.Pop()
130-
} else if randomValue < randomPeerProbability {
131+
case randomValue < randomPeerProbability:
131132
random = true
132133
nodeID, averager, ok = p.getResponsivePeer()
133-
} else {
134+
default:
134135
nodeID, averager, ok = p.bandwidthHeap.Pop()
135136
}
136137
if ok {

plugin/evm/atomic/atomictest/tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func GenerateTestExportTx() *atomic.Tx {
150150
}
151151

152152
func NewTestTx() *atomic.Tx {
153-
txType := rand.Intn(2) //nolint:gosec
153+
txType := rand.Intn(2)
154154
switch txType {
155155
case 0:
156156
return GenerateTestImportTx()

plugin/evm/atomic/sync/syncer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestSyncerScenarios(t *testing.T) {
6868

6969
for _, tt := range tests {
7070
t.Run(tt.name, func(t *testing.T) {
71-
r := rand.New(rand.NewSource(1)) //nolint:gosec
71+
r := rand.New(rand.NewSource(1))
7272
targetHeight := 10 * uint64(testCommitInterval)
7373
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
7474
root, _, _ := statesynctest.GenerateTrie(t, r, serverTrieDB, int(targetHeight), state.TrieKeyLength)
@@ -104,7 +104,7 @@ func TestSyncerResumeScenarios(t *testing.T) {
104104

105105
for _, tt := range tests {
106106
t.Run(tt.name, func(t *testing.T) {
107-
r := rand.New(rand.NewSource(1)) //nolint:gosec
107+
r := rand.New(rand.NewSource(1))
108108
targetHeight := 10 * uint64(testCommitInterval)
109109
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
110110
numTrieKeys := int(targetHeight) - 1 // no atomic ops for genesis
@@ -148,7 +148,7 @@ func TestSyncerResumeNewRootCheckpointScenarios(t *testing.T) {
148148

149149
for _, tt := range tests {
150150
t.Run(tt.name, func(t *testing.T) {
151-
r := rand.New(rand.NewSource(1)) //nolint:gosec
151+
r := rand.New(rand.NewSource(1))
152152
targetHeight1 := 10 * uint64(testCommitInterval)
153153
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
154154
numTrieKeys1 := int(targetHeight1) - 1 // no atomic ops for genesis
@@ -220,7 +220,7 @@ func TestSyncerContextCancellation(t *testing.T) {
220220
// It returns the context, mock client, atomic backend, client DB, and root hash for testing.
221221
func setupParallelizationTest(t *testing.T, targetHeight uint64) (context.Context, *syncclient.TestClient, *state.AtomicBackend, *versiondb.Database, common.Hash) {
222222
// Create a simple test trie with some data.
223-
r := rand.New(rand.NewSource(1)) //nolint:gosec
223+
r := rand.New(rand.NewSource(1))
224224
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
225225
root, _, _ := statesynctest.GenerateTrie(t, r, serverTrieDB, int(targetHeight), state.TrieKeyLength)
226226

plugin/evm/message/block_request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestMarshalBlockRequest(t *testing.T) {
3939
// ensure compatibility with the network.
4040
func TestMarshalBlockResponse(t *testing.T) {
4141
// Create some random bytes and then set the seed to ensure deterministic behaviour
42-
rand := rand.New(rand.NewSource(1)) //nolint:gosec
42+
rand := rand.New(rand.NewSource(1))
4343
blocksBytes := make([][]byte, 32)
4444
for i := range blocksBytes {
4545
blocksBytes[i] = make([]byte, rand.Intn(32)+32) // min 32 length, max 64

plugin/evm/message/code_request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestMarshalCodeRequest(t *testing.T) {
3535
// ensure compatibility with the network.
3636
func TestMarshalCodeResponse(t *testing.T) {
3737
// Create some random bytes and then set the seed to ensure deterministic behaviour
38-
rand := rand.New(rand.NewSource(1)) //nolint:gosec
38+
rand := rand.New(rand.NewSource(1))
3939

4040
codeData := make([]byte, 50)
4141
_, err := rand.Read(codeData)

plugin/evm/message/leafs_request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// ensure compatibility with the network.
1717
func TestMarshalLeafsRequest(t *testing.T) {
1818
// Create some random bytes and then set the seed to ensure deterministic behaviour
19-
rand := rand.New(rand.NewSource(1)) //nolint:gosec
19+
rand := rand.New(rand.NewSource(1))
2020

2121
startBytes := make([]byte, common.HashLength)
2222
endBytes := make([]byte, common.HashLength)
@@ -55,7 +55,7 @@ func TestMarshalLeafsRequest(t *testing.T) {
5555
// ensure compatibility with the network.
5656
func TestMarshalLeafsResponse(t *testing.T) {
5757
// Create some random bytes and then set the seed to ensure deterministic behaviour
58-
rand := rand.New(rand.NewSource(1)) //nolint:gosec
58+
rand := rand.New(rand.NewSource(1))
5959

6060
keysBytes := make([][]byte, 16)
6161
valsBytes := make([][]byte, 16)

plugin/evm/vmtest/test_syncervm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func initSyncServerAndClientVMs(t *testing.T, test SyncTestParams, numBlocks int
312312
generateAndAcceptBlocks(t, serverVM, numBlocks, testSetup.GenFn, nil, cb)
313313

314314
// make some accounts
315-
r := rand.New(rand.NewSource(1)) //nolint:gosec
315+
r := rand.New(rand.NewSource(1))
316316
root, accounts := statesynctest.FillAccountsWithOverlappingStorage(t, r, serverVM.Ethereum().BlockChain().TrieDB(), types.EmptyRootHash, 1000, 16)
317317

318318
// patch serverVM's lastAcceptedBlock to have the new root

sync/client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func buildGetter(blocks []*types.Block) handlers.BlockProvider {
374374

375375
func TestGetLeafs(t *testing.T) {
376376
const leafsLimit = 1024
377-
r := rand.New(rand.NewSource(1)) //nolint:gosec
377+
r := rand.New(rand.NewSource(1))
378378

379379
trieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
380380
largeTrieRoot, largeTrieKeys, _ := statesynctest.GenerateTrie(t, r, trieDB, 100_000, common.HashLength)
@@ -684,7 +684,7 @@ func TestGetLeafs(t *testing.T) {
684684
}
685685

686686
func TestGetLeafsRetries(t *testing.T) {
687-
r := rand.New(rand.NewSource(1)) //nolint:gosec
687+
r := rand.New(rand.NewSource(1))
688688
trieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
689689
root, _, _ := statesynctest.GenerateTrie(t, r, trieDB, 100_000, common.HashLength)
690690

0 commit comments

Comments
 (0)