/
genesis.go
98 lines (84 loc) · 2.97 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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/provenance-io/provenance/x/marker/types"
)
// Simulation parameter constants
const (
MaxSupply = "max_supply"
EnableGovernance = "enable_governance"
UnrestrictedDenomRegex = "unresticted_denom_regex"
)
// GenMaxSupply randomized Maximum amount of supply to allow for markers
func GenMaxSupply(r *rand.Rand) math.Int {
maxSupply := fmt.Sprintf("%d%d", r.Uint64(), r.Uint64())
return types.StringToBigInt(maxSupply)
}
// GenEnableGovernance returns a randomized EnableGovernance parameter.
func GenEnableGovernance(r *rand.Rand) bool {
return r.Int63n(100) < 50 // 50% chance of unrestricted names being enabled
}
// GenUnrestrictedDenomRegex returns a randomized length focused string for the unrestricted denom validation expression
func GenUnrestrictedDenomRegex(r *rand.Rand) string {
min := r.Int31n(16) + 3
max := r.Int31n(64-min) + min
return fmt.Sprintf(`[a-zA-Z][a-zA-Z0-9\\-\\.]{%d,%d}`, min, max)
}
// RandomizedGenState generates a random GenesisState for marker
func RandomizedGenState(simState *module.SimulationState) {
var maxSupply math.Int
simState.AppParams.GetOrGenerate(
simState.Cdc, MaxSupply, &maxSupply, simState.Rand,
func(r *rand.Rand) { maxSupply = GenMaxSupply(r) },
)
var enableGovernance bool
simState.AppParams.GetOrGenerate(
simState.Cdc, EnableGovernance, &enableGovernance, simState.Rand,
func(r *rand.Rand) { enableGovernance = GenEnableGovernance(r) },
)
var unrestrictedDenomRegex string
simState.AppParams.GetOrGenerate(
simState.Cdc, UnrestrictedDenomRegex, &unrestrictedDenomRegex, simState.Rand,
func(r *rand.Rand) { unrestrictedDenomRegex = GenUnrestrictedDenomRegex(r) },
)
markerGenesis := types.GenesisState{
Params: types.Params{
MaxSupply: maxSupply,
EnableGovernance: enableGovernance,
UnrestrictedDenomRegex: unrestrictedDenomRegex,
},
Markers: []types.MarkerAccount{
{
BaseAccount: &authtypes.BaseAccount{
Address: types.MustGetMarkerAddress(sdk.DefaultBondDenom).String(),
},
AccessControl: []types.AccessGrant{
{
Address: simState.Accounts[0].Address.String(),
Permissions: types.AccessListByNames("mint,burn,delete,admin"),
},
},
Status: types.StatusActive,
Denom: sdk.DefaultBondDenom,
MarkerType: types.MarkerType_Coin,
SupplyFixed: false,
AllowGovernanceControl: true,
AllowForcedTransfer: false,
RequiredAttributes: []string{},
},
},
}
bz, err := json.MarshalIndent(&markerGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated marker parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&markerGenesis)
}