forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
110 lines (91 loc) · 3.59 KB
/
genesis.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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
// Simulation parameter constants
const (
DepositParamsMinDeposit = "deposit_params_min_deposit"
DepositParamsDepositPeriod = "deposit_params_deposit_period"
VotingParamsVotingPeriod = "voting_params_voting_period"
TallyParamsQuorum = "tally_params_quorum"
TallyParamsThreshold = "tally_params_threshold"
TallyParamsVeto = "tally_params_veto"
)
// GenDepositParamsDepositPeriod randomized DepositParamsDepositPeriod
func GenDepositParamsDepositPeriod(r *rand.Rand) time.Duration {
return time.Duration(simulation.RandIntBetween(r, 1, 2*60*60*24*2)) * time.Second
}
// GenDepositParamsMinDeposit randomized DepositParamsMinDeposit
func GenDepositParamsMinDeposit(r *rand.Rand) sdk.Coins {
return sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(simulation.RandIntBetween(r, 1, 1e3))))
}
// GenVotingParamsVotingPeriod randomized VotingParamsVotingPeriod
func GenVotingParamsVotingPeriod(r *rand.Rand) time.Duration {
return time.Duration(simulation.RandIntBetween(r, 1, 2*60*60*24*2)) * time.Second
}
// GenTallyParamsQuorum randomized TallyParamsQuorum
func GenTallyParamsQuorum(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(int64(simulation.RandIntBetween(r, 334, 500)), 3)
}
// GenTallyParamsThreshold randomized TallyParamsThreshold
func GenTallyParamsThreshold(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(int64(simulation.RandIntBetween(r, 450, 550)), 3)
}
// GenTallyParamsVeto randomized TallyParamsVeto
func GenTallyParamsVeto(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(int64(simulation.RandIntBetween(r, 250, 334)), 3)
}
// RandomizedGenState generates a random GenesisState for gov
func RandomizedGenState(simState *module.SimulationState) {
startingProposalID := uint64(simState.Rand.Intn(100))
var minDeposit sdk.Coins
simState.AppParams.GetOrGenerate(
simState.Cdc, DepositParamsMinDeposit, &minDeposit, simState.Rand,
func(r *rand.Rand) { minDeposit = GenDepositParamsMinDeposit(r) },
)
var depositPeriod time.Duration
simState.AppParams.GetOrGenerate(
simState.Cdc, DepositParamsDepositPeriod, &depositPeriod, simState.Rand,
func(r *rand.Rand) { depositPeriod = GenDepositParamsDepositPeriod(r) },
)
var votingPeriod time.Duration
simState.AppParams.GetOrGenerate(
simState.Cdc, VotingParamsVotingPeriod, &votingPeriod, simState.Rand,
func(r *rand.Rand) { votingPeriod = GenVotingParamsVotingPeriod(r) },
)
var quorum sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, TallyParamsQuorum, &quorum, simState.Rand,
func(r *rand.Rand) { quorum = GenTallyParamsQuorum(r) },
)
var threshold sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, TallyParamsThreshold, &threshold, simState.Rand,
func(r *rand.Rand) { threshold = GenTallyParamsThreshold(r) },
)
var veto sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, TallyParamsVeto, &veto, simState.Rand,
func(r *rand.Rand) { veto = GenTallyParamsVeto(r) },
)
govGenesis := types.NewGenesisState(
startingProposalID,
types.NewDepositParams(minDeposit, depositPeriod),
types.NewVotingParams(votingPeriod),
types.NewTallyParams(quorum, threshold, veto),
)
bz, err := json.MarshalIndent(&govGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis)
}