From 97f695aab3d13e27f85072253e55fff098fbdd20 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Wed, 16 Aug 2023 02:48:05 +0800 Subject: [PATCH] refactor: this PR adds the testutil folder to the linter configuration (#1080) * this PR adds the testutil folder to the linter configuration * run golangci-lint --------- Co-authored-by: Marius Poke Co-authored-by: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> --- .golangci.yml | 2 -- testutil/crypto/crypto.go | 8 ++++---- testutil/ibc_testing/generic_setup.go | 13 +++++++------ testutil/ibc_testing/specific_setup.go | 2 +- testutil/integration/interfaces.go | 4 +++- testutil/keeper/expectations.go | 27 ++++++++++++-------------- testutil/keeper/unit_test_helpers.go | 26 ++++++++++++------------- testutil/simibc/chain_util.go | 6 ++++-- testutil/simibc/relay_util.go | 20 +++++++++++-------- testutil/simibc/relayed_path.go | 1 + 10 files changed, 57 insertions(+), 52 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5bf3cfb98f..d86d8ae7af 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,8 +3,6 @@ run: timeout: 10m sort-results: true allow-parallel-runners: true - skip-dirs: - - 'testutil' linters: disable-all: true diff --git a/testutil/crypto/crypto.go b/testutil/crypto/crypto.go index dd733f0ab3..53babef942 100644 --- a/testutil/crypto/crypto.go +++ b/testutil/crypto/crypto.go @@ -1,9 +1,8 @@ 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" @@ -11,11 +10,12 @@ import ( 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 @@ -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) diff --git a/testutil/ibc_testing/generic_setup.go b/testutil/ibc_testing/generic_setup.go index e784ee23b7..25c483fca5 100644 --- a/testutil/ibc_testing/generic_setup.go +++ b/testutil/ibc_testing/generic_setup.go @@ -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, diff --git a/testutil/ibc_testing/specific_setup.go b/testutil/ibc_testing/specific_setup.go index 01c8315de8..948007d212 100644 --- a/testutil/ibc_testing/specific_setup.go +++ b/testutil/ibc_testing/specific_setup.go @@ -8,7 +8,6 @@ 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" @@ -16,6 +15,7 @@ import ( 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 diff --git a/testutil/integration/interfaces.go b/testutil/integration/interfaces.go index 41e6fd70c3..b677d46789 100644 --- a/testutil/integration/interfaces.go +++ b/testutil/integration/interfaces.go @@ -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" @@ -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" diff --git a/testutil/keeper/expectations.go b/testutil/keeper/expectations.go index 8a231f4760..07d4d320ba 100644 --- a/testutil/keeper/expectations.go +++ b/testutil/keeper/expectations.go @@ -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" ) // @@ -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"}, @@ -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), } } @@ -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) } diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index b8e69a4045..c5540f4601 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -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 diff --git a/testutil/simibc/chain_util.go b/testutil/simibc/chain_util.go index 0e6d14cd38..98622695d3 100644 --- a/testutil/simibc/chain_util.go +++ b/testutil/simibc/chain_util.go @@ -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" ) diff --git a/testutil/simibc/relay_util.go b/testutil/simibc/relay_util.go index 7015dc72c1..97bcabf57c 100644 --- a/testutil/simibc/relay_util.go +++ b/testutil/simibc/relay_util.go @@ -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 @@ -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 { @@ -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) @@ -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) @@ -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 ( diff --git a/testutil/simibc/relayed_path.go b/testutil/simibc/relayed_path.go index dfc5febe9c..7ef97c4bee 100644 --- a/testutil/simibc/relayed_path.go +++ b/testutil/simibc/relayed_path.go @@ -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" )