-
Notifications
You must be signed in to change notification settings - Fork 182
/
genesis.go
82 lines (67 loc) · 2.62 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
package simulation
// DONTCOVER
import (
"fmt"
"math/rand"
"github.com/okex/exchain/libs/cosmos-sdk/codec"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/types/module"
"github.com/okex/exchain/libs/cosmos-sdk/x/distribution/types"
)
// Simulation parameter constants
const (
CommunityTax = "community_tax"
BaseProposerReward = "base_proposer_reward"
BonusProposerReward = "bonus_proposer_reward"
WithdrawEnabled = "withdraw_enabled"
)
// GenCommunityTax randomized CommunityTax
func GenCommunityTax(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
}
// GenBaseProposerReward randomized BaseProposerReward
func GenBaseProposerReward(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
}
// GenBonusProposerReward randomized BonusProposerReward
func GenBonusProposerReward(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
}
// GenWithdrawEnabled returns a randomized WithdrawEnabled parameter.
func GenWithdrawEnabled(r *rand.Rand) bool {
return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled
}
// RandomizedGenState generates a random GenesisState for distribution
func RandomizedGenState(simState *module.SimulationState) {
var communityTax sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, CommunityTax, &communityTax, simState.Rand,
func(r *rand.Rand) { communityTax = GenCommunityTax(r) },
)
var baseProposerReward sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, BaseProposerReward, &baseProposerReward, simState.Rand,
func(r *rand.Rand) { baseProposerReward = GenBaseProposerReward(r) },
)
var bonusProposerReward sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, BonusProposerReward, &bonusProposerReward, simState.Rand,
func(r *rand.Rand) { bonusProposerReward = GenBonusProposerReward(r) },
)
var withdrawEnabled bool
simState.AppParams.GetOrGenerate(
simState.Cdc, WithdrawEnabled, &withdrawEnabled, simState.Rand,
func(r *rand.Rand) { withdrawEnabled = GenWithdrawEnabled(r) },
)
distrGenesis := types.GenesisState{
FeePool: types.InitialFeePool(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawEnabled,
},
}
fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, distrGenesis))
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(distrGenesis)
}