Skip to content

Commit 995b46f

Browse files
fix linter issues
1 parent 30b67db commit 995b46f

File tree

13 files changed

+87
-80
lines changed

13 files changed

+87
-80
lines changed

.github/workflows/golangci-lint.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
uses: cachix/install-nix-action@3715ab1a11cac9e991980d7b4a28d80c7ebdd8f9 # nix:v2.24.6
1515
with:
1616
nix_path: nixpkgs=channel:nixos-unstable
17+
- name: Print golangci-lint Version
18+
run: nix develop -c golangci-lint --version
1719
- name: golangci-lint
1820
run: nix develop -c make lint-go-integration-tests
1921
- name: Print lint report artifact
@@ -37,6 +39,8 @@ jobs:
3739
uses: cachix/install-nix-action@3715ab1a11cac9e991980d7b4a28d80c7ebdd8f9 # nix:v2.24.6
3840
with:
3941
nix_path: nixpkgs=channel:nixos-unstable
42+
- name: Print golangci-lint Version
43+
run: nix develop -c golangci-lint --version
4044
- name: golangci-lint
4145
run: nix develop -c make lint-go-relay
4246
- name: Print lint report artifact

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ run:
33
linters:
44
enable:
55
- exhaustive
6-
- exportloopref
6+
- copyloopvar
77
- revive
88
- goimports
99
- gosec

