Skip to content

Commit

Permalink
bump golangci-lint to 1.55.0 (#11037)
Browse files Browse the repository at this point in the history
* bump golangci-lint to 1.55.0

* - File is not `goimports`-ed with -local X (goimports)

- superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)

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

- dot-imports: should not use dot imports (revive)
  • Loading branch information
jmank88 authored Oct 23, 2023
1 parent ff84f9f commit a9ddfa1
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/actions/golangci-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ runs:
- name: golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: v1.54.2
version: v1.55.0
# We already cache these directories in setup-go
skip-pkg-cache: true
skip-build-cache: true
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ nodejs 16.16.0
postgres 13.3
helm 3.10.3
zig 0.10.1
golangci-lint 1.54.2
golangci-lint 1.55.0
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ config-docs: ## Generate core node configuration documentation
.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint for all issues.
[ -d "./golangci-lint" ] || mkdir ./golangci-lint && \
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%H:%M:%S).txt
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.55.0 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%H:%M:%S).txt


GORELEASER_CONFIG ?= .goreleaser.yaml
Expand Down
3 changes: 1 addition & 2 deletions common/headtracker/head_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ func (hl *HeadListener[HTH, S, ID, BLOCK_HASH]) ListenForNewHeads(handleNewHead
} else if err != nil {
hl.logger.Errorw("Error in new head subscription, unsubscribed", "err", err)
continue
} else {
break
}
break
}
}

Expand Down
29 changes: 14 additions & 15 deletions core/chains/cosmos/cosmostxm/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,72 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

cosmosdb "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"

"github.com/smartcontractkit/chainlink/v2/core/chains/cosmos/cosmostxm"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/cosmostest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"

. "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"

. "github.com/smartcontractkit/chainlink/v2/core/chains/cosmos/cosmostxm"
)

func TestORM(t *testing.T) {
db := pgtest.NewSqlxDB(t)
lggr := logger.TestLogger(t)
logCfg := pgtest.NewQConfig(true)
chainID := cosmostest.RandomChainID()
o := NewORM(chainID, db, lggr, logCfg)
o := cosmostxm.NewORM(chainID, db, lggr, logCfg)

// Create
mid, err := o.InsertMsg("0x123", "", []byte("hello"))
require.NoError(t, err)
assert.NotEqual(t, 0, int(mid))

// Read
unstarted, err := o.GetMsgsState(Unstarted, 5)
unstarted, err := o.GetMsgsState(cosmosdb.Unstarted, 5)
require.NoError(t, err)
require.Equal(t, 1, len(unstarted))
assert.Equal(t, "hello", string(unstarted[0].Raw))
assert.Equal(t, chainID, unstarted[0].ChainID)
t.Log(unstarted[0].UpdatedAt, unstarted[0].CreatedAt)

// Limit
unstarted, err = o.GetMsgsState(Unstarted, 0)
unstarted, err = o.GetMsgsState(cosmosdb.Unstarted, 0)
assert.Error(t, err)
assert.Empty(t, unstarted)
unstarted, err = o.GetMsgsState(Unstarted, -1)
unstarted, err = o.GetMsgsState(cosmosdb.Unstarted, -1)
assert.Error(t, err)
assert.Empty(t, unstarted)
mid2, err := o.InsertMsg("0xabc", "", []byte("test"))
require.NoError(t, err)
assert.NotEqual(t, 0, int(mid2))
unstarted, err = o.GetMsgsState(Unstarted, 1)
unstarted, err = o.GetMsgsState(cosmosdb.Unstarted, 1)
require.NoError(t, err)
require.Equal(t, 1, len(unstarted))
assert.Equal(t, "hello", string(unstarted[0].Raw))
assert.Equal(t, chainID, unstarted[0].ChainID)
unstarted, err = o.GetMsgsState(Unstarted, 2)
unstarted, err = o.GetMsgsState(cosmosdb.Unstarted, 2)
require.NoError(t, err)
require.Equal(t, 2, len(unstarted))
assert.Equal(t, "test", string(unstarted[1].Raw))
assert.Equal(t, chainID, unstarted[1].ChainID)

// Update
txHash := "123"
err = o.UpdateMsgs([]int64{mid}, Started, &txHash)
err = o.UpdateMsgs([]int64{mid}, cosmosdb.Started, &txHash)
require.NoError(t, err)
err = o.UpdateMsgs([]int64{mid}, Broadcasted, &txHash)
err = o.UpdateMsgs([]int64{mid}, cosmosdb.Broadcasted, &txHash)
require.NoError(t, err)
broadcasted, err := o.GetMsgsState(Broadcasted, 5)
broadcasted, err := o.GetMsgsState(cosmosdb.Broadcasted, 5)
require.NoError(t, err)
require.Equal(t, 1, len(broadcasted))
assert.Equal(t, broadcasted[0].Raw, unstarted[0].Raw)
require.NotNil(t, broadcasted[0].TxHash)
assert.Equal(t, *broadcasted[0].TxHash, txHash)
assert.Equal(t, chainID, broadcasted[0].ChainID)

err = o.UpdateMsgs([]int64{mid}, Confirmed, nil)
err = o.UpdateMsgs([]int64{mid}, cosmosdb.Confirmed, nil)
require.NoError(t, err)
confirmed, err := o.GetMsgsState(Confirmed, 5)
confirmed, err := o.GetMsgsState(cosmosdb.Confirmed, 5)
require.NoError(t, err)
require.Equal(t, 1, len(confirmed))
}
59 changes: 29 additions & 30 deletions core/chains/cosmos/cosmostxm/txm_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

