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

removing initmodule from ica #4977

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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))
}
})
}
}
1 change: 0 additions & 1 deletion modules/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

var (
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that theres associated functions that can additionally be removed, currently they should be duplicated (e.g Name() IIRC)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will incorporate this in another PR, for now edited the issues addressed and reverted changes

_ module.AppModuleSimulation = (*AppModule)(nil)
_ module.HasName = (*AppModule)(nil)
_ module.HasConsensusVersion = (*AppModule)(nil)
Expand Down