integration-tests/smoke/ocr2_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
func TestSolanaOCRV2Smoke(t *testing.T) {
23-
for _, test := range []struct {
23+
tests := []struct {
2424
name string
2525
env map[string]string
2626
}{
@@ -29,13 +29,16 @@ func TestSolanaOCRV2Smoke(t *testing.T) {
2929
"CL_MEDIAN_CMD": "chainlink-feeds",
3030
"CL_SOLANA_CMD": "chainlink-solana",
3131
}},
32-
} {
32+
}
33+
34+
for idx := range tests {
35+
test := tests[idx]
36+
3337
config, err := tc.GetConfig("Smoke", tc.OCR2)
3438
if err != nil {
3539
t.Fatal(err)
3640
}
3741

38-
test := test
3942
t.Run(test.name, func(t *testing.T) {
4043
t.Parallel()
4144
_, sg := startOCR2DataFeedsSmokeTest(t, test.name, test.env, config, "")

integration-tests/soak/ocr2_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
func TestSolanaOCRV2Soak(t *testing.T) {
23-
for _, test := range []struct {
23+
tests := []struct {
2424
name string
2525
env map[string]string
2626
}{
@@ -29,13 +29,16 @@ func TestSolanaOCRV2Soak(t *testing.T) {
2929
"CL_MEDIAN_CMD": "chainlink-feeds",
3030
"CL_SOLANA_CMD": "chainlink-solana",
3131
}},
32-
} {
32+
}
33+
34+
for idx := range tests {
35+
test := tests[idx]
36+
3337
config, err := tc.GetConfig("Soak", tc.OCR2)
3438
if err != nil {
3539
t.Fatal(err)
3640
}
3741

38-
test := test
3942
t.Run(test.name, func(t *testing.T) {
4043
t.Parallel()
4144

integration-tests/solclient/deployer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,13 @@ func (c *ContractDeployer) DeployAnchorProgramsRemote(contractsDir string, env *
502502
}
503503
log.Debug().Interface("Binaries", contractBinaries).Msg("Program binaries")
504504
g := errgroup.Group{}
505-
for _, bin := range contractBinaries {
506-
bin := bin
505+
506+
for idx := range contractBinaries {
507507
g.Go(func() error {
508-
return c.DeployProgramRemote(bin, env)
508+
return c.DeployProgramRemote(contractBinaries[idx], env)
509509
})
510510
}
511+
511512
return g.Wait()
512513
}
513514

@@ -518,10 +519,9 @@ func (c *ContractDeployer) DeployAnchorProgramsRemoteDocker(baseDir, subDir stri
518519
}
519520
log.Info().Interface("Binaries", contractBinaries).Msg(fmt.Sprintf("Program binaries [%s]", filepath.Join("programs", subDir)))
520521
g := errgroup.Group{}
521-
for _, bin := range contractBinaries {
522-
bin := bin
522+
for idx := range contractBinaries {
523523
g.Go(func() error {
524-
return c.DeployProgramRemoteLocal(filepath.Join(subDir, bin), sol, programIDBuilder)
524+
return c.DeployProgramRemoteLocal(filepath.Join(subDir, contractBinaries[idx]), sol, programIDBuilder)
525525
})
526526
}
527527
return g.Wait()

pkg/solana/config_tracker.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ func (c *ConfigTracker) LatestConfigDetails(ctx context.Context) (changedInBlock
2626
func ConfigFromState(ctx context.Context, state State) (types.ContractConfig, error) {
2727
pubKeys := []types.OnchainPublicKey{}
2828
accounts := []types.Account{}
29+
2930
oracles, err := state.Oracles.Data()
3031
if err != nil {
3132
return types.ContractConfig{}, err
3233
}
33-
for _, o := range oracles {
34-
o := o // https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable
35-
pubKeys = append(pubKeys, o.Signer.Key[:])
36-
accounts = append(accounts, types.Account(o.Transmitter.String()))
34+
35+
for idx := range oracles {
36+
pubKeys = append(pubKeys, oracles[idx].Signer.Key[:])
37+
accounts = append(accounts, types.Account(oracles[idx].Transmitter.String()))
3738
}
3839

3940
onchainConfigStruct := median.OnchainConfig{

pkg/solana/fees/block_history_test.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func TestBlockHistoryEstimator_InvalidBlockHistorySize(t *testing.T) {
4141

4242
func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
4343
// Helper variables for tests
44-
min := uint64(10)
45-
max := uint64(100_000)
44+
minPrice := uint64(10)
45+
maxPrice := uint64(100_000)
4646
defaultPrice := uint64(100)
4747
depth := uint64(1) // 1 is LatestBlockEstimator
4848
pollPeriod := 100 * time.Millisecond
@@ -63,21 +63,21 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
6363
t.Run("Successful Estimation", func(t *testing.T) {
6464
// Setup
6565
cfg := cfgmock.NewConfig(t)
66-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
66+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
6767
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
6868

6969
// Assert the computed price matches the expected price
7070
require.NoError(t, estimator.calculatePrice(ctx), "Failed to calculate price")
71-
cfg.On("ComputeUnitPriceMin").Return(min)
72-
cfg.On("ComputeUnitPriceMax").Return(max)
71+
cfg.On("ComputeUnitPriceMin").Return(minPrice)
72+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
7373
assert.Equal(t, uint64(lastBlockMedianPrice), estimator.BaseComputeUnitPrice())
7474
})
7575

7676
t.Run("Min Gate: Price Should Be Floored at Min", func(t *testing.T) {
7777
// Setup
7878
cfg := cfgmock.NewConfig(t)
7979
tmpMin := uint64(lastBlockMedianPrice) + 100 // Set min higher than the median price
80-
setupConfigMock(cfg, defaultPrice, tmpMin, max, pollPeriod, depth)
80+
setupConfigMock(cfg, defaultPrice, tmpMin, pollPeriod, depth)
8181
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
8282

8383
// Call calculatePrice and ensure no error
@@ -91,14 +91,14 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
9191
// Setup
9292
cfg := cfgmock.NewConfig(t)
9393
tmpMax := uint64(lastBlockMedianPrice) - 100 // Set max lower than the median price
94-
setupConfigMock(cfg, defaultPrice, min, tmpMax, pollPeriod, depth)
94+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
9595
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
9696

9797
// Call calculatePrice and ensure no error
9898
// Assert the compute unit price is capped at max
9999
require.NoError(t, estimator.calculatePrice(ctx), "Failed to calculate price with price above max")
100100
cfg.On("ComputeUnitPriceMax").Return(tmpMax)
101-
cfg.On("ComputeUnitPriceMin").Return(min)
101+
cfg.On("ComputeUnitPriceMin").Return(minPrice)
102102
assert.Equal(t, tmpMax, estimator.BaseComputeUnitPrice(), "Price should be capped at max")
103103
})
104104

@@ -109,13 +109,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
109109
return rw, nil
110110
})
111111
cfg := cfgmock.NewConfig(t)
112-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
112+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
113113
rw.On("GetLatestBlock", mock.Anything).Return(nil, fmt.Errorf("fail rpc call")) // Mock GetLatestBlock returning error
114114
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
115115

116116
// Ensure the price remains unchanged
117117
require.Error(t, estimator.calculatePrice(ctx), "Expected error when GetLatestBlock fails")
118-
cfg.On("ComputeUnitPriceMax").Return(max)
118+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
119119
assert.Equal(t, uint64(100), estimator.BaseComputeUnitPrice(), "Price should not change when GetLatestBlock fails")
120120
})
121121

@@ -126,13 +126,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
126126
return rw, nil
127127
})
128128
cfg := cfgmock.NewConfig(t)
129-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
129+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
130130
rw.On("GetLatestBlock", mock.Anything).Return(nil, nil) // Mock GetLatestBlock returning nil
131131
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
132132

133133
// Ensure the price remains unchanged
134134
require.Error(t, estimator.calculatePrice(ctx), "Expected error when parsing fails")
135-
cfg.On("ComputeUnitPriceMax").Return(max)
135+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
136136
assert.Equal(t, uint64(100), estimator.BaseComputeUnitPrice(), "Price should not change when parsing fails")
137137
})
138138

@@ -143,13 +143,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
143143
return rw, nil
144144
})
145145
cfg := cfgmock.NewConfig(t)
146-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
146+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
147147
rw.On("GetLatestBlock", mock.Anything).Return(&rpc.GetBlockResult{}, nil) // Mock GetLatestBlock returning empty block
148148
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
149149

150150
// Ensure the price remains unchanged
151151
require.EqualError(t, estimator.calculatePrice(ctx), errNoComputeUnitPriceCollected.Error(), "Expected error when no compute unit prices are collected")
152-
cfg.On("ComputeUnitPriceMax").Return(max)
152+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
153153
assert.Equal(t, uint64(100), estimator.BaseComputeUnitPrice(), "Price should not change when median calculation fails")
154154
})
155155

@@ -160,21 +160,21 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
160160
return nil, fmt.Errorf("fail client load")
161161
})
162162
cfg := cfgmock.NewConfig(t)
163-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
163+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
164164
estimator := initializeEstimator(ctx, t, rwFailLoader, cfg, logger.Test(t))
165165

