/
operations.go
108 lines (93 loc) · 3.17 KB
/
operations.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 simulation
// DONTCOVER
import (
"math/rand"
subspaceskeeper "github.com/desmos-labs/desmos/v5/x/subspaces/keeper"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/codec"
sim "github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/desmos-labs/desmos/v5/app/params"
"github.com/desmos-labs/desmos/v5/x/posts/keeper"
)
// Simulation operation weights constants
//
//nolint:gosec // These are not hardcoded credentials
const (
OpWeightMsgCreatePost = "op_weight_msg_create_post"
OpWeightMsgEditPost = "op_weight_msg_edit_post"
OpWeightMsgDeletePost = "op_weight_msg_delete_post"
OpWeightMsgAddPostAttachment = "op_weight_msg_add_post_attachment"
OpWeightMsgRemovePostAttachment = "op_weight_msg_remove_post_attachment"
OpWeightMsgAnswerPoll = "op_weight_msg_answer_poll"
DefaultGasValue = 200000
)
// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec,
k keeper.Keeper, sk subspaceskeeper.Keeper, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper,
) sim.WeightedOperations {
var weightMsgCreatePost int
appParams.GetOrGenerate(cdc, OpWeightMsgCreatePost, &weightMsgCreatePost, nil,
func(_ *rand.Rand) {
weightMsgCreatePost = params.DefaultWeightMsgCreatePost
},
)
var weightMsgEditPost int
appParams.GetOrGenerate(cdc, OpWeightMsgEditPost, &weightMsgEditPost, nil,
func(_ *rand.Rand) {
weightMsgEditPost = params.DefaultWeightMsgEditPost
},
)
var weightMsgDeletePost int
appParams.GetOrGenerate(cdc, OpWeightMsgDeletePost, &weightMsgDeletePost, nil,
func(_ *rand.Rand) {
weightMsgDeletePost = params.DefaultWeightMsgDeletePost
},
)
var weightMsgAddPostAttachment int
appParams.GetOrGenerate(cdc, OpWeightMsgAddPostAttachment, &weightMsgAddPostAttachment, nil,
func(_ *rand.Rand) {
weightMsgAddPostAttachment = params.DefaultWeightMsgAddPostAttachment
},
)
var weightMsgRemovePostAttachment int
appParams.GetOrGenerate(cdc, OpWeightMsgRemovePostAttachment, &weightMsgRemovePostAttachment, nil,
func(r *rand.Rand) {
weightMsgRemovePostAttachment = params.DefaultWeightMsgRemovePostAttachment
},
)
var weightMsgAnswerPoll int
appParams.GetOrGenerate(cdc, OpWeightMsgAnswerPoll, &weightMsgAnswerPoll, nil,
func(r *rand.Rand) {
weightMsgAnswerPoll = params.DefaultWeightMsgAnswerPoll
},
)
return sim.WeightedOperations{
sim.NewWeightedOperation(
weightMsgCreatePost,
SimulateMsgCreatePost(k, sk, ak, bk),
),
sim.NewWeightedOperation(
weightMsgEditPost,
SimulateMsgEditPost(k, sk, ak, bk),
),
sim.NewWeightedOperation(
weightMsgDeletePost,
SimulateMsgDeletePost(k, sk, ak, bk),
),
sim.NewWeightedOperation(
weightMsgAddPostAttachment,
SimulateMsgAddPostAttachment(k, ak, bk),
),
sim.NewWeightedOperation(
weightMsgRemovePostAttachment,
SimulateMsgRemovePostAttachment(k, sk, ak, bk),
),
sim.NewWeightedOperation(
weightMsgAnswerPoll,
SimulateMsgAnswerPoll(k, sk, ak, bk),
),
}
}