Skip to content

Commit

Permalink
fix: adjust InitModule to account for empty controller and host keepe…
Browse files Browse the repository at this point in the history
…rs (#1120) (#1121)

## Description

closes: #XXXX

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [x] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [x] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [x] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [x] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [x] Re-reviewed `Files changed` in the Github PR explorer
- [x] Review `Codecov Report` in the comment section below once CI passes

(cherry picked from commit 0a81a52)

Co-authored-by: colin axnér <[email protected]>
  • Loading branch information
mergify[bot] and colin-axner authored Mar 15, 2022
1 parent eaf9d67 commit 6e1b25a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 16 deletions.
7 changes: 5 additions & 2 deletions docs/migrations/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,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 @@ -82,6 +82,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))
}

0 comments on commit 6e1b25a

Please sign in to comment.