166166
// Call calculatePrice and expect an error
167167
// Ensure the price remains unchanged
168168
require.Error(t, estimator.calculatePrice(ctx), "Expected error when getting client fails")
169-
cfg.On("ComputeUnitPriceMax").Return(max)
169+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
170170
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice(), "Price should remain at default when client fails")
171171
})
172172
}
173173

174174
func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
175175
// helpers vars for tests
176-
min := uint64(100)
177-
max := uint64(100_000)
176+
minPrice := uint64(100)
177+
maxPrice := uint64(100_000)
178178
depth := uint64(3)
179179
defaultPrice := uint64(100)
180180
pollPeriod := 3 * time.Second
@@ -220,20 +220,20 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
220220
t.Run("Successful Estimation", func(t *testing.T) {
221221
// Setup
222222
cfg := cfgmock.NewConfig(t)
223-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
223+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
224224
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
225225

226226
// Calculated avg price should be equal to the one extracted manually from the blocks.
227227
require.NoError(t, estimator.calculatePrice(ctx))
228-
cfg.On("ComputeUnitPriceMax").Return(max)
228+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
229229
assert.Equal(t, uint64(multipleBlocksAvg), estimator.BaseComputeUnitPrice())
230230
})
231231

232232
t.Run("Min Gate: Price Should Be Floored at Min", func(t *testing.T) {
233233
// Setup
234234
cfg := cfgmock.NewConfig(t)
235235
tmpMin := uint64(multipleBlocksAvg) + 100 // Set min higher than the avg price
236-
setupConfigMock(cfg, defaultPrice, tmpMin, max, pollPeriod, depth)
236+
setupConfigMock(cfg, defaultPrice, tmpMin, pollPeriod, depth)
237237
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
238238

239239
// Compute unit price should be floored at min
@@ -246,13 +246,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
246246
// Setup
247247
cfg := cfgmock.NewConfig(t)
248248
tmpMax := uint64(multipleBlocksAvg) - 100 // Set tmpMax lower than the avg price
249-
setupConfigMock(cfg, defaultPrice, min, tmpMax, pollPeriod, depth)
249+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
250250
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
251251

252252
// Compute unit price should be capped at max
253253
require.NoError(t, estimator.calculatePrice(ctx), "Failed to calculate price with price above max")
254254
cfg.On("ComputeUnitPriceMax").Return(tmpMax)
255-
cfg.On("ComputeUnitPriceMin").Return(min)
255+
cfg.On("ComputeUnitPriceMin").Return(minPrice)
256256
assert.Equal(t, tmpMax, estimator.BaseComputeUnitPrice(), "Price should be capped at max")
257257
})
258258

