forked from AstraProtocol/astra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_simulation.go
244 lines (208 loc) · 8.72 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package channel
import (
"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/dungtt-astra/astra/v3/testutil/sample"
channelsimulation "github.com/dungtt-astra/astra/v3/x/channel/simulation"
"github.com/dungtt-astra/astra/v3/x/channel/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = channelsimulation.FindAccount
_ = simappparams.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
const (
opWeightMsgOpenchannel = "op_weight_msg_openchannel"
// TODO: Determine the simulation weight value
defaultWeightMsgOpenchannel int = 100
opWeightMsgClosechannel = "op_weight_msg_closechannel"
// TODO: Determine the simulation weight value
defaultWeightMsgClosechannel int = 100
opWeightMsgCommitment = "op_weight_msg_commitment"
// TODO: Determine the simulation weight value
defaultWeightMsgCommitment int = 100
opWeightMsgWithdrawTimelock = "op_weight_msg_withdraw_timelock"
// TODO: Determine the simulation weight value
defaultWeightMsgWithdrawTimelock int = 100
opWeightMsgWithdrawHashlock = "op_weight_msg_withdraw_hashlock"
// TODO: Determine the simulation weight value
defaultWeightMsgWithdrawHashlock int = 100
opWeightMsgFund = "op_weight_msg_fund"
// TODO: Determine the simulation weight value
defaultWeightMsgFund int = 100
opWeightMsgAcceptfund = "op_weight_msg_acceptfund"
// TODO: Determine the simulation weight value
defaultWeightMsgAcceptfund int = 100
opWeightMsgSendercommit = "op_weight_msg_sendercommit"
// TODO: Determine the simulation weight value
defaultWeightMsgSendercommit int = 100
opWeightMsgReceivercommit = "op_weight_msg_receivercommit"
// TODO: Determine the simulation weight value
defaultWeightMsgReceivercommit int = 100
opWeightMsgSenderwithdrawtimelock = "op_weight_msg_senderwithdrawtimelock"
// TODO: Determine the simulation weight value
defaultWeightMsgSenderwithdrawtimelock int = 100
opWeightMsgSenderwithdrawhashlock = "op_weight_msg_senderwithdrawhashlock"
// TODO: Determine the simulation weight value
defaultWeightMsgSenderwithdrawhashlock int = 100
opWeightMsgReceiverwithdraw = "op_weight_msg_receiverwithdraw"
// TODO: Determine the simulation weight value
defaultWeightMsgReceiverwithdraw 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()
}
channelGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&channelGenesis)
}
// 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(_ *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{}
}
// 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 weightMsgOpenchannel int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgOpenchannel, &weightMsgOpenchannel, nil,
func(_ *rand.Rand) {
weightMsgOpenchannel = defaultWeightMsgOpenchannel
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgOpenchannel,
channelsimulation.SimulateMsgOpenchannel(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgClosechannel int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgClosechannel, &weightMsgClosechannel, nil,
func(_ *rand.Rand) {
weightMsgClosechannel = defaultWeightMsgClosechannel
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgClosechannel,
channelsimulation.SimulateMsgClosechannel(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgCommitment int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCommitment, &weightMsgCommitment, nil,
func(_ *rand.Rand) {
weightMsgCommitment = defaultWeightMsgCommitment
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCommitment,
channelsimulation.SimulateMsgCommitment(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgWithdrawTimelock int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgWithdrawTimelock, &weightMsgWithdrawTimelock, nil,
func(_ *rand.Rand) {
weightMsgWithdrawTimelock = defaultWeightMsgWithdrawTimelock
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgWithdrawTimelock,
channelsimulation.SimulateMsgWithdrawTimelock(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgWithdrawHashlock int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgWithdrawHashlock, &weightMsgWithdrawHashlock, nil,
func(_ *rand.Rand) {
weightMsgWithdrawHashlock = defaultWeightMsgWithdrawHashlock
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgWithdrawHashlock,
channelsimulation.SimulateMsgWithdrawHashlock(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgFund int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgFund, &weightMsgFund, nil,
func(_ *rand.Rand) {
weightMsgFund = defaultWeightMsgFund
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgFund,
channelsimulation.SimulateMsgFund(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgAcceptfund int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAcceptfund, &weightMsgAcceptfund, nil,
func(_ *rand.Rand) {
weightMsgAcceptfund = defaultWeightMsgAcceptfund
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAcceptfund,
channelsimulation.SimulateMsgAcceptfund(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgSendercommit int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgSendercommit, &weightMsgSendercommit, nil,
func(_ *rand.Rand) {
weightMsgSendercommit = defaultWeightMsgSendercommit
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgSendercommit,
channelsimulation.SimulateMsgSendercommit(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgReceivercommit int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgReceivercommit, &weightMsgReceivercommit, nil,
func(_ *rand.Rand) {
weightMsgReceivercommit = defaultWeightMsgReceivercommit
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgReceivercommit,
channelsimulation.SimulateMsgReceivercommit(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgSenderwithdrawtimelock int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgSenderwithdrawtimelock, &weightMsgSenderwithdrawtimelock, nil,
func(_ *rand.Rand) {
weightMsgSenderwithdrawtimelock = defaultWeightMsgSenderwithdrawtimelock
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgSenderwithdrawtimelock,
channelsimulation.SimulateMsgSenderwithdrawtimelock(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgSenderwithdrawhashlock int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgSenderwithdrawhashlock, &weightMsgSenderwithdrawhashlock, nil,
func(_ *rand.Rand) {
weightMsgSenderwithdrawhashlock = defaultWeightMsgSenderwithdrawhashlock
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgSenderwithdrawhashlock,
channelsimulation.SimulateMsgSenderwithdrawhashlock(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgReceiverwithdraw int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgReceiverwithdraw, &weightMsgReceiverwithdraw, nil,
func(_ *rand.Rand) {
weightMsgReceiverwithdraw = defaultWeightMsgReceiverwithdraw
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgReceiverwithdraw,
channelsimulation.SimulateMsgReceiverwithdraw(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}