From 324ebe27c455dc4fa9f949cf987ff3e12ab2cbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Mon, 28 Oct 2024 11:29:33 +0700 Subject: [PATCH] iplm AppModuleSimulation --- x/multi-staking/module.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/x/multi-staking/module.go b/x/multi-staking/module.go index 4e5c8e3..57651f1 100644 --- a/x/multi-staking/module.go +++ b/x/multi-staking/module.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "math/rand" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/realio-tech/multi-staking-module/x/multi-staking/client/cli" @@ -17,14 +18,17 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/simulation" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // AppModule embeds the Cosmos SDK's x/staking AppModuleBasic. @@ -176,3 +180,30 @@ func (am AppModule) EndBlock(ctx sdk.Context, requestEndBlock abci.RequestEndBlo // ConsensusVersion return module consensus version func (AppModule) ConsensusVersion() uint64 { return 1 } + +// GenerateGenesisState creates a randomized GenState of the staking module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized staking param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return simulation.ParamChanges(r) +} + +// RegisterStoreDecoder registers a decoder for staking module's types +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { + sdr[multistakingtypes.StoreKey] = simulation.NewDecodeStore(am.cdc) +} + +// WeightedOperations returns the all the staking module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return simulation.WeightedOperations( + simState.AppParams, simState.Cdc, am.ak, am.bk, am.keeper.Keeper, + ) +}