-
Notifications
You must be signed in to change notification settings - Fork 47
/
genesis.go
41 lines (33 loc) · 1.23 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
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
"time"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/Nolus-Protocol/nolus-core/x/mint/types"
)
// GenMaxMintableNanoseconds generates random MaxMintableNanoseconds in range [1-60).
func GenMaxMintableNanoseconds(r *rand.Rand) sdkmath.Uint {
return sdkmath.NewUint(uint64(time.Second.Nanoseconds() * int64(r.Intn(59)+1)))
}
// RandomizedGenState generates a random GenesisState for mint.
func RandomizedGenState(simState *module.SimulationState) {
// minter
var maxMintableNSecs sdkmath.Uint
simState.AppParams.GetOrGenerate(
simState.Cdc, string(types.KeyMaxMintableNanoseconds), &maxMintableNSecs, simState.Rand,
func(r *rand.Rand) { maxMintableNSecs = GenMaxMintableNanoseconds(r) },
)
mintDenom := sdk.DefaultBondDenom
params := types.NewParams(mintDenom, maxMintableNSecs)
mintGenesis := types.NewGenesisState(types.InitialMinter(), 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)
}