cosmos-sdk/x/ibc-transfer/simulation/genesis.go

51 lines
1.5 KiB
Go
Raw Normal View History

package simulation
import (
"fmt"
"math/rand"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/ibc-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),
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, codec.MustMarshalJSONIndent(simState.Cdc, &transferGenesis))
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&transferGenesis)
}