Skip to content

Commit

Permalink
imp(apps): added 'WithICS4Wrapper' function to keepers (backport #4187)…
Browse files Browse the repository at this point in the history
… (#4210)

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

* imp(ica, transfer): added WithICS4Wrapper api function

* docs(ica, transfer): updated 'WithICS4Wrapper's godocs

* docs(adr8): updated godocs for withics4wrapper

* imp(ica/host): removed withics4wrapper from icahost

* style(ica, tranfer): ran golanci-lint

* imp(ica/controller_test): added WithICS4Wrapper test

* imp(transfer_test): added WithICS4Wrapper test

* style(transfer_test, ica/controller_test): added spacing to TestWithICS4Wrapper

* feat(ica/host): implemented 'WithICS4Wrapper'

* feat(fee): implemented 'WithICS4Wrapper'

(cherry picked from commit 561eb36)

# Conflicts:
#	modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go
#	modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
#	modules/apps/transfer/keeper/keeper.go
#	modules/apps/transfer/keeper/keeper_test.go

* fix: fixed backport conflicts

---------

Co-authored-by: srdtrk <[email protected]>
Co-authored-by: srdtrk <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2023
1 parent fd6e6a7 commit 001236b
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 1 deletion.
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 @@ -60,6 +60,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

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 @@ -255,3 +257,24 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
suite.Require().True(found)
suite.Require().Equal(expectedAccAddr, retrievedAddr)
}

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 @@ -68,6 +68,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 @@ -8,6 +8,8 @@ import (

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"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
Expand Down Expand Up @@ -268,3 +270,24 @@ func (suite *KeeperTestSuite) TestMetadataNotFound() {
suite.Require().ErrorIs(err, ibcerrors.ErrNotFound)
suite.Require().Contains(err.Error(), fmt.Sprintf("app version not found for port %s and channel %s", invalidPortID, invalidChannelID))
}

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 @@ -49,6 +49,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 @@ -8,7 +8,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

"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 @@ -301,3 +303,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)
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 @@ -62,6 +62,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/"+exported.ModuleName+"-"+types.ModuleName)
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 @@ -11,7 +11,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

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 @@ -229,3 +231,24 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
})
}
}

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)
}

0 comments on commit 001236b

Please sign in to comment.