Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jan 29, 2025
1 parent a59f8b3 commit 9248319
Show file tree
Hide file tree
Showing 36 changed files with 135 additions and 732 deletions.
25 changes: 13 additions & 12 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
type Keeper struct {
appmodule.Environment

cdc codec.Codec
legacySubspace icatypes.ParamSubspace
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
cdc codec.Codec
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
Expand All @@ -38,20 +37,22 @@ type Keeper struct {

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.Codec, env appmodule.Environment, legacySubspace icatypes.ParamSubspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, authority string,
cdc codec.Codec,
env appmodule.Environment,
ics4Wrapper porttypes.ICS4Wrapper,
channelKeeper icatypes.ChannelKeeper,
authority string,
) Keeper {
if strings.TrimSpace(authority) == "" {
panic(errors.New("authority must be non-empty"))
}

return Keeper{
Environment: env,
cdc: cdc,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
authority: authority,
Environment: env,
cdc: cdc,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
authority: authority,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
Expand All @@ -131,7 +130,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
"", // authority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

controllertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -21,15 +17,6 @@ func NewMigrator(k *Keeper) Migrator {
}

// MigrateParams migrates the controller submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx context.Context) error {
if m.keeper != nil {
params := controllertypes.DefaultParams()
if m.keeper.legacySubspace != nil {
// NOTE: legacy params still rely on sdk context
m.keeper.legacySubspace.GetParamSetIfExists(sdk.UnwrapSDKContext(ctx), &params)
}
m.keeper.SetParams(ctx, params)
m.keeper.Logger.Info("successfully migrated ica/controller submodule to self-manage params")
}
func (Migrator) MigrateParams(_ context.Context) error {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
package keeper_test

import (
"fmt"

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/runtime"

icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
)

func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
testCases := []struct {
msg string
malleate func()
expectedParams icacontrollertypes.Params
}{
{
"success: default params",
func() {
params := icacontrollertypes.DefaultParams()
subspace := suite.chainA.GetSimApp().GetSubspace(icacontrollertypes.SubModuleName) // get subspace
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
icacontrollertypes.DefaultParams(),
},
{
"success: no legacy params pre-migration",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
suite.chainA.Codec,
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)), log.NewNopLogger()),
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
)
},
icacontrollertypes.DefaultParams(),
},
}

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

suite.Run(fmt.Sprintf("case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate() // explicitly set params

migrator := icacontrollerkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper)
err := migrator.MigrateParams(suite.chainA.GetContext())
suite.Require().NoError(err)

params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(tc.expectedParams, params)
})
}
}
3 changes: 3 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ const (
// ParamsKey is the store key for the interchain accounts controller parameters
ParamsKey = "params"
)

// KeyControllerEnabled is the store key for ControllerEnabled Params for legacy purposes.
var KeyControllerEnabled = []byte("ControllerEnabled")

This file was deleted.

27 changes: 14 additions & 13 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
type Keeper struct {
appmodule.Environment

cdc codec.Codec
legacySubspace icatypes.ParamSubspace
cdc codec.Codec

ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
Expand All @@ -49,9 +48,12 @@ type Keeper struct {

// NewKeeper creates a new interchain accounts host Keeper instance
func NewKeeper(
cdc codec.Codec, env appmodule.Environment, legacySubspace icatypes.ParamSubspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
authKeeper icatypes.AuthKeeper, authority string,
cdc codec.Codec,
env appmodule.Environment,
ics4Wrapper porttypes.ICS4Wrapper,
channelKeeper icatypes.ChannelKeeper,
authKeeper icatypes.AuthKeeper,
authority string,
) Keeper {
// ensure ibc interchain accounts module account is set
if addr := authKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil {
Expand All @@ -63,14 +65,13 @@ func NewKeeper(
}

return Keeper{
Environment: env,
cdc: cdc,
legacySubspace: legacySubspace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
authKeeper: authKeeper,
mqsAllowList: newModuleQuerySafeAllowList(),
authority: authority,
Environment: env,
cdc: cdc,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
authKeeper: authKeeper,
mqsAllowList: newModuleQuerySafeAllowList(),
authority: authority,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().AuthKeeper,
Expand All @@ -156,7 +155,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
authkeeper.AccountKeeper{}, // empty account keeper
Expand All @@ -167,7 +165,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()),
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().AuthKeeper,
Expand Down
19 changes: 1 addition & 18 deletions modules/apps/27-interchain-accounts/host/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

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

// Migrator is a struct for handling in-place state migrations.
Expand All @@ -20,19 +16,6 @@ func NewMigrator(k *Keeper) Migrator {
}
}

// MigrateParams migrates the host submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx context.Context) error {
if m.keeper != nil {
params := types.DefaultParams()
if m.keeper.legacySubspace != nil {
// NOTE: legacy params still rely on sdk context
m.keeper.legacySubspace.GetParamSetIfExists(sdk.UnwrapSDKContext(ctx), &params)
}
if err := params.Validate(); err != nil {
return err
}
m.keeper.SetParams(ctx, params)
m.keeper.Logger.Info("successfully migrated ica/host submodule to self-manage params")
}
func (Migrator) MigrateParams(_ context.Context) error {
return nil
}
63 changes: 0 additions & 63 deletions modules/apps/27-interchain-accounts/host/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,64 +1 @@
package keeper_test

import (
"fmt"

"cosmossdk.io/log"
govtypes "cosmossdk.io/x/gov/types"

"github.com/cosmos/cosmos-sdk/runtime"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

icahostkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types"
)

func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
testCases := []struct {
msg string
malleate func()
expectedParams icahosttypes.Params
}{
{
"success: default params",
func() {
params := icahosttypes.DefaultParams()
subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
icahosttypes.DefaultParams(),
},
{
"success: no legacy params pre-migration",
func() {
suite.chainA.GetSimApp().ICAHostKeeper = icahostkeeper.NewKeeper(
suite.chainA.Codec,
runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)), log.NewNopLogger()),
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCFeeKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().AuthKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
},
icahosttypes.DefaultParams(),
},
}

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

suite.Run(fmt.Sprintf("case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate() // explicitly set params

migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper)
err := migrator.MigrateParams(suite.chainA.GetContext())
suite.Require().NoError(err)

params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(tc.expectedParams, params)
})
}
}
9 changes: 9 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ func ContainsMsgType(allowMsgs []string, msg sdk.Msg) bool {

return slices.Contains(allowMsgs, sdk.MsgTypeURL(msg))
}

var (
// KeyHostEnabled is the store key for HostEnabled Params for legacy purposes.
// Deprecated: this will be removed.
KeyHostEnabled = []byte("HostEnabled")
// KeyAllowMessages is the store key for the AllowMessages Params for legacy purposes.
// Deprecated: this will be removed.
KeyAllowMessages = []byte("AllowMessages")
)
Loading

0 comments on commit 9248319

Please sign in to comment.