Skip to content

Commit

Permalink
lint legacy ibc testing (#1078)
Browse files Browse the repository at this point in the history
* remove depguard

* lint legacy-ibc-testing

* revert the use of using a newer call

* run linter

---------

Co-authored-by: Jehan <[email protected]>
Co-authored-by: Shawn <[email protected]>
  • Loading branch information
3 people committed Aug 15, 2023
1 parent 89eca8c commit 361277c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: '1.20'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.52.2
version: v1.53.3

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
21 changes: 8 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ run:
timeout: 10m
sort-results: true
allow-parallel-runners: true
skip-dirs:
- "legacy_ibc_testing"
- "testutil"
skip-dirs:
- 'testutil'

linters:
disable-all: true
Expand All @@ -31,28 +30,24 @@ linters:
- unconvert
- unused





issues:
exclude-rules:
- text: "Use of weak random number generator"
- text: 'Use of weak random number generator'
linters:
- gosec
- text: "ST1003:"
- text: 'ST1003:'
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
- text: 'ST1016:'
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
- path: 'migrations'
text: 'SA1019:'
linters:
- staticcheck
- text: "leading space"
- text: 'leading space'
linters:
- nolintlint

Expand Down
8 changes: 4 additions & 4 deletions legacy_ibc_testing/core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package core
import (
"strconv"

abci "github.com/cometbft/cometbft/abci/types"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

abci "github.com/cometbft/cometbft/abci/types"
)

/*
Expand All @@ -20,7 +20,7 @@ These files will be deprecated once ICS is able to upgrade to ibc-go v5.
func ReconstructPacketFromEvent(event abci.Event) (packet types.Packet, err error) {
attrMap := make(map[string][]byte)
for _, attr := range event.Attributes {
attrMap[string(attr.Key)] = []byte(attr.Value)
attrMap[attr.Key] = []byte(attr.Value)
}

sequence, err := strconv.Atoi(string(attrMap[string(types.AttributeKeySequence)]))
Expand All @@ -36,7 +36,7 @@ func ReconstructPacketFromEvent(event abci.Event) (packet types.Packet, err erro
return packet, err
}
return types.NewPacket(
attrMap[string(types.AttributeKeyData)], // data
attrMap[string(types.AttributeKeyData)], //nolint:staticcheck // data
uint64(sequence),
string(attrMap[string(types.AttributeKeySrcPort)]), // sourcePort,
string(attrMap[string(types.AttributeKeySrcChannel)]), // sourceChannel,
Expand Down
14 changes: 9 additions & 5 deletions legacy_ibc_testing/simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import (
"testing"
"time"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/require"

errorsmod "cosmossdk.io/errors"

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"

"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/simapp/helpers"
)
Expand Down Expand Up @@ -60,7 +64,7 @@ func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
return valAddrs
}

func TestAddr(addr string, bech string) (sdk.AccAddress, error) {
func TestAddr(addr, bech string) (sdk.AccAddress, error) {
res, err := sdk.AccAddressFromHexUnsafe(addr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -140,7 +144,7 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) {
panic(err)
}
if len(pkBytes) != ed25519.PubKeySize {
panic(errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size"))
panic(errorsmod.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size"))
}
return &ed25519.PubKey{Key: pkBytes}
}
Expand Down
13 changes: 7 additions & 6 deletions legacy_ibc_testing/testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"testing"
"time"

"github.com/cosmos/ibc-go/v7/modules/core/keeper"
"github.com/stretchr/testify/require"

"cosmossdk.io/math"
"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"

abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -22,10 +21,12 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v7/modules/core/keeper"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"

"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"
"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/simapp"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)
Expand Down
32 changes: 17 additions & 15 deletions legacy_ibc_testing/testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
"testing"
"time"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/modules/core/types"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/ibc-go/v7/testing/mock"
"github.com/stretchr/testify/require"

errorsmod "cosmossdk.io/errors"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
tmtypes "github.com/cometbft/cometbft/types"
tmversion "github.com/cometbft/cometbft/version"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand All @@ -24,16 +29,13 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
teststaking "github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/modules/core/types"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/ibc-go/v7/testing/mock"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
tmtypes "github.com/cometbft/cometbft/types"
tmversion "github.com/cometbft/cometbft/version"

ibctestingcore "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"
"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/simapp"
Expand Down
3 changes: 2 additions & 1 deletion legacy_ibc_testing/testing/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"testing"
"time"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/require"

abci "github.com/cometbft/cometbft/abci/types"
)

/*
Expand Down
6 changes: 3 additions & 3 deletions legacy_ibc_testing/testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package testing
import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/stretchr/testify/require"

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

/*
Expand Down
18 changes: 9 additions & 9 deletions legacy_ibc_testing/testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package testing
import (
"fmt"

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

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

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

/*
Expand All @@ -23,8 +23,8 @@ func ParseClientIDFromEvents(events sdk.Events) (string, error) {
for _, ev := range events {
if ev.Type == clienttypes.EventTypeCreateClient {
for _, attr := range ev.Attributes {
if string(attr.Key) == clienttypes.AttributeKeyClientID {
return string(attr.Value), nil
if attr.Key == clienttypes.AttributeKeyClientID {
return attr.Value, nil
}
}
}
Expand All @@ -39,8 +39,8 @@ func ParseConnectionIDFromEvents(events sdk.Events) (string, error) {
if ev.Type == connectiontypes.EventTypeConnectionOpenInit ||
ev.Type == connectiontypes.EventTypeConnectionOpenTry {
for _, attr := range ev.Attributes {
if string(attr.Key) == connectiontypes.AttributeKeyConnectionID {
return string(attr.Value), nil
if attr.Key == connectiontypes.AttributeKeyConnectionID {
return attr.Value, nil
}
}
}
Expand All @@ -54,8 +54,8 @@ func ParseChannelIDFromEvents(events sdk.Events) (string, error) {
for _, ev := range events {
if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry {
for _, attr := range ev.Attributes {
if string(attr.Key) == channeltypes.AttributeKeyChannelID {
return string(attr.Value), nil
if attr.Key == channeltypes.AttributeKeyChannelID {
return attr.Value, nil
}
}
}
Expand All @@ -69,7 +69,7 @@ func ParseAckFromEvents(events sdk.Events) ([]byte, error) {
for _, ev := range events {
if ev.Type == channeltypes.EventTypeWriteAck {
for _, attr := range ev.Attributes {
if string(attr.Key) == channeltypes.AttributeKeyAck {
if attr.Key == channeltypes.AttributeKeyAck { //nolint:staticcheck // data
return []byte(attr.Value), nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion legacy_ibc_testing/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package testing
import (
"testing"

"github.com/stretchr/testify/require"

abci "github.com/cometbft/cometbft/abci/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/require"
)

/*
Expand Down

0 comments on commit 361277c

Please sign in to comment.