cosmosclient "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client"
tcmocks "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client/mocks"
coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
cosmosdb "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"
relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils"

"github.com/smartcontractkit/chainlink/v2/core/chains/cosmos"
Expand All @@ -25,11 +29,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/utils"

cosmosclient "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client"
tcmocks "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client/mocks"
coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
. "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"
)

func generateExecuteMsg(t *testing.T, msg []byte, from, to cosmostypes.AccAddress) cosmostypes.Msg {
Expand Down Expand Up @@ -125,7 +124,7 @@ func TestTxm(t *testing.T) {
completed, err := txm.ORM().GetMsgs(id1)
require.NoError(t, err)
require.Equal(t, 1, len(completed))
assert.Equal(t, completed[0].State, Confirmed)
assert.Equal(t, completed[0].State, cosmosdb.Confirmed)
})

t.Run("two msgs different accounts", func(t *testing.T) {
Expand Down Expand Up @@ -180,8 +179,8 @@ func TestTxm(t *testing.T) {
completed, err := txm.ORM().GetMsgs(id1, id2)
require.NoError(t, err)
require.Equal(t, 2, len(completed))
assert.Equal(t, Errored, completed[0].State) // cancelled
assert.Equal(t, Confirmed, completed[1].State)
assert.Equal(t, cosmosdb.Errored, completed[0].State) // cancelled
assert.Equal(t, cosmosdb.Confirmed, completed[1].State)
})

t.Run("two msgs different contracts", func(t *testing.T) {
Expand Down Expand Up @@ -240,8 +239,8 @@ func TestTxm(t *testing.T) {
completed, err := txm.ORM().GetMsgs(id1, id2)
require.NoError(t, err)
require.Equal(t, 2, len(completed))
assert.Equal(t, Confirmed, completed[0].State)
assert.Equal(t, Confirmed, completed[1].State)
assert.Equal(t, cosmosdb.Confirmed, completed[0].State)
assert.Equal(t, cosmosdb.Confirmed, completed[1].State)
})

t.Run("failed to confirm", func(t *testing.T) {
Expand All @@ -256,14 +255,14 @@ func TestTxm(t *testing.T) {
i, err := txm.ORM().InsertMsg("blah", "", []byte{0x01})
require.NoError(t, err)
txh := "0x123"
require.NoError(t, txm.ORM().UpdateMsgs([]int64{i}, Started, &txh))
require.NoError(t, txm.ORM().UpdateMsgs([]int64{i}, Broadcasted, &txh))
require.NoError(t, txm.ORM().UpdateMsgs([]int64{i}, cosmosdb.Started, &txh))
require.NoError(t, txm.ORM().UpdateMsgs([]int64{i}, cosmosdb.Broadcasted, &txh))
err = txm.ConfirmTx(testutils.Context(t), tc, txh, []int64{i}, 2, 1*time.Millisecond)
require.NoError(t, err)
m, err := txm.ORM().GetMsgs(i)
require.NoError(t, err)
require.Equal(t, 1, len(m))
assert.Equal(t, Errored, m[0].State)
assert.Equal(t, cosmosdb.Errored, m[0].State)
})

t.Run("confirm any unconfirmed", func(t *testing.T) {
Expand Down Expand Up @@ -292,27 +291,27 @@ func TestTxm(t *testing.T) {
require.NoError(t, err)
id3, err := txm.ORM().InsertMsg("blah", "", []byte{0x03})
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id1}, Started, &txHash1)
err = txm.ORM().UpdateMsgs([]int64{id1}, cosmosdb.Started, &txHash1)
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id2}, Started, &txHash2)
err = txm.ORM().UpdateMsgs([]int64{id2}, cosmosdb.Started, &txHash2)
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id3}, Started, &txHash3)
err = txm.ORM().UpdateMsgs([]int64{id3}, cosmosdb.Started, &txHash3)
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id1}, Broadcasted, &txHash1)
err = txm.ORM().UpdateMsgs([]int64{id1}, cosmosdb.Broadcasted, &txHash1)
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id2}, Broadcasted, &txHash2)
err = txm.ORM().UpdateMsgs([]int64{id2}, cosmosdb.Broadcasted, &txHash2)
require.NoError(t, err)
err = txm.ORM().UpdateMsgs([]int64{id3}, Broadcasted, &txHash3)
err = txm.ORM().UpdateMsgs([]int64{id3}, cosmosdb.Broadcasted, &txHash3)
require.NoError(t, err)

