-
Notifications
You must be signed in to change notification settings - Fork 178
/
genesis.go
59 lines (48 loc) · 1.58 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 (
"fmt"
"math/big"
"math/rand"
"strconv"
"time"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/ethereum/go-ethereum/common/math"
"github.com/maticnetwork/heimdall/topup/types"
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/maticnetwork/heimdall/types/module"
"github.com/maticnetwork/heimdall/types/simulation"
)
// SequenceNumber ...
var SequenceNumber = "sequence_number"
// GenSequenceNumber returns randomc chainID
func GenSequenceNumber(r *rand.Rand) string {
return strconv.Itoa(simulation.RandIntBetween(r, 0, math.MaxInt32))
}
// RandomizeGenState returns topup genesis
func RandomizeGenState(simState *module.SimulationState) {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1) //nolint
n := 5
accounts := simulation.RandomAccounts(r1, n)
var (
sequences = make([]string, 5)
dividendAccounts = make([]hmTypes.DividendAccount, 5)
)
for i := 0; i < 5; i++ {
var sequenceNumber string
simState.AppParams.GetOrGenerate(simState.Cdc, SequenceNumber, &sequenceNumber, simState.Rand,
func(r *rand.Rand) {
sequenceNumber = GenSequenceNumber(r)
},
)
sequences[i] = sequenceNumber
// create dividend account for validator
dividendAccounts[i] = hmTypes.NewDividendAccount(
accounts[i].Address,
big.NewInt(0).String(),
)
}
topupGenesis := types.NewGenesisState(sequences, dividendAccounts)
fmt.Printf("Selected randomly generated topup sequences:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, topupGenesis))
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(topupGenesis)
}