-
Notifications
You must be signed in to change notification settings - Fork 182
/
genesis.go
54 lines (45 loc) · 1.58 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
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"github.com/okex/exchain/libs/cosmos-sdk/types/module"
simtypes "github.com/okex/exchain/libs/cosmos-sdk/x/simulation"
"github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types"
)
// Simulation parameter constants
const port = "port_id"
// RadomEnabled randomized send or receive enabled param with 75% prob of being true.
func RadomEnabled(r *rand.Rand) bool {
return r.Int63n(101) <= 75
}
// RandomizedGenState generates a random GenesisState for transfer.
func RandomizedGenState(simState *module.SimulationState) {
var portID string
simState.AppParams.GetOrGenerate(
simState.Cdc, port, &portID, simState.Rand,
func(r *rand.Rand) { portID = strings.ToLower(simtypes.RandStringOfLength(r, 20)) },
)
var sendEnabled bool
simState.AppParams.GetOrGenerate(
simState.Cdc, string(types.KeySendEnabled), &sendEnabled, simState.Rand,
func(r *rand.Rand) { sendEnabled = RadomEnabled(r) },
)
var receiveEnabled bool
simState.AppParams.GetOrGenerate(
simState.Cdc, string(types.KeyReceiveEnabled), &receiveEnabled, simState.Rand,
func(r *rand.Rand) { receiveEnabled = RadomEnabled(r) },
)
transferGenesis := types.GenesisState{
PortId: portID,
DenomTraces: types.Traces{},
Params: types.NewParams(sendEnabled, receiveEnabled),
}
bz, err := json.MarshalIndent(&transferGenesis, "", " ")
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(&transferGenesis)
}