-
Notifications
You must be signed in to change notification settings - Fork 577
/
genesis.go
70 lines (58 loc) · 2.15 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
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/types/module"
controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
hosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
)
// RandomEnabled randomized controller or host enabled param with 75% prob of being true.
func RandomEnabled(r *rand.Rand) bool {
return r.Int63n(101) <= 75
}
// RandomizedGenState generates a random GenesisState for ics27.
// Only the params are non nil
func RandomizedGenState(simState *module.SimulationState) {
var controllerEnabled bool
simState.AppParams.GetOrGenerate(
simState.Cdc, string(controllertypes.KeyControllerEnabled), &controllerEnabled, simState.Rand,
func(r *rand.Rand) { controllerEnabled = RandomEnabled(r) },
)
controllerParams := controllertypes.Params{
ControllerEnabled: controllerEnabled,
}
controllerGenesisState := genesistypes.ControllerGenesisState{
ActiveChannels: nil,
InterchainAccounts: nil,
Ports: []string{},
Params: controllerParams,
}
var hostEnabled bool
simState.AppParams.GetOrGenerate(
simState.Cdc, string(hosttypes.KeyHostEnabled), &hostEnabled, simState.Rand,
func(r *rand.Rand) { hostEnabled = RandomEnabled(r) },
)
hostParams := hosttypes.Params{
HostEnabled: hostEnabled,
AllowMessages: []string{"*"}, // allow all messages
}
hostGenesisState := genesistypes.HostGenesisState{
ActiveChannels: nil,
InterchainAccounts: nil,
Port: types.HostPortID,
Params: hostParams,
}
icaGenesis := genesistypes.GenesisState{
ControllerGenesisState: controllerGenesisState,
HostGenesisState: hostGenesisState,
}
bz, err := json.MarshalIndent(&icaGenesis, "", " ")
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(&icaGenesis)
}