Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint run --fix #15840

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion common/client/multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"math/big"
"sync"
Expand All @@ -22,7 +23,7 @@ var (
Name: "multi_node_states",
Help: "The number of RPC nodes currently in the given state for the given chain",
}, []string{"network", "chainId", "state"})
ErroringNodeError = fmt.Errorf("no live nodes available")
ErroringNodeError = errors.New("no live nodes available")
)

// MultiNode is a generalized multi node client interface that includes methods to interact with different chains.
Expand Down
15 changes: 11 additions & 4 deletions common/client/node.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually tweaked this one since the autofix exposed a lot of appending.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/url"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -162,14 +163,20 @@ func NewNode[
}

func (n *node[CHAIN_ID, HEAD, RPC]) String() string {
s := fmt.Sprintf("(%s)%s", Primary.String(), n.name)
var s strings.Builder
s.WriteByte('(')
s.WriteString(Primary.String())
s.WriteByte(')')
s.WriteString(n.name)
if n.ws != nil {
s = s + fmt.Sprintf(":%s", n.ws.String())
s.WriteByte(':')
s.WriteString(n.ws.String())
}
if n.http != nil {
s = s + fmt.Sprintf(":%s", n.http.String())
s.WriteByte(':')
s.WriteString(n.http.String())
}
return s
return s.String()
}

