-
Notifications
You must be signed in to change notification settings - Fork 51
/
genesis.go
59 lines (50 loc) · 1.55 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
53
54
55
56
57
58
59
package simulation
import (
"math/rand"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/certikfoundation/shentu/x/oracle/types"
)
// RandomizedGenState creates a random genesis state for module simulation.
func RandomizedGenState(simState *module.SimulationState) {
var poolParams types.LockedPoolParams
simState.AppParams.GetOrGenerate(
simState.Cdc, string(types.ParamsStoreKeyPoolParams), &poolParams, simState.Rand,
func(r *rand.Rand) {
poolParams = GenPoolParams(r)
})
var taskParams types.TaskParams
simState.AppParams.GetOrGenerate(
simState.Cdc, string(types.ParamsStoreKeyTaskParams), &taskParams, simState.Rand,
func(r *rand.Rand) {
taskParams = GenTaskParams(r)
})
gs := types.NewGenesisState(
nil,
nil,
poolParams,
taskParams,
nil,
nil,
)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(gs)
}
// GenPoolParams returns a randomized LockedPoolParams object.
func GenPoolParams(r *rand.Rand) types.LockedPoolParams {
return types.LockedPoolParams{
LockedInBlocks: r.Int63n(10),
MinimumCollateral: r.Int63n(10000),
}
}
// GenTaskParams returns a randomized TaskParams object.
func GenTaskParams(r *rand.Rand) types.TaskParams {
return types.TaskParams{
ExpirationDuration: time.Duration(48) * time.Hour,
AggregationWindow: r.Int63n(40),
AggregationResult: sdk.NewInt(r.Int63n(100)),
ThresholdScore: sdk.NewInt(r.Int63n(100)),
Epsilon1: sdk.NewInt(r.Int63n(10)),
Epsilon2: sdk.NewInt(r.Int63n(10) + 90),
}
}