-
Notifications
You must be signed in to change notification settings - Fork 563
/
genesis.go
64 lines (53 loc) · 2.16 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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/types/module"
clientsims "github.com/cosmos/ibc-go/v3/modules/core/02-client/simulation"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
connectionsims "github.com/cosmos/ibc-go/v3/modules/core/03-connection/simulation"
connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types"
channelsims "github.com/cosmos/ibc-go/v3/modules/core/04-channel/simulation"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/cosmos/ibc-go/v3/modules/core/types"
)
// Simulation parameter constants
const (
clientGenesis = "client_genesis"
connectionGenesis = "connection_genesis"
channelGenesis = "channel_genesis"
)
// RandomizedGenState generates a random GenesisState for evidence
func RandomizedGenState(simState *module.SimulationState) {
var (
clientGenesisState clienttypes.GenesisState
connectionGenesisState connectiontypes.GenesisState
channelGenesisState channeltypes.GenesisState
)
simState.AppParams.GetOrGenerate(
simState.Cdc, clientGenesis, &clientGenesisState, simState.Rand,
func(r *rand.Rand) { clientGenesisState = clientsims.GenClientGenesis(r, simState.Accounts) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, connectionGenesis, &connectionGenesisState, simState.Rand,
func(r *rand.Rand) { connectionGenesisState = connectionsims.GenConnectionGenesis(r, simState.Accounts) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, channelGenesis, &channelGenesisState, simState.Rand,
func(r *rand.Rand) { channelGenesisState = channelsims.GenChannelGenesis(r, simState.Accounts) },
)
ibcGenesis := types.GenesisState{
ClientGenesis: clientGenesisState,
ConnectionGenesis: connectionGenesisState,
ChannelGenesis: channelGenesisState,
}
bz, err := json.MarshalIndent(&ibcGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", host.ModuleName, bz)
simState.GenState[host.ModuleName] = simState.Cdc.MustMarshalJSON(&ibcGenesis)
}