@@ -264,12 +264,12 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
264264
return nil, fmt.Errorf("fail client load")
265265
})
266266
cfg := cfgmock.NewConfig(t)
267-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
267+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
268268
estimator := initializeEstimator(ctx, t, rwFailLoader, cfg, logger.Test(t))
269269

270270
// Price should remain unchanged
271271
require.Error(t, estimator.calculatePrice(ctx), "Expected error when getting client fails")
272-
cfg.On("ComputeUnitPriceMax").Return(max)
272+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
273273
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice())
274274
})
275275

@@ -280,13 +280,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
280280
return rw, nil
281281
})
282282
cfg := cfgmock.NewConfig(t)
283-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
283+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
284284
rw.On("SlotHeight", mock.Anything).Return(uint64(0), fmt.Errorf("failed to get current slot")) // Mock SlotHeight returning error
285285
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
286286

287287
// Price should remain unchanged
288288
require.Error(t, estimator.calculatePrice(ctx), "Expected error when getting current slot fails")
289-
cfg.On("ComputeUnitPriceMax").Return(max)
289+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
290290
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice())
291291
})
292292

@@ -297,13 +297,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
297297
return rw, nil
298298
})
299299
cfg := cfgmock.NewConfig(t)
300-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
300+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
301301
rw.On("SlotHeight", mock.Anything).Return(depth-1, nil) // Mock SlotHeight returning less than desiredBlockCount
302302
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
303303

304304
// Price should remain unchanged
305305
require.Error(t, estimator.calculatePrice(ctx), "Expected error when current slot is less than desired block count")
306-
cfg.On("ComputeUnitPriceMax").Return(max)
306+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
307307
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice())
308308
})
309309

@@ -314,15 +314,15 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
314314
return rw, nil
315315
})
316316
cfg := cfgmock.NewConfig(t)
317-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
317+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
318318
rw.On("SlotHeight", mock.Anything).Return(testSlots[len(testSlots)-1], nil)
319319
rw.On("GetBlocksWithLimit", mock.Anything, mock.Anything, mock.Anything).
320320
Return(nil, fmt.Errorf("failed to get blocks with limit")) // Mock GetBlocksWithLimit returning error
321321
estimator := initializeEstimator(ctx, t, rwLoader, cfg, logger.Test(t))
322322

323323
// Price should remain unchanged
324324
require.Error(t, estimator.calculatePrice(ctx), "Expected error when getting blocks with limit fails")
325-
cfg.On("ComputeUnitPriceMax").Return(max)
325+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
326326
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice())
327327
})
328328

@@ -333,7 +333,7 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
333333
return rw, nil
334334
})
335335
cfg := cfgmock.NewConfig(t)
336-
setupConfigMock(cfg, defaultPrice, min, max, pollPeriod, depth)
336+
setupConfigMock(cfg, defaultPrice, minPrice, pollPeriod, depth)
337337
rw.On("SlotHeight", mock.Anything).Return(testSlots[len(testSlots)-1], nil)
338338
emptyBlocks := rpc.BlocksResult{} // No blocks with compute unit prices
339339
rw.On("GetBlocksWithLimit", mock.Anything, mock.Anything, mock.Anything).
@@ -342,15 +342,15 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
342342

343343
// Price should remain unchanged
344344
require.EqualError(t, estimator.calculatePrice(ctx), errNoComputeUnitPriceCollected.Error(), "Expected error when no compute unit prices are collected")
345-
cfg.On("ComputeUnitPriceMax").Return(max)
345+
cfg.On("ComputeUnitPriceMax").Return(maxPrice)
346346
assert.Equal(t, defaultPrice, estimator.BaseComputeUnitPrice())
347347
})
348348
}
349349

350350
// setupConfigMock configures the Config mock with necessary return values.
351-
func setupConfigMock(cfg *cfgmock.Config, defaultPrice uint64, min, max uint64, pollPeriod time.Duration, depth uint64) {
351+
func setupConfigMock(cfg *cfgmock.Config, defaultPrice uint64, minPrice uint64, pollPeriod time.Duration, depth uint64) {
352352
cfg.On("ComputeUnitPriceDefault").Return(defaultPrice).Once()
353-
cfg.On("ComputeUnitPriceMin").Return(min).Once()
353+
cfg.On("ComputeUnitPriceMin").Return(minPrice).Once()
354354
cfg.On("BlockHistoryPollPeriod").Return(pollPeriod).Once()
355355
cfg.On("BlockHistorySize").Return(depth)
356356
}

0 commit comments

Comments
 (0)