/
genesis.go
52 lines (42 loc) · 1.3 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
package simulation
// DONTCOVER
import (
"encoding/json"
"fmt"
"math/rand"
"github.com/CosmosContracts/juno/v9/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
)
// Simulation parameter constants
const (
Inflation = "inflation"
)
// GenInflation randomized Inflation
func GenInflation(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
}
// GenBlocksPerYear randomized BlocksPerYear
func GenBlocksPerYear(r *rand.Rand) sdk.Dec {
return sdk.NewDec(60 * 60 * 8766 / 5)
}
// RandomizedGenState generates a random GenesisState for mint
func RandomizedGenState(simState *module.SimulationState) {
// minter
var inflation sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, Inflation, &inflation, simState.Rand,
func(r *rand.Rand) { inflation = GenInflation(r) },
)
// params
mintDenom := sdk.DefaultBondDenom
blocksPerYear := uint64(60 * 60 * 8766 / 5)
params := types.NewParams(mintDenom, blocksPerYear)
mintGenesis := types.NewGenesisState(types.InitialMinter(inflation), params)
bz, err := json.MarshalIndent(&mintGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated minting parameters:\n%s\n", bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis)
}