planetmint-go/x/machine/module/simulation.go
Lorenz Herzberger ec77745fcd
wip: updated machine module
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2024-06-17 09:29:05 +02:00

131 lines
4.5 KiB
Go

package machine
import (
"math/rand"
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/x/machine/types"
machinesimulation "github.com/planetmint/planetmint-go/x/machine/simulation"
"github.com/planetmint/planetmint-go/testutil/sample"
)
// avoid unused import issue
var (
_ = machinesimulation.FindAccount
_ = rand.Rand{}
_ = sample.AccAddress
_ = sdk.AccAddress{}
_ = simulation.MsgEntryKind
)
const (
opWeightMsgAttestMachine = "op_weight_msg_attest_machine"
// TODO: Determine the simulation weight value
defaultWeightMsgAttestMachine int = 100
opWeightMsgNotarizeLiquidAsset = "op_weight_msg_notarize_liquid_asset"
// TODO: Determine the simulation weight value
defaultWeightMsgNotarizeLiquidAsset int = 100
opWeightMsgRegisterTrustAnchor = "op_weight_msg_register_trust_anchor"
// TODO: Determine the simulation weight value
defaultWeightMsgRegisterTrustAnchor 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()
}
machineGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&machineGenesis)
}
// RegisterStoreDecoder registers a decoder.
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}
// 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 weightMsgAttestMachine int
simState.AppParams.GetOrGenerate(opWeightMsgAttestMachine, &weightMsgAttestMachine, nil,
func(_ *rand.Rand) {
weightMsgAttestMachine = defaultWeightMsgAttestMachine
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAttestMachine,
machinesimulation.SimulateMsgAttestMachine(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgNotarizeLiquidAsset int
simState.AppParams.GetOrGenerate(opWeightMsgNotarizeLiquidAsset, &weightMsgNotarizeLiquidAsset, nil,
func(_ *rand.Rand) {
weightMsgNotarizeLiquidAsset = defaultWeightMsgNotarizeLiquidAsset
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgNotarizeLiquidAsset,
machinesimulation.SimulateMsgNotarizeLiquidAsset(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgRegisterTrustAnchor int
simState.AppParams.GetOrGenerate(opWeightMsgRegisterTrustAnchor, &weightMsgRegisterTrustAnchor, nil,
func(_ *rand.Rand) {
weightMsgRegisterTrustAnchor = defaultWeightMsgRegisterTrustAnchor
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgRegisterTrustAnchor,
machinesimulation.SimulateMsgRegisterTrustAnchor(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(
opWeightMsgAttestMachine,
defaultWeightMsgAttestMachine,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
machinesimulation.SimulateMsgAttestMachine(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgNotarizeLiquidAsset,
defaultWeightMsgNotarizeLiquidAsset,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
machinesimulation.SimulateMsgNotarizeLiquidAsset(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgRegisterTrustAnchor,
defaultWeightMsgRegisterTrustAnchor,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
machinesimulation.SimulateMsgRegisterTrustAnchor(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}