-
Notifications
You must be signed in to change notification settings - Fork 50
/
proposals.go
executable file
·64 lines (56 loc) · 1.92 KB
/
proposals.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
package simulation
import (
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/certikfoundation/shentu/app/params"
"github.com/certikfoundation/shentu/x/cert/keeper"
"github.com/certikfoundation/shentu/x/cert/types"
)
// OpWeightSubmitCertifierUpdateProposal app params key for certifier update proposal
const OpWeightSubmitCertifierUpdateProposal = "op_weight_submit_certifier_update_proposal"
// ProposalContents defines the module weighted proposals' contents
func ProposalContents(k keeper.Keeper) []simulation.WeightedProposalContent {
return []simulation.WeightedProposalContent{
{
AppParamsKey: OpWeightSubmitCertifierUpdateProposal,
DefaultWeight: params.DefaultWeightCertifierUpdateProposal,
ContentSimulatorFn: SimulateCertifierUpdateProposalContent(k),
},
}
}
// SimulateCertifierUpdateProposalContent generates random certifier update proposal content
// nolint: funlen
func SimulateCertifierUpdateProposalContent(k keeper.Keeper) simulation.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simulation.Account) govtypes.Content {
certifiers := k.GetAllCertifiers(ctx)
proposer_index := r.Intn(len(certifiers))
var addorremove types.AddOrRemove
var certifier sdk.AccAddress
switch r.Intn(2) {
case 0:
addorremove = types.Add
for _, acc := range accs {
if k.IsCertifier(ctx, acc.Address) {
continue
} else {
certifier = acc.Address
break
}
}
case 1:
addorremove = types.Remove
certifier_index := r.Intn(len(certifiers))
certifier = certifiers[certifier_index].Address
}
return types.NewCertifierUpdateProposal(
simulation.RandStringOfLength(r, 140),
simulation.RandStringOfLength(r, 5000),
certifier,
simulation.RandStringOfLength(r, 30),
certifiers[proposer_index].Address,
addorremove,
)
}
}