From 83a62da21ba19fd6ae75a9e62b77ed2c754380a2 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Wed, 6 Mar 2024 12:17:16 +0200 Subject: [PATCH] continue updating wasm hooks --- modules/ibc-hooks/go.mod | 3 +- modules/ibc-hooks/hooks.go | 2 +- modules/ibc-hooks/ibc_module.go | 2 +- modules/ibc-hooks/ics4_middleware.go | 2 +- modules/ibc-hooks/keeper/keeper.go | 4 +- modules/ibc-hooks/simapp/ante.go | 55 ++-- modules/ibc-hooks/simapp/app.go | 33 +- modules/ibc-hooks/simapp/export.go | 142 +++++--- modules/ibc-hooks/simapp/simulation_test.go | 70 ++-- modules/ibc-hooks/simapp/test_helpers.go | 340 ++++++++------------ modules/ibc-hooks/wasm_hook.go | 4 +- 11 files changed, 327 insertions(+), 330 deletions(-) diff --git a/modules/ibc-hooks/go.mod b/modules/ibc-hooks/go.mod index 1561c40e..b2487916 100644 --- a/modules/ibc-hooks/go.mod +++ b/modules/ibc-hooks/go.mod @@ -12,6 +12,7 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.2.0 cosmossdk.io/store v1.0.2 + cosmossdk.io/x/circuit v0.1.0 cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.1.0 cosmossdk.io/x/nft v0.1.0 @@ -19,7 +20,6 @@ require ( cosmossdk.io/x/upgrade v0.1.0 github.com/CosmWasm/wasmd v0.50.0 github.com/cometbft/cometbft v0.38.5 - github.com/cometbft/cometbft-db v0.11.0 github.com/cosmos/cosmos-db v1.0.0 github.com/cosmos/cosmos-sdk v0.50.4 github.com/cosmos/gogoproto v1.4.11 @@ -63,6 +63,7 @@ require ( github.com/cockroachdb/pebble v1.1.0 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft-db v0.11.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect diff --git a/modules/ibc-hooks/hooks.go b/modules/ibc-hooks/hooks.go index 4b07f97d..d6b2339c 100644 --- a/modules/ibc-hooks/hooks.go +++ b/modules/ibc-hooks/hooks.go @@ -3,8 +3,8 @@ package ibc_hooks import ( // external libraries sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // ibc-go channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" diff --git a/modules/ibc-hooks/ibc_module.go b/modules/ibc-hooks/ibc_module.go index 95174077..1e9d8cc8 100644 --- a/modules/ibc-hooks/ibc_module.go +++ b/modules/ibc-hooks/ibc_module.go @@ -3,8 +3,8 @@ package ibc_hooks import ( // external libraries sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // ibc-go channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" diff --git a/modules/ibc-hooks/ics4_middleware.go b/modules/ibc-hooks/ics4_middleware.go index e34016f6..8485f8ef 100644 --- a/modules/ibc-hooks/ics4_middleware.go +++ b/modules/ibc-hooks/ics4_middleware.go @@ -3,8 +3,8 @@ package ibc_hooks import ( // external libraries sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // ibc-go porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" diff --git a/modules/ibc-hooks/keeper/keeper.go b/modules/ibc-hooks/keeper/keeper.go index d4630b3d..f86d5577 100644 --- a/modules/ibc-hooks/keeper/keeper.go +++ b/modules/ibc-hooks/keeper/keeper.go @@ -5,11 +5,11 @@ import ( "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - - "github.com/cometbft/cometbft/libs/log" ) type ( diff --git a/modules/ibc-hooks/simapp/ante.go b/modules/ibc-hooks/simapp/ante.go index 300cfa9a..46f41a41 100644 --- a/modules/ibc-hooks/simapp/ante.go +++ b/modules/ibc-hooks/simapp/ante.go @@ -1,52 +1,61 @@ package simapp import ( - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" + "errors" + + ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante" + "github.com/cosmos/ibc-go/v8/modules/core/keeper" - errors "cosmossdk.io/errors" + corestoretypes "cosmossdk.io/core/store" + circuitante "cosmossdk.io/x/circuit/ante" + circuitkeeper "cosmossdk.io/x/circuit/keeper" - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" - ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante" - ibckeeper "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" ) -// HandlerOptions extends the SDK's AnteHandler options by requiring the IBC +// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC // channel keeper. type HandlerOptions struct { ante.HandlerOptions - IBCKeeper *ibckeeper.Keeper - TxCounterStoreKey storetypes.StoreKey - WasmConfig wasmTypes.WasmConfig - Cdc codec.BinaryCodec + IBCKeeper *keeper.Keeper + WasmConfig *wasmTypes.WasmConfig + WasmKeeper *wasmkeeper.Keeper + TXCounterStoreService corestoretypes.KVStoreService + CircuitKeeper *circuitkeeper.Keeper } -// NewAnteHandler returns an AnteHandler that checks and increments sequence -// numbers, checks signatures & account numbers, and deducts fees from the first -// signer. +// NewAnteHandler constructor func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, errors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") + return nil, errors.New("account keeper is required for ante builder") } - if options.BankKeeper == nil { - return nil, errors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") + return nil, errors.New("bank keeper is required for ante builder") } - if options.SignModeHandler == nil { - return nil, errors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, errors.New("sign mode handler is required for ante builder") + } + if options.WasmConfig == nil { + return nil, errors.New("wasm config is required for ante builder") + } + if options.TXCounterStoreService == nil { + return nil, errors.New("wasm store service is required for ante builder") + } + if options.CircuitKeeper == nil { + return nil, errors.New("circuit keeper is required for ante builder") } anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first - wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), - wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), + wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early + wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService), + wasmkeeper.NewGasRegisterDecorator(options.WasmKeeper.GetGasRegister()), + circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), diff --git a/modules/ibc-hooks/simapp/app.go b/modules/ibc-hooks/simapp/app.go index 02f71cb0..4d1be785 100644 --- a/modules/ibc-hooks/simapp/app.go +++ b/modules/ibc-hooks/simapp/app.go @@ -25,7 +25,6 @@ import ( "cosmossdk.io/api/tendermint/abci" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" - "cosmossdk.io/log" runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" storetypes "cosmossdk.io/store/types" @@ -432,21 +431,22 @@ func NewSimApp( // 2. 'auth' // 3. 'bank' app.MintKeeper = mintkeeper.NewKeeper( - cdc, - app.keys[minttypes.StoreKey], + appCodec, + runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, - app.AuthKeeper, + app.AccountKeeper, app.BankKeeper, - authtypes.FeeCollectorName, // TODO: Find out what this is + authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - app.NftKeeper = nftkeeper.NewKeeper( - app.keys[nftkeeper.StoreKey], - cdc, - app.AuthKeeper, + app.NFTKeeper = nftkeeper.NewKeeper( + runtime.NewKVStoreService(keys[nftkeeper.StoreKey]), + appCodec, + app.AccountKeeper, app.BankKeeper, ) + app.SlashingKeeper = slashingkeeper.NewKeeper( cdc, encodingConfig.Amino, @@ -882,12 +882,12 @@ func (app *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci. if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } - - if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil { + err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + if err != nil { panic(err) } - - return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState) + response, err := app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState) + return response, err } // LoadHeight loads a particular height @@ -1017,3 +1017,10 @@ func (app *App) ModuleAccountAddrs() map[string]bool { return modAccAddrs } + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey { + return app.keys[storeKey] +} diff --git a/modules/ibc-hooks/simapp/export.go b/modules/ibc-hooks/simapp/export.go index 8b1ecea1..26e242c2 100644 --- a/modules/ibc-hooks/simapp/export.go +++ b/modules/ibc-hooks/simapp/export.go @@ -2,54 +2,55 @@ package simapp import ( "encoding/json" + "fmt" "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" - - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis // file. -func (app *App) ExportAppStateAndValidators( - forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string, -) (servertypes.ExportedApp, error) { +func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block - ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) // We export at last height + 1, because that's the height at which - // Tendermint will start InitChain. + // CometBFT will start InitChain. height := app.LastBlockHeight() + 1 if forZeroHeight { height = 0 app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } - genState := app.ModuleManager.ExportGenesisForModules(ctx, app.cdc, modulesToExport) - appState, err := json.MarshalIndent(genState, "", " ") + genState, err := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) if err != nil { return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + appState, err := json.MarshalIndent(genState, "", " ") if err != nil { return servertypes.ExportedApp{}, err } + + validators, err := staking.WriteValidators(ctx, app.StakingKeeper) return servertypes.ExportedApp{ AppState: appState, Validators: validators, Height: height, ConsensusParams: app.BaseApp.GetConsensusParams(ctx), - }, nil + }, err } // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// in favour of export at a block height +// +// in favor of export at a block height func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false @@ -74,21 +75,35 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str /* Handle fee distribution state. */ // withdraw all validator commission - app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) if err != nil { panic(err) } + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) return false }) + if err != nil { + panic(err) + } // withdraw all delegator rewards - dels := app.StakingKeeper.GetAllDelegations(ctx) + dels, err := app.StakingKeeper.GetAllDelegations(ctx) + if err != nil { + panic(err) + } + for _, delegation := range dels { - _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr()) + valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) if err != nil { panic(err) } + + delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + + if _, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr); err != nil { + panic(err) + } } // clear validator slash events @@ -102,29 +117,50 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str ctx = ctx.WithBlockHeight(0) // reinitialize all validators - app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + panic(err) + } // donate any unwithdrawn outstanding reward fraction tokens to the community pool - scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) - feePool := app.DistrKeeper.GetFeePool(ctx) + scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz) + if err != nil { + panic(err) + } + feePool, err := app.DistrKeeper.FeePool.Get(ctx) + if err != nil { + panic(err) + } feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) - app.DistrKeeper.SetFeePool(ctx, feePool) + if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil { + panic(err) + } - err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) - if err != nil { + if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil { panic(err) } return false }) + if err != nil { + panic(err) + } // reinitialize all delegations for _, del := range dels { - err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) if err != nil { panic(err) } - err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) - if err != nil { - panic(err) + delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress) + + if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil { + // never called as BeforeDelegationCreated always returns nil + panic(fmt.Errorf("error while incrementing period: %w", err)) + } + + if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil { + // never called as AfterDelegationModified always returns nil + panic(fmt.Errorf("error while creating a new delegation period record: %w", err)) } } @@ -134,33 +170,44 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str /* Handle staking state. */ // iterate through redelegations, reset creation height - app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { for i := range red.Entries { red.Entries[i].CreationHeight = 0 } - app.StakingKeeper.SetRedelegation(ctx, red) + err = app.StakingKeeper.SetRedelegation(ctx, red) + if err != nil { + panic(err) + } return false }) + if err != nil { + panic(err) + } // iterate through unbonding delegations, reset creation height - app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { for i := range ubd.Entries { ubd.Entries[i].CreationHeight = 0 } - app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + if err != nil { + panic(err) + } return false }) + if err != nil { + panic(err) + } // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. - store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) - iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) - counter := int16(0) + store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) + iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) for ; iter.Valid(); iter.Next() { - addr := sdk.ValAddress(iter.Key()[1:]) - validator, found := app.StakingKeeper.GetValidator(ctx, addr) - if !found { + addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) + validator, err := app.StakingKeeper.GetValidator(ctx, addr) + if err != nil { panic("expected validator, not found") } @@ -169,27 +216,36 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str validator.Jailed = true } - app.StakingKeeper.SetValidator(ctx, validator) - counter++ + err = app.StakingKeeper.SetValidator(ctx, validator) + if err != nil { + panic(err) + } } if err := iter.Close(); err != nil { - panic(err) + app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err) + return } - if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil { - panic(err) + _, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + log.Fatal(err) } /* Handle slashing state. */ // reset start height on signing infos - app.SlashingKeeper.IterateValidatorSigningInfos( + err = app.SlashingKeeper.IterateValidatorSigningInfos( ctx, func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { info.StartHeight = 0 - app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) + if err := app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info); err != nil { + panic(err) + } return false }, ) + if err != nil { + panic(err) + } } diff --git a/modules/ibc-hooks/simapp/simulation_test.go b/modules/ibc-hooks/simapp/simulation_test.go index 690f230f..77676e5f 100644 --- a/modules/ibc-hooks/simapp/simulation_test.go +++ b/modules/ibc-hooks/simapp/simulation_test.go @@ -6,7 +6,10 @@ import ( "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" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -28,55 +31,22 @@ func init() { // // go test -v -run=TestFullAppSimulation ./app -NumBlocks 200 -BlockSize 50 -Commit -Enabled -Period 1 -Seed 40 func TestFullAppSimulation(t *testing.T) { - config := simcli.NewConfigFromFlags() - config.ChainID = simulationAppChainID - - if !simcli.FlagEnabledValue { - t.Skip("skipping application simulation") - } - - db, dir, logger, _, err := simtestutil.SetupSimulation( - config, - simulationDirPrefix, - simulationDbName, - simcli.FlagVerboseValue, - true, // Don't use this as it is confusing - ) - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, db.Close()) - require.NoError(t, os.RemoveAll(dir)) - }() - - app := NewSimApp(logger, - db, - nil, - true, - map[int64]bool{}, - DefaultNodeHome, - simcli.FlagPeriodValue, - MakeEncodingConfig(), - simtestutil.EmptyAppOptions{}, - baseapp.SetChainID(simulationAppChainID), - ) - require.Equal(t, AppName, app.Name()) - + config, db, _, app := setupSimulationApp(t, "skipping application simulation") // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( t, os.Stdout, app.BaseApp, simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()), - simtypes.RandomAccounts, + simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 simtestutil.SimulationOperations(app, app.AppCodec(), config), - app.BankKeeper.GetBlockedAddresses(), + BlockedAddresses(), config, app.AppCodec(), ) - // export state and simParams before the simulatino error is checked - err = simtestutil.CheckExportSimulation(app, config, simParams) + // export state and simParams before the simulation error is checked + err := simtestutil.CheckExportSimulation(app, config, simParams) require.NoError(t, err) require.NoError(t, simErr) @@ -84,3 +54,27 @@ func TestFullAppSimulation(t *testing.T) { simtestutil.PrintStats(db) } } + +func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *App) { + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) + if skip { + t.Skip(msg) + } + require.NoError(t, err, "simulation setup failed") + + t.Cleanup(func() { + require.NoError(t, db.Close()) + require.NoError(t, os.RemoveAll(dir)) + }) + + appOptions := make(simtestutil.AppOptionsMap, 0) + appOptions[flags.FlagHome] = dir // ensure a unique folder + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue + + app := NewApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) + require.Equal(t, "WasmApp", 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 ea5b320b..ead5ca75 100644 --- a/modules/ibc-hooks/simapp/test_helpers.go +++ b/modules/ibc-hooks/simapp/test_helpers.go @@ -9,13 +9,19 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm" + abci "github.com/cometbft/cometbft/abci/types" + cmtjson "github.com/cometbft/cometbft/libs/json" + cmttypes "github.com/cometbft/cometbft/types" + dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" - "cosmossdk.io/math" - + "cosmossdk.io/log" + sdkmath "cosmossdk.io/math" pruningtypes "cosmossdk.io/store/pruning/types" - "github.com/cosmos/cosmos-sdk/baseapp" + "cosmossdk.io/store/snapshots" + snapshottypes "cosmossdk.io/store/snapshots/types" + + bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -31,18 +37,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - dbm "github.com/cometbft/cometbft-db" - abci "github.com/cometbft/cometbft/abci/types" - tmjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/libs/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - tmtypes "github.com/cometbft/cometbft/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" ) // SetupOptions defines arguments that are passed into `WasmApp` constructor. @@ -50,145 +50,74 @@ type SetupOptions struct { Logger log.Logger DB *dbm.MemDB AppOpts servertypes.AppOptions - WasmOpts []wasm.Option -} - -// NewTestNetworkFixture returns a new simapp AppConstructor for network simulation tests -func NewTestNetworkFixture() network.TestFixture { - dir, err := os.MkdirTemp("", "simapp") - if err != nil { - panic(fmt.Sprintf("failed creating temporary directory: %v", err)) - } - defer os.RemoveAll(dir) - - app := NewSimApp(log.NewNopLogger(), - dbm.NewMemDB(), - nil, - true, - map[int64]bool{}, - "", - 0, - MakeEncodingConfig(), - simtestutil.NewAppOptionsWithFlagHome(dir)) - - appCtr := func(val network.ValidatorI) servertypes.Application { - return NewSimApp( - val.GetCtx().Logger, - dbm.NewMemDB(), - nil, - true, - map[int64]bool{}, - "", - 0, - MakeEncodingConfig(), - simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), - baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), - baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), - baseapp.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), - ) - } - - return network.TestFixture{ - AppConstructor: appCtr, - GenesisState: app.DefaultGenesis(), - EncodingConfig: testutil.TestEncodingConfig{ - InterfaceRegistry: app.InterfaceRegistry(), - Codec: app.AppCodec(), - TxConfig: app.TxConfig(), - Amino: app.LegacyAmino(), - }, - } + WasmOpts []wasmkeeper.Option } -func setup(tb testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*App, GenesisState) { - tb.Helper() +func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*App, GenesisState) { db := dbm.NewMemDB() - nodeHome := tb.TempDir() + nodeHome := t.TempDir() snapshotDir := filepath.Join(nodeHome, "data", "snapshots") snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir) - require.NoError(tb, err) - tb.Cleanup(func() { - err := snapshotDB.Close() - require.NoError(tb, err) - }) + require.NoError(t, err) + t.Cleanup(func() { snapshotDB.Close() }) + snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) + require.NoError(t, err) appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = nodeHome // ensure unique folder appOptions[server.FlagInvCheckPeriod] = invCheckPeriod - app := NewSimApp(log.NewNopLogger(), - db, - nil, - true, - map[int64]bool{}, - DefaultNodeHome, - simcli.FlagPeriodValue, - MakeEncodingConfig(), - appOptions, - baseapp.SetChainID("testing"), - ) - + app := NewWasmApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2})) if withGenesis { - return app, NewDefaultGenesisState(app.AppCodec()) + return app, app.DefaultGenesis() } return app, GenesisState{} } -// NewAppWithCustomOptions initializes a new WasmApp with custom options. -func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *App { +// NewWasmAppWithCustomOptions initializes a new WasmApp with custom options. +func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *App { t.Helper() - db := dbm.NewMemDB() privVal := mock.NewPV() pubKey, err := privVal.GetPubKey() require.NoError(t, err) // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + validator := cmttypes.NewValidator(pubKey, 1) + valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}) // generate genesis account senderPrivKey := secp256k1.GenPrivKey() acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) balance := banktypes.Balance{ Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), } - app := NewSimApp(log.NewNopLogger(), - db, - nil, - true, - map[int64]bool{}, - DefaultNodeHome, - simcli.FlagPeriodValue, - MakeEncodingConfig(), - options.AppOpts, - baseapp.SetChainID("testing"), - ) - genesisState := NewDefaultGenesisState(app.AppCodec()) + app := NewWasmApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts) + genesisState := app.DefaultGenesis() genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) if !isCheckTx { // init chain must be called to stop deliverState from being nil - stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + stateBytes, err := cmtjson.MarshalIndent(genesisState, "", " ") require.NoError(t, err) // Initialize the chain - app.InitChain( - abci.RequestInitChain{ + _, err = app.InitChain( + &abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, ConsensusParams: simtestutil.DefaultConsensusParams, AppStateBytes: stateBytes, - }, - ) + }) + require.NoError(t, err) } return app } // Setup initializes a new WasmApp. A Nop logger is set in WasmApp. -func Setup(t *testing.T, opts ...wasm.Option) (*App, sdk.Context, *authtypes.BaseAccount) { +func Setup(t *testing.T, opts ...wasmkeeper.Option) *App { t.Helper() privVal := mock.NewPV() @@ -196,47 +125,34 @@ func Setup(t *testing.T, opts ...wasm.Option) (*App, sdk.Context, *authtypes.Bas require.NoError(t, err) // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + validator := cmttypes.NewValidator(pubKey, 1) + valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}) // generate genesis account - accPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(accPrivKey.PubKey().Address().Bytes(), accPrivKey.PubKey(), 1, 1) + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) balance := banktypes.Balance{ Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), } chainID := "testing" app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, chainID, opts, balance) - ctx := app.BaseApp.NewContext(false, tmproto.Header{ - Height: app.LastBlockHeight(), - ChainID: chainID, - Time: time.Now().UTC(), - }) - - // Mint coins and send to the acc - err = app.BankKeeper.MintCoins(ctx, - minttypes.ModuleName, - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, - sdk.NewInt(100000000000000))), - ) - require.NoError(t, err) - err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, - minttypes.ModuleName, - acc.GetAddress(), - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), - ) - require.NoError(t, err) - - return app, ctx, acc + return app } // SetupWithGenesisValSet initializes a new WasmApp with a validator set and genesis accounts // that also act as delegators. For simplicity, each validator is bonded with a delegation // of one consensus engine unit in the default token of the WasmApp from first genesis // account. A Nop logger is set in WasmApp. -func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasm.Option, balances ...banktypes.Balance) *App { +func SetupWithGenesisValSet( + t *testing.T, + valSet *cmttypes.ValidatorSet, + genAccs []authtypes.GenesisAccount, + chainID string, + opts []wasmkeeper.Option, + balances ...banktypes.Balance, +) *App { t.Helper() app, genesisState := setup(t, chainID, true, 5, opts...) @@ -249,32 +165,29 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs // init chain will set the validator set and initialize the genesis accounts consensusParams := simtestutil.DefaultConsensusParams consensusParams.Block.MaxGas = 100 * simtestutil.DefaultGenTxGas - app.InitChain( - abci.RequestInitChain{ - ChainId: chainID, - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: consensusParams, - AppStateBytes: stateBytes, - }, - ) - // commit genesis changes - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - ChainID: chainID, + _, err = app.InitChain(&abci.RequestInitChain{ + ChainId: chainID, + Time: time.Now().UTC(), + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: consensusParams, + InitialHeight: app.LastBlockHeight() + 1, + AppStateBytes: stateBytes, + }) + require.NoError(t, err) + + _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ Height: app.LastBlockHeight() + 1, - AppHash: app.LastCommitID().Hash, - Time: time.Now().UTC(), - ValidatorsHash: valSet.Hash(), + Hash: app.LastCommitID().Hash, NextValidatorsHash: valSet.Hash(), - }}) + }) + require.NoError(t, err) return app } // SetupWithEmptyStore set up a wasmd app instance with empty DB -func SetupWithEmptyStore(tb testing.TB) *App { - tb.Helper() - app, _ := setup(tb, "testing", false, 0) +func SetupWithEmptyStore(t testing.TB) *App { + app, _ := setup(t, "testing", false, 0) return app } @@ -288,8 +201,8 @@ func GenesisStateWithSingleValidator(t *testing.T, app *App) GenesisState { require.NoError(t, err) // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + validator := cmttypes.NewValidator(pubKey, 1) + valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}) // generate genesis account senderPrivKey := secp256k1.GenPrivKey() @@ -297,11 +210,11 @@ func GenesisStateWithSingleValidator(t *testing.T, app *App) GenesisState { balances := []banktypes.Balance{ { Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), }, } - genesisState := NewDefaultGenesisState(app.AppCodec()) + genesisState := app.DefaultGenesis() genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) require.NoError(t, err) @@ -310,14 +223,18 @@ func GenesisStateWithSingleValidator(t *testing.T, app *App) GenesisState { // AddTestAddrsIncremental constructs and returns accNum amount of accounts with an // initial balance of accAmt in random order -func AddTestAddrsIncremental(app *App, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { +func AddTestAddrsIncremental(app *App, ctx sdk.Context, accNum int, accAmt sdkmath.Int) []sdk.AccAddress { return addTestAddrs(app, ctx, accNum, accAmt, simtestutil.CreateIncrementalAccounts) } -func addTestAddrs(app *App, ctx sdk.Context, accNum int, accAmt math.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress { +func addTestAddrs(app *App, ctx sdk.Context, accNum int, accAmt sdkmath.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress { testAddrs := strategy(accNum) + bondDenom, err := app.StakingKeeper.BondDenom(ctx) + if err != nil { + panic(err) + } - initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt)) + initCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, accAmt)) for _, addr := range testAddrs { initAccountWithCoins(app, ctx, addr, initCoins) @@ -338,18 +255,47 @@ func initAccountWithCoins(app *App, ctx sdk.Context, addr sdk.AccAddress, coins } } +var emptyWasmOptions []wasmkeeper.Option + +// NewTestNetworkFixture returns a new WasmApp AppConstructor for network simulation tests +func NewTestNetworkFixture() network.TestFixture { + dir, err := os.MkdirTemp("", "simapp") + if err != nil { + panic(fmt.Sprintf("failed creating temporary directory: %v", err)) + } + defer os.RemoveAll(dir) + + app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions) + appCtr := func(val network.ValidatorI) servertypes.Application { + return NewWasmApp( + 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)), + ) + } + + return network.TestFixture{ + AppConstructor: appCtr, + GenesisState: app.DefaultGenesis(), + EncodingConfig: testutil.TestEncodingConfig{ + InterfaceRegistry: app.InterfaceRegistry(), + Codec: app.AppCodec(), + TxConfig: app.TxConfig(), + Amino: app.LegacyAmino(), + }, + } +} + // SignAndDeliverWithoutCommit signs and delivers a transaction. No commit -func SignAndDeliverWithoutCommit( - t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header tmproto.Header, msgs []sdk.Msg, - chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey, -) (sdk.GasInfo, *sdk.Result, error) { - t.Helper() +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) { tx, err := simtestutil.GenSignedMockTx( - /* #nosec */ rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, msgs, - sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, + fees, simtestutil.DefaultGenTxGas, chainID, accNums, @@ -358,13 +304,14 @@ func SignAndDeliverWithoutCommit( ) require.NoError(t, err) - // Simulate a sending a transaction and committing a block - // app.BeginBlock(abci.RequestBeginBlock{Header: header}) - gInfo, res, err := app.SimDeliver(txCfg.TxEncoder(), tx) - // app.EndBlock(abci.RequestEndBlock{}) - // app.Commit() + bz, err := txCfg.TxEncoder()(tx) + require.NoError(t, err) - return gInfo, res, err + return app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: app.LastBlockHeight() + 1, + Time: blockTime, + Txs: [][]byte{bz}, + }) } // GenesisStateWithValSet returns a new genesis state with the validator set @@ -372,7 +319,7 @@ func SignAndDeliverWithoutCommit( func GenesisStateWithValSet( codec codec.Codec, genesisState map[string]json.RawMessage, - valSet *tmtypes.ValidatorSet, + valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance, ) (map[string]json.RawMessage, error) { @@ -386,7 +333,7 @@ func GenesisStateWithValSet( bondAmt := sdk.DefaultPowerReduction for _, val := range valSet.Validators { - pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) + pk, err := cryptocodec.FromCmtPubKeyInterface(val.PubKey) if err != nil { return nil, fmt.Errorf("failed to convert pubkey: %w", err) } @@ -402,21 +349,32 @@ func GenesisStateWithValSet( Jailed: false, Status: stakingtypes.Bonded, Tokens: bondAmt, - DelegatorShares: math.LegacyOneDec(), + DelegatorShares: sdkmath.LegacyOneDec(), Description: stakingtypes.Description{}, UnbondingHeight: int64(0), UnbondingTime: time.Unix(0, 0).UTC(), - Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()), - MinSelfDelegation: math.ZeroInt(), + Commission: stakingtypes.NewCommission(sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()), + MinSelfDelegation: sdkmath.ZeroInt(), } validators = append(validators, validator) - delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), math.LegacyOneDec())) + delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String(), sdkmath.LegacyOneDec())) + } // set validators and delegations stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) genesisState[stakingtypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis) + signingInfos := make([]slashingtypes.SigningInfo, len(valSet.Validators)) + for i, val := range valSet.Validators { + signingInfos[i] = slashingtypes.SigningInfo{ + Address: sdk.ConsAddress(val.Address).String(), + ValidatorSigningInfo: slashingtypes.ValidatorSigningInfo{}, + } + } + slashingGenesis := slashingtypes.NewGenesisState(slashingtypes.DefaultParams(), signingInfos, nil) + genesisState[slashingtypes.ModuleName] = codec.MustMarshalJSON(slashingGenesis) + // add bonded amount to bonded pool module account balances = append(balances, banktypes.Balance{ Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(), @@ -435,31 +393,3 @@ func GenesisStateWithValSet( println(string(genesisState[banktypes.ModuleName])) return genesisState, nil } - -// FundAccount is a utility function that funds an account by minting and -// sending the coins to the address. This should be used for testing purposes -// only! -// -// Instead of using the mint module account, which has the -// permission of minting, create a "faucet" account. (@fdymylja) -func FundAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error { - if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { - return err - } - - return bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts) -} - -// FundModuleAccount is a utility function that funds a module account by -// minting and sending the coins to the address. This should be used for testing -// purposes only! -// -// Instead of using the mint module account, which has the -// permission of minting, create a "faucet" account. (@fdymylja) -func FundModuleAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, recipientMod string, amounts sdk.Coins) error { - if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { - return err - } - - return bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts) -} diff --git a/modules/ibc-hooks/wasm_hook.go b/modules/ibc-hooks/wasm_hook.go index 49944828..d221be83 100644 --- a/modules/ibc-hooks/wasm_hook.go +++ b/modules/ibc-hooks/wasm_hook.go @@ -4,17 +4,17 @@ import ( "encoding/json" "fmt" - sdkmath "cosmossdk.io/math" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/keeper" "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types" errors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"