github.com/cosmos/cosmos-sdk@v0.50.10/x/mint/simulation/genesis.go (about) 1 package simulation 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "math/rand" 7 8 "cosmossdk.io/math" 9 10 "github.com/cosmos/cosmos-sdk/types/module" 11 "github.com/cosmos/cosmos-sdk/x/mint/types" 12 ) 13 14 // Simulation parameter constants 15 const ( 16 Inflation = "inflation" 17 InflationRateChange = "inflation_rate_change" 18 InflationMax = "inflation_max" 19 InflationMin = "inflation_min" 20 GoalBonded = "goal_bonded" 21 ) 22 23 // GenInflation randomized Inflation 24 func GenInflation(r *rand.Rand) math.LegacyDec { 25 return math.LegacyNewDecWithPrec(int64(r.Intn(99)), 2) 26 } 27 28 // GenInflationRateChange randomized InflationRateChange 29 func GenInflationRateChange(r *rand.Rand) math.LegacyDec { 30 return math.LegacyNewDecWithPrec(int64(r.Intn(99)), 2) 31 } 32 33 // GenInflationMax randomized InflationMax 34 func GenInflationMax(r *rand.Rand) math.LegacyDec { 35 return math.LegacyNewDecWithPrec(20, 2) 36 } 37 38 // GenInflationMin randomized InflationMin 39 func GenInflationMin(r *rand.Rand) math.LegacyDec { 40 return math.LegacyNewDecWithPrec(7, 2) 41 } 42 43 // GenGoalBonded randomized GoalBonded 44 func GenGoalBonded(r *rand.Rand) math.LegacyDec { 45 return math.LegacyNewDecWithPrec(67, 2) 46 } 47 48 // RandomizedGenState generates a random GenesisState for mint 49 func RandomizedGenState(simState *module.SimulationState) { 50 // minter 51 var inflation math.LegacyDec 52 simState.AppParams.GetOrGenerate(Inflation, &inflation, simState.Rand, func(r *rand.Rand) { inflation = GenInflation(r) }) 53 54 // params 55 var inflationRateChange math.LegacyDec 56 simState.AppParams.GetOrGenerate(InflationRateChange, &inflationRateChange, simState.Rand, func(r *rand.Rand) { inflationRateChange = GenInflationRateChange(r) }) 57 58 var inflationMax math.LegacyDec 59 simState.AppParams.GetOrGenerate(InflationMax, &inflationMax, simState.Rand, func(r *rand.Rand) { inflationMax = GenInflationMax(r) }) 60 61 var inflationMin math.LegacyDec 62 simState.AppParams.GetOrGenerate(InflationMin, &inflationMin, simState.Rand, func(r *rand.Rand) { inflationMin = GenInflationMin(r) }) 63 64 var goalBonded math.LegacyDec 65 simState.AppParams.GetOrGenerate(GoalBonded, &goalBonded, simState.Rand, func(r *rand.Rand) { goalBonded = GenGoalBonded(r) }) 66 67 mintDenom := simState.BondDenom 68 blocksPerYear := uint64(60 * 60 * 8766 / 5) 69 params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear) 70 71 mintGenesis := types.NewGenesisState(types.InitialMinter(inflation), params) 72 73 bz, err := json.MarshalIndent(&mintGenesis, "", " ") 74 if err != nil { 75 panic(err) 76 } 77 fmt.Printf("Selected randomly generated minting parameters:\n%s\n", bz) 78 simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis) 79 }