Skip to content

Commit 0d227ec

Browse files
sync: coreth PR #1372: style: use t.Context() (#1861)
1 parent e0942e7 commit 0d227ec

22 files changed

+474
-473
lines changed

.avalanche-golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ linters:
8282
- unparam
8383
- unused
8484
- usestdlibvars
85+
- usetesting
8586
- whitespace
8687
settings:
8788
depguard:
@@ -228,6 +229,14 @@ linters:
228229
# Mark all local variables as used.
229230
# default: true
230231
local-variables-are-used: false
232+
usetesting:
233+
os-create-temp: true # Disallow `os.CreateTemp("", ...)`
234+
os-mkdir-temp: true # Disallow `os.MkdirTemp()`
235+
os-setenv: true # Disallow `os.Setenv()`
236+
os-temp-dir: true # Disallow `os.TempDir()`
237+
os-chdir: true # Disallow `os.Chdir()`
238+
context-background: true # Disallow `context.Background()`
239+
context-todo: true # Disallow `context.TODO()`
231240
exclusions:
232241
generated: lax
233242
presets:

eth/gasprice/fee_info_provider_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package gasprice
55

66
import (
7-
"context"
87
"math/big"
98
"sync"
109
"testing"
@@ -52,7 +51,7 @@ func TestFeeInfoProviderCacheSize(t *testing.T) {
5251
// to test eviction behavior.
5352
for i := 0; i < size+feeCacheExtraSlots+overflow; i++ {
5453
header := &types.Header{Number: big.NewInt(int64(i))}
55-
_, err := f.addHeader(context.Background(), header, []*types.Transaction{})
54+
_, err := f.addHeader(t.Context(), header, []*types.Transaction{})
5655
require.NoError(t, err)
5756
}
5857

eth/tracers/api_extra_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package tracers
55

66
import (
7-
"context"
87
"encoding/json"
98
"fmt"
109
"math/big"
@@ -132,7 +131,7 @@ func testTraceBlockPrecompileActivation(t *testing.T, scheme string) {
132131
},
133132
}
134133
for i, tc := range testSuite {
135-
result, err := api.TraceBlockByNumber(context.Background(), tc.blockNumber, tc.config)
134+
result, err := api.TraceBlockByNumber(t.Context(), tc.blockNumber, tc.config)
136135
if tc.expectErr != nil {
137136
if err == nil {
138137
t.Errorf("test %d, want error %v", i, tc.expectErr)
@@ -210,7 +209,7 @@ func testTraceTransactionPrecompileActivation(t *testing.T, scheme string) {
210209
api := NewAPI(backend)
211210
for i, target := range blockNoTxMap {
212211
t.Run(fmt.Sprintf("blockNumber %d", i), func(t *testing.T) {
213-
result, err := api.TraceTransaction(context.Background(), target, nil)
212+
result, err := api.TraceTransaction(t.Context(), target, nil)
214213
require := require.New(t)
215214
require.NoError(err)
216215
var have *logger.ExecutionResult
@@ -300,8 +299,8 @@ func testTraceChainPrecompileActivation(t *testing.T, scheme string) {
300299
ref.Store(0)
301300
rel.Store(0)
302301

303-
from, _ := api.blockByNumber(context.Background(), rpc.BlockNumber(c.start))
304-
to, _ := api.blockByNumber(context.Background(), rpc.BlockNumber(c.end))
302+
from, _ := api.blockByNumber(t.Context(), rpc.BlockNumber(c.start))
303+
to, _ := api.blockByNumber(t.Context(), rpc.BlockNumber(c.end))
305304
resCh := api.traceChain(from, to, c.config, nil)
306305

307306
next := c.start + 1
@@ -443,7 +442,7 @@ func testTraceCallWithOverridesStateUpgrade(t *testing.T, scheme string) {
443442
},
444443
}
445444
for i, testspec := range testSuite {
446-
result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config)
445+
result, err := api.TraceCall(t.Context(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config)
447446
if testspec.expectErr != nil {
448447
require.ErrorIs(t, err, testspec.expectErr, "test %d", i)
449448
continue

internal/ethapi/api_extra_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package ethapi
55

66
import (
7-
"context"
87
"errors"
98
"math/big"
109
"os"
@@ -47,7 +46,7 @@ func TestBlockchainAPI_GetChainConfig(t *testing.T) {
4746

4847
api := NewBlockChainAPI(backend)
4948

50-
gotConfig := api.GetChainConfig(context.Background())
49+
gotConfig := api.GetChainConfig(t.Context())
5150
assert.Equal(t, params.ToWithUpgradesJSON(wantConfig), gotConfig)
5251
}
5352

@@ -77,7 +76,7 @@ func TestBlockchainAPI_CallDetailed(t *testing.T) {
7776
}))
7877

7978
result, err := api.CallDetailed(
80-
context.Background(),
79+
t.Context(),
8180
TransactionArgs{
8281
From: &accounts[0].addr,
8382
To: &accounts[1].addr,

0 commit comments

Comments
 (0)