* x/capability: simulations * update logs * validate genesis state * InitGenesis and ExportGenesis functions * update validation func * fix import-export sim * remove nondeterminism from capability genesis * Update x/capability/types/genesis.go * Update x/capability/types/genesis.go * fix tests * fix merge * consistency updates * try fix nondeterminism * fix conditional * Fix random index logic * lint * lint Co-authored-by: Aditya Sripal <adityasripal@gmail.com> Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
37 lines
951 B
Go
37 lines
951 B
Go
package simulation
|
|
|
|
// DONTCOVER
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
)
|
|
|
|
// Simulation parameter constants
|
|
const index = "index"
|
|
|
|
// GenIndex returns a random global index between 1-1000
|
|
func GenIndex(r *rand.Rand) uint64 {
|
|
return uint64(r.Int63n(1000)) + 1
|
|
}
|
|
|
|
// RandomizedGenState generates a random GenesisState for capability
|
|
func RandomizedGenState(simState *module.SimulationState) {
|
|
var idx uint64
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
simState.Cdc, index, &idx, simState.Rand,
|
|
func(r *rand.Rand) { idx = GenIndex(r) },
|
|
)
|
|
|
|
capabilityGenesis := types.GenesisState{Index: idx}
|
|
|
|
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, codec.MustMarshalJSONIndent(simState.Cdc, capabilityGenesis))
|
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(capabilityGenesis)
|
|
}
|