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

refactor: this PR adds the testutil folder to the linter configuration #1080

Merged
merged 7 commits into from
Aug 15, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ run:
timeout: 10m
sort-results: true
allow-parallel-runners: true
skip-dirs:
- 'testutil'

linters:
disable-all: true
Expand Down
8 changes: 4 additions & 4 deletions testutil/crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package crypto

import (
"encoding/binary"

cryptoEd25519 "crypto/ed25519"
"encoding/binary"

sdkcryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdkcryptoEd25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdkcryptoSecp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdkcryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
sdkstakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"

tmcrypto "github.com/cometbft/cometbft/crypto"
tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
tmtypes "github.com/cometbft/cometbft/types"

providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
)

// CryptoIdentity is a test helper for generating keys and addresses of
Expand Down Expand Up @@ -48,7 +48,7 @@ func NewCryptoIdentityFromIntSeed(i int) *CryptoIdentity {
}

// GenMultipleCryptoIds generates and returns multiple CryptoIdentities from a starting int seed.
func GenMultipleCryptoIds(num int, fromIntSeed int) []*CryptoIdentity {
func GenMultipleCryptoIds(num, fromIntSeed int) []*CryptoIdentity {
ids := make([]*CryptoIdentity, num)
for i := 0; i < num; i++ {
ids[i] = NewCryptoIdentityFromIntSeed(fromIntSeed + i)
Expand Down
13 changes: 7 additions & 6 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
testutil "github.com/cosmos/interchain-security/v3/testutil/integration"
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"

"github.com/stretchr/testify/suite"

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

tmencoding "github.com/cometbft/cometbft/crypto/encoding"
tmtypes "github.com/cometbft/cometbft/types"

ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
testutil "github.com/cosmos/interchain-security/v3/testutil/integration"
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
)

// Contains generic setup code for running integration tests against a provider, consumer,
Expand Down
2 changes: 1 addition & 1 deletion testutil/ibc_testing/specific_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"encoding/json"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"

tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"

appConsumer "github.com/cosmos/interchain-security/v3/app/consumer"
appConsumerDemocracy "github.com/cosmos/interchain-security/v3/app/consumer-democracy"
appProvider "github.com/cosmos/interchain-security/v3/app/provider"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
)

// ProviderAppIniter implements ibctesting.AppIniter for a provider app
Expand Down
4 changes: 3 additions & 1 deletion testutil/integration/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -16,6 +16,8 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"

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

ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
providerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper"
Expand Down
27 changes: 12 additions & 15 deletions testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ package keeper
import (
time "time"

sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/golang/mock/gomock"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
"github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/golang/mock/gomock"
extra "github.com/oxyno-zeta/gomock-extra-matcher"

host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

extra "github.com/oxyno-zeta/gomock-extra-matcher"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
"github.com/cosmos/interchain-security/v3/x/ccv/types"
)

//
Expand Down Expand Up @@ -68,7 +65,7 @@ func GetMocksForSetConsumerChain(ctx sdk.Context, mocks *MockedKeepers,
chainIDToInject string,
) []*gomock.Call {
return []*gomock.Call{
mocks.MockChannelKeeper.EXPECT().GetChannel(ctx, ccv.ProviderPortID, gomock.Any()).Return(
mocks.MockChannelKeeper.EXPECT().GetChannel(ctx, types.ProviderPortID, gomock.Any()).Return(
channeltypes.Channel{
State: channeltypes.OPEN,
ConnectionHops: []string{"connectionID"},
Expand All @@ -88,11 +85,11 @@ func GetMocksForSetConsumerChain(ctx sdk.Context, mocks *MockedKeepers,
func GetMocksForStopConsumerChain(ctx sdk.Context, mocks *MockedKeepers) []*gomock.Call {
dummyCap := &capabilitytypes.Capability{}
return []*gomock.Call{
mocks.MockChannelKeeper.EXPECT().GetChannel(gomock.Any(), ccv.ProviderPortID, "channelID").Return(
mocks.MockChannelKeeper.EXPECT().GetChannel(gomock.Any(), types.ProviderPortID, "channelID").Return(
channeltypes.Channel{State: channeltypes.OPEN}, true,
).Times(1),
mocks.MockScopedKeeper.EXPECT().GetCapability(gomock.Any(), gomock.Any()).Return(dummyCap, true).Times(1),
mocks.MockChannelKeeper.EXPECT().ChanCloseInit(gomock.Any(), ccv.ProviderPortID, "channelID", dummyCap).Times(1),
mocks.MockChannelKeeper.EXPECT().ChanCloseInit(gomock.Any(), types.ProviderPortID, "channelID", dummyCap).Times(1),
}
}

Expand Down Expand Up @@ -137,7 +134,7 @@ func ExpectCreateClientMock(ctx sdk.Context, mocks MockedKeepers, clientID strin

func ExpectGetCapabilityMock(ctx sdk.Context, mocks MockedKeepers, times int) *gomock.Call {
return mocks.MockScopedKeeper.EXPECT().GetCapability(
ctx, host.PortPath(ccv.ConsumerPortID),
ctx, host.PortPath(types.ConsumerPortID),
).Return(nil, true).Times(times)
}

Expand Down
26 changes: 13 additions & 13 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ import (
"testing"
"time"

abci "github.com/cometbft/cometbft/abci/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tmdb "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
providerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
"github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

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

// Parameters needed to instantiate an in-memory keeper
Expand Down
6 changes: 4 additions & 2 deletions testutil/simibc/chain_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package simibc
import (
"time"

abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

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

ibctestingcore "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
)
Expand Down
20 changes: 12 additions & 8 deletions testutil/simibc/relay_util.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package simibc

import (
errorsmod "cosmossdk.io/errors"
tmtypes "github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/stretchr/testify/require"

errorsmod "cosmossdk.io/errors"

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

tmtypes "github.com/cometbft/cometbft/types"

simapp "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/simapp"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
"github.com/stretchr/testify/require"
)

// UpdateReceiverClient DELIVERs a header to the receiving endpoint
Expand All @@ -20,7 +24,7 @@ import (
// must have a client of the sender chain that it can update.
//
// NOTE: this function MAY be used independently of the rest of simibc.
func UpdateReceiverClient(sender *ibctesting.Endpoint, receiver *ibctesting.Endpoint, header *ibctmtypes.Header) (err error) {
func UpdateReceiverClient(sender, receiver *ibctesting.Endpoint, header *ibctmtypes.Header) (err error) {
err = augmentHeader(sender.Chain, receiver.Chain, receiver.ClientID, header)

if err != nil {
Expand Down Expand Up @@ -65,7 +69,7 @@ func UpdateReceiverClient(sender *ibctesting.Endpoint, receiver *ibctesting.Endp
// The packet must be sent from the sender chain to the receiver chain, and the
// receiver chain must have a client for the sender chain which has been updated
// to a recent height of the sender chain so that it can verify the packet.
func TryRecvPacket(sender *ibctesting.Endpoint, receiver *ibctesting.Endpoint, packet channeltypes.Packet) (ack []byte, err error) {
func TryRecvPacket(sender, receiver *ibctesting.Endpoint, packet channeltypes.Packet) (ack []byte, err error) {
packetKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
proof, proofHeight := sender.Chain.QueryProof(packetKey)

Expand Down Expand Up @@ -107,7 +111,7 @@ func TryRecvPacket(sender *ibctesting.Endpoint, receiver *ibctesting.Endpoint, p
// to packet which was previously delivered from the receiver to the sender.
// The receiver chain must have a client for the sender chain which has been
// updated to a recent height of the sender chain so that it can verify the packet.
func TryRecvAck(sender *ibctesting.Endpoint, receiver *ibctesting.Endpoint, packet channeltypes.Packet, ack []byte) (err error) {
func TryRecvAck(sender, receiver *ibctesting.Endpoint, packet channeltypes.Packet, ack []byte) (err error) {
p := packet
packetKey := host.PacketAcknowledgementKey(p.GetDestPort(), p.GetDestChannel(), p.GetSequence())
proof, proofHeight := sender.Chain.QueryProof(packetKey)
Expand Down Expand Up @@ -141,7 +145,7 @@ func TryRecvAck(sender *ibctesting.Endpoint, receiver *ibctesting.Endpoint, pack

// augmentHeader is a helper that augments the header with the height and validators that are most recently trusted
// by the receiver chain. If there is an error, the header will not be modified.
func augmentHeader(sender *ibctesting.TestChain, receiver *ibctesting.TestChain, clientID string, header *ibctmtypes.Header) error {
func augmentHeader(sender, receiver *ibctesting.TestChain, clientID string, header *ibctmtypes.Header) error {
trustedHeight := receiver.GetClientState(clientID).GetLatestHeight().(clienttypes.Height)

var (
Expand Down
1 change: 1 addition & 0 deletions testutil/simibc/relayed_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
)

Expand Down
Loading