Skip to content

Commit

Permalink
update ignore directive
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Oct 9, 2024
1 parent 4e75446 commit 02b14ff
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 44 deletions.
4 changes: 2 additions & 2 deletions api/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func httpPost(t *testing.T, url string, body interface{}) ([]byte, int) {
if err != nil {
t.Fatal(err)
}
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data))
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data)) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand All @@ -556,7 +556,7 @@ func httpPost(t *testing.T, url string, body interface{}) ([]byte, int) {
}

func httpGet(t *testing.T, url string) ([]byte, int) {
res, err := http.Get(url)
res, err := http.Get(url) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func checkExpandedBlock(t *testing.T, expBl *block.Block, actBl *blocks.JSONExpa
}

func httpGet(t *testing.T, url string) ([]byte, int) {
res, err := http.Get(url)
res, err := http.Get(url) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func httpPostAndCheckResponseStatus(t *testing.T, url string, obj interface{}, r
if err != nil {
t.Fatal(err)
}
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data))
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data)) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func httpPost(t *testing.T, url string, body interface{}) ([]byte, int) {
if err != nil {
t.Fatal(err)
}
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data))
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data)) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestWebsocketMetrics(t *testing.T) {
}

func httpGet(t *testing.T, url string) ([]byte, int) {
res, err := http.Get(url)
res, err := http.Get(url) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func initCommServer(t *testing.T) {
}

func httpGet(t *testing.T, url string) []byte {
res, err := http.Get(url)
res, err := http.Get(url) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions api/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func httpPostAndCheckResponseStatus(t *testing.T, url string, obj interface{}, r
if err != nil {
t.Fatal(err)
}
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data))
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data)) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func checkMatchingTx(t *testing.T, expectedTx *tx.Transaction, actualTx *transac
}

