-
Notifications
You must be signed in to change notification settings - Fork 330
/
module_simulation.go
108 lines (93 loc) · 3.59 KB
/
module_simulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package rollapp
import (
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
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/dymensionxyz/dymension/v3/testutil/sample"
rollappsimulation "github.com/dymensionxyz/dymension/v3/x/rollapp/simulation"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = simappparams.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
const (
// nolint: gosec
opWeightMsgCreateRollapp = "op_weight_msg_create_rollapp"
// TODO: Determine the simulation weight value
defaultWeightMsgCreateRollapp int = 100
// nolint: gosec
opWeightMsgUpdateState = "op_weight_msg_update_state"
// TODO: Determine the simulation weight value
defaultWeightMsgUpdateState 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()
}
rollappGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&rollappGenesis)
}
// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
// RandomizedParams creates randomized param changes for the simulator
func (am AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
_ = r
rollappParams := types.DefaultParams()
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.KeyDisputePeriodInBlocks),
func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(rollappParams.DisputePeriodInBlocks))
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyDeployerWhitelist),
func(r *rand.Rand) string {
return fmt.Sprintf("%v", []string{})
},
),
}
}
// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.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 weightMsgCreateRollapp int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCreateRollapp, &weightMsgCreateRollapp, nil,
func(_ *rand.Rand) {
weightMsgCreateRollapp = defaultWeightMsgCreateRollapp
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCreateRollapp,
rollappsimulation.SimulateMsgCreateRollapp(am.accountKeeper, am.bankKeeper, *am.keeper),
))
var weightMsgUpdateState int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUpdateState, &weightMsgUpdateState, nil,
func(_ *rand.Rand) {
weightMsgUpdateState = defaultWeightMsgUpdateState
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUpdateState,
rollappsimulation.SimulateMsgUpdateState(am.accountKeeper, am.bankKeeper, *am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}