planetmint-go/x/der/module_simulation.go
Jürgen Eckel 057171938c
./ignite scaffold message registerDER der:DER --module der
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
2025-05-20 23:12:32 +02:00

88 lines
2.9 KiB
Go

package der
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
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/simulation"
"github.com/planetmint/planetmint-go/testutil/sample"
dersimulation "github.com/planetmint/planetmint-go/x/der/simulation"
"github.com/planetmint/planetmint-go/x/der/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = dersimulation.FindAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
_ = rand.Rand{}
)
const (
opWeightMsgRegisterDER = "op_weight_msg_register_der"
// TODO: Determine the simulation weight value
defaultWeightMsgRegisterDER int = 100
// this line is used by starport scaffolding # simapp/module/const
)
// GenerateGenesisState creates a randomized GenState of the module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
derGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&derGenesis)
}
// RegisterStoreDecoder registers a decoder.
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)
var weightMsgRegisterDER int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegisterDER, &weightMsgRegisterDER, nil,
func(_ *rand.Rand) {
weightMsgRegisterDER = defaultWeightMsgRegisterDER
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgRegisterDER,
dersimulation.SimulateMsgRegisterDER(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgRegisterDER,
defaultWeightMsgRegisterDER,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
dersimulation.SimulateMsgRegisterDER(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}