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

chore: fix linter warnings #1270

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'

- name: checkout interchaintest
uses: actions/checkout@v4
Expand All @@ -35,10 +35,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache: false

- name: checkout interchaintest
Expand All @@ -57,10 +57,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache: false

- name: checkout interchaintest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ jobs:
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.57.2
version: v1.61.0
args: --timeout 15m
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'

- name: checkout interchaintest
uses: actions/checkout@v4
Expand Down
11 changes: 8 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ linters:
- asciicheck
- bidichk
- bodyclose
- copyloopvar
- decorder
- dupl
- dupword
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- forbidigo
- gci
- goconst
Expand All @@ -32,8 +32,8 @@ linters:
- ineffassign
- loggercheck
- misspell
- nilerr
- nilnil
# - nilerr disabled because we return nil when there are errors in places that need to keep running e.g. polling/waiting for a condition
# - nilnil disabled because we return nil, nil when polling but waiting for a conditional
- noctx
- staticcheck
- stylecheck
Expand Down Expand Up @@ -64,6 +64,11 @@ linters-settings:
gosec:
excludes:
- G404 # disables checks on insecure random number source
- G115 # disables checks on type conversions between signed and unsigned integers
- G306 # disables checks on WriteFile perms. Not an issue since we are writing configs/logs in a local test env
gocritic:
disabled-checks:
- appendAssign # we use append to build cmds from a config and always assign to a new slice to not overwrite cfg

issues:
max-issues-per-linter: 0
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ protoVer=0.13.2
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
golangci_lint_cmd=golangci-lint
golangci_version=v1.57.2
golangci_version=v1.61.0
gofumpt_cmd=gofumpt
gofumpt_version=v0.6.0
gofumpt_version=v0.7.0

default: help

Expand All @@ -19,7 +19,19 @@ interchaintest: gen ## Build interchaintest binary into ./bin

.PHONY: test
test: ## Run unit tests
@go test -cover -short -race -timeout=60s ./...
@go test -cover -short -race -timeout=30m -failfast -p 2 $(go list ./... | grep -v /cmd | grep -v /examples)

.PHONY: test-conformance
test-conformance: ## Run e2e conformance tests
@go test -race -timeout 30m -failfast -v -p 2 ./cmd/interchaintest

.PHONY: test-ibc-examples
test-ibc-examples: ## Run e2e ibc example tests
@go test -race -timeout 30m -failfast -v -p 2 ./examples/ibc

.PHONY: test-cosmos-examples
test-cosmos-examples: ## Run e2e cosmos example tests
@go test -race -failfast -timeout 30m -v -p 2 ./examples/cosmos

.PHONY: docker-reset
docker-reset: ## Attempt to delete all running containers. Useful if interchaintest does not exit cleanly.
Expand Down
26 changes: 16 additions & 10 deletions blockdb/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func TestChain_SaveBlock(t *testing.T) {
)

t.Run("happy path", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down Expand Up @@ -98,27 +100,29 @@ ORDER BY tendermint_event_attr.id`)
for i = 0; rows.Next(); i++ {
var gotData, gotType, gotKey, gotValue string
require.NoError(t, rows.Scan(&gotData, &gotType, &gotKey, &gotValue))
require.Equal(t, gotData, `{"test":1}`)
require.Equal(t, `{"test":1}`, gotData)
switch i {
case 0:
require.Equal(t, gotType, "e1")
require.Equal(t, gotKey, "k1")
require.Equal(t, gotValue, "v1")
require.Equal(t, "e1", gotType)
require.Equal(t, "k1", gotKey)
require.Equal(t, "v1", gotValue)
case 1:
require.Equal(t, gotType, "e2")
require.Equal(t, gotKey, "k2")
require.Equal(t, gotValue, "v2")
require.Equal(t, "e2", gotType)
require.Equal(t, "k2", gotKey)
require.Equal(t, "v2", gotValue)
case 2:
require.Equal(t, gotType, "e2")
require.Equal(t, gotKey, "k3")
require.Equal(t, gotValue, "v3")
require.Equal(t, "e2", gotType)
require.Equal(t, "k3", gotKey)
require.Equal(t, "v3", gotValue)
default:
t.Fatalf("expected 3 results, got i=%d", i)
}
}
})

t.Run("idempotent", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down Expand Up @@ -152,6 +156,8 @@ ORDER BY tendermint_event_attr.id`)
})

