feat(sims): Add simsx support to modules (#24145)

Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
Alexander Peters
2025-04-02 13:23:36 +00:00
committed by GitHub
co-authored by Alex | Interchain Labs
parent 99da3279be
commit ea908cef68
53 changed files with 2025 additions and 241 deletions
+14
View File
@@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simsx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@@ -141,6 +142,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
// migrate to ProposalMsgsX. This method is ignored when ProposalMsgsX exists and will be removed in the future.
func (AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return simulation.ProposalMsgs()
}
@@ -149,6 +151,8 @@ func (AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedPropo
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {
}
// WeightedOperations returns the all the protocolpool module operations with their respective weights.
// migrate to WeightedOperationsX. This method is ignored when WeightedOperationsX exists and will be removed in the future
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return simulation.WeightedOperations(
simState.AppParams,
@@ -158,3 +162,13 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
am.keeper,
)
}
// ProposalMsgsX registers governance proposal messages in the simulation registry.
func (am AppModule) ProposalMsgsX(weight simsx.WeightSource, reg simsx.Registry) {
reg.Add(weight.Get("msg_community_pool_spend", 50), simulation.MsgCommunityPoolSpendFactory())
}
// WeightedOperationsX registers weighted protocolpool module operations for simulation.
func (am AppModule) WeightedOperationsX(weight simsx.WeightSource, reg simsx.Registry) {
reg.Add(weight.Get("msg_fund_community_pool", 50), simulation.MsgFundCommunityPoolFactory())
}
+36
View File
@@ -0,0 +1,36 @@
package simulation
import (
"context"
"github.com/cosmos/cosmos-sdk/simsx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/protocolpool/types"
)
func MsgFundCommunityPoolFactory() simsx.SimMsgFactoryFn[*types.MsgFundCommunityPool] {
return func(_ context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgFundCommunityPool) {
funder := testData.AnyAccount(reporter, simsx.WithSpendableBalance())
fundAmount := funder.LiquidBalance().RandSubsetCoins(reporter)
msg := types.NewMsgFundCommunityPool(fundAmount, funder.AddressBech32)
return []simsx.SimAccount{funder}, msg
}
}
// MsgCommunityPoolSpendFactory creates a gov proposal to send tokens from the community pool to a random account
func MsgCommunityPoolSpendFactory() simsx.SimMsgFactoryFn[*types.MsgCommunityPoolSpend] {
return func(_ context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgCommunityPoolSpend) {
return nil, &types.MsgCommunityPoolSpend{
Authority: testData.ModuleAccountAddress(reporter, "gov"),
Recipient: testData.AnyAccount(reporter).AddressBech32,
Amount: must(sdk.ParseCoinsNormalized("100stake,2testtoken")),
}
}
}
func must[T any](r T, err error) T {
if err != nil {
panic(err)
}
return r
}