From 346d83d2e5d9ee00e51cfc30e7f6b686edd29217 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 21 Nov 2024 18:13:01 +0100 Subject: [PATCH] feat: adding runtime Environment --- .../controller/keeper/account.go | 12 ++++------- .../controller/keeper/keeper.go | 6 +++++- .../controller/keeper/keeper_test.go | 3 +++ .../controller/keeper/migrations_test.go | 3 +++ modules/apps/callbacks/testing/simapp/app.go | 6 ++++-- .../08-wasm/testing/simapp/app.go | 21 +++++++++++-------- simapp/app.go | 4 +++- testing/simapp/app.go | 4 +++- 8 files changed, 37 insertions(+), 22 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index b49662ad049..9ee8392c086 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" @@ -65,19 +64,16 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por k.setPort(ctx, portID) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) - handler := k.msgRouter.Handler(msg) - res, err := handler(sdkCtx, msg) + res, err := k.Environment.MsgRouterService.Invoke(ctx, msg) if err != nil { return "", err } - firstMsgResponse := res.MsgResponses[0] - channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse) + chanOpenInitResp, ok := res.(*channeltypes.MsgChannelOpenInitResponse) if !ok { - return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to convert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{}) + return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to convert %T message response to %T", res, &channeltypes.MsgChannelOpenInitResponse{}) } - return channelOpenInitResponse.ChannelId, nil + return chanOpenInitResp.ChannelId, nil } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index b118915bf87..1ac8f2a8243 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "fmt" "strings" + "cosmossdk.io/core/appmodule" corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" @@ -28,6 +29,8 @@ import ( // Keeper defines the IBC interchain accounts controller keeper type Keeper struct { + appmodule.Environment + storeService corestore.KVStoreService cdc codec.Codec legacySubspace icatypes.ParamSubspace @@ -43,7 +46,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts controller Keeper instance func NewKeeper( - cdc codec.Codec, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace, + cdc codec.Codec, env appmodule.Environment, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, msgRouter icatypes.MessageRouter, authority string, ) Keeper { @@ -52,6 +55,7 @@ func NewKeeper( } return Keeper{ + Environment: env, storeService: storeService, cdc: cdc, legacySubspace: legacySubspace, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index 754f7c84198..dd2a77c8b58 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -5,6 +5,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" + "cosmossdk.io/log" govtypes "cosmossdk.io/x/gov/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -119,6 +120,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"success", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), + runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -130,6 +132,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: empty authority", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), + runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go index 0a9da175f92..a69caa9229f 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go @@ -3,9 +3,11 @@ 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" + "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" ) @@ -29,6 +31,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { func() { suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper( suite.chainA.Codec, + runtime.NewEnvironment(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), log.NewNopLogger()), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)), nil, // assign a nil legacy param subspace suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 4f73b8a0aba..a409b6695e2 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -433,11 +433,13 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, + runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())), + runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.MsgServiceRouter(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + govModuleAddr, ) // ICA Host keeper diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index a17fdbb96d9..5debc2de103 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -1,6 +1,14 @@ package simapp import ( + "encoding/json" + "fmt" + "io" + "math/rand" + "os" + "path/filepath" + "strconv" + coreaddress "cosmossdk.io/core/address" "cosmossdk.io/x/accounts/accountstd" baseaccount "cosmossdk.io/x/accounts/defaults/base" @@ -9,17 +17,10 @@ import ( epochstypes "cosmossdk.io/x/epochs/types" nftkeeper "cosmossdk.io/x/nft/keeper" txdecode "cosmossdk.io/x/tx/decode" - "encoding/json" - "fmt" cmtcrypto "github.com/cometbft/cometbft/crypto" cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - "io" - "math/rand" - "os" - "path/filepath" - "strconv" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cast" @@ -559,11 +560,13 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, + runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())), + runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.MsgServiceRouter(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + govModuleAddr, ) // ICA Host keeper diff --git a/simapp/app.go b/simapp/app.go index 00a1148747c..d7834f23870 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -539,7 +539,9 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, + runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())), + runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.MsgServiceRouter(), diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 53c0d583b70..5476d9476c5 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -515,7 +515,9 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, + runtime.NewEnvironment(runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), logger.With(log.ModuleKey, "x/icacontroller"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter())), + runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.MsgServiceRouter(),