Skip to content

Commit

Permalink
removing initmodule from ica (cosmos#4977)
Browse files Browse the repository at this point in the history
* remoing appmodulebasic interface from capability and initmodule function which mimicks initgenesis

* undoing capability change
  • Loading branch information
muku314115 authored Oct 31, 2023
1 parent 016443d commit 50ac22e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 122 deletions.
21 changes: 0 additions & 21 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,6 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee
}
}

// InitModule will initialize the interchain accounts module. 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) {
if am.controllerKeeper != nil {
controllerkeeper.InitGenesis(ctx, *am.controllerKeeper, genesistypes.ControllerGenesisState{
Params: controllerParams,
})
}

if am.hostKeeper != nil {
if err := hostParams.Validate(); err != nil {
panic(fmt.Errorf("could not set ica host params at initialization: %v", err))
}

hostkeeper.InitGenesis(ctx, *am.hostKeeper, genesistypes.HostGenesisState{
Params: hostParams,
Port: types.HostPortID,
})
}
}

// RegisterServices registers module services
func (am AppModule) RegisterServices(cfg module.Configurator) {
if am.controllerKeeper != nil {
Expand Down
101 changes: 0 additions & 101 deletions modules/apps/27-interchain-accounts/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ package ica_test
import (
"testing"

dbm "github.com/cosmos/cosmos-db"
testifysuite "github.com/stretchr/testify/suite"

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
hosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
"github.com/cosmos/ibc-go/v8/testing/simapp"
)

type InterchainAccountsTestSuite struct {
Expand All @@ -32,93 +21,3 @@ func TestICATestSuite(t *testing.T) {
func (suite *InterchainAccountsTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
}

func (suite *InterchainAccountsTestSuite) TestInitModule() {
// setup and basic testing
chainID := "testchain"
app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, baseapp.SetChainID(chainID))
appModule, ok := app.ModuleManager.Modules[types.ModuleName].(ica.AppModule)
suite.Require().True(ok)

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

// ensure params are not set
suite.Require().Panics(func() {
app.ICAControllerKeeper.GetParams(ctx)
})
suite.Require().Panics(func() {
app.ICAHostKeeper.GetParams(ctx)
})

controllerParams := controllertypes.DefaultParams()
controllerParams.ControllerEnabled = true

hostParams := hosttypes.DefaultParams()
expAllowMessages := []string{"sdk.Msg"}
hostParams.HostEnabled = true
hostParams.AllowMessages = expAllowMessages
suite.Require().False(app.IBCKeeper.PortKeeper.IsBound(ctx, types.HostPortID))

testCases := []struct {
name string
malleate func()
expControllerPass bool
expHostPass bool
}{
{
"both controller and host set", func() {
var ok bool
appModule, ok = app.ModuleManager.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
chainID := "testchain"
app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, baseapp.SetChainID(chainID))

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

tc.malleate()

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

0 comments on commit 50ac22e

Please sign in to comment.