/
module_simulation.go
119 lines (100 loc) · 3.91 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
109
110
111
112
113
114
115
116
117
118
119
package subscription
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"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/lavanet/lava/testutil/sample"
subscriptionsimulation "github.com/lavanet/lava/x/subscription/simulation"
"github.com/lavanet/lava/x/subscription/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = subscriptionsimulation.FindAccount
_ = sims.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
const (
opWeightMsgBuy = "op_weight_msg_buy"
// TODO: Determine the simulation weight value
defaultWeightMsgBuy int = 100
opWeightMsgAddProject = "op_weight_msg_add_project"
// TODO: Determine the simulation weight value
defaultWeightMsgAddProject int = 100
opWeightMsgDelProject = "op_weight_msg_del_project"
// TODO: Determine the simulation weight value
defaultWeightMsgDelProject int = 100
opWeightMsgAutoRenewal = "op_weight_msg_auto_renewal"
// TODO: Determine the simulation weight value
defaultWeightMsgAutoRenewal 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()
}
subscriptionGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&subscriptionGenesis)
}
// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}
// 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 weightMsgBuy int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgBuy, &weightMsgBuy, nil,
func(_ *rand.Rand) {
weightMsgBuy = defaultWeightMsgBuy
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgBuy,
subscriptionsimulation.SimulateMsgBuy(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgAddProject int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAddProject, &weightMsgAddProject, nil,
func(_ *rand.Rand) {
weightMsgAddProject = defaultWeightMsgAddProject
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAddProject,
subscriptionsimulation.SimulateMsgAddProject(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgDelProject int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgDelProject, &weightMsgDelProject, nil,
func(_ *rand.Rand) {
weightMsgDelProject = defaultWeightMsgDelProject
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgDelProject,
subscriptionsimulation.SimulateMsgDelProject(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgAutoRenewal int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAutoRenewal, &weightMsgAutoRenewal, nil,
func(_ *rand.Rand) {
weightMsgAutoRenewal = defaultWeightMsgAutoRenewal
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAutoRenewal,
subscriptionsimulation.SimulateMsgAutoRenewal(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}