Skip to content

Commit

Permalink
golangci-lint (#10420)
Browse files Browse the repository at this point in the history
* Error return value of * is not checked (errcheck)

* ineffectual assignment to orm (ineffassign)

* unnecessary use of fmt.Sprintf (gosimple)

* unnecessary nil check around range (gosimple)

* should merge variable declaration with assignment on next line (gosimple)

* type * is unused (unused)

* if-return: redundant if ...; err != nil check, just return error instead. (revive)

* receiver-naming: receiver name * should be consistent with previous receiver name * for * (revive)

* indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

* Implicit memory aliasing in for loop. (gosec)
  • Loading branch information
jmank88 authored Aug 31, 2023
1 parent aa888f1 commit 876e81d
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 49 deletions.
4 changes: 0 additions & 4 deletions core/chains/evm/logpoller/log_poller_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func TestLogPoller_RegisterFilter(t *testing.T) {

orm := NewORM(chainID, db, lggr, pgtest.NewQConfig(true))

db.Close()
db = pgtest.NewSqlxDB(t)
orm = NewORM(chainID, db, lggr, pgtest.NewQConfig(true))

// Set up a test chain with a log emitting contract deployed.
lp := NewLogPoller(orm, nil, lggr, time.Hour, 1, 1, 2, 1000)

Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (g *gasEstimatorConfig) PriceMax() *assets.Wei { return asse
func (g *gasEstimatorConfig) PriceMin() *assets.Wei { return assets.NewWeiI(42) }
func (g *gasEstimatorConfig) Mode() string { return "FixedPrice" }
func (g *gasEstimatorConfig) LimitJobType() evmconfig.LimitJobType { return &limitJobTypeConfig{} }
func (e *gasEstimatorConfig) PriceMaxKey(addr common.Address) *assets.Wei {
func (g *gasEstimatorConfig) PriceMaxKey(addr common.Address) *assets.Wei {
return assets.NewWeiI(42)
}

Expand Down
6 changes: 2 additions & 4 deletions core/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,15 @@ func NewApp(s *Shell) *cli.App {
if c.IsSet("config") {
if s.configFilesIsSet || s.secretsFileIsSet {
return errNoDuplicateFlags
} else {
s.configFiles = c.StringSlice("config")
}
s.configFiles = c.StringSlice("config")
}

if c.IsSet("secrets") {
if s.configFilesIsSet || s.secretsFileIsSet {
return errNoDuplicateFlags
} else {
s.secretsFiles = c.StringSlice("secrets")
}
s.secretsFiles = c.StringSlice("secrets")
}

// flags here, or ENV VAR only
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/cosmos_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestShell_IndexCosmosNodes(t *testing.T) {
//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 10, len(renderLines))
assert.Contains(t, renderLines[2], "Name")
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestShell_IndexEVMNodes(t *testing.T) {
//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 23, len(renderLines))
assert.Contains(t, renderLines[2], "Name")
Expand Down
7 changes: 3 additions & 4 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ func (s *Shell) configExitErr(validateFn func() error) cli.ExitCoder {
fmt.Println("Invalid configuration:", err)
fmt.Println()
return s.errorOut(errors.New("invalid configuration"))
} else {
fmt.Printf("Notification for upcoming configuration change: %v\n", err)
fmt.Println("This configuration will be disallowed in future production releases.")
fmt.Println()
}
fmt.Printf("Notification for upcoming configuration change: %v\n", err)
fmt.Println("This configuration will be disallowed in future production releases.")
fmt.Println()
}
return nil
}
Expand Down
5 changes: 1 addition & 4 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ func TestShell_RunNodeWithPasswords(t *testing.T) {
if err := cli.Before(c); err != nil {
return err
}
if err := client.RunNode(c); err != nil {
return err
}
return nil
return client.RunNode(c)
}

if test.wantUnlocked {
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/solana_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestShell_IndexSolanaNodes(t *testing.T) {
//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 17, len(renderLines))
assert.Contains(t, renderLines[2], "Name")
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/starknet_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestShell_IndexStarkNetNodes(t *testing.T) {
//Render table and check the fields order
b := new(bytes.Buffer)
rt := cmd.RendererTable{b}
nodes.RenderTable(rt)
require.NoError(t, nodes.RenderTable(rt))
renderLines := strings.Split(b.String(), "\n")
assert.Equal(t, 17, len(renderLines))
assert.Contains(t, renderLines[2], "Name")
Expand Down
6 changes: 2 additions & 4 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,10 +1634,8 @@ func FlagSetApplyFromAction(action interface{}, flagSet *flag.FlagSet, parentCom
for _, command := range app.Commands {
flags := recursiveFindFlagsWithName(actionFuncName, command, parentCommand, foundName)

if flags != nil {
for _, flag := range flags {
flag.Apply(flagSet)
}
for _, flag := range flags {
flag.Apply(flagSet)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/services/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func TestMaxPerformDataSize(t *testing.T) {
backend.Commit()

// setup app
config, db := heavyweight.FullTestDBV2(t, fmt.Sprintf("keeper_max_perform_data_test"), func(c *chainlink.Config, s *chainlink.Secrets) {
config, db := heavyweight.FullTestDBV2(t, "keeper_max_perform_data_test", func(c *chainlink.Config, s *chainlink.Secrets) {
c.Keeper.MaxGracePeriod = ptr[int64](0) // avoid waiting to re-submit for upkeeps
c.Keeper.Registry.SyncInterval = models.MustNewDuration(24 * time.Hour) // disable full sync ticker for test
c.Keeper.Registry.MaxPerformDataSize = ptr(uint32(maxPerformDataSize)) // set the max perform data size
Expand Down
8 changes: 0 additions & 8 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
ocr2keepers20runner "github.com/smartcontractkit/ocr2keepers/pkg/v2/runner"
ocr2keepers21config "github.com/smartcontractkit/ocr2keepers/pkg/v3/config"
ocr2keepers21 "github.com/smartcontractkit/ocr2keepers/pkg/v3/plugin"
ocr2keepers21types "github.com/smartcontractkit/ocr2keepers/pkg/v3/types"
"github.com/smartcontractkit/ocr2vrf/altbn_128"
dkgpkg "github.com/smartcontractkit/ocr2vrf/dkg"
"github.com/smartcontractkit/ocr2vrf/ocr2vrf"
Expand Down Expand Up @@ -1312,10 +1311,3 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
n = len(p)
return
}

type mockRecoverableProvider struct {
}

func (_m *mockRecoverableProvider) GetRecoveryProposals(ctx context.Context) ([]ocr2keepers21types.UpkeepPayload, error) {
return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func CreateAndFundSubscriptions(t *testing.T, b *backends.SimulatedBackend, owne
var s [32]byte
copy(s[:], flatSignature[32:64])
v := flatSignature[65]
allowListContract.AcceptTermsOfService(owner, owner.From, owner.From, r, s, v)
_, err = allowListContract.AcceptTermsOfService(owner, owner.From, owner.From, r, s, v)
require.NoError(t, err)
}

_, err = routerContract.CreateSubscription(owner)
Expand Down
7 changes: 2 additions & 5 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,8 @@ func (r *Relayer) NewMedianProvider(rargs relaytypes.RelayArgs, pargs relaytypes
return nil, err
}

var contractTransmitter ContractTransmitter
var reportCodec median.ReportCodec

reportCodec = evmreportcodec.ReportCodec{}
contractTransmitter, err = newContractTransmitter(r.lggr, rargs, pargs.TransmitterID, configWatcher, r.ks.Eth())
reportCodec := evmreportcodec.ReportCodec{}
contractTransmitter, err := newContractTransmitter(r.lggr, rargs, pargs.TransmitterID, configWatcher, r.ks.Eth())
if err != nil {
return nil, err
}
Expand Down
10 changes: 4 additions & 6 deletions core/services/vrf/v2/integration_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,19 +2099,17 @@ func TestStartingCountsV1(t *testing.T) {
ChainID: chainID.ToInt(),
})
}
txes := append(confirmedTxes, unconfirmedTxes...)
sql := `INSERT INTO eth_txes (nonce, from_address, to_address, encoded_payload, value, gas_limit, state, created_at, broadcast_at, initial_broadcast_at, meta, subject, evm_chain_id, min_confirmations, pipeline_task_run_id)
VALUES (:nonce, :from_address, :to_address, :encoded_payload, :value, :gas_limit, :state, :created_at, :broadcast_at, :initial_broadcast_at, :meta, :subject, :evm_chain_id, :min_confirmations, :pipeline_task_run_id);`
for _, tx := range txes {
for _, tx := range append(confirmedTxes, unconfirmedTxes...) {
dbEtx := txmgr.DbEthTxFromEthTx(&tx)
_, err = db.NamedExec(sql, &dbEtx)
txmgr.DbEthTxToEthTx(dbEtx, &tx)
require.NoError(t, err)
}

// add eth_tx_attempts for confirmed
broadcastBlock := int64(1)
txAttempts := []txmgr.TxAttempt{}
var txAttempts []txmgr.TxAttempt
for i := range confirmedTxes {
txAttempts = append(txAttempts, txmgr.TxAttempt{
TxID: int64(i + 1),
Expand Down Expand Up @@ -2142,10 +2140,10 @@ VALUES (:nonce, :from_address, :to_address, :encoded_payload, :value, :gas_limit
sql = `INSERT INTO eth_tx_attempts (eth_tx_id, gas_price, signed_raw_tx, hash, state, created_at, chain_specific_gas_limit)
VALUES (:eth_tx_id, :gas_price, :signed_raw_tx, :hash, :state, :created_at, :chain_specific_gas_limit)`
for _, attempt := range txAttempts {
dbAttempt := txmgr.DbEthTxAttemptFromEthTxAttempt(&attempt)
dbAttempt := txmgr.DbEthTxAttemptFromEthTxAttempt(&attempt) //nolint:gosec - just copying fields
_, err = db.NamedExec(sql, &dbAttempt)
txmgr.DbEthTxAttemptToEthTxAttempt(dbAttempt, &attempt)
require.NoError(t, err)
txmgr.DbEthTxAttemptToEthTxAttempt(dbAttempt, &attempt) //nolin:gosec - just copying fields
}

// add eth_receipts
Expand Down
5 changes: 2 additions & 3 deletions core/web/solana_transfer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ func (tc *SolanaTransfersController) Create(c *gin.Context) {
if errors.Is(err, chainlink.ErrNoSuchRelayer) {
jsonAPIError(c, http.StatusBadRequest, err)
return
} else {
jsonAPIError(c, http.StatusInternalServerError, err)
return
}
jsonAPIError(c, http.StatusInternalServerError, err)
return
}
// note the [loop.Relayer] API is in intermediate state. we found the relayer above; we should not need to pass
// the chain id here
Expand Down

0 comments on commit 876e81d

Please sign in to comment.