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

imp(apps): added 'WithICS4Wrapper' function to keepers #4187

Merged
merged 16 commits into from
Jul 31, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package keeper

/*
This file is to allow for unexported functions and fields to be accessible to the testing package.
*/

import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"

// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
return k.ics4Wrapper
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func NewKeeper(
}
}

// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
// the keepers creation to set the middleware which is above this module
// in the IBC application stack.
Comment on lines +69 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I would try to elaborate a bit more in what circumstances you would use this function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of other circumstances 😅

func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
k.ics4Wrapper = wrapper
}

// Logger returns the application logger, scoped to the associated module
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)
Expand Down Expand Up @@ -292,3 +294,24 @@ func (suite *KeeperTestSuite) TestGetAuthority() {
expectedAuth := authtypes.NewModuleAddress(govtypes.ModuleName).String()
suite.Require().Equal(expectedAuth, authority)
}

func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
suite.SetupTest()

// test if the ics4 wrapper is the fee keeper initially
ics4Wrapper := suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()

_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().True(isFeeKeeper)
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

// set the ics4 wrapper to the channel keeper
suite.chainA.GetSimApp().ICAControllerKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
ics4Wrapper = suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().False(isFeeKeeper)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package keeper

/*
This file is to allow for unexported functions to be accessible to the testing package.
This file is to allow for unexported functions and fields to be accessible to the testing package.
*/

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

icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
)

// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
return k.ics4Wrapper
}

// GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests.
func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) {
return k.getAppMetadata(ctx, portID, channelID)
Expand Down
7 changes: 7 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func NewKeeper(
}
}

// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
// the keepers creation to set the middleware which is above this module
// in the IBC application stack.
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
k.ics4Wrapper = wrapper
}

// Logger returns the application logger, scoped to the associated module
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName))
Expand Down
23 changes: 23 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
Expand Down Expand Up @@ -301,3 +303,24 @@ func (suite *KeeperTestSuite) TestUnsetParams() {
suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx)
})
}

func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
suite.SetupTest()

// test if the ics4 wrapper is the fee keeper initially
ics4Wrapper := suite.chainA.GetSimApp().ICAHostKeeper.GetICS4Wrapper()

_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().True(isFeeKeeper)
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

// set the ics4 wrapper to the channel keeper
suite.chainA.GetSimApp().ICAHostKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
ics4Wrapper = suite.chainA.GetSimApp().ICAHostKeeper.GetICS4Wrapper()

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().False(isFeeKeeper)
}
12 changes: 12 additions & 0 deletions modules/apps/29-fee/keeper/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package keeper

/*
This file is to allow for unexported functions and fields to be accessible to the testing package.
*/

import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"

// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
return k.ics4Wrapper
}
7 changes: 7 additions & 0 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func NewKeeper(
}
}

// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
// the keepers creation to set the middleware which is above this module
// in the IBC application stack.
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
k.ics4Wrapper = wrapper
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+ibcexported.ModuleName+"-"+types.ModuleName)
Expand Down
23 changes: 23 additions & 0 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

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

"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock"
Expand Down Expand Up @@ -297,3 +299,24 @@ func (suite *KeeperTestSuite) TestGetAllCounterpartyPayees() {
suite.Require().Len(counterpartyPayeeAddr, len(expectedCounterpartyPayee))
suite.Require().Equal(counterpartyPayeeAddr, expectedCounterpartyPayee)
}

func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
suite.SetupTest()

// test if the ics4 wrapper is the channel keeper initially
ics4Wrapper := suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()

_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
_, isFeeKeeper := ics4Wrapper.(keeper.Keeper)
suite.Require().False(isFeeKeeper)

// set the ics4 wrapper to itself (don't do this in production)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

suite.chainA.GetSimApp().IBCFeeKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCFeeKeeper)
ics4Wrapper = suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()

_, isFeeKeeper = ics4Wrapper.(keeper.Keeper)
suite.Require().True(isFeeKeeper)
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)
}
12 changes: 12 additions & 0 deletions modules/apps/transfer/keeper/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package keeper

/*
This file is to allow for unexported functions and fields to be accessible to the testing package.
*/

import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"

// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
return k.ics4Wrapper
}
7 changes: 7 additions & 0 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func NewKeeper(
}
}

// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
// the keepers creation to set the middleware which is above this module
// in the IBC application stack.
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
k.ics4Wrapper = wrapper
}

// GetAuthority returns the transfer module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
Expand Down
23 changes: 23 additions & 0 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

Expand Down Expand Up @@ -263,3 +265,24 @@ func (suite *KeeperTestSuite) TestUnsetParams() {
suite.chainA.GetSimApp().TransferKeeper.GetParams(ctx)
})
}

func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
suite.SetupTest()

// test if the ics4 wrapper is the fee keeper initially
ics4Wrapper := suite.chainA.GetSimApp().TransferKeeper.GetICS4Wrapper()
_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)

suite.Require().True(isFeeKeeper)
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

// set the ics4 wrapper to the channel keeper
suite.chainA.GetSimApp().TransferKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
ics4Wrapper = suite.chainA.GetSimApp().TransferKeeper.GetICS4Wrapper()

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().False(isFeeKeeper)
}
Loading