From 5f187da6e7e05cbe3e649371bf17b22617bf72fc Mon Sep 17 00:00:00 2001 From: Awbrey Hughlett Date: Tue, 24 Dec 2024 10:16:23 -0600 Subject: [PATCH] fix linting issues --- .golangci.yml | 2 +- pkg/solana/config_tracker.go | 9 +++++---- pkg/solana/logpoller/parser.go | 4 +--- pkg/solana/report_test.go | 13 ++++++------- pkg/solana/txm/pendingtx_test.go | 11 +++++------ 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d0542f400..6744196f9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,7 +3,7 @@ run: linters: enable: - exhaustive - - exportloopref + - copyloopvar - revive - goimports - gosec diff --git a/pkg/solana/config_tracker.go b/pkg/solana/config_tracker.go index 3ddff2715..96185bf5b 100644 --- a/pkg/solana/config_tracker.go +++ b/pkg/solana/config_tracker.go @@ -26,14 +26,15 @@ func (c *ConfigTracker) LatestConfigDetails(ctx context.Context) (changedInBlock func ConfigFromState(ctx context.Context, state State) (types.ContractConfig, error) { pubKeys := []types.OnchainPublicKey{} accounts := []types.Account{} + oracles, err := state.Oracles.Data() if err != nil { return types.ContractConfig{}, err } - for _, o := range oracles { - o := o // https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable - pubKeys = append(pubKeys, o.Signer.Key[:]) - accounts = append(accounts, types.Account(o.Transmitter.String())) + + for idx := range oracles { + pubKeys = append(pubKeys, oracles[idx].Signer.Key[:]) + accounts = append(accounts, types.Account(oracles[idx].Transmitter.String())) } onchainConfigStruct := median.OnchainConfig{ diff --git a/pkg/solana/logpoller/parser.go b/pkg/solana/logpoller/parser.go index dc9a36e29..aad71a875 100644 --- a/pkg/solana/logpoller/parser.go +++ b/pkg/solana/logpoller/parser.go @@ -90,11 +90,9 @@ func (v *pgDSLParser) Timestamp(prim primitives.Timestamp) { return } - var tm int64 + tm := int64(prim.Timestamp) //nolint:gosec // disable G115 if prim.Timestamp > math.MaxInt64 { tm = 0 - } else { - tm = int64(prim.Timestamp) } v.expression = fmt.Sprintf( diff --git a/pkg/solana/report_test.go b/pkg/solana/report_test.go index 84452dada..97c55f7c0 100644 --- a/pkg/solana/report_test.go +++ b/pkg/solana/report_test.go @@ -142,12 +142,11 @@ func TestMedianFromReport(t *testing.T) { tt = append(tt, test) } - for _, tc := range tt { - tc := tc - t.Run(tc.name, func(t *testing.T) { + for idx := range tt { + t.Run(tt[idx].name, func(t *testing.T) { ctx := tests.Context(t) var pos []median.ParsedAttributedObservation - for i, obs := range tc.obs { + for i, obs := range tt[idx].obs { pos = append(pos, median.ParsedAttributedObservation{ Value: obs, JuelsPerFeeCoin: obs, @@ -156,15 +155,15 @@ func TestMedianFromReport(t *testing.T) { } report, err := cdc.BuildReport(ctx, pos) require.NoError(t, err) - max, err := cdc.MaxReportLength(ctx, len(tc.obs)) + max, err := cdc.MaxReportLength(ctx, len(tt[idx].obs)) require.NoError(t, err) assert.Equal(t, len(report), max) med, err := cdc.MedianFromReport(ctx, report) require.NoError(t, err) - assert.Equal(t, tc.expectedMedian.String(), med.String()) + assert.Equal(t, tt[idx].expectedMedian.String(), med.String()) count, err := cdc.ObserversCountFromReport(report) require.NoError(t, err) - assert.Equal(t, len(tc.obs), int(count)) + assert.Equal(t, len(tt[idx].obs), int(count)) }) } } diff --git a/pkg/solana/txm/pendingtx_test.go b/pkg/solana/txm/pendingtx_test.go index a79f9f7aa..d04cf883f 100644 --- a/pkg/solana/txm/pendingtx_test.go +++ b/pkg/solana/txm/pendingtx_test.go @@ -1303,17 +1303,16 @@ func TestPendingTxContext_ListAllExpiredBroadcastedTxs(t *testing.T) { }, } - for _, tt := range tests { - tt := tt // capture range variable - t.Run(tt.name, func(t *testing.T) { + for idx := range tests { + t.Run(tests[idx].name, func(t *testing.T) { // Initialize a new PendingTxContext ctx := newPendingTxContext() // Setup the test case - tt.setup(t, ctx) + tests[idx].setup(t, ctx) // Execute the function under test - result := ctx.ListAllExpiredBroadcastedTxs(tt.currBlockHeight) + result := ctx.ListAllExpiredBroadcastedTxs(tests[idx].currBlockHeight) // Extract the IDs from the result var resultIDs []string @@ -1322,7 +1321,7 @@ func TestPendingTxContext_ListAllExpiredBroadcastedTxs(t *testing.T) { } // Assert that the expected IDs match the result IDs (order does not matter) - assert.ElementsMatch(t, tt.expectedTxIDs, resultIDs) + assert.ElementsMatch(t, tests[idx].expectedTxIDs, resultIDs) }) } }