Skip to content

Commit

Permalink
Integrate ICA into testing package, add simple keeper tests (#282)
Browse files Browse the repository at this point in the history
* add ica to simapp

* add simple keeper tests
  • Loading branch information
colin-axner committed Jul 22, 2021
1 parent 0148576 commit b870be4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
return ok
}

// BindPort defines a wrapper function for the ort Keeper's function in
// BindPort defines a wrapper function for the port Keeper's BindPort function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
// Set the portID into our store so we can retrieve it later
Expand Down
50 changes: 50 additions & 0 deletions modules/apps/27-interchain-accounts/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/testing"
)

type KeeperTestSuite struct {
suite.Suite

coordinator *ibctesting.Coordinator

// testing chains used for convenience and readability
chainA *ibctesting.TestChain
chainB *ibctesting.TestChain
chainC *ibctesting.TestChain
}

func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2))
}

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = types.PortID
path.EndpointB.ChannelConfig.PortID = types.PortID

return path
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (suite *KeeperTestSuite) TestIsBound() {
isBound := suite.chainA.GetSimApp().ICAKeeper.IsBound(suite.chainA.GetContext(), types.PortID)
suite.Require().True(isBound)
}

func (suite *KeeperTestSuite) TestGetPort() {
port := suite.chainA.GetSimApp().ICAKeeper.GetPort(suite.chainA.GetContext())
suite.Require().Equal(types.PortID, port)
}
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// module supports
Version = "ics27-1"

PortID = "ibcaccount"
PortID = "interchain-account"

StoreKey = ModuleName
RouterKey = ModuleName
Expand Down
29 changes: 27 additions & 2 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts"
icakeeper "github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/keeper"
icatypes "github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/types"
transfer "github.com/cosmos/ibc-go/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
Expand Down Expand Up @@ -131,6 +134,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
ibcmock.AppModuleBasic{},
ica.AppModuleBasic{},
authzmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
)
Expand Down Expand Up @@ -182,13 +186,15 @@ type SimApp struct {
ParamsKeeper paramskeeper.Keeper
AuthzKeeper authzkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICAKeeper icakeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAKeeper capabilitykeeper.ScopedKeeper
ScopedIBCMockKeeper capabilitykeeper.ScopedKeeper

// the module manager
Expand Down Expand Up @@ -230,7 +236,7 @@ func NewSimApp(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icatypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand All @@ -256,6 +262,8 @@ func NewSimApp(
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAKeeper := app.CapabilityKeeper.ScopeToModule(icatypes.ModuleName)

// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
// note replicate if you do not need to test core IBC or light clients.
scopedIBCMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName)
Expand Down Expand Up @@ -321,13 +329,21 @@ func NewSimApp(
)
transferModule := transfer.NewAppModule(app.TransferKeeper)

app.ICAKeeper = icakeeper.NewKeeper(
keys[icatypes.MemStoreKey], appCodec, keys[icatypes.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAKeeper, app.MsgServiceRouter(), app,
)
icaModule := ica.NewAppModule(app.ICAKeeper)

// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
// note replicate if you do not need to test core IBC or light clients.
mockModule := ibcmock.NewAppModule(scopedIBCMockKeeper, &app.IBCKeeper.PortKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
ibcRouter.AddRoute(icatypes.ModuleName, icaModule)
ibcRouter.AddRoute(ibcmock.ModuleName, mockModule)
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -368,6 +384,7 @@ func NewSimApp(
params.NewAppModule(app.ParamsKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
transferModule,
icaModule,
mockModule,
)

Expand All @@ -390,7 +407,7 @@ func NewSimApp(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName,
ibcmock.ModuleName, feegrant.ModuleName,
icatypes.ModuleName, ibcmock.ModuleName, feegrant.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -467,6 +484,7 @@ func NewSimApp(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICAKeeper = scopedICAKeeper

// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
// note replicate if you do not need to test core IBC or light clients.
Expand Down Expand Up @@ -664,3 +682,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

// Interchain Accounts code
func (*SimApp) OnTxSucceeded(ctx sdk.Context, sourcePort, sourceChannel string, txHash []byte, txBytes []byte) {
}

func (*SimApp) OnTxFailed(ctx sdk.Context, sourcePort, sourceChannel string, txHash []byte, txBytes []byte) {
}

0 comments on commit b870be4

Please sign in to comment.