/
params.go
69 lines (60 loc) · 1.73 KB
/
params.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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
const (
keyVotingParams = "votingparams"
keyDepositParams = "depositparams"
keyTallyParams = "tallyparams"
subkeyQuorum = "quorum"
subkeyThreshold = "threshold"
subkeyVeto = "veto"
)
// ParamChanges defines the parameters that can be modified by param change proposals
// on the simulation
func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, keyVotingParams,
func(r *rand.Rand) string {
return fmt.Sprintf(`{"voting_period": "%d"}`, GenVotingParamsVotingPeriod(r))
},
),
simulation.NewSimParamChange(types.ModuleName, keyDepositParams,
func(r *rand.Rand) string {
return fmt.Sprintf(`{"max_deposit_period": "%d"}`, GenDepositParamsDepositPeriod(r))
},
),
simulation.NewSimParamChange(types.ModuleName, keyTallyParams,
func(r *rand.Rand) string {
changes := []struct {
key string
value sdk.Dec
}{
{subkeyQuorum, GenTallyParamsQuorum(r)},
{subkeyThreshold, GenTallyParamsThreshold(r)},
{subkeyVeto, GenTallyParamsVeto(r)},
}
pc := make(map[string]string)
numChanges := simtypes.RandIntBetween(r, 1, len(changes))
for i := 0; i < numChanges; i++ {
c := changes[r.Intn(len(changes))]
_, ok := pc[c.key]
for ok {
c := changes[r.Intn(len(changes))]
_, ok = pc[c.key]
}
pc[c.key] = c.value.String()
}
bz, _ := json.Marshal(pc)
return string(bz)
},
),
}
}