/
module_simulation.go
204 lines (173 loc) · 6.5 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
package rns
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/jackalLabs/canine-chain/testutil/sample"
rnssimulation "github.com/jackalLabs/canine-chain/v3/x/rns/simulation"
)
// TODO: rewrite tests but don't use ignite
// avoid unused import issue
var (
// _ = sample.AccAddress
_ = rnssimulation.FindAccount
_ = simappparams.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
//nolint:gosec // these aren't hard-coded credentials
const (
opWeightMsgRegister = "op_weight_msg_register"
// TODO: Determine the simulation weight value
defaultWeightMsgRegister int = 100
opWeightMsgBid = "op_weight_msg_bid"
// TODO: Determine the simulation weight value
defaultWeightMsgBid int = 100
opWeightMsgCancelBid = "op_weight_msg_cancel_bid"
// TODO: Determine the simulation weight value
defaultWeightMsgCancelBid int = 10
opWeightMsgAcceptBid = "op_weight_msg_accept_bid"
// TODO: Determine the simulation weight value
defaultWeightMsgAcceptBid int = 100
opWeightMsgList = "op_weight_msg_list"
// TODO: Determine the simulation weight value
defaultWeightMsgList int = 100
opWeightMsgBuy = "op_weight_msg_buy"
// TODO: Determine the simulation weight value
defaultWeightMsgBuy int = 100
opWeightMsgDelist = "op_weight_msg_delist"
// TODO: Determine the simulation weight value
defaultWeightMsgDelist int = 100
opWeightMsgTransfer = "op_weight_msg_transfer"
// TODO: Determine the simulation weight value
defaultWeightMsgTransfer int = 100
opWeightMsgAddRecord = "op_weight_msg_add_record"
// TODO: Determine the simulation weight value
defaultWeightMsgAddRecord int = 60
opWeightMsgDelRecord = "op_weight_msg_del_record"
// TODO: Determine the simulation weight value
defaultWeightMsgDelRecord int = 40
)
// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
rnssimulation.RandomizedGenState(simState)
}
// 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 {
return rnssimulation.ParamChanges(r)
}
// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// WeightedOperations returns the all the rns module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)
var weightMsgRegister int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegister, &weightMsgRegister, nil,
func(_ *rand.Rand) {
weightMsgRegister = defaultWeightMsgRegister
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgRegister,
rnssimulation.SimulateMsgRegister(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgBid int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgBid, &weightMsgBid, nil,
func(_ *rand.Rand) {
weightMsgBid = defaultWeightMsgBid
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgBid,
rnssimulation.SimulateMsgBid(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgAcceptBid int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAcceptBid, &weightMsgAcceptBid, nil,
func(_ *rand.Rand) {
weightMsgAcceptBid = defaultWeightMsgAcceptBid
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAcceptBid,
rnssimulation.SimulateMsgAcceptBid(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgCancelBid int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCancelBid, &weightMsgCancelBid, nil,
func(_ *rand.Rand) {
weightMsgCancelBid = defaultWeightMsgCancelBid
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCancelBid,
rnssimulation.SimulateMsgCancelBid(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgList int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgList, &weightMsgList, nil,
func(_ *rand.Rand) {
weightMsgList = defaultWeightMsgList
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgList,
rnssimulation.SimulateMsgList(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgBuy int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgBuy, &weightMsgBuy, nil,
func(_ *rand.Rand) {
weightMsgBuy = defaultWeightMsgBuy
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgBuy,
rnssimulation.SimulateMsgBuy(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgDelist int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgDelist, &weightMsgDelist, nil,
func(_ *rand.Rand) {
weightMsgDelist = defaultWeightMsgDelist
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgDelist,
rnssimulation.SimulateMsgDelist(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgTransfer int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgTransfer, &weightMsgTransfer, nil,
func(_ *rand.Rand) {
weightMsgTransfer = defaultWeightMsgTransfer
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgTransfer,
rnssimulation.SimulateMsgTransfer(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgAddRecord int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAddRecord, &weightMsgAddRecord, nil,
func(_ *rand.Rand) {
weightMsgAddRecord = defaultWeightMsgAddRecord
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgAddRecord,
rnssimulation.SimulateMsgAddRecord(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgDelRecord int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgDelRecord, &weightMsgDelRecord, nil,
func(_ *rand.Rand) {
weightMsgDelRecord = defaultWeightMsgDelRecord
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgDelRecord,
rnssimulation.SimulateMsgDelRecord(am.accountKeeper, am.bankKeeper, am.keeper),
))
return operations
}