github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/mint/simulation/genesis.go (about)

     1  package simulation
     2  
     3  // DONTCOVER
     4  
     5  import (
     6  	"fmt"
     7  	"math/rand"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    10  
    11  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    12  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/internal/types"
    14  )
    15  
    16  // Simulation parameter constants
    17  const (
    18  	Inflation           = "inflation"
    19  	InflationRateChange = "inflation_rate_change"
    20  	InflationMax        = "inflation_max"
    21  	InflationMin        = "inflation_min"
    22  	GoalBonded          = "goal_bonded"
    23  )
    24  
    25  // GenInflation randomized Inflation
    26  func GenInflation(r *rand.Rand) sdk.Dec {
    27  	return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
    28  }
    29  
    30  // GenInflationRateChange randomized InflationRateChange
    31  func GenInflationRateChange(r *rand.Rand) sdk.Dec {
    32  	return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
    33  }
    34  
    35  // GenInflationMax randomized InflationMax
    36  func GenInflationMax(r *rand.Rand) sdk.Dec {
    37  	return sdk.NewDecWithPrec(20, 2)
    38  }
    39  
    40  // GenInflationMin randomized InflationMin
    41  func GenInflationMin(r *rand.Rand) sdk.Dec {
    42  	return sdk.NewDecWithPrec(7, 2)
    43  }
    44  
    45  // GenGoalBonded randomized GoalBonded
    46  func GenGoalBonded(r *rand.Rand) sdk.Dec {
    47  	return sdk.NewDecWithPrec(67, 2)
    48  }
    49  
    50  // RandomizedGenState generates a random GenesisState for mint
    51  func RandomizedGenState(simState *module.SimulationState) {
    52  	// minter
    53  	var inflation sdk.Dec
    54  	simState.AppParams.GetOrGenerate(
    55  		simState.Cdc, Inflation, &inflation, simState.Rand,
    56  		func(r *rand.Rand) { inflation = GenInflation(r) },
    57  	)
    58  
    59  	// params
    60  	var inflationRateChange sdk.Dec
    61  	simState.AppParams.GetOrGenerate(
    62  		simState.Cdc, InflationRateChange, &inflationRateChange, simState.Rand,
    63  		func(r *rand.Rand) { inflationRateChange = GenInflationRateChange(r) },
    64  	)
    65  
    66  	var inflationMax sdk.Dec
    67  	simState.AppParams.GetOrGenerate(
    68  		simState.Cdc, InflationMax, &inflationMax, simState.Rand,
    69  		func(r *rand.Rand) { inflationMax = GenInflationMax(r) },
    70  	)
    71  
    72  	var inflationMin sdk.Dec
    73  	simState.AppParams.GetOrGenerate(
    74  		simState.Cdc, InflationMin, &inflationMin, simState.Rand,
    75  		func(r *rand.Rand) { inflationMin = GenInflationMin(r) },
    76  	)
    77  
    78  	var goalBonded sdk.Dec
    79  	simState.AppParams.GetOrGenerate(
    80  		simState.Cdc, GoalBonded, &goalBonded, simState.Rand,
    81  		func(r *rand.Rand) { goalBonded = GenGoalBonded(r) },
    82  	)
    83  
    84  	mintDenom := sdk.DefaultBondDenom
    85  	blocksPerYear := uint64(60 * 60 * 8766 / 5)
    86  	params := types.NewParams(mintDenom, inflationRateChange, inflationMax,
    87  		inflationMin, goalBonded, blocksPerYear, blocksPerYear, inflationRateChange, inflationRateChange)
    88  
    89  	mintGenesis := types.NewGenesisState(types.InitialMinterCustom(), params, inflationRateChange)
    90  
    91  	fmt.Printf("Selected randomly generated minting parameters:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, mintGenesis))
    92  	simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis)
    93  }