func httpGetAndCheckResponseStatus(t *testing.T, url string, responseStatusCode int) []byte {
res, err := http.Get(url)
res, err := http.Get(url) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/transfers/transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func httpPost(t *testing.T, url string, body interface{}) ([]byte, int) {
if err != nil {
t.Fatal(err)
}
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data))
res, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewReader(data)) //#nosec G107
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion block/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestHeader_BetterThan(t *testing.T) {

func TestHeaderEncoding(t *testing.T) {
var sig [65]byte
rand.Read(sig[:]) // nolint
rand.Read(sig[:])

block := new(Builder).Build().WithSignature(sig[:])
h := block.Header()
Expand Down
7 changes: 4 additions & 3 deletions cache/prio_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

// #nosec G404
package cache_test

import (
Expand Down Expand Up @@ -44,9 +45,9 @@ func TestPrioCache(t *testing.T) {

for i := 0; i < 100; i++ {
e := kvp{
rand.Int(), // #nosec
rand.Int(), // #nosec
rand.Float64()} // #nosec
rand.Int(),
rand.Int(),
rand.Float64()}
kvps = append(kvps, e)
c.Set(e.k, e.v, e.p)
}
Expand Down
4 changes: 2 additions & 2 deletions cache/rnd_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (rc *RandCache) Pick() *Entry {
if len(rc.s) == 0 {
return nil
}
ent := rc.s[rand.N(len(rc.s))] // #nosec
ent := rc.s[rand.N(len(rc.s))] //#nosec G404
cpy := ent.Entry
return &cpy
}
Expand Down Expand Up @@ -136,6 +136,6 @@ func (rc *RandCache) randDrop() {
if len(rc.s) == 0 {
return
}
ent := rc.s[rand.N(len(rc.s))] // #nosec
ent := rc.s[rand.N(len(rc.s))] //#nosec
rc.remove(ent.Key)
}
2 changes: 1 addition & 1 deletion cmd/thor/node/tx_stash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func newTx() *tx.Transaction {
tx := new(tx.Builder).Nonce(rand.Uint64()).Build() // #nosec
tx := new(tx.Builder).Nonce(rand.Uint64()).Build() //#nosec G404
sig, _ := crypto.Sign(tx.SigningHash().Bytes(), genesis.DevAccounts()[0].PrivateKey)
return tx.WithSignature(sig)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thor/solo/solo.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *Solo) newTx(clauses []*tx.Clause, from genesis.DevAccount) (*tx.Transac

newTx := builder.BlockRef(tx.NewBlockRef(0)).
Expiration(math.MaxUint32).
Nonce(rand.Uint64()). // #nosec
Nonce(rand.Uint64()). //#nosec G404
DependsOn(nil).
Gas(1_000_000).
Build()
Expand Down
2 changes: 1 addition & 1 deletion comm/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *Peer) UpdateHead(id thor.Bytes32, totalScore uint64) {
// MarkTransaction marks a transaction to known.
func (p *Peer) MarkTransaction(hash thor.Bytes32) {
// that's 10~100 block intervals
expiration := mclock.AbsTime(time.Second * time.Duration(thor.BlockInterval*uint64(rand.N(91)+10))) // #nosec
expiration := mclock.AbsTime(time.Second * time.Duration(thor.BlockInterval*uint64(rand.N(91)+10))) //#nosec G404

deadline := mclock.Now() + expiration
p.knownTxs.Add(hash, deadline)
Expand Down
4 changes: 2 additions & 2 deletions log/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func BenchmarkPrettyInt64Logfmt(b *testing.B) {
buf := make([]byte, 100)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
sink = appendInt64(buf, rand.Int64()) // #nosec
sink = appendInt64(buf, rand.Int64()) //#nosec G404
}
}

func BenchmarkPrettyUint64Logfmt(b *testing.B) {
buf := make([]byte, 100)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
sink = appendUint64(buf, rand.Uint64(), false) // #nosec
sink = appendUint64(buf, rand.Uint64(), false) //#nosec G404
}
}
7 changes: 4 additions & 3 deletions metrics/noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

// #nosec G404
package metrics

import (
Expand All @@ -26,21 +27,21 @@ func TestNoopMetrics(t *testing.T) {
Counter("count2")

count1.Add(1)
randCount2 := rand.N(100) + 1 // #nosec
randCount2 := rand.N(100) + 1
for i := 0; i < randCount2; i++ {
Counter("count2").Add(1)
}

hist := Histogram("hist1", nil)
histVect := HistogramVec("hist2", []string{"zeroOrOne"}, nil)
for i := 0; i < rand.N(100)+1; i++ { // #nosec
for i := 0; i < rand.N(100)+1; i++ {
hist.Observe(int64(i))
histVect.ObserveWithLabels(int64(i), map[string]string{"thisIsNonsense": "butDoesntBreak"})
}

countVect := CounterVec("countVec1", []string{"zeroOrOne"})
gaugeVec := GaugeVec("gaugeVec1", []string{"zeroOrOne"})
for i := 0; i < rand.N(100)+1; i++ { // #nosec
for i := 0; i < rand.N(100)+1; i++ {
countVect.AddWithLabel(int64(i), map[string]string{"thisIsNonsense": "butDoesntBreak"})
gaugeVec.AddWithLabel(int64(i), map[string]string{"thisIsNonsense": "butDoesntBreak"})
}
Expand Down
9 changes: 5 additions & 4 deletions metrics/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

// #nosec G404
package metrics

import (
Expand Down Expand Up @@ -31,13 +32,13 @@ func TestPromMetrics(t *testing.T) {
gaugeVec := GaugeVec("gaugeVec1", []string{"zeroOrOne"})

count1.Add(1)
randCount2 := rand.N(100) + 1 // #nosec
randCount2 := rand.N(100) + 1
for i := 0; i < randCount2; i++ {
Counter("count2").Add(1)
}

histTotal := 0
for i := 0; i < rand.N(100)+2; i++ { // #nosec
for i := 0; i < rand.N(100)+2; i++ {
zeroOrOne := i % 2
hist.Observe(int64(i))
HistogramVec("hist2", []string{"zeroOrOne"}, nil).
Expand All @@ -46,15 +47,15 @@ func TestPromMetrics(t *testing.T) {
}

totalCountVec := 0
randCountVec := rand.N(100) + 2 // #nosec
randCountVec := rand.N(100) + 2
for i := 0; i < randCountVec; i++ {
zeroOrOne := i % 2
countVect.AddWithLabel(int64(i), map[string]string{"zeroOrOne": strconv.Itoa(zeroOrOne)})
totalCountVec += i
}

totalGaugeVec := 0
randGaugeVec := rand.N(100) + 2 // #nosec
randGaugeVec := rand.N(100) + 2
for i := 0; i < randGaugeVec; i++ {
zeroOrOne := i % 2
gaugeVec.AddWithLabel(int64(i), map[string]string{"zeroOrOne": strconv.Itoa(zeroOrOne)})
Expand Down
2 changes: 1 addition & 1 deletion p2psrv/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *RPC) prepareCall(msgCode uint64, onResult func(*p2p.Msg) error) uint32
r.lock.Lock()
defer r.lock.Unlock()
for {
id := rand.Uint32() // #nosec
id := rand.Uint32() //#nosec G404
if id == 0 {
// 0 id is taken by Notify
continue
Expand Down
2 changes: 1 addition & 1 deletion runtime/statedb/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
nameargs = append(nameargs, addr.Hex())
}
for _, i := range action.args {
action.args[i] = rand.Int63n(100) // #nosec
action.args[i] = rand.Int63n(100) //#nosec G404
nameargs = append(nameargs, fmt.Sprint(action.args[i]))
}
action.name += strings.Join(nameargs, ", ")
Expand Down
6 changes: 3 additions & 3 deletions test/datagen/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
package datagen

import (
mathrand "math/rand"
mathrand "math/rand/v2"
)

func RandInt() int {
return mathrand.Int() // #nosec
return mathrand.Int() //#nosec G404
}

func RandIntN(n int) int {
return mathrand.Intn(n) // #nosec
return mathrand.N(n) //#nosec G404
}
4 changes: 2 additions & 2 deletions thor/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func BenchmarkHash(b *testing.B) {
data := make([]byte, 10)

rand.New(rand.NewSource(1)).Read(data) // #nosec
rand.New(rand.NewSource(1)).Read(data) //#nosec G404

b.Run("keccak", func(b *testing.B) {
type keccakState interface {
Expand All @@ -45,7 +45,7 @@ func BenchmarkHash(b *testing.B) {

func BenchmarkBlake2b(b *testing.B) {
data := make([]byte, 100)
rand.New(rand.NewSource(1)).Read(data) // #nosec
rand.New(rand.NewSource(1)).Read(data) //#nosec G404
b.Run("Blake2b", func(b *testing.B) {
for i := 0; i < b.N; i++ {
thor.Blake2b(data).Bytes()
Expand Down
3 changes: 2 additions & 1 deletion trie/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ func TestIteratorContinueAfterError(t *testing.T) {
// because that one is already loaded.
var rkey []byte
for {
if rkey = keys[rand.N(len(keys))]; !bytes.Equal(rkey, tr.Hash().Bytes()) { // #nosec
//#nosec G404
if rkey = keys[rand.N(len(keys))]; !bytes.Equal(rkey, tr.Hash().Bytes()) {
break
}
}
Expand Down
7 changes: 4 additions & 3 deletions trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// #nosec G404
package trie

import (
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestVerifyBadProof(t *testing.T) {
t.Fatal("zero length proof")
}
keys := proofs.Keys()
key := keys[mrand.N(len(keys))] // #nosec
key := keys[mrand.N(len(keys))]
node, _ := proofs.Get(key)
proofs.Delete(key)
mutateByte(node)
Expand All @@ -85,8 +86,8 @@ func TestVerifyBadProof(t *testing.T) {

// mutateByte changes one byte in b.
func mutateByte(b []byte) {
for r := mrand.N(len(b)); ; { // #nosec
new := byte(mrand.N(255)) // #nosec
for r := mrand.N(len(b)); ; {
new := byte(mrand.N(255))
if new != b[r] {
b[r] = new
break
Expand Down
2 changes: 1 addition & 1 deletion trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
// insert into the trie before measuring the hashing.
func BenchmarkHash(b *testing.B) {
// Make the random benchmark deterministic
random := rand.New(rand.NewSource(0)) // #nosec
random := rand.New(rand.NewSource(0)) //#nosec G404

// Create a realistic account trie to hash
addresses := make([][20]byte, b.N)
Expand Down
2 changes: 1 addition & 1 deletion txpool/blocklist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SetupTempFile(t *testing.T, dummyData string) string {
}
testFilePath := tempFile.Name()

err = os.WriteFile(testFilePath, []byte(dummyData), 0644) // #nosec
err = os.WriteFile(testFilePath, []byte(dummyData), 0600)
if err != nil {
t.Fatalf("Failed to write to temp file: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions txpool/tx_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newTx(chainTag byte, clauses []*tx.Clause, gas uint64, blockRef tx.BlockRef

tx := builder.BlockRef(blockRef).
Expiration(expiration).
Nonce(rand.Uint64()). // #nosec
Nonce(rand.Uint64()). //#nosec G404
DependsOn(dependsOn).
Features(features).
Gas(gas).Build()
Expand All @@ -61,7 +61,7 @@ func newDelegatedTx(chainTag byte, clauses []*tx.Clause, gas uint64, blockRef tx

tx := builder.BlockRef(blockRef).
Expiration(expiration).
Nonce(rand.Uint64()). // #nosec
Nonce(rand.Uint64()). //#nosec G404
DependsOn(dependsOn).
Features(features).
Gas(gas).Build()
Expand Down
2 changes: 1 addition & 1 deletion txpool/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (p *TxPool) fetchBlocklistLoop() {

for {
// delay 1~2 min
delay := time.Second * time.Duration(rand.Int()%60+60) // #nosec
delay := time.Second * time.Duration(rand.Int()%60+60) //#nosec G404
select {
case <-p.ctx.Done():
return
Expand Down

0 comments on commit 02b14ff

Please sign in to comment.