diff --git a/modules/ibc-hooks/go.mod b/modules/ibc-hooks/go.mod index b2487916..1187ec1e 100644 --- a/modules/ibc-hooks/go.mod +++ b/modules/ibc-hooks/go.mod @@ -5,7 +5,6 @@ go 1.21 toolchain go1.21.0 require ( - cosmossdk.io/api v0.7.3 cosmossdk.io/client/v2 v2.0.0-beta.1 cosmossdk.io/core v0.11.0 cosmossdk.io/errors v1.0.1 @@ -34,6 +33,7 @@ require ( ) require ( + cosmossdk.io/api v0.7.3 // indirect cloud.google.com/go v0.110.10 // indirect cloud.google.com/go/compute v1.23.3 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect diff --git a/modules/ibc-hooks/simapp/ante.go b/modules/ibc-hooks/simapp/ante.go index 46f41a41..90626f0b 100644 --- a/modules/ibc-hooks/simapp/ante.go +++ b/modules/ibc-hooks/simapp/ante.go @@ -3,8 +3,8 @@ package simapp import ( "errors" - ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante" - "github.com/cosmos/ibc-go/v8/modules/core/keeper" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" corestoretypes "cosmossdk.io/core/store" circuitante "cosmossdk.io/x/circuit/ante" @@ -13,8 +13,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" + ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante" + "github.com/cosmos/ibc-go/v8/modules/core/keeper" ) // HandlerOptions extend the SDK's AnteHandler options by requiring the IBC diff --git a/modules/ibc-hooks/simapp/app.go b/modules/ibc-hooks/simapp/app.go index 3c006352..71d53aba 100644 --- a/modules/ibc-hooks/simapp/app.go +++ b/modules/ibc-hooks/simapp/app.go @@ -6,32 +6,28 @@ import ( "io" "os" "path/filepath" + "strings" + wasmd "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" - authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8" ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/keeper" - - consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" - "cosmossdk.io/api/tendermint/abci" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" - runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" - + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/circuit" + circuitkeeper "cosmossdk.io/x/circuit/keeper" + circuittypes "cosmossdk.io/x/circuit/types" "cosmossdk.io/x/evidence" - "cosmossdk.io/x/tx/signing" - dbm "github.com/cosmos/cosmos-db" - evidencekeeper "cosmossdk.io/x/evidence/keeper" evidencetypes "cosmossdk.io/x/evidence/types" "cosmossdk.io/x/feegrant" @@ -40,17 +36,21 @@ import ( "cosmossdk.io/x/nft" nftkeeper "cosmossdk.io/x/nft/keeper" nftmodule "cosmossdk.io/x/nft/module" + "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" @@ -61,7 +61,9 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -72,12 +74,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/ibc-go/modules/capability" - - capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" - - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" - "github.com/cosmos/cosmos-sdk/x/consensus" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" @@ -112,10 +108,12 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "cosmossdk.io/log" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/ibc-go/modules/capability" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" - icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" icahost "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" @@ -192,6 +190,7 @@ var ( authtypes.FeeCollectorName: nil, distrtypes.ModuleName: nil, ibcfeetypes.ModuleName: nil, + nft.ModuleName: nil, minttypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, @@ -233,7 +232,7 @@ type App struct { memKeys map[string]*storetypes.MemoryStoreKey // keepers - AuthKeeper authkeeper.AccountKeeper // TODO: Do we even need to store this state? + AccountKeeper authkeeper.AccountKeeper // TODO: Do we even need to store this state? AuthzKeeper authzkeeper.Keeper BankKeeper bankkeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper @@ -254,6 +253,7 @@ type App struct { GroupKeeper groupkeeper.Keeper WasmKeeper wasm.Keeper ConsensusParamsKeeper consensuskeeper.Keeper + CircuitKeeper circuitkeeper.Keeper IBCFeeKeeper ibcfeekeeper.Keeper ContractKeeper wasmtypes.ContractOpsKeeper @@ -264,6 +264,13 @@ type App struct { ModuleManager *module.Manager BasicModuleManager module.BasicManager + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper + ScopedWasmKeeper capabilitykeeper.ScopedKeeper + // sm is the simulation manager sm *module.SimulationManager configurator module.Configurator @@ -307,10 +314,10 @@ func NewSimApp( keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, + govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, consensustypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, ibcfeetypes.StoreKey, ibctransfertypes.StoreKey, - authzkeeper.StoreKey, capabilitytypes.StoreKey, + authzkeeper.StoreKey, capabilitytypes.StoreKey, nftkeeper.StoreKey, circuittypes.StoreKey, ) tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -342,17 +349,18 @@ func NewSimApp( } app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) + govModAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String() // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper( + app.ConsensusParamsKeeper = consensuskeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), + runtime.NewKVStoreService(keys[consensustypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{}, ) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) - app.AuthKeeper = authkeeper.NewAccountKeeper( + app.AccountKeeper = authkeeper.NewAccountKeeper( appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, @@ -364,25 +372,40 @@ func NewSimApp( app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, runtime.NewKVStoreService(keys[banktypes.StoreKey]), - app.AuthKeeper, + app.AccountKeeper, app.ModuleAccountAddrs(), authority, logger, ) + app.CircuitKeeper = circuitkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[circuittypes.StoreKey]), + govModAddress, + app.AccountKeeper.AddressCodec(), + ) + app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) + app.keys[authzkeeper.StoreKey] = storetypes.NewKVStoreKey(authzkeeper.StoreKey) app.AuthzKeeper = authzkeeper.NewKeeper( - app.keys[authzkeeper.StoreKey], - cdc, + runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), + appCodec, app.MsgServiceRouter(), - app.AuthKeeper, + app.AccountKeeper, ) - modules = append(modules, authzmodule.NewAppModule(cdc, app.AuthzKeeper, app.AuthKeeper, app.BankKeeper, interfaceRegistry)) - simModules = append(simModules, authzmodule.NewAppModule(cdc, app.AuthzKeeper, app.AuthKeeper, app.BankKeeper, interfaceRegistry)) + + simModules := make([]module.AppModuleSimulation, 0) + + simModules = append(simModules, authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry)) // add capability keeper and ScopeToModule for ibc module app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) + scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName) + // seal capability keeper after scoping modules app.CapabilityKeeper.Seal() @@ -393,13 +416,13 @@ func NewSimApp( app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), - app.AuthKeeper.AddressCodec(), + app.AccountKeeper.AddressCodec(), ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), - app.AuthKeeper, + app.AccountKeeper, ) // 'group' module - depends on @@ -408,18 +431,17 @@ func NewSimApp( app.keys[group.StoreKey] = storetypes.NewKVStoreKey(group.StoreKey) app.GroupKeeper = groupkeeper.NewKeeper( app.keys[group.StoreKey], - cdc, + appCodec, app.MsgServiceRouter(), - app.AuthKeeper, + app.AccountKeeper, group.DefaultConfig(), ) - modules = append(modules, groupmodule.NewAppModule(cdc, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, interfaceRegistry)) - simModules = append(simModules, groupmodule.NewAppModule(cdc, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, interfaceRegistry)) + simModules = append(simModules, groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry)) app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), - app.AuthKeeper, + app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), @@ -440,7 +462,7 @@ func NewSimApp( authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - app.NFTKeeper = nftkeeper.NewKeeper( + app.NftKeeper = nftkeeper.NewKeeper( runtime.NewKVStoreService(keys[nftkeeper.StoreKey]), appCodec, app.AccountKeeper, @@ -448,39 +470,42 @@ func NewSimApp( ) app.SlashingKeeper = slashingkeeper.NewKeeper( - cdc, - encodingConfig.Amino, - app.keys[slashingtypes.StoreKey], + appCodec, + legacyAmino, + runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + app.GovKeeper = *govkeeper.NewKeeper( - cdc, - app.keys[govtypes.StoreKey], - app.AuthKeeper, - app.BankKeeper, - app.StakingKeeper, - app.MsgServiceRouter(), - govtypes.DefaultConfig(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, // Codec + runtime.NewKVStoreService(keys[govtypes.StoreKey]), // KVStoreService + app.AccountKeeper, // AccountKeeper + app.BankKeeper, // BankKeeper + app.StakingKeeper, // StakingKeeper + app.DistrKeeper, // DistributionKeeper, assuming you have this + app.MsgServiceRouter(), // MessageRouter + govtypes.DefaultConfig(), // Config + authtypes.NewModuleAddress(govtypes.ModuleName).String(), // the address ) + // Set legacy router for backwards compatibility with gov v1beta1 govLegacyRouter := govv1beta1.NewRouter() defer app.GovKeeper.SetLegacyRouter(govLegacyRouter) govLegacyRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler) app.DistrKeeper = distrkeeper.NewKeeper( - cdc, - app.keys[distrtypes.StoreKey], - app.AuthKeeper, + appCodec, + runtime.NewKVStoreService(keys[distrtypes.StoreKey]), + app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + govModAddress, ) app.ParamsKeeper = paramskeeper.NewKeeper( - cdc, + appCodec, legacyAmino, app.keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey], @@ -490,25 +515,27 @@ func NewSimApp( // 'evidence' module - depends on // 1. 'staking' // 2. 'slashing' - app.EvidenceKeeper = *evidencekeeper.NewKeeper( - cdc, - app.keys[evidencetypes.StoreKey], + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), app.StakingKeeper, app.SlashingKeeper, + app.AccountKeeper.AddressCodec(), + runtime.ProvideCometInfoService(), ) - + // If evidence needs to be handled for the app, set routes in router here and seal + app.EvidenceKeeper = *evidenceKeeper // 'upgrade' module - depends on // 1. 'gov' app.keys[upgradetypes.StoreKey] = storetypes.NewKVStoreKey(upgradetypes.StoreKey) app.UpgradeKeeper = upgradekeeper.NewKeeper( - skipUpgradeHeights, // TODO: What is this? - app.keys[upgradetypes.StoreKey], - cdc, + skipUpgradeHeights, + runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), + appCodec, homePath, - app, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + app.BaseApp, + govModAddress, ) - govLegacyRouter.AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) // 'ibc' module - depends on // 1. 'staking' @@ -518,15 +545,16 @@ func NewSimApp( // 5. 'params' app.keys[ibcexported.StoreKey] = storetypes.NewKVStoreKey(ibcexported.StoreKey) app.IBCKeeper = ibckeeper.NewKeeper( - cdc, - app.keys[ibcexported.StoreKey], - app.ParamsKeeper.Subspace(ibcexported.ModuleName), + appCodec, + keys[ibcexported.StoreKey], + app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, - app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName), + scopedIBCKeeper, + govModAddress, ) + govLegacyRouter.AddRoute(ibcexported.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) - modules = append(modules, ibc.NewAppModule(app.IBCKeeper)) simModules = append(simModules, ibc.NewAppModule(app.IBCKeeper)) // 'ibcfeekeeper' module - depends on @@ -534,21 +562,21 @@ func NewSimApp( // 2. 'auth' // 3. 'ibc channel' // 4. 'ibc port' - app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - app.cdc, - app.keys[ibcfeetypes.StoreKey], - app.IBCKeeper.ChannelKeeper, - app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.AuthKeeper, - app.BankKeeper, + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, + keys[ibcexported.StoreKey], + app.GetSubspace(ibcexported.ModuleName), + app.StakingKeeper, + app.UpgradeKeeper, + scopedIBCKeeper, + govModAddress, ) + app.keys[ibcporttypes.StoreKey] = storetypes.NewKVStoreKey(ibcporttypes.StoreKey) - app.AuthKeeper.GetModulePermissions()[ibctransfertypes.ModuleName] = authtypes.NewPermissionsForAddress(ibcfeetypes.ModuleName, nil) + app.AccountKeeper.GetModulePermissions()[ibctransfertypes.ModuleName] = authtypes.NewPermissionsForAddress(ibcfeetypes.ModuleName, nil) icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) icaHostStack := ibcfee.NewIBCMiddleware(icaHostIBCModule, app.IBCFeeKeeper) - modules = append(modules, ibcfee.NewAppModule(app.IBCFeeKeeper)) simModules = append(simModules, ibcfee.NewAppModule(app.IBCFeeKeeper)) // Create fee enabled wasm ibc Stack @@ -579,89 +607,98 @@ func NewSimApp( // 2. 'auth' // 3. 'bank' // 4. 'capability' - app.AuthKeeper.GetModulePermissions()[ibctransfertypes.ModuleName] = authtypes.NewPermissionsForAddress(ibctransfertypes.ModuleName, []string{authtypes.Minter, authtypes.Burner}) + app.AccountKeeper.GetModulePermissions()[ibctransfertypes.ModuleName] = authtypes.NewPermissionsForAddress(ibctransfertypes.ModuleName, []string{authtypes.Minter, authtypes.Burner}) app.BankKeeper.GetBlockedAddresses()[authtypes.NewModuleAddress(ibctransfertypes.ModuleName).String()] = true app.keys[ibctransfertypes.StoreKey] = storetypes.NewKVStoreKey(ibctransfertypes.StoreKey) app.TransferKeeper = ibctransferkeeper.NewKeeper( - cdc, + appCodec, app.keys[ibctransfertypes.StoreKey], app.ParamsKeeper.Subspace(ibctransfertypes.ModuleName), hooksICS4Wrapper, app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.AuthKeeper, + app.IBCKeeper.PortKeeper, + app.AccountKeeper, app.BankKeeper, - app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName), + scopedTransferKeeper, + govModAddress, ) - modules = append(modules, ibctransfer.NewAppModule(app.TransferKeeper)) simModules = append(simModules, ibctransfer.NewAppModule(app.TransferKeeper)) // 'ica' - app.AuthKeeper.GetModulePermissions()[icatypes.ModuleName] = authtypes.NewPermissionsForAddress(icatypes.ModuleName, nil) + app.AccountKeeper.GetModulePermissions()[icatypes.ModuleName] = authtypes.NewPermissionsForAddress(icatypes.ModuleName, nil) app.BankKeeper.GetBlockedAddresses()[authtypes.NewModuleAddress(icatypes.ModuleName).String()] = true // 'icacontroller' module - depends on // 1. 'ibc' // 2. 'capability' app.keys[icacontrollertypes.StoreKey] = storetypes.NewKVStoreKey(icacontrollertypes.StoreKey) - icaControllerKeeper := icacontrollerkeeper.NewKeeper( - cdc, - app.keys[icacontrollertypes.StoreKey], - app.ParamsKeeper.Subspace(icacontrollertypes.SubModuleName), - app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + keys[ibctransfertypes.StoreKey], + app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName), - app.MsgServiceRouter(), + app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + scopedTransferKeeper, + govModAddress, ) app.keys[icahosttypes.StoreKey] = storetypes.NewKVStoreKey(icahosttypes.StoreKey) app.ICAHostKeeper = icahostkeeper.NewKeeper( - cdc, - app.keys[icahosttypes.StoreKey], - app.ParamsKeeper.Subspace(icahosttypes.SubModuleName), - app.IBCKeeper.ChannelKeeper, + appCodec, + keys[icahosttypes.StoreKey], + app.GetSubspace(icahosttypes.SubModuleName), + app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.AuthKeeper, - app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName), + app.IBCKeeper.PortKeeper, + app.AccountKeeper, + scopedICAHostKeeper, app.MsgServiceRouter(), + govModAddress, ) - app.AuthKeeper.GetModulePermissions()[wasmtypes.ModuleName] = authtypes.NewPermissionsForAddress(wasmtypes.ModuleName, []string{authtypes.Burner}) + app.AccountKeeper.GetModulePermissions()[wasmtypes.ModuleName] = authtypes.NewPermissionsForAddress(wasmtypes.ModuleName, []string{authtypes.Burner}) app.BankKeeper.GetBlockedAddresses()[authtypes.NewModuleAddress(wasmtypes.ModuleName).String()] = true app.keys[wasmtypes.StoreKey] = storetypes.NewKVStoreKey(wasmtypes.StoreKey) + + // availableCapabilities := strings.Join(AllCapabilities(), ",") + wasmDir := filepath.Join(homePath, "wasm") wasmConfig, err := wasm.ReadWasmConfig(appOpts) if err != nil { panic(fmt.Sprintf("error while reading wasm config: %s", err)) } - app.WasmKeeper = wasm.NewKeeper( - cdc, - app.keys[wasmtypes.StoreKey], - app.AuthKeeper, + + // The last arguments can contain custom message handlers, and custom query handlers, + // if we want to allow any custom callbacks + // availableCapabilities := strings.Join(AllCapabilities(), ",") + app.WasmKeeper = wasmkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), + app.AccountKeeper, app.BankKeeper, app.StakingKeeper, distrkeeper.NewQuerier(app.DistrKeeper), + app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, - &app.IBCKeeper.PortKeeper, - app.CapabilityKeeper.ScopeToModule(wasm.ModuleName), + app.IBCKeeper.PortKeeper, + scopedWasmKeeper, app.TransferKeeper, app.MsgServiceRouter(), app.GRPCQueryRouter(), - filepath.Join(homePath, "wasm"), + wasmDir, wasmConfig, - "iterator,staking,stargate,token_factory,cosmwasm_1_1", - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - GetWasmOpts(app, appOpts)..., + strings.Join(wasmd.AllCapabilities(), ","), + govModAddress, ) - govLegacyRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, wasm.EnableAllProposals)) app.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&app.WasmKeeper) /**** Module Options ****/ // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. - + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) app.ModuleManager = module.NewManager( // SDK app modules genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app, txConfig), @@ -682,9 +719,12 @@ func NewSimApp( params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), + circuit.NewAppModule(appCodec, app.CircuitKeeper), + wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), // IBC modules ibc.NewAppModule(app.IBCKeeper), + ibctransfer.NewAppModule(app.TransferKeeper), ibctm.NewAppModule(), ibcfee.NewAppModule(app.IBCFeeKeeper), ) @@ -736,7 +776,7 @@ func NewSimApp( vestingtypes.ModuleName, nft.ModuleName, ibchookstypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, // this line is used by starport scaffolding # stargate/app/beginBlockers ) @@ -765,7 +805,7 @@ func NewSimApp( nft.ModuleName, ibcfeetypes.ModuleName, ibchookstypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, // this line is used by starport scaffolding # stargate/app/endBlockers ) @@ -782,6 +822,7 @@ func NewSimApp( stakingtypes.ModuleName, slashingtypes.ModuleName, consensustypes.ModuleName, + circuittypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, @@ -799,19 +840,21 @@ func NewSimApp( nft.ModuleName, ibcfeetypes.ModuleName, ibchookstypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis ) // Uncomment if you want to set a custom migration order here. // app.mm.SetOrderMigrations(custom order) - app.configurator = module.NewConfigurator(cdc, app.MsgServiceRouter(), app.GRPCQueryRouter()) - app.ModuleManager.RegisterServices(app.configurator) + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + if err := app.ModuleManager.RegisterServices(app.configurator); err != nil { + panic(fmt.Errorf("failed to register module services: %w", err)) + } app.MountKVStores(app.keys) app.MountTransientStores(tkeys) - app.MountMemoryStores(memkeys) + app.MountMemoryStores(memKeys) // create the simulation manager and define the order of the modules for deterministic simulations app.sm = module.NewSimulationManager(simModules...) @@ -820,27 +863,7 @@ func NewSimApp( // initialize BaseApp app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) - - anteHandler, err := NewAnteHandler( - HandlerOptions{ - HandlerOptions: ante.HandlerOptions{ - AccountKeeper: app.AuthKeeper, - BankKeeper: app.BankKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - IBCKeeper: app.IBCKeeper, - TxCounterStoreKey: app.keys[wasmtypes.StoreKey], - WasmConfig: wasmConfig, - Cdc: cdc, - }, - ) - if err != nil { - panic(fmt.Errorf("failed to create AnteHandler: %s", err)) - } - - app.SetAnteHandler(anteHandler) + app.setAnteHandler(txConfig, wasmConfig, keys[wasmtypes.StoreKey]) app.SetEndBlocker(app.EndBlocker) if loadLatest { @@ -985,7 +1008,7 @@ func (app *App) AutoCliOpts() autocli.AppOptions { return autocli.AppOptions{ Modules: modules, - ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules), + ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules), AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), @@ -1025,6 +1048,11 @@ func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey { return app.keys[storeKey] } +func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + // BlockedAddresses returns all the app's blocked account addresses. func BlockedAddresses() map[string]bool { modAccAddrs := make(map[string]bool) @@ -1038,6 +1066,29 @@ func BlockedAddresses() map[string]bool { return modAccAddrs } +func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.WasmConfig, txCounterStoreKey *storetypes.KVStoreKey) { + anteHandler, err := NewAnteHandler( + HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + SignModeHandler: txConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + IBCKeeper: app.IBCKeeper, + WasmConfig: &wasmConfig, + WasmKeeper: &app.WasmKeeper, + TXCounterStoreService: runtime.NewKVStoreService(txCounterStoreKey), + CircuitKeeper: &app.CircuitKeeper, + }, + ) + if err != nil { + panic(fmt.Errorf("failed to create AnteHandler: %s", err)) + } + app.SetAnteHandler(anteHandler) +} + // GetMaccPerms returns a copy of the module account permissions // // NOTE: This is solely to be used for testing purposes. diff --git a/modules/ibc-hooks/simapp/export.go b/modules/ibc-hooks/simapp/export.go index 26e242c2..8d14d6f1 100644 --- a/modules/ibc-hooks/simapp/export.go +++ b/modules/ibc-hooks/simapp/export.go @@ -6,12 +6,14 @@ import ( "log" storetypes "cosmossdk.io/store/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis diff --git a/modules/ibc-hooks/simapp/simulation_test.go b/modules/ibc-hooks/simapp/simulation_test.go index 01bc7615..dcae8f86 100644 --- a/modules/ibc-hooks/simapp/simulation_test.go +++ b/modules/ibc-hooks/simapp/simulation_test.go @@ -4,9 +4,9 @@ import ( "os" "testing" + dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" - dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -56,8 +56,9 @@ func TestFullAppSimulation(t *testing.T) { } func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *App) { + t.Helper() config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID + config.ChainID = simulationAppChainID db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if skip { @@ -74,7 +75,7 @@ func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simt appOptions[flags.FlagHome] = dir // ensure a unique folder appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - app := NewSimApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) + app := NewSimApp(logger, db, nil, true, appOptions, baseapp.SetChainID(simulationAppChainID)) require.Equal(t, "SimApp", app.Name()) return config, db, appOptions, app } diff --git a/modules/ibc-hooks/simapp/test_helpers.go b/modules/ibc-hooks/simapp/test_helpers.go index b0fdf018..f7d8c7d4 100644 --- a/modules/ibc-hooks/simapp/test_helpers.go +++ b/modules/ibc-hooks/simapp/test_helpers.go @@ -9,17 +9,13 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" - cmtjson "github.com/cometbft/cometbft/libs/json" - cmttypes "github.com/cometbft/cometbft/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" pruningtypes "cosmossdk.io/store/pruning/types" - "cosmossdk.io/store/snapshots" - snapshottypes "cosmossdk.io/store/snapshots/types" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -42,7 +38,9 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + abci "github.com/cometbft/cometbft/abci/types" + cmtjson "github.com/cometbft/cometbft/libs/json" + cmttypes "github.com/cometbft/cometbft/types" ) // SetupOptions defines arguments that are passed into `App` constructor. @@ -53,21 +51,21 @@ type SetupOptions struct { WasmOpts []wasmkeeper.Option } -func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*App, GenesisState) { +func setup(tb testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*App, GenesisState) { + tb.Helper() db := dbm.NewMemDB() - nodeHome := t.TempDir() + nodeHome := tb.TempDir() snapshotDir := filepath.Join(nodeHome, "data", "snapshots") snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir) - require.NoError(t, err) - t.Cleanup(func() { snapshotDB.Close() }) - snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - require.NoError(t, err) + require.NoError(tb, err) + tb.Cleanup(func() { snapshotDB.Close() }) + require.NoError(tb, err) appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = nodeHome // ensure unique folder appOptions[server.FlagInvCheckPeriod] = invCheckPeriod - app := NewApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2})) + app := NewSimApp(log.NewNopLogger(), db, nil, true, appOptions, bam.SetChainID(chainID)) if withGenesis { return app, app.DefaultGenesis() } @@ -93,7 +91,7 @@ func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), } - app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts) + app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts, bam.SetChainID("testing")) genesisState := app.DefaultGenesis() genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) @@ -117,7 +115,7 @@ func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) } // Setup initializes a new App. A Nop logger is set in App. -func Setup(t *testing.T, opts ...wasmkeeper.Option) *App { +func Setup(t *testing.T, opts ...wasmkeeper.Option) (*App, sdk.Context, *authtypes.BaseAccount) { t.Helper() privVal := mock.NewPV() @@ -136,9 +134,13 @@ func Setup(t *testing.T, opts ...wasmkeeper.Option) *App { Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), } chainID := "testing" + app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, chainID, opts, balance) - return app + ctx := app.BaseApp.NewContext(false) + ctx = ctx.WithBlockTime(time.Now()) + + return app, ctx, acc } // SetupWithGenesisValSet initializes a new App with a validator set and genesis accounts @@ -186,8 +188,9 @@ func SetupWithGenesisValSet( } // SetupWithEmptyStore set up a wasmd app instance with empty DB -func SetupWithEmptyStore(t testing.TB) *App { - app, _ := setup(t, "testing", false, 0) +func SetupWithEmptyStore(tb testing.TB) *App { + tb.Helper() + app, _ := setup(tb, "testing", false, 0) return app } @@ -255,8 +258,6 @@ func initAccountWithCoins(app *App, ctx sdk.Context, addr sdk.AccAddress, coins } } -var emptyWasmOptions []wasmkeeper.Option - // NewTestNetworkFixture returns a new App AppConstructor for network simulation tests func NewTestNetworkFixture() network.TestFixture { dir, err := os.MkdirTemp("", "simapp") @@ -265,12 +266,11 @@ func NewTestNetworkFixture() network.TestFixture { } defer os.RemoveAll(dir) - app := NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions) + app := NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), bam.SetChainID("test")) appCtr := func(val network.ValidatorI) servertypes.Application { return NewSimApp( val.GetCtx().Logger, dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), - emptyWasmOptions, bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), @@ -291,6 +291,7 @@ func NewTestNetworkFixture() network.TestFixture { // SignAndDeliverWithoutCommit signs and delivers a transaction. No commit func SignAndDeliverWithoutCommit(t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins, chainID string, accNums, accSeqs []uint64, blockTime time.Time, priv ...cryptotypes.PrivKey) (*abci.ResponseFinalizeBlock, error) { + t.Helper() tx, err := simtestutil.GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, diff --git a/modules/ibc-hooks/tests/unit/module_test.go b/modules/ibc-hooks/tests/unit/module_test.go index e8078e93..82b7648a 100644 --- a/modules/ibc-hooks/tests/unit/module_test.go +++ b/modules/ibc-hooks/tests/unit/module_test.go @@ -15,8 +15,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" @@ -46,7 +46,7 @@ func TestIBCHooksTestSuite(t *testing.T) { func (suite *HooksTestSuite) SetupEnv() { // Setup the environment - app := simapp.Setup(suite.T()) + app, ctx, acc := simapp.Setup(suite.T()) // create the echo contract contractID, _, err := app.ContractKeeper.Create(ctx, acc.GetAddress(), counterWasm, nil)