func (n *node[CHAIN_ID, HEAD, RPC]) ConfiguredChainID() (chainID CHAIN_ID) {
Expand Down
2 changes: 1 addition & 1 deletion common/client/node_fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (fm *fnMock) AssertNotCalled(t *testing.T) {
}

func (fm *fnMock) AssertCalled(t *testing.T) {
assert.Greater(t, fm.calls, 0)
assert.Positive(t, fm.calls)
}

func TestUnit_Node_StateTransitions(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions common/client/node_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,15 +1593,15 @@ func TestUnit_NodeLifecycle_outOfSyncWithPool(t *testing.T) {
t.Run("skip if nLiveNodes is not configured", func(t *testing.T) {
node := newTestNode(t, testNodeOpts{})
outOfSync, liveNodes := node.isOutOfSyncWithPool()
assert.Equal(t, false, outOfSync)
assert.False(t, outOfSync)
assert.Equal(t, 0, liveNodes)
})
t.Run("skip if syncThreshold is not configured", func(t *testing.T) {
node := newTestNode(t, testNodeOpts{})
poolInfo := newMockPoolChainInfoProvider(t)
node.SetPoolChainInfoProvider(poolInfo)
outOfSync, liveNodes := node.isOutOfSyncWithPool()
assert.Equal(t, false, outOfSync)
assert.False(t, outOfSync)
assert.Equal(t, 0, liveNodes)
})
t.Run("panics on invalid selection mode", func(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions common/client/node_selector.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package client

import (
"fmt"

"github.com/smartcontractkit/chainlink/v2/common/types"
)

Expand Down Expand Up @@ -38,6 +36,6 @@ func newNodeSelector[
case NodeSelectionModePriorityLevel:
return NewPriorityLevelNodeSelector[CHAIN_ID, RPC](nodes)
default:
panic(fmt.Sprintf("unsupported NodeSelectionMode: %s", selectionMode))
panic("unsupported NodeSelectionMode: " + selectionMode)
}
}
2 changes: 1 addition & 1 deletion common/client/node_selector_highest_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestHighestHeadNodeSelectorName(t *testing.T) {
selector := newNodeSelector[types.ID, RPCClient[types.ID, Head]](NodeSelectionModeHighestHead, nil)
assert.Equal(t, selector.Name(), NodeSelectionModeHighestHead)
assert.Equal(t, NodeSelectionModeHighestHead, selector.Name())
}

func TestHighestHeadNodeSelector(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion common/client/node_selector_priority_level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestPriorityLevelNodeSelectorName(t *testing.T) {
selector := newNodeSelector[types.ID, RPCClient[types.ID, Head]](NodeSelectionModePriorityLevel, nil)
assert.Equal(t, selector.Name(), NodeSelectionModePriorityLevel)
assert.Equal(t, NodeSelectionModePriorityLevel, selector.Name())
}

func TestPriorityLevelNodeSelector(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion common/client/node_selector_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestRoundRobinNodeSelectorName(t *testing.T) {
selector := newNodeSelector[types.ID, RPCClient[types.ID, Head]](NodeSelectionModeRoundRobin, nil)
assert.Equal(t, selector.Name(), NodeSelectionModeRoundRobin)
assert.Equal(t, NodeSelectionModeRoundRobin, selector.Name())
}

func TestRoundRobinNodeSelector(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion common/client/node_selector_total_difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestTotalDifficultyNodeSelectorName(t *testing.T) {
selector := newNodeSelector[types.ID, RPCClient[types.ID, Head]](NodeSelectionModeTotalDifficulty, nil)
assert.Equal(t, selector.Name(), NodeSelectionModeTotalDifficulty)
assert.Equal(t, NodeSelectionModeTotalDifficulty, selector.Name())
}

func TestTotalDifficultyNodeSelector(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion common/client/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ func Test_Poller_Unsubscribe(t *testing.T) {
require.NoError(t, err)

poller.Unsubscribe()
require.Equal(t, <-channel, nil)
require.Nil(t, <-channel)
})
}
10 changes: 5 additions & 5 deletions common/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) handleInitialHead(ctx context.Con
}

if !latestFinalized.IsValid() {
return fmt.Errorf("latest finalized block is not valid")
return errors.New("latest finalized block is not valid")
}

latestChain, err := ht.headSaver.Load(ctx, latestFinalized.BlockNumber())
Expand Down Expand Up @@ -231,7 +231,7 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) handleNewHead(ctx context.Context

headWithChain := ht.headSaver.Chain(head.BlockHash())
if !headWithChain.IsValid() {
return fmt.Errorf("HeadTracker#handleNewHighestHead headWithChain was unexpectedly nil")
return errors.New("HeadTracker#handleNewHighestHead headWithChain was unexpectedly nil")
}
ht.backfillMB.Deliver(headWithChain)
ht.broadcastMB.Deliver(headWithChain)
Expand Down Expand Up @@ -327,7 +327,7 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) LatestAndFinalizedBlock(ctx conte
}

if !latest.IsValid() {
err = fmt.Errorf("expected latest block to be valid")
err = errors.New("expected latest block to be valid")
return
}

Expand All @@ -337,7 +337,7 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) LatestAndFinalizedBlock(ctx conte
return
}
if !finalized.IsValid() {
err = fmt.Errorf("expected finalized block to be valid")
err = errors.New("expected finalized block to be valid")
return
}

Expand Down Expand Up @@ -373,7 +373,7 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) calculateLatestFinalized(ctx cont
}

if !latestFinalized.IsValid() {
return latestFinalized, fmt.Errorf("failed to get valid latest finalized block")
return latestFinalized, errors.New("failed to get valid latest finalized block")
}

if ht.config.FinalizedBlockOffset() == 0 {
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *Reaper[CHAIN_ID]) ReapTxes(headNum int64) error {
mark := time.Now()
timeThreshold := mark.Add(-threshold)

r.log.Debugw(fmt.Sprintf("reaping old txes created before %s", timeThreshold.Format(time.RFC3339)), "ageThreshold", threshold, "timeThreshold", timeThreshold)
r.log.Debugw("reaping old txes created before "+timeThreshold.Format(time.RFC3339), "ageThreshold", threshold, "timeThreshold", timeThreshold)

if err := r.store.ReapTxHistory(ctx, timeThreshold, r.chainID); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran
// Calls forwarderMgr to get a proper forwarder for a given EOA.
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOA(ctx context.Context, eoa ADDR) (forwarder ADDR, err error) {
if !b.txConfig.ForwardersEnabled() {
return forwarder, fmt.Errorf("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
return forwarder, errors.New("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
}
forwarder, err = b.fwdMgr.ForwarderFor(ctx, eoa)
return
Expand All @@ -575,7 +575,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForward
// GetForwarderForEOAOCR2Feeds calls forwarderMgr to get a proper forwarder for a given EOA and checks if its set as a transmitter on the OCR2Aggregator contract.
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOAOCR2Feeds(ctx context.Context, eoa, ocr2Aggregator ADDR) (forwarder ADDR, err error) {
if !b.txConfig.ForwardersEnabled() {
return forwarder, fmt.Errorf("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
return forwarder, errors.New("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
}
forwarder, err = b.fwdMgr.ForwarderForOCR2Feeds(ctx, eoa, ocr2Aggregator)
return
Expand Down
3 changes: 2 additions & 1 deletion common/txmgr/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/big"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -247,7 +248,7 @@ func (e *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetError() error {

// GetID allows Tx to be used as jsonapi.MarshalIdentifier
func (e *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetID() string {
return fmt.Sprintf("%d", e.ID)
return strconv.FormatInt(e.ID, 10)
}

// GetMeta returns an Tx's meta in struct form, unmarshalling it from JSON first.
Expand Down
4 changes: 2 additions & 2 deletions core/bridges/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestBridgeCache_Type(t *testing.T) {
btp.Confirmations = req.Confirmations
})
require.NoError(t, cache.UpdateBridgeType(ctx, expected, btr))
assert.Equal(t, btr.Confirmations, expected.Confirmations)
assert.Equal(t, expected.Confirmations, btr.Confirmations)

result, err = cache.FindBridge(ctx, bridge)

Expand All @@ -124,7 +124,7 @@ func TestBridgeCache_Type(t *testing.T) {
// bridge type is removed from cache so call to find fallsback to the data store
mORM.On("FindBridge", mock.Anything, bridge).Return(bridges.BridgeType{}, errors.New("not found"))
_, err = cache.FindBridge(ctx, bridge)
require.NotNil(t, err)
require.Error(t, err)
})
}

Expand Down
6 changes: 3 additions & 3 deletions core/bridges/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestORM_FindBridges(t *testing.T) {
assert.NoError(t, orm.CreateBridgeType(ctx, &bt2))
bts, err := orm.FindBridges(ctx, []bridges.BridgeName{"bridge2", "bridge1"})
require.NoError(t, err)
require.Equal(t, 2, len(bts))
require.Len(t, bts, 2)

bts, err = orm.FindBridges(ctx, []bridges.BridgeName{"bridge1"})
require.NoError(t, err)
require.Equal(t, 1, len(bts))
require.Len(t, bts, 1)
require.Equal(t, "bridge1", bts[0].Name.String())

// One invalid bridge errors
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestORM_UpdateBridgeType(t *testing.T) {
bs, count, err = orm.BridgeTypes(ctx, 0, 10)
require.NoError(t, err)
require.Equal(t, 0, count)
require.Len(t, bs, 0)
require.Empty(t, bs)
}

func TestORM_TestCachedResponse(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion core/capabilities/ccip/ccipevm/commitcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ccipevm

import (
"context"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -96,7 +97,7 @@ func (c *CommitPluginCodecV1) Encode(ctx context.Context, report cciptypes.Commi
func (c *CommitPluginCodecV1) Decode(ctx context.Context, bytes []byte) (cciptypes.CommitPluginReport, error) {
method, ok := ccipEncodingUtilsABI.Methods["exposeCommitReport"]
if !ok {
return cciptypes.CommitPluginReport{}, fmt.Errorf("missing method exposeCommitReport")
return cciptypes.CommitPluginReport{}, errors.New("missing method exposeCommitReport")
}

unpacked, err := method.Inputs.Unpack(bytes)
Expand Down
9 changes: 5 additions & 4 deletions core/capabilities/ccip/ccipevm/executecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ccipevm

import (
"context"
"errors"
"fmt"
"strings"

Expand All @@ -23,7 +24,7 @@ type ExecutePluginCodecV1 struct {
func NewExecutePluginCodecV1() *ExecutePluginCodecV1 {
abiParsed, err := abi.JSON(strings.NewReader(offramp.OffRampABI))
if err != nil {
panic(fmt.Errorf("parse multi offramp abi: %s", err))
panic(fmt.Errorf("parse multi offramp abi: %w", err))
}
methodInputs := abihelpers.MustGetMethodInputs("manuallyExecute", abiParsed)
if len(methodInputs) == 0 {
Expand All @@ -40,7 +41,7 @@ func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report cciptypes.Exec

for _, chainReport := range report.ChainReports {
if chainReport.ProofFlagBits.IsEmpty() {
return nil, fmt.Errorf("proof flag bits are empty")
return nil, errors.New("proof flag bits are empty")
}

evmProofs := make([][32]byte, 0, len(chainReport.Proofs))
Expand Down Expand Up @@ -112,7 +113,7 @@ func (e *ExecutePluginCodecV1) Decode(ctx context.Context, encodedReport []byte)
return cciptypes.ExecutePluginReport{}, fmt.Errorf("unpack encoded report: %w", err)
}
if len(unpacked) != 1 {
return cciptypes.ExecutePluginReport{}, fmt.Errorf("unpacked report is empty")
return cciptypes.ExecutePluginReport{}, errors.New("unpacked report is empty")
}

evmReportRaw := abi.ConvertType(unpacked[0], new([]offramp.InternalExecutionReport))
Expand All @@ -121,7 +122,7 @@ func (e *ExecutePluginCodecV1) Decode(ctx context.Context, encodedReport []byte)
return cciptypes.ExecutePluginReport{}, fmt.Errorf("got an unexpected report type %T", unpacked[0])
}
if evmReportPtr == nil {
return cciptypes.ExecutePluginReport{}, fmt.Errorf("evm report is nil")
return cciptypes.ExecutePluginReport{}, errors.New("evm report is nil")
}

evmReport := *evmReportPtr
Expand Down
3 changes: 2 additions & 1 deletion core/capabilities/ccip/ccipevm/msghasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccipevm
import (
"context"
cryptorand "crypto/rand"
"encoding/hex"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -81,7 +82,7 @@ func testHasherEVM2EVM(ctx context.Context, t *testing.T, d *testSetupData, evmE
actualHash, err := evmMsgHasher.Hash(ctx, ccipMsg)
require.NoError(t, err)

require.Equal(t, fmt.Sprintf("%x", expectedHash), strings.TrimPrefix(actualHash.String(), "0x"))
require.Equal(t, hex.EncodeToString(expectedHash[:]), strings.TrimPrefix(actualHash.String(), "0x"))
}

type evmExtraArgs struct {
Expand Down
Loading
Loading