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

fix: adjust InitModule to account for empty controller and host keepers #1120

Merged
merged 2 commits into from
Mar 15, 2022
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
7 changes: 5 additions & 2 deletions docs/migrations/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ app.UpgradeKeeper.SetUpgradeHandler("v3",

```

The host and controller submodule params only need to be set if you integrate those submodules.
For example, if a chain chooses not to integrate a controller submodule, it does not need to set the controller params.
The host and controller submodule params only need to be set if the chain integrates those submodules.
For example, if a chain chooses not to integrate a controller submodule, it may pass empty params into `InitModule`.

#### Add `StoreUpgrades` for ICS27 module

Expand All @@ -76,6 +76,9 @@ if upgradeInfo.Name == "v3" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Heigh
```

This ensures that the new module's stores are added to the multistore before the migrations begin.
The host and controller submodule keys only need to be added if the chain integrates those submodules.
For example, if a chain chooses not to integrate a controller submodule, it does not need to add the controller key to the `Added` field.


### Genesis migrations

Expand Down
15 changes: 10 additions & 5 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee
// InitModule will initialize the interchain accounts moudule. It should only be
// called once and as an alternative to InitGenesis.
func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) {
am.controllerKeeper.SetParams(ctx, controllerParams)
am.hostKeeper.SetParams(ctx, hostParams)
if am.controllerKeeper != nil {
am.controllerKeeper.SetParams(ctx, controllerParams)
}

if am.hostKeeper != nil {
am.hostKeeper.SetParams(ctx, hostParams)

cap := am.hostKeeper.BindPort(ctx, types.PortID)
if err := am.hostKeeper.ClaimCapability(ctx, cap, ibchost.PortPath(types.PortID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
cap := am.hostKeeper.BindPort(ctx, types.PortID)
if err := am.hostKeeper.ClaimCapability(ctx, cap, ibchost.PortPath(types.PortID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
}

Expand Down
76 changes: 67 additions & 9 deletions modules/apps/27-interchain-accounts/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func (suite *InterchainAccountsTestSuite) SetupTest() {
}

func (suite *InterchainAccountsTestSuite) TestInitModule() {
// setup and basic testing
app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{})
icamodule, ok := app.GetModuleManager().Modules[types.ModuleName].(ica.AppModule)
appModule, ok := app.GetModuleManager().Modules[types.ModuleName].(ica.AppModule)
suite.Require().True(ok)

header := tmproto.Header{
Expand All @@ -58,17 +59,74 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() {
expAllowMessages := []string{"sdk.Msg"}
hostParams.HostEnabled = true
hostParams.AllowMessages = expAllowMessages

suite.Require().False(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID))

icamodule.InitModule(ctx, controllerParams, hostParams)
testCases := []struct {
name string
malleate func()
expControllerPass bool
expHostPass bool
}{
{
"both controller and host set", func() {
var ok bool
appModule, ok = app.GetModuleManager().Modules[types.ModuleName].(ica.AppModule)
suite.Require().True(ok)
}, true, true,
},
{
"neither controller or host is set", func() {
appModule = ica.NewAppModule(nil, nil)
}, false, false,
},
{
"only controller is set", func() {
appModule = ica.NewAppModule(&app.ICAControllerKeeper, nil)
}, true, false,
},
{
"only host is set", func() {
appModule = ica.NewAppModule(nil, &app.ICAHostKeeper)
}, false, true,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

// reset app state
app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{})
header := tmproto.Header{
ChainID: "testchain",
Height: 1,
Time: suite.coordinator.CurrentTime.UTC(),
}

ctx := app.GetBaseApp().NewContext(true, header)

controllerParams = app.ICAControllerKeeper.GetParams(ctx)
suite.Require().True(controllerParams.ControllerEnabled)
tc.malleate()

hostParams = app.ICAHostKeeper.GetParams(ctx)
suite.Require().True(hostParams.HostEnabled)
suite.Require().Equal(expAllowMessages, hostParams.AllowMessages)
suite.Require().NotPanics(func() {
appModule.InitModule(ctx, controllerParams, hostParams)
})

if tc.expControllerPass {
controllerParams = app.ICAControllerKeeper.GetParams(ctx)
suite.Require().True(controllerParams.ControllerEnabled)
}

if tc.expHostPass {
hostParams = app.ICAHostKeeper.GetParams(ctx)
suite.Require().True(hostParams.HostEnabled)
suite.Require().Equal(expAllowMessages, hostParams.AllowMessages)

suite.Require().True(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID))
}

})
}

suite.Require().True(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID))
}