Skip to content

Commit

Permalink
golangci-lint (#10882)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
jmank88 authored Oct 9, 2023
1 parent 7dbb38b commit 5a0197b
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 61 deletions.
1 change: 0 additions & 1 deletion core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var (
// LegacyChains implements [LegacyChainContainer]
type LegacyChains struct {
*chains.ChainsKV[Chain]
dflt Chain

cfgs toml.EVMConfigs
}
Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/gas/fixed_price_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/transmitchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions core/cmd/cosmos_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions core/gethwrappers/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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],
Expand Down
6 changes: 1 addition & 5 deletions core/services/chainlink/config_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chainlink
import (
_ "embed"
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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{}
26 changes: 13 additions & 13 deletions core/services/functions/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 0 additions & 18 deletions core/services/keystore/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions core/services/ocr2/plugins/ocr2keeper/evm21/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/services/pipeline/task.bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions core/services/vrf/v2/integration_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -423,7 +422,6 @@ func deployOldCoordinator(
backend *backends.SimulatedBackend,
neil *bind.TransactOpts,
) (
error,
common.Address,
*vrf_coordinator_v2.VRFCoordinatorV2,
) {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/services/vrf/v2/listener_v2_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions core/services/vrf/vrftesthelpers/consumer_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/web/bridge_types_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/web/nodes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core/web/resolver/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolver

import (
"github.com/graph-gophers/graphql-go"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
)

Expand Down
6 changes: 0 additions & 6 deletions tools/flakeytests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}`

Expand Down

0 comments on commit 5a0197b

Please sign in to comment.