From 5a0197bb6cb3e576339be0a0f8f768ce24259e58 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 9 Oct 2023 05:47:33 -0500 Subject: [PATCH] golangci-lint (#10882) * x is unused (unused) * error-return: error should be the last type when returning multiple items (revive) * var-declaration: should omit type X from declaration of Y; it will be inferred from the right-hand side (revive) * defer: prefer not to defer inside loops (revive) * error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) * File is not 'goimports'-ed with -local github.com/smartcontractkit/chainlink (goimports) * SA1012: do not pass a nil Context, even if a function permits it; pass context. * ineffectual assignment to err (ineffassign) --- core/chains/evm/chain.go | 1 - core/chains/evm/gas/fixed_price_estimator.go | 1 + core/chains/evm/txmgr/strategies_test.go | 2 +- core/chains/evm/txmgr/transmitchecker_test.go | 2 +- core/cmd/cosmos_node_commands_test.go | 5 ++-- core/gethwrappers/versions.go | 4 +-- core/services/chainlink/config_general.go | 6 +---- core/services/functions/listener_test.go | 26 +++++++++---------- core/services/keystore/eth.go | 18 ------------- .../ocr2/plugins/ocr2keeper/evm21/registry.go | 5 ++-- core/services/pipeline/task.bridge_test.go | 2 +- core/services/vrf/v2/integration_v2_test.go | 6 ++--- .../vrf/v2/listener_v2_helpers_test.go | 2 +- .../vrf/vrftesthelpers/consumer_v2.go | 1 + core/web/bridge_types_controller_test.go | 2 +- core/web/nodes_controller.go | 4 +-- core/web/resolver/chain.go | 1 + tools/flakeytests/runner_test.go | 6 ----- 18 files changed, 33 insertions(+), 61 deletions(-) diff --git a/core/chains/evm/chain.go b/core/chains/evm/chain.go index ddd9a38c755..58c793cc646 100644 --- a/core/chains/evm/chain.go +++ b/core/chains/evm/chain.go @@ -64,7 +64,6 @@ var ( // LegacyChains implements [LegacyChainContainer] type LegacyChains struct { *chains.ChainsKV[Chain] - dflt Chain cfgs toml.EVMConfigs } diff --git a/core/chains/evm/gas/fixed_price_estimator.go b/core/chains/evm/gas/fixed_price_estimator.go index 733dd179fec..a45df741a27 100644 --- a/core/chains/evm/gas/fixed_price_estimator.go +++ b/core/chains/evm/gas/fixed_price_estimator.go @@ -4,6 +4,7 @@ import ( "context" "github.com/pkg/errors" + commonfee "github.com/smartcontractkit/chainlink/v2/common/fee" feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types" "github.com/smartcontractkit/chainlink/v2/core/assets" diff --git a/core/chains/evm/txmgr/strategies_test.go b/core/chains/evm/txmgr/strategies_test.go index 3d9fed8fce1..9c5a1be37f1 100644 --- a/core/chains/evm/txmgr/strategies_test.go +++ b/core/chains/evm/txmgr/strategies_test.go @@ -21,7 +21,7 @@ func Test_SendEveryStrategy(t *testing.T) { assert.Equal(t, uuid.NullUUID{}, s.Subject()) - n, err := s.PruneQueue(nil, nil) + n, err := s.PruneQueue(testutils.Context(t), nil) assert.NoError(t, err) assert.Equal(t, int64(0), n) } diff --git a/core/chains/evm/txmgr/transmitchecker_test.go b/core/chains/evm/txmgr/transmitchecker_test.go index f8a80990d31..d536eaf40b6 100644 --- a/core/chains/evm/txmgr/transmitchecker_test.go +++ b/core/chains/evm/txmgr/transmitchecker_test.go @@ -164,7 +164,7 @@ func TestTransmitCheckers(t *testing.T) { mock.AnythingOfType("*hexutil.Bytes"), "eth_call", mock.MatchedBy(func(callarg map[string]interface{}) bool { return fmt.Sprintf("%s", callarg["value"]) == "0x282" // 642 - }), "latest").Return(errors.New("error!")).Once() + }), "latest").Return(errors.New("error")).Once() // Non-revert errors are logged but should not prevent transmission, and do not need // to be passed to the caller diff --git a/core/cmd/cosmos_node_commands_test.go b/core/cmd/cosmos_node_commands_test.go index 93364b74e0b..c19749ecd12 100644 --- a/core/cmd/cosmos_node_commands_test.go +++ b/core/cmd/cosmos_node_commands_test.go @@ -6,11 +6,12 @@ import ( "testing" "github.com/pelletier/go-toml/v2" - coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config" + "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/chains/cosmos" diff --git a/core/gethwrappers/versions.go b/core/gethwrappers/versions.go index 5b65e2f411a..acdefd06a59 100644 --- a/core/gethwrappers/versions.go +++ b/core/gethwrappers/versions.go @@ -54,7 +54,7 @@ func versionsDBLineReader() (*bufio.Scanner, error) { } -// readVersionsDB populates an IntegratedVersion with all the info in the +// ReadVersionsDB populates an IntegratedVersion with all the info in the // versions DB func ReadVersionsDB() (*IntegratedVersion, error) { rv := IntegratedVersion{} @@ -87,7 +87,7 @@ func ReadVersionsDB() (*IntegratedVersion, error) { } _, alreadyExists := rv.ContractVersions[topic] if alreadyExists { - return nil, errors.Errorf(`topic "%s" already mentioned!`, topic) + return nil, errors.Errorf(`topic "%s" already mentioned`, topic) } rv.ContractVersions[topic] = ContractVersion{ AbiPath: line[1], BinaryPath: line[2], Hash: line[3], diff --git a/core/services/chainlink/config_general.go b/core/services/chainlink/config_general.go index 688215c6978..33be81add5d 100644 --- a/core/services/chainlink/config_general.go +++ b/core/services/chainlink/config_general.go @@ -3,7 +3,6 @@ package chainlink import ( _ "embed" "fmt" - "net/url" "os" "path/filepath" "strings" @@ -506,7 +505,4 @@ func (g *generalConfig) Threshold() coreconfig.Threshold { return &thresholdConfig{s: g.secrets.Threshold} } -var ( - zeroURL = url.URL{} - zeroSha256Hash = models.Sha256Hash{} -) +var zeroSha256Hash = models.Sha256Hash{} diff --git a/core/services/functions/listener_test.go b/core/services/functions/listener_test.go index a06fcf3e3b2..2bcf2542638 100644 --- a/core/services/functions/listener_test.go +++ b/core/services/functions/listener_test.go @@ -63,19 +63,19 @@ type FunctionsListenerUniverse struct { func ptr[T any](t T) *T { return &t } var ( - RequestID functions_service.RequestID = newRequestID() - RequestIDStr = fmt.Sprintf("0x%x", [32]byte(RequestID)) - SubscriptionOwner common.Address = common.BigToAddress(big.NewInt(42069)) - SubscriptionID = uint64(5) - ResultBytes = []byte{0xab, 0xcd} - ErrorBytes = []byte{0xff, 0x11} - Domains = []string{"github.com", "google.com"} - EncryptedSecretsUrls []byte = []byte{0x11, 0x22} - EncryptedSecrets []byte = []byte(`{"TDH2Ctxt":"eyJHcm","SymCtxt":"+yHR","Nonce":"kgjHyT3Jar0M155E"}`) - DecryptedSecrets []byte = []byte(`{"0x0":"lhcK"}`) - SignedCBORRequestHex = "a666736f75726365782172657475726e2046756e6374696f6e732e656e636f646555696e743235362831296773656372657473421234686c616e6775616765006c636f64654c6f636174696f6e006f736563726574734c6f636174696f6e0170726571756573745369676e617475726558416fb6d10871aa3865b6620dc5f4594d2a9ad9166ba6b1dbc3f508362fd27aa0461babada48979092a11ecadec9c663a2ea99da4e368408b36a3fb414acfefdd2a1c" - SubOwnerAddr common.Address = common.HexToAddress("0x2334dE553AB93c69b0ccbe278B6f5E8350Db6204") - NonSubOwnerAddr common.Address = common.HexToAddress("0x60C9CF55b9de9A956d921A97575108149b758131") + RequestID = newRequestID() + RequestIDStr = fmt.Sprintf("0x%x", [32]byte(RequestID)) + SubscriptionOwner = common.BigToAddress(big.NewInt(42069)) + SubscriptionID = uint64(5) + ResultBytes = []byte{0xab, 0xcd} + ErrorBytes = []byte{0xff, 0x11} + Domains = []string{"github.com", "google.com"} + EncryptedSecretsUrls = []byte{0x11, 0x22} + EncryptedSecrets = []byte(`{"TDH2Ctxt":"eyJHcm","SymCtxt":"+yHR","Nonce":"kgjHyT3Jar0M155E"}`) + DecryptedSecrets = []byte(`{"0x0":"lhcK"}`) + SignedCBORRequestHex = "a666736f75726365782172657475726e2046756e6374696f6e732e656e636f646555696e743235362831296773656372657473421234686c616e6775616765006c636f64654c6f636174696f6e006f736563726574734c6f636174696f6e0170726571756573745369676e617475726558416fb6d10871aa3865b6620dc5f4594d2a9ad9166ba6b1dbc3f508362fd27aa0461babada48979092a11ecadec9c663a2ea99da4e368408b36a3fb414acfefdd2a1c" + SubOwnerAddr = common.HexToAddress("0x2334dE553AB93c69b0ccbe278B6f5E8350Db6204") + NonSubOwnerAddr = common.HexToAddress("0x60C9CF55b9de9A956d921A97575108149b758131") ) func NewFunctionsListenerUniverse(t *testing.T, timeoutSec int, pruneFrequencySec int, setTiers bool, version uint32) *FunctionsListenerUniverse { diff --git a/core/services/keystore/eth.go b/core/services/keystore/eth.go index 9909f398bf4..362baed6afc 100644 --- a/core/services/keystore/eth.go +++ b/core/services/keystore/eth.go @@ -664,24 +664,6 @@ func (ks *eth) add(key ethkey.KeyV2, chainIDs ...*big.Int) (err error) { return err } -func (ks *eth) addWithNonce(key ethkey.KeyV2, chainID *big.Int, nonce int64, isDisabled bool) (err error) { - ks.lock.Lock() - defer ks.lock.Unlock() - err = ks.safeAddKey(key, func(tx pg.Queryer) (merr error) { - state := new(ethkey.State) - sql := `INSERT INTO evm.key_states (address, next_nonce, disabled, evm_chain_id, created_at, updated_at) -VALUES ($1, $2, $3, $4, NOW(), NOW()) RETURNING *;` - if err = ks.orm.q.Get(state, sql, key.Address, nonce, isDisabled, chainID); err != nil { - return errors.Wrap(err, "failed to insert evm_key_state") - } - - ks.keyStates.add(state) - return nil - }) - ks.notify() - return err -} - // notify notifies subscribers that eth keys have changed func (ks *eth) notify() { ks.subscribersMu.RLock() diff --git a/core/services/ocr2/plugins/ocr2keeper/evm21/registry.go b/core/services/ocr2/plugins/ocr2keeper/evm21/registry.go index d7cd5f26250..1cad587e635 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evm21/registry.go +++ b/core/services/ocr2/plugins/ocr2keeper/evm21/registry.go @@ -15,9 +15,10 @@ import ( coreTypes "github.com/ethereum/go-ethereum/core/types" "github.com/patrickmn/go-cache" "github.com/pkg/errors" - ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types" "go.uber.org/multierr" + ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" @@ -144,8 +145,6 @@ type EvmRegistry struct { lastPollBlock int64 ctx context.Context headFunc func(ocr2keepers.BlockKey) - runState int - runError error mercury *MercuryConfig hc HttpClient bs *BlockSubscriber diff --git a/core/services/pipeline/task.bridge_test.go b/core/services/pipeline/task.bridge_test.go index e37b2095236..6f542d485e0 100644 --- a/core/services/pipeline/task.bridge_test.go +++ b/core/services/pipeline/task.bridge_test.go @@ -138,7 +138,7 @@ func fakeIntermittentlyFailingPriceResponder(t *testing.T, requestData map[strin if reqBody.Meta["shouldFail"].(bool) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusBadGateway) - require.NoError(t, json.NewEncoder(w).Encode(errors.New("EA failure!"))) + require.NoError(t, json.NewEncoder(w).Encode(errors.New("EA failure"))) return } w.Header().Set("Content-Type", "application/json") diff --git a/core/services/vrf/v2/integration_v2_test.go b/core/services/vrf/v2/integration_v2_test.go index 531c7ebb663..b26bdf750ba 100644 --- a/core/services/vrf/v2/integration_v2_test.go +++ b/core/services/vrf/v2/integration_v2_test.go @@ -222,9 +222,8 @@ func newVRFCoordinatorV2Universe(t *testing.T, key ethkey.KeyV2, numConsumers in backend.Commit() // Deploy old VRF v2 coordinator from bytecode - err, oldRootContractAddress, oldRootContract := deployOldCoordinator( + oldRootContractAddress, oldRootContract := deployOldCoordinator( t, linkAddress, bhsAddress, linkEthFeed, backend, neil) - require.NoError(t, err) // Deploy the VRFOwner contract, which will own the VRF coordinator // in some tests. @@ -423,7 +422,6 @@ func deployOldCoordinator( backend *backends.SimulatedBackend, neil *bind.TransactOpts, ) ( - error, common.Address, *vrf_coordinator_v2.VRFCoordinatorV2, ) { @@ -447,7 +445,7 @@ func deployOldCoordinator( require.NotEqual(t, common.HexToAddress("0x0"), oldRootContractAddress, "old vrf coordinator address equal to zero address, deployment failed") oldRootContract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(oldRootContractAddress, backend) require.NoError(t, err, "could not create wrapper object for old vrf coordinator v2") - return err, oldRootContractAddress, oldRootContract + return oldRootContractAddress, oldRootContract } // Send eth from prefunded account. diff --git a/core/services/vrf/v2/listener_v2_helpers_test.go b/core/services/vrf/v2/listener_v2_helpers_test.go index 204d1e1fcab..8ba900bdc3a 100644 --- a/core/services/vrf/v2/listener_v2_helpers_test.go +++ b/core/services/vrf/v2/listener_v2_helpers_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/assets" - "github.com/smartcontractkit/chainlink/v2/core/services/vrf/v2" + v2 "github.com/smartcontractkit/chainlink/v2/core/services/vrf/v2" ) func TestListener_EstimateFeeJuels(t *testing.T) { diff --git a/core/services/vrf/vrftesthelpers/consumer_v2.go b/core/services/vrf/vrftesthelpers/consumer_v2.go index ec3d727f7ab..abaf97b828b 100644 --- a/core/services/vrf/vrftesthelpers/consumer_v2.go +++ b/core/services/vrf/vrftesthelpers/consumer_v2.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2_plus_upgradeable_example" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2_upgradeable_example" diff --git a/core/web/bridge_types_controller_test.go b/core/web/bridge_types_controller_test.go index 7184b05f5e0..e0048cc64d4 100644 --- a/core/web/bridge_types_controller_test.go +++ b/core/web/bridge_types_controller_test.go @@ -140,7 +140,7 @@ func BenchmarkBridgeTypesController_Index(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { resp, cleanup := client.Get("/v2/bridge_types") - defer cleanup() + b.Cleanup(cleanup) assert.Equal(b, http.StatusOK, resp.StatusCode, "Response should be successful") } } diff --git a/core/web/nodes_controller.go b/core/web/nodes_controller.go index 1eddc67c364..3547b150bc7 100644 --- a/core/web/nodes_controller.go +++ b/core/web/nodes_controller.go @@ -76,9 +76,9 @@ func (n *nodesController[R]) Index(c *gin.Context, size, page, offset int) { // fetch nodes for chain ID // backward compatibility var rid relay.ID - err := rid.UnmarshalString(id) + err = rid.UnmarshalString(id) if err != nil { - rid.ChainID = relay.ChainID(id) + rid.ChainID = id rid.Network = n.nodeSet.network } nodes, count, err = n.nodeSet.NodeStatuses(c, offset, size, rid) diff --git a/core/web/resolver/chain.go b/core/web/resolver/chain.go index 02573f423a4..53f1016d72b 100644 --- a/core/web/resolver/chain.go +++ b/core/web/resolver/chain.go @@ -2,6 +2,7 @@ package resolver import ( "github.com/graph-gophers/graphql-go" + "github.com/smartcontractkit/chainlink-relay/pkg/types" ) diff --git a/tools/flakeytests/runner_test.go b/tools/flakeytests/runner_test.go index 8fa81db5ba0..c4509ff2cc9 100644 --- a/tools/flakeytests/runner_test.go +++ b/tools/flakeytests/runner_test.go @@ -232,12 +232,6 @@ func TestRunner_RootLevelTest(t *testing.T) { assert.True(t, ok) } -type exitError struct{} - -func (e *exitError) ExitCode() int { return 1 } - -func (e *exitError) Error() string { return "exit code: 1" } - func TestRunner_RerunFailsWithNonzeroExitCode(t *testing.T) { output := `{"Time":"2023-09-07T15:39:46.378315+01:00","Action":"fail","Package":"github.com/smartcontractkit/chainlink/v2/core/assets","Test":"TestLink","Elapsed":0}`