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: use mock module for ics29 genesis_test.go #931

Merged
merged 4 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 6 additions & 10 deletions modules/apps/29-fee/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -38,7 +35,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
},
FeeEnabledChannels: []*types.FeeEnabledChannel{
{
PortId: transfertypes.PortID,
PortId: ibctesting.MockFeePort,
ChannelId: ibctesting.FirstChannelID,
},
},
Expand All @@ -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
Expand All @@ -68,13 +65,12 @@ 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, 1)
packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1)
fee := types.Fee{
RecvFee: defaultReceiveFee,
AckFee: defaultAckFee,
Expand All @@ -98,7 +94,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)
Expand Down
21 changes: 21 additions & 0 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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))
Expand All @@ -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))
}
Expand Down