Skip to content

Commit

Permalink
feat: adding runtime Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Nov 21, 2024
1 parent 6ca4a43 commit 346d83d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
12 changes: 4 additions & 8 deletions modules/apps/27-interchain-accounts/controller/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strings"

"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -52,6 +55,7 @@ func NewKeeper(
}

return Keeper{
Environment: env,
storeService: storeService,
cdc: cdc,
legacySubspace: legacySubspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 346d83d

Please sign in to comment.