-
Notifications
You must be signed in to change notification settings - Fork 236
/
genesis.go
86 lines (70 loc) · 2.3 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
package simulation
import (
"encoding/hex"
"encoding/json"
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/crypto-org-chain/cronos/x/cronos/types"
)
const (
ibcCroDenomKey = "ibc_cro_denom"
ibcTimeoutKey = "ibc_timeout"
cronosAdminKey = "cronos_admin"
enableAutoDeploymentKey = "enable_auto_deployment"
)
func GenIbcCroDenom(r *rand.Rand) string {
randDenom := make([]byte, 32)
r.Read(randDenom)
return fmt.Sprintf("ibc/%s", hex.EncodeToString(randDenom))
}
func GenIbcTimeout(r *rand.Rand) uint64 {
timeout := r.Uint64()
return timeout
}
func GenCronosAdmin(r *rand.Rand, simState *module.SimulationState) string {
adminAccount, _ := simtypes.RandomAcc(r, simState.Accounts)
return adminAccount.Address.String()
}
func GenEnableAutoDeployment(r *rand.Rand) bool {
return r.Intn(2) > 0
}
// RandomizedGenState generates a random GenesisState for the cronos module
func RandomizedGenState(simState *module.SimulationState) {
// cronos params
var (
ibcCroDenom string
ibcTimeout uint64
cronosAdmin string
enableAutoDeployment bool
)
simState.AppParams.GetOrGenerate(
simState.Cdc, ibcCroDenomKey, &ibcCroDenom, simState.Rand,
func(r *rand.Rand) { ibcCroDenom = GenIbcCroDenom(r) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, ibcTimeoutKey, &ibcTimeout, simState.Rand,
func(r *rand.Rand) { ibcTimeout = GenIbcTimeout(r) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, cronosAdminKey, &cronosAdmin, simState.Rand,
func(r *rand.Rand) { cronosAdmin = GenCronosAdmin(r, simState) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, enableAutoDeploymentKey, &enableAutoDeployment, simState.Rand,
func(r *rand.Rand) { enableAutoDeployment = GenEnableAutoDeployment(r) },
)
params := types.NewParams(ibcCroDenom, ibcTimeout, cronosAdmin, enableAutoDeployment)
cronosGenesis := &types.GenesisState{
Params: params,
ExternalContracts: nil,
AutoContracts: nil,
}
bz, err := json.MarshalIndent(cronosGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(cronosGenesis)
}