From cc2c27dbd377d447c2c639a47b2f4afbd0ad385c Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 21 Sep 2023 10:50:01 +0530 Subject: [PATCH] fix linters --- core/blockchain_snapshot_test.go | 2 ++ core/txpool/blobpool/evictheap_test.go | 2 ++ core/txpool/legacypool/legacypool_test.go | 28 +++++++++++------------ core/txpool/txpool.go | 3 +-- core/vm/instructions_test.go | 4 ++-- core/vm/memory.go | 6 ++--- crypto/kzg4844/kzg4844_test.go | 7 ++++++ ethclient/gethclient/gethclient_test.go | 4 ++++ graphql/graphql_test.go | 2 ++ internal/ethapi/api_test.go | 1 + les/peer.go | 2 +- metrics/registry_test.go | 1 + miner/worker_test.go | 1 + p2p/protocol.go | 10 ++++---- trie/iterator_test.go | 3 +++ trie/sync_test.go | 10 ++++++++ trie/trie_test.go | 1 + trie/triedb/pathdb/database_test.go | 1 + trie/triedb/pathdb/difflayer_test.go | 1 + trie/triedb/pathdb/history_test.go | 2 ++ 20 files changed, 64 insertions(+), 27 deletions(-) diff --git a/core/blockchain_snapshot_test.go b/core/blockchain_snapshot_test.go index 0cb411cd73..3be2c2deac 100644 --- a/core/blockchain_snapshot_test.go +++ b/core/blockchain_snapshot_test.go @@ -58,6 +58,7 @@ type snapshotTestBasic struct { } func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Block) { + t.Helper() // Create a temporary persistent database datadir := t.TempDir() @@ -129,6 +130,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo } func (basic *snapshotTestBasic) verify(t *testing.T, chain *BlockChain, blocks []*types.Block) { + t.Helper() // Iterate over all the remaining blocks and ensure there are no gaps verifyNoGaps(t, chain, true, blocks) verifyCutoff(t, chain, true, blocks, basic.expCanonicalBlocks) diff --git a/core/txpool/blobpool/evictheap_test.go b/core/txpool/blobpool/evictheap_test.go index 01b136551c..9cea4f8924 100644 --- a/core/txpool/blobpool/evictheap_test.go +++ b/core/txpool/blobpool/evictheap_test.go @@ -184,6 +184,7 @@ func BenchmarkPriceHeapReinit50GB(b *testing.B) { benchmarkPriceHeapReinit(b, 5 func BenchmarkPriceHeapReinit100GB(b *testing.B) { benchmarkPriceHeapReinit(b, 100*1024*1024*1024) } func benchmarkPriceHeapReinit(b *testing.B, datacap uint64) { + b.Helper() // Calculate how many unique transactions we can fit into the provided disk // data cap blobs := datacap / (params.BlobTxBytesPerFieldElement * params.BlobTxFieldElementsPerBlob) @@ -244,6 +245,7 @@ func BenchmarkPriceHeapOverflow50GB(b *testing.B) { benchmarkPriceHeapOverflow( func BenchmarkPriceHeapOverflow100GB(b *testing.B) { benchmarkPriceHeapOverflow(b, 100*1024*1024*1024) } func benchmarkPriceHeapOverflow(b *testing.B, datacap uint64) { + b.Helper() // Calculate how many unique transactions we can fit into the provided disk // data cap blobs := datacap / (params.BlobTxBytesPerFieldElement * params.BlobTxFieldElementsPerBlob) diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index 870631902e..81b492f5dd 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -349,15 +349,15 @@ func testSetNonce(pool *LegacyPool, addr common.Address, nonce uint64) { pool.mu.Unlock() } -func getBalance(pool *LegacyPool, addr common.Address) *big.Int { - bal := big.NewInt(0) +// func getBalance(pool *LegacyPool, addr common.Address) *big.Int { +// bal := big.NewInt(0) - pool.mu.Lock() - bal.Set(pool.currentState.GetBalance(addr)) - pool.mu.Unlock() +// pool.mu.Lock() +// bal.Set(pool.currentState.GetBalance(addr)) +// pool.mu.Unlock() - return bal -} +// return bal +// } func TestInvalidTransactions(t *testing.T) { t.Parallel() @@ -3263,15 +3263,15 @@ func BenchmarkPoolAccountsBatchInsert(b *testing.B) { // <-done // } -func newTxs(pool *LegacyPool) *types.Transaction { - key, _ := crypto.GenerateKey() - account := crypto.PubkeyToAddress(key.PublicKey) - tx := transaction(uint64(0), 100000, key) +// func newTxs(pool *LegacyPool) *types.Transaction { +// key, _ := crypto.GenerateKey() +// account := crypto.PubkeyToAddress(key.PublicKey) +// tx := transaction(uint64(0), 100000, key) - pool.currentState.AddBalance(account, big.NewInt(1_000_000_000)) +// pool.currentState.AddBalance(account, big.NewInt(1_000_000_000)) - return tx -} +// return tx +// } type acc struct { nonce uint64 diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 7d4a794be2..149766a466 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -70,8 +70,7 @@ type TxPool struct { reservations map[common.Address]SubPool // Map with the account to pool reservations reserveLock sync.Mutex // Lock protecting the account reservations - subs event.SubscriptionScope // Subscription scope to unscubscribe all on shutdown - quit chan chan error // Quit channel to tear down the head updater + quit chan chan error // Quit channel to tear down the head updater } // New creates a new transaction pool to gather, sort and filter inbound diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index dd412f4622..bdd10e7f91 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -929,11 +929,11 @@ func TestOpMCopy(t *testing.T) { mem.Resize(uint64(len(data))) mem.Set(0, uint64(len(data)), data) // Push stack args - len, _ := uint256.FromHex(tc.len) + length, _ := uint256.FromHex(tc.len) src, _ := uint256.FromHex(tc.src) dst, _ := uint256.FromHex(tc.dst) - stack.push(len) + stack.push(length) stack.push(src) stack.push(dst) wantErr := (tc.wantGas == 0) diff --git a/core/vm/memory.go b/core/vm/memory.go index 8af2067abe..8f8cbaed74 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -109,9 +109,9 @@ func (m *Memory) Data() []byte { // The source and destination may overlap. // OBS: This operation assumes that any necessary memory expansion has already been performed, // and this method may panic otherwise. -func (m *Memory) Copy(dst, src, len uint64) { - if len == 0 { +func (m *Memory) Copy(dst, src, length uint64) { + if length == 0 { return } - copy(m.store[dst:], m.store[src:src+len]) + copy(m.store[dst:], m.store[src:src+length]) } diff --git a/crypto/kzg4844/kzg4844_test.go b/crypto/kzg4844/kzg4844_test.go index fae8a7a76e..28f572f1e4 100644 --- a/crypto/kzg4844/kzg4844_test.go +++ b/crypto/kzg4844/kzg4844_test.go @@ -48,6 +48,7 @@ func randBlob() Blob { func TestCKZGWithPoint(t *testing.T) { testKZGWithPoint(t, true) } func TestGoKZGWithPoint(t *testing.T) { testKZGWithPoint(t, false) } func testKZGWithPoint(t *testing.T, ckzg bool) { + t.Helper() if ckzg && !ckzgAvailable { t.Skip("CKZG unavailable in this test build") } @@ -73,6 +74,7 @@ func testKZGWithPoint(t *testing.T, ckzg bool) { func TestCKZGWithBlob(t *testing.T) { testKZGWithBlob(t, true) } func TestGoKZGWithBlob(t *testing.T) { testKZGWithBlob(t, false) } func testKZGWithBlob(t *testing.T, ckzg bool) { + t.Helper() if ckzg && !ckzgAvailable { t.Skip("CKZG unavailable in this test build") } @@ -97,6 +99,7 @@ func testKZGWithBlob(t *testing.T, ckzg bool) { func BenchmarkCKZGBlobToCommitment(b *testing.B) { benchmarkBlobToCommitment(b, true) } func BenchmarkGoKZGBlobToCommitment(b *testing.B) { benchmarkBlobToCommitment(b, false) } func benchmarkBlobToCommitment(b *testing.B, ckzg bool) { + b.Helper() if ckzg && !ckzgAvailable { b.Skip("CKZG unavailable in this test build") } @@ -114,6 +117,7 @@ func benchmarkBlobToCommitment(b *testing.B, ckzg bool) { func BenchmarkCKZGComputeProof(b *testing.B) { benchmarkComputeProof(b, true) } func BenchmarkGoKZGComputeProof(b *testing.B) { benchmarkComputeProof(b, false) } func benchmarkComputeProof(b *testing.B, ckzg bool) { + b.Helper() if ckzg && !ckzgAvailable { b.Skip("CKZG unavailable in this test build") } @@ -134,6 +138,7 @@ func benchmarkComputeProof(b *testing.B, ckzg bool) { func BenchmarkCKZGVerifyProof(b *testing.B) { benchmarkVerifyProof(b, true) } func BenchmarkGoKZGVerifyProof(b *testing.B) { benchmarkVerifyProof(b, false) } func benchmarkVerifyProof(b *testing.B, ckzg bool) { + b.Helper() if ckzg && !ckzgAvailable { b.Skip("CKZG unavailable in this test build") } @@ -156,6 +161,7 @@ func benchmarkVerifyProof(b *testing.B, ckzg bool) { func BenchmarkCKZGComputeBlobProof(b *testing.B) { benchmarkComputeBlobProof(b, true) } func BenchmarkGoKZGComputeBlobProof(b *testing.B) { benchmarkComputeBlobProof(b, false) } func benchmarkComputeBlobProof(b *testing.B, ckzg bool) { + b.Helper() if ckzg && !ckzgAvailable { b.Skip("CKZG unavailable in this test build") } @@ -176,6 +182,7 @@ func benchmarkComputeBlobProof(b *testing.B, ckzg bool) { func BenchmarkCKZGVerifyBlobProof(b *testing.B) { benchmarkVerifyBlobProof(b, true) } func BenchmarkGoKZGVerifyBlobProof(b *testing.B) { benchmarkVerifyBlobProof(b, false) } func benchmarkVerifyBlobProof(b *testing.B, ckzg bool) { + b.Helper() if ckzg && !ckzgAvailable { b.Skip("CKZG unavailable in this test build") } diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index ed34811b6a..d06ef8e055 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -47,6 +47,7 @@ var ( ) func newTestBackend(t *testing.T) (*node.Node, []*types.Block) { + t.Helper() // Generate test chain. genesis, blocks := generateTestChain() // Create node @@ -168,6 +169,7 @@ func TestGethClient(t *testing.T) { } func testAccessList(t *testing.T, client *rpc.Client) { + t.Helper() ec := New(client) // Test transfer msg := ethereum.CallMsg{ @@ -271,6 +273,7 @@ func testGetProof(t *testing.T, client *rpc.Client) { } func testGetProofCanonicalizeKeys(t *testing.T, client *rpc.Client) { + t.Helper() ec := New(client) // Tests with non-canon input for storage keys. @@ -533,6 +536,7 @@ func TestBlockOverridesMarshal(t *testing.T) { } func testCallContractWithBlockOverrides(t *testing.T, client *rpc.Client) { + t.Helper() ec := New(client) msg := ethereum.CallMsg{ From: testAddr, diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index 4bbfb7251d..bbef1d4dff 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -423,6 +423,7 @@ func TestWithdrawals(t *testing.T) { } func createNode(t *testing.T) *node.Node { + t.Helper() stack, err := node.New(&node.Config{ HTTPHost: "127.0.0.1", HTTPPort: 0, @@ -437,6 +438,7 @@ func createNode(t *testing.T) *node.Node { } func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Genesis, genBlocks int, genfunc func(i int, gen *core.BlockGen)) (*handler, []*types.Block) { + t.Helper() ethConf := ðconfig.Config{ Genesis: gspec, NetworkId: 1337, diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 6f8469fbdc..bb44bfdfe8 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -387,6 +387,7 @@ type testBackend struct { } func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i int, b *core.BlockGen)) *testBackend { + t.Helper() var ( engine = ethash.NewFaker() cacheConfig = &core.CacheConfig{ diff --git a/les/peer.go b/les/peer.go index b3c60ba8e3..f379dbad07 100644 --- a/les/peer.go +++ b/les/peer.go @@ -1012,7 +1012,7 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge // If local ethereum node is running in archive mode, advertise ourselves we have // all version state data. Otherwise only recent state is available. - stateRecent := uint64(core.DefaultCacheConfig.TriesInMemory - blockSafetyMargin) + stateRecent := core.DefaultCacheConfig.TriesInMemory - blockSafetyMargin if server.archiveMode { stateRecent = 0 } diff --git a/metrics/registry_test.go b/metrics/registry_test.go index c47d7caccd..2e7afb2420 100644 --- a/metrics/registry_test.go +++ b/metrics/registry_test.go @@ -24,6 +24,7 @@ func BenchmarkRegistryGetOrRegisterParallel_32(b *testing.B) { } func benchmarkRegistryGetOrRegisterParallel(b *testing.B, amount int) { + b.Helper() r := NewRegistry() b.ResetTimer() var wg sync.WaitGroup diff --git a/miner/worker_test.go b/miner/worker_test.go index f854aeee17..a31d1aa1ea 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -407,6 +407,7 @@ func TestEmptyWorkClique(t *testing.T) { } func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) { + t.Helper() defer engine.Close() w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0) diff --git a/p2p/protocol.go b/p2p/protocol.go index 9bb6785a22..8d3085655f 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -79,15 +79,15 @@ func (cap Cap) String() string { } // Cmp defines the canonical sorting order of capabilities. -func (cap Cap) Cmp(other Cap) int { - if cap.Name == other.Name { - if cap.Version < other.Version { +func (capacity Cap) Cmp(other Cap) int { + if capacity.Name == other.Name { + if capacity.Version < other.Version { return -1 } - if cap.Version > other.Version { + if capacity.Version > other.Version { return 1 } return 0 } - return strings.Compare(cap.Name, other.Name) + return strings.Compare(capacity.Name, other.Name) } diff --git a/trie/iterator_test.go b/trie/iterator_test.go index 89b461f493..249cf7b811 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -140,6 +140,7 @@ func TestNodeIteratorCoverage(t *testing.T) { } func testNodeIteratorCoverage(t *testing.T, scheme string) { + t.Helper() // Create some arbitrary test trie to iterate db, nodeDb, trie, _ := makeTestTrie(scheme) @@ -492,6 +493,7 @@ func TestIteratorContinueAfterSeekError(t *testing.T) { } func testIteratorContinueAfterSeekError(t *testing.T, memonly bool, scheme string) { + t.Helper() // Commit test trie to db, then remove the node containing "bars". var ( barNodePath []byte @@ -660,6 +662,7 @@ func TestNodeIteratorLargeTrie(t *testing.T) { } func testIteratorNodeBlob(t *testing.T, scheme string) { + t.Helper() var ( db = rawdb.NewMemoryDatabase() triedb = newTestDatabase(db, scheme) diff --git a/trie/sync_test.go b/trie/sync_test.go index 2e43c6ab36..e1058d0398 100644 --- a/trie/sync_test.go +++ b/trie/sync_test.go @@ -72,6 +72,7 @@ func makeTestTrie(scheme string) (ethdb.Database, *Database, *StateTrie, map[str // checkTrieContents cross references a reconstructed trie with an expected data // content map. func checkTrieContents(t *testing.T, db ethdb.Database, scheme string, root []byte, content map[string][]byte) { + t.Helper() // Check root availability and trie contents ndb := newTestDatabase(db, scheme) trie, err := NewStateTrie(TrieID(common.BytesToHash(root)), ndb) @@ -144,6 +145,7 @@ func TestIterativeSync(t *testing.T) { } func testIterativeSync(t *testing.T, count int, bypath bool, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -229,6 +231,7 @@ func TestIterativeDelayedSync(t *testing.T) { } func testIterativeDelayedSync(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -305,6 +308,7 @@ func TestIterativeRandomSyncIndividual(t *testing.T) { } func testIterativeRandomSync(t *testing.T, count int, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -378,6 +382,7 @@ func TestIterativeRandomDelayedSync(t *testing.T) { } func testIterativeRandomDelayedSync(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -458,6 +463,7 @@ func TestDuplicateAvoidanceSync(t *testing.T) { } func testDuplicateAvoidanceSync(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -538,6 +544,7 @@ func TestIncompleteSyncHash(t *testing.T) { } func testIncompleteSync(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, _ := makeTestTrie(scheme) @@ -634,6 +641,7 @@ func TestSyncOrdering(t *testing.T) { } func testSyncOrdering(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) @@ -720,6 +728,7 @@ func testSyncOrdering(t *testing.T, scheme string) { } func syncWith(t *testing.T, root common.Hash, db ethdb.Database, srcDb *Database) { + t.Helper() // Create a destination trie and sync with the scheduler sched := NewSync(root, db, nil, srcDb.Scheme()) @@ -779,6 +788,7 @@ func TestSyncMovingTarget(t *testing.T) { } func testSyncMovingTarget(t *testing.T, scheme string) { + t.Helper() // Create a random trie to copy _, srcDb, srcTrie, srcData := makeTestTrie(scheme) diff --git a/trie/trie_test.go b/trie/trie_test.go index 75613bc1e7..a4a7ed17a4 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -86,6 +86,7 @@ func TestMissingNode(t *testing.T) { } func testMissingNode(t *testing.T, memonly bool, scheme string) { + t.Helper() diskdb := rawdb.NewMemoryDatabase() triedb := newTestDatabase(diskdb, scheme) diff --git a/trie/triedb/pathdb/database_test.go b/trie/triedb/pathdb/database_test.go index bcc37e59c8..7573d95435 100644 --- a/trie/triedb/pathdb/database_test.go +++ b/trie/triedb/pathdb/database_test.go @@ -96,6 +96,7 @@ type tester struct { } func newTester(t *testing.T) *tester { + t.Helper() var ( disk, _ = rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false) db = New(disk, &Config{CleanSize: 256 * 1024, DirtySize: 256 * 1024}) diff --git a/trie/triedb/pathdb/difflayer_test.go b/trie/triedb/pathdb/difflayer_test.go index 77c4cd5722..3523ff17a1 100644 --- a/trie/triedb/pathdb/difflayer_test.go +++ b/trie/triedb/pathdb/difflayer_test.go @@ -55,6 +55,7 @@ func BenchmarkSearch512Layers(b *testing.B) { benchmarkSearch(b, 0, 512) } func BenchmarkSearch1Layer(b *testing.B) { benchmarkSearch(b, 127, 128) } func benchmarkSearch(b *testing.B, depth int, total int) { + b.Helper() var ( npath []byte nhash common.Hash diff --git a/trie/triedb/pathdb/history_test.go b/trie/triedb/pathdb/history_test.go index 6c250c2591..124092cd49 100644 --- a/trie/triedb/pathdb/history_test.go +++ b/trie/triedb/pathdb/history_test.go @@ -103,6 +103,7 @@ func TestEncodeDecodeHistory(t *testing.T) { } func checkHistory(t *testing.T, db ethdb.KeyValueReader, freezer *rawdb.ResettableFreezer, id uint64, root common.Hash, exist bool) { + t.Helper() blob := rawdb.ReadStateHistoryMeta(freezer, id) if exist && len(blob) == 0 { t.Fatalf("Failed to load trie history, %d", id) @@ -119,6 +120,7 @@ func checkHistory(t *testing.T, db ethdb.KeyValueReader, freezer *rawdb.Resettab } func checkHistoriesInRange(t *testing.T, db ethdb.KeyValueReader, freezer *rawdb.ResettableFreezer, from, to uint64, roots []common.Hash, exist bool) { + t.Helper() for i, j := from, 0; i <= to; i, j = i+1, j+1 { checkHistory(t, db, freezer, i, roots[j], exist) }