From 7cb5a00e55c55e071aeabaa72c6a2a0d23ecb554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:18:34 +0100 Subject: [PATCH] refactor: use mock module for ics29 genesis_test.go --- modules/apps/29-fee/keeper/genesis_test.go | 16 ++++++---------- modules/apps/29-fee/keeper/keeper_test.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 568335daed1..e5f60cbf308 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -2,19 +2,16 @@ package keeper_test import ( "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" ) func (suite *KeeperTestSuite) TestInitGenesis() { - suite.SetupTest() - // build PacketId & Fee refundAcc := suite.chainA.SenderAccount.GetAddress() packetId := channeltypes.NewPacketId( ibctesting.FirstChannelID, - transfertypes.PortID, + ibctesting.MockFeePort, uint64(1), ) fee := types.Fee{ @@ -38,7 +35,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { }, FeeEnabledChannels: []*types.FeeEnabledChannel{ { - PortId: transfertypes.PortID, + PortId: ibctesting.MockFeePort, ChannelId: ibctesting.FirstChannelID, }, }, @@ -58,7 +55,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().Equal(genesisState.IdentifiedFees[0], identifiedFee) // check fee is enabled - isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) suite.Require().True(isEnabled) // check relayers @@ -68,15 +65,14 @@ func (suite *KeeperTestSuite) TestInitGenesis() { } func (suite *KeeperTestSuite) TestExportGenesis() { - suite.SetupTest() // set fee enabled - suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) // setup & escrow the packet fee refundAcc := suite.chainA.SenderAccount.GetAddress() packetId := channeltypes.NewPacketId( ibctesting.FirstChannelID, - transfertypes.PortID, + ibctesting.MockFeePort, uint64(1), ) fee := types.Fee{ @@ -102,7 +98,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { // check fee enabled suite.Require().Equal(ibctesting.FirstChannelID, genesisState.FeeEnabledChannels[0].ChannelId) - suite.Require().Equal(transfertypes.PortID, genesisState.FeeEnabledChannels[0].PortId) + suite.Require().Equal(ibctesting.MockFeePort, genesisState.FeeEnabledChannels[0].PortId) // check fee suite.Require().Equal(packetId, genesisState.IdentifiedFees[0].PacketId) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 3e21e268597..7f6777c2cee 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" + ibcmock "github.com/cosmos/ibc-go/v3/testing/mock" ) var ( @@ -34,6 +35,7 @@ type KeeperTestSuite struct { queryClient types.QueryClient } +// TODO: remove and rename 'SetupMockTest' to 'SetupTest' func (suite *KeeperTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) @@ -52,6 +54,25 @@ func (suite *KeeperTestSuite) SetupTest() { suite.queryClient = types.NewQueryClient(queryHelper) } +// TODO: rename to 'SetupTest' when the above function is removed +func (suite *KeeperTestSuite) SetupMockTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + + path := ibctesting.NewPath(suite.chainA, suite.chainB) + mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) + path.EndpointA.ChannelConfig.Version = mockFeeVersion + path.EndpointB.ChannelConfig.Version = mockFeeVersion + path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort + path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort + suite.path = path + + queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().IBCFeeKeeper) + suite.queryClient = types.NewQueryClient(queryHelper) +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) }