// Confirm them as in a restart while confirming scenario
txm.ConfirmAnyUnconfirmed(testutils.Context(t))
msgs, err := txm.ORM().GetMsgs(id1, id2, id3)
require.NoError(t, err)
require.Equal(t, 3, len(msgs))
assert.Equal(t, Confirmed, msgs[0].State)
assert.Equal(t, Confirmed, msgs[1].State)
assert.Equal(t, Confirmed, msgs[2].State)
assert.Equal(t, cosmosdb.Confirmed, msgs[0].State)
assert.Equal(t, cosmosdb.Confirmed, msgs[1].State)
assert.Equal(t, cosmosdb.Confirmed, msgs[2].State)
})

t.Run("expired msgs", func(t *testing.T) {
Expand All @@ -337,7 +336,7 @@ func TestTxm(t *testing.T) {
// Should be marked errored
m, err := txm.ORM().GetMsgs(id1)
require.NoError(t, err)
assert.Equal(t, Errored, m[0].State)
assert.Equal(t, cosmosdb.Errored, m[0].State)

// Send a batch which is all expired
id2, err := txm.ORM().InsertMsg("blah", "", []byte{0x03})
Expand All @@ -349,8 +348,8 @@ func TestTxm(t *testing.T) {
require.NoError(t, err)
ms, err := txm.ORM().GetMsgs(id2, id3)
require.NoError(t, err)
assert.Equal(t, Errored, ms[0].State)
assert.Equal(t, Errored, ms[1].State)
assert.Equal(t, cosmosdb.Errored, ms[0].State)
assert.Equal(t, cosmosdb.Errored, ms[1].State)
})

t.Run("started msgs", func(t *testing.T) {
Expand Down Expand Up @@ -378,7 +377,7 @@ func TestTxm(t *testing.T) {
// Leftover started is processed
msg1 := generateExecuteMsg(t, []byte{0x03}, sender1, contract)
id1 := mustInsertMsg(t, txm, contract.String(), msg1)
require.NoError(t, txm.ORM().UpdateMsgs([]int64{id1}, Started, nil))
require.NoError(t, txm.ORM().UpdateMsgs([]int64{id1}, cosmosdb.Started, nil))
msgs := cosmosclient.SimMsgs{{ID: id1, Msg: &wasmtypes.MsgExecuteContract{
Sender: sender1.String(),
Msg: []byte{0x03},
Expand All @@ -390,13 +389,13 @@ func TestTxm(t *testing.T) {
txm.SendMsgBatch(testutils.Context(t))
m, err := txm.ORM().GetMsgs(id1)
require.NoError(t, err)
assert.Equal(t, Confirmed, m[0].State)
assert.Equal(t, cosmosdb.Confirmed, m[0].State)

// Leftover started is not cancelled
msg2 := generateExecuteMsg(t, []byte{0x04}, sender1, contract)
msg3 := generateExecuteMsg(t, []byte{0x05}, sender1, contract)
id2 := mustInsertMsg(t, txm, contract.String(), msg2)
require.NoError(t, txm.ORM().UpdateMsgs([]int64{id2}, Started, nil))
require.NoError(t, txm.ORM().UpdateMsgs([]int64{id2}, cosmosdb.Started, nil))
time.Sleep(time.Millisecond) // ensure != CreatedAt
id3 := mustInsertMsg(t, txm, contract.String(), msg3)
msgs = cosmosclient.SimMsgs{{ID: id2, Msg: &wasmtypes.MsgExecuteContract{
Expand All @@ -415,8 +414,8 @@ func TestTxm(t *testing.T) {
require.NoError(t, err)
ms, err := txm.ORM().GetMsgs(id2, id3)
require.NoError(t, err)
assert.Equal(t, Confirmed, ms[0].State)
assert.Equal(t, Confirmed, ms[1].State)
assert.Equal(t, cosmosdb.Confirmed, ms[0].State)
assert.Equal(t, cosmosdb.Confirmed, ms[1].State)
})
}

Expand Down
17 changes: 8 additions & 9 deletions core/chains/evm/txmgr/transmitchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@ func (v *VRFV1Checker) Check(
"meta", tx.Meta,
"reqID", reqID)
return errors.New("request already fulfilled")
} else {
// Request not fulfilled
return nil
}
// Request not fulfilled
return nil
}

// VRFV2Checker is an implementation of TransmitChecker that checks whether a VRF V2 fulfillment
Expand Down Expand Up @@ -351,11 +350,11 @@ func (v *VRFV2Checker) Check(
"meta", tx.Meta,
"vrfRequestId", vrfRequestID)
return errors.New("request already fulfilled")
} else {
l.Debugw("Request not yet fulfilled",
"ethTxID", tx.ID,
"meta", tx.Meta,
"vrfRequestId", vrfRequestID)
return nil
}
l.Debugw("Request not yet fulfilled",
"ethTxID", tx.ID,
"meta", tx.Meta,
"vrfRequestId", vrfRequestID)
return nil

}
12 changes: 5 additions & 7 deletions core/chains/evm/txmgr/transmitchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ func TestTransmitCheckers(t *testing.T) {
} else if reqID == r2 {
// Request 2 errors
return v1.Callbacks{}, errors.New("error getting commitment")
} else {
return v1.Callbacks{
SeedAndBlockNum: [32]byte{1},
}, nil
}
return v1.Callbacks{
SeedAndBlockNum: [32]byte{1},
}, nil
},
Client: client,
}
Expand Down Expand Up @@ -325,10 +324,9 @@ func TestTransmitCheckers(t *testing.T) {
} else if requestID.String() == "2" {
// Request 2 errors
return [32]byte{}, errors.New("error getting commitment")
} else {
// All other requests are unfulfilled
return [32]byte{1}, nil
}
// All other requests are unfulfilled
return [32]byte{1}, nil
},
HeadByNumber: func(ctx context.Context, n *big.Int) (*evmtypes.Head, error) {
return &evmtypes.Head{
Expand Down
3 changes: 1 addition & 2 deletions core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,7 @@ func confirmAction(c *cli.Context) bool {
return true
} else if answer == "no" {
return false
} else {
fmt.Printf("%s is not valid. Please type yes or no\n", answer)
}
fmt.Printf("%s is not valid. Please type yes or no\n", answer)
}
}
2 changes: 1 addition & 1 deletion core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (

coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils"
"github.com/smartcontractkit/chainlink-solana/pkg/solana"
solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"

"github.com/smartcontractkit/chainlink-solana/pkg/solana"
"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/cosmos"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand Down
3 changes: 1 addition & 2 deletions core/services/gateway/handlers/functions/allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ func (a *onchainAllowlist) UpdateFromContract(ctx context.Context) error {
return a.updateFromContractV0(ctx, blockNum)
} else if a.config.ContractVersion == 1 {
return a.updateFromContractV1(ctx, blockNum)
} else {
return fmt.Errorf("unknown contract version %d", a.config.ContractVersion)
}
return fmt.Errorf("unknown contract version %d", a.config.ContractVersion)
}

func (a *onchainAllowlist) updateFromContractV0(ctx context.Context, blockNum *big.Int) error {
Expand Down
3 changes: 1 addition & 2 deletions core/services/ocr2/plugins/ocr2vrf/coordinator/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ func (v *vrfRouter) ParseLog(log types.Log) (generated.AbigenLog, error) {
return v.beacon.ParseLog(log)
} else if log.Address == v.coordinator.Address() {
return v.coordinator.ParseLog(log)
} else {
return nil, errors.Errorf("failed to parse log. contractAddress: %x logs: %x", log.Address, log.Topics)
}
return nil, errors.Errorf("failed to parse log. contractAddress: %x logs: %x", log.Address, log.Topics)
}

// GetConfirmationDelays retrieves confirmation delays from the on-chain contract.
Expand Down
Loading

0 comments on commit a9ddfa1

Please sign in to comment.