Skip to content

Commit 561eb36

Browse files
authored
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'
1 parent 117604a commit 561eb36

File tree

12 files changed

+163
-1
lines changed

12 files changed

+163
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package keeper
2+
3+
/*
4+
This file is to allow for unexported functions and fields to be accessible to the testing package.
5+
*/
6+
7+
import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
8+
9+
// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
10+
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
11+
return k.ics4Wrapper
12+
}

modules/apps/27-interchain-accounts/controller/keeper/keeper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ func NewKeeper(
6666
}
6767
}
6868

69+
// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
70+
// the keepers creation to set the middleware which is above this module
71+
// in the IBC application stack.
72+
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
73+
k.ics4Wrapper = wrapper
74+
}
75+
6976
// Logger returns the application logger, scoped to the associated module
7077
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
7178
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName))

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
1212
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
1313
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
14+
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
15+
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
1416
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1517
ibctesting "github.com/cosmos/ibc-go/v7/testing"
1618
)
@@ -292,3 +294,24 @@ func (suite *KeeperTestSuite) TestGetAuthority() {
292294
expectedAuth := authtypes.NewModuleAddress(govtypes.ModuleName).String()
293295
suite.Require().Equal(expectedAuth, authority)
294296
}
297+
298+
func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
299+
suite.SetupTest()
300+
301+
// test if the ics4 wrapper is the fee keeper initially
302+
ics4Wrapper := suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()
303+
304+
_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
305+
suite.Require().True(isFeeKeeper)
306+
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
307+
suite.Require().False(isChannelKeeper)
308+
309+
// set the ics4 wrapper to the channel keeper
310+
suite.chainA.GetSimApp().ICAControllerKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
311+
ics4Wrapper = suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()
312+
313+
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
314+
suite.Require().True(isChannelKeeper)
315+
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
316+
suite.Require().False(isFeeKeeper)
317+
}

modules/apps/27-interchain-accounts/host/keeper/export_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package keeper
22

33
/*
4-
This file is to allow for unexported functions to be accessible to the testing package.
4+
This file is to allow for unexported functions and fields to be accessible to the testing package.
55
*/
66

77
import (
88
sdk "github.com/cosmos/cosmos-sdk/types"
99

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

14+
// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
15+
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
16+
return k.ics4Wrapper
17+
}
18+
1319
// GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests.
1420
func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) {
1521
return k.getAppMetadata(ctx, portID, channelID)

modules/apps/27-interchain-accounts/host/keeper/keeper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ func NewKeeper(
7474
}
7575
}
7676

77+
// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
78+
// the keepers creation to set the middleware which is above this module
79+
// in the IBC application stack.
80+
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
81+
k.ics4Wrapper = wrapper
82+
}
83+
7784
// Logger returns the application logger, scoped to the associated module
7885
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
7986
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName))

modules/apps/27-interchain-accounts/host/keeper/keeper_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
1010
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
1111
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
12+
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
13+
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
1214
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1315
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
1416
ibctesting "github.com/cosmos/ibc-go/v7/testing"
@@ -301,3 +303,24 @@ func (suite *KeeperTestSuite) TestUnsetParams() {
301303
suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx)
302304
})
303305
}
306+
307+
func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
308+
suite.SetupTest()
309+
310+
// test if the ics4 wrapper is the fee keeper initially
311+
ics4Wrapper := suite.chainA.GetSimApp().ICAHostKeeper.GetICS4Wrapper()
312+
313+
_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
314+
suite.Require().True(isFeeKeeper)
315+
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
316+
suite.Require().False(isChannelKeeper)
317+
318+
// set the ics4 wrapper to the channel keeper
319+
suite.chainA.GetSimApp().ICAHostKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
320+
ics4Wrapper = suite.chainA.GetSimApp().ICAHostKeeper.GetICS4Wrapper()
321+
322+
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
323+
suite.Require().True(isChannelKeeper)
324+
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
325+
suite.Require().False(isFeeKeeper)
326+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package keeper
2+
3+
/*
4+
This file is to allow for unexported functions and fields to be accessible to the testing package.
5+
*/
6+
7+
import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
8+
9+
// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
10+
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
11+
return k.ics4Wrapper
12+
}

modules/apps/29-fee/keeper/keeper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func NewKeeper(
5050
}
5151
}
5252

53+
// WithICS4Wrapper sets the ICS4Wrapper. This function may be used after
54+
// the keepers creation to set the middleware which is above this module
55+
// in the IBC application stack.
56+
func (k *Keeper) WithICS4Wrapper(wrapper porttypes.ICS4Wrapper) {
57+
k.ics4Wrapper = wrapper
58+
}
59+
5360
// Logger returns a module-specific logger.
5461
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
5562
return ctx.Logger().With("module", "x/"+ibcexported.ModuleName+"-"+types.ModuleName)

modules/apps/29-fee/keeper/keeper_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010

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

13+
"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
1314
"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
15+
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
1416
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1517
ibctesting "github.com/cosmos/ibc-go/v7/testing"
1618
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock"
@@ -297,3 +299,24 @@ func (suite *KeeperTestSuite) TestGetAllCounterpartyPayees() {
297299
suite.Require().Len(counterpartyPayeeAddr, len(expectedCounterpartyPayee))
298300
suite.Require().Equal(counterpartyPayeeAddr, expectedCounterpartyPayee)
299301
}
302+
303+
func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
304+
suite.SetupTest()
305+
306+
// test if the ics4 wrapper is the channel keeper initially
307+
ics4Wrapper := suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()
308+
309+
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
310+
suite.Require().True(isChannelKeeper)
311+
_, isFeeKeeper := ics4Wrapper.(keeper.Keeper)
312+
suite.Require().False(isFeeKeeper)
313+
314+
// set the ics4 wrapper to itself (don't do this in production)
315+
suite.chainA.GetSimApp().IBCFeeKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCFeeKeeper)
316+
ics4Wrapper = suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()
317+
318+
_, isFeeKeeper = ics4Wrapper.(keeper.Keeper)
319+
suite.Require().True(isFeeKeeper)
320+
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
321+
suite.Require().False(isChannelKeeper)
322+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package keeper
2+
3+
/*
4+
This file is to allow for unexported functions and fields to be accessible to the testing package.
5+
*/
6+
7+
import porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
8+
9+
// GetICS4Wrapper is a getter for the keeper's ICS4Wrapper.
10+
func (k *Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
11+
return k.ics4Wrapper
12+
}

0 commit comments

Comments
 (0)