t.Run("zero state", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down
39 changes: 20 additions & 19 deletions blockdb/messages_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
"path/filepath"
"testing"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/types"

"github.com/strangelove-ventures/interchaintest/v8"
Copy link
Member

@Reecepbcups Reecepbcups Oct 4, 2024

Choose a reason for hiding this comment

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

optional: add optional git hooks for vscode peeps

"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)

func TestMessagesView(t *testing.T) {
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestMessagesView(t *testing.T) {
var count int
row := db.QueryRow(`SELECT COUNT(*) FROM v_cosmos_messages`)
require.NoError(t, row.Scan(&count))
require.Equal(t, count, 0)
require.Equal(t, 0, count)

// Generate the path.
// No transactions happen here.
Expand All @@ -105,10 +106,10 @@ FROM v_cosmos_messages
WHERE type = "/ibc.core.client.v1.MsgCreateClient" AND chain_id = ?;`
var clientChainID string
require.NoError(t, db.QueryRow(qCreateClient, gaia0ChainID).Scan(&clientChainID))
require.Equal(t, clientChainID, gaia1ChainID)
require.Equal(t, gaia1ChainID, clientChainID)

require.NoError(t, db.QueryRow(qCreateClient, gaia1ChainID).Scan(&clientChainID))
require.Equal(t, clientChainID, gaia0ChainID)
require.Equal(t, gaia0ChainID, clientChainID)
})
if t.Failed() {
return
Expand Down Expand Up @@ -208,8 +209,8 @@ WHERE type = "/ibc.core.channel.v1.MsgChannelOpenInit" AND chain_id = ?
`
var portID, counterpartyPortID string
require.NoError(t, db.QueryRow(qChannelOpenInit, gaia0ChainID).Scan(&portID, &counterpartyPortID))
require.Equal(t, portID, gaia0Port)
require.Equal(t, counterpartyPortID, gaia1Port)
require.Equal(t, gaia0Port, portID)
require.Equal(t, gaia1Port, counterpartyPortID)

// OpenTry happens on second chain.
const qChannelOpenTry = `SELECT
Expand All @@ -219,8 +220,8 @@ WHERE type = "/ibc.core.channel.v1.MsgChannelOpenTry" AND chain_id = ?
`
var counterpartyChannelID string
require.NoError(t, db.QueryRow(qChannelOpenTry, gaia1ChainID).Scan(&portID, &counterpartyPortID, &counterpartyChannelID))
require.Equal(t, portID, gaia1Port)
require.Equal(t, counterpartyPortID, gaia0Port)
require.Equal(t, gaia1Port, portID)
require.Equal(t, gaia0Port, counterpartyPortID)
require.Equal(t, counterpartyChannelID, gaia0ChannelID)

// OpenAck happens on first chain again.
Expand All @@ -231,7 +232,7 @@ WHERE type = "/ibc.core.channel.v1.MsgChannelOpenAck" AND chain_id = ?
`
var channelID string
require.NoError(t, db.QueryRow(qChannelOpenAck, gaia0ChainID).Scan(&portID, &channelID, &counterpartyChannelID))
require.Equal(t, portID, gaia0Port)
require.Equal(t, gaia0Port, portID)
require.Equal(t, channelID, gaia0ChannelID)
require.Equal(t, counterpartyChannelID, gaia1ChannelID)

Expand All @@ -242,7 +243,7 @@ FROM v_cosmos_messages
WHERE type = "/ibc.core.channel.v1.MsgChannelOpenConfirm" AND chain_id = ?
`
require.NoError(t, db.QueryRow(qChannelOpenConfirm, gaia1ChainID).Scan(&portID, &channelID))
require.Equal(t, portID, gaia1Port)
require.Equal(t, gaia1Port, portID)
require.Equal(t, channelID, gaia1ChannelID)
})
if t.Failed() {
Expand Down Expand Up @@ -274,7 +275,7 @@ WHERE type = "/ibc.applications.transfer.v1.MsgTransfer" AND chain_id = ?
`
var portID, channelID string
require.NoError(t, db.QueryRow(qMsgTransfer, gaia0ChainID).Scan(&portID, &channelID))
require.Equal(t, portID, gaia0Port)
require.Equal(t, gaia0Port, portID)
require.Equal(t, channelID, gaia0ChannelID)
})
if t.Failed() {
Expand All @@ -299,9 +300,9 @@ WHERE type = "/ibc.core.channel.v1.MsgRecvPacket" AND chain_id = ?

require.NoError(t, db.QueryRow(qMsgRecvPacket, gaia1ChainID).Scan(&portID, &channelID, &counterpartyPortID, &counterpartyChannelID))

require.Equal(t, portID, gaia0Port)
require.Equal(t, gaia0Port, portID)
require.Equal(t, channelID, gaia0ChannelID)
require.Equal(t, counterpartyPortID, gaia1Port)
require.Equal(t, gaia1Port, counterpartyPortID)
require.Equal(t, counterpartyChannelID, gaia1ChannelID)

const qMsgAck = `SELECT
Expand All @@ -311,9 +312,9 @@ WHERE type = "/ibc.core.channel.v1.MsgAcknowledgement" AND chain_id = ?
`
require.NoError(t, db.QueryRow(qMsgAck, gaia0ChainID).Scan(&portID, &channelID, &counterpartyPortID, &counterpartyChannelID))

require.Equal(t, portID, gaia0Port)
require.Equal(t, gaia0Port, portID)
require.Equal(t, channelID, gaia0ChannelID)
require.Equal(t, counterpartyPortID, gaia1Port)
require.Equal(t, gaia1Port, counterpartyPortID)
require.Equal(t, counterpartyChannelID, gaia1ChannelID)
})
}
2 changes: 1 addition & 1 deletion blockdb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func timeToLocal(timeStr string) (time.Time, error) {
if err != nil {
return time.Time{}, fmt.Errorf("time.Parse RFC3339: %w", err)
}
return t.In(time.Local), nil
return t.In(time.Local), nil //nolint: gosmopolitan
}

type SchemaVersionResult struct {
Expand Down
12 changes: 11 additions & 1 deletion blockdb/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestQuery_RecentTestCases(t *testing.T) {
ctx := context.Background()

t.Run("happy path", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down Expand Up @@ -83,6 +85,8 @@ func TestQuery_RecentTestCases(t *testing.T) {
})

t.Run("limit", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand All @@ -99,6 +103,8 @@ func TestQuery_RecentTestCases(t *testing.T) {
})

t.Run("no test cases", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down Expand Up @@ -174,6 +180,8 @@ func TestQuery_Transactions(t *testing.T) {
ctx := context.Background()

t.Run("happy path", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand Down Expand Up @@ -201,6 +209,8 @@ func TestQuery_Transactions(t *testing.T) {
})

t.Run("no txs", func(t *testing.T) {
t.Parallel()

db := migratedDB()
defer db.Close()

Expand All @@ -212,6 +222,6 @@ func TestQuery_Transactions(t *testing.T) {
results, err := NewQuery(db).Transactions(ctx, chain.id)
require.NoError(t, err)

require.Len(t, results, 0)
require.Empty(t, results)
})
}
6 changes: 1 addition & 5 deletions blockdb/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func TestDB_Concurrency(t *testing.T) {
// and a shared context so all fail if one fails.
egWrites, egCtx := errgroup.WithContext(ctx)
for i := 0; i < nWriters; i++ {
i := i

// Connecting to the database in the main goroutine
// because concurrently connecting to the same database
// causes a data race inside sqlite.
Expand Down Expand Up @@ -98,8 +96,6 @@ func TestDB_Concurrency(t *testing.T) {
// Separate errgroup for the queriers.
var egQueries errgroup.Group
for i := 0; i < nQueriers; i++ {
i := i

db, err := ConnectDB(ctx, dbPath)
require.NoErrorf(t, err, "failed to connect to db for querier %d: %v", i, err)
defer db.Close()
Expand All @@ -112,7 +108,7 @@ func TestDB_Concurrency(t *testing.T) {
for {
if ctx.Err() != nil {
// Context was canceled; querying is finished.
return nil
return nil //nolint: nilerr
Copy link
Member

Choose a reason for hiding this comment

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

remove since ignoring this linter type now

}

// Deliberately using context.Background() here so that
Expand Down
Loading
Loading