forked from evmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
67 lines (60 loc) · 1.85 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
60
61
62
63
64
65
66
67
package simulation
import (
"math/rand"
"github.com/adminoid/cosmos-sdk/types/module"
simtypes "github.com/adminoid/cosmos-sdk/types/simulation"
"github.com/adminoid/cosmos-sdk/x/nft"
)
// genClasses returns a slice of nft class.
func genClasses(r *rand.Rand, accounts []simtypes.Account) []*nft.Class {
classes := make([]*nft.Class, len(accounts)-1)
for i := 0; i < len(accounts)-1; i++ {
classes[i] = &nft.Class{
Id: simtypes.RandStringOfLength(r, 10),
Name: simtypes.RandStringOfLength(r, 10),
Symbol: simtypes.RandStringOfLength(r, 10),
Description: simtypes.RandStringOfLength(r, 10),
Uri: simtypes.RandStringOfLength(r, 10),
}
}
return classes
}
// genNFT returns a slice of nft.
func genNFT(r *rand.Rand, classID string, accounts []simtypes.Account) []*nft.Entry {
entries := make([]*nft.Entry, len(accounts)-1)
for i := 0; i < len(accounts)-1; i++ {
owner := accounts[i]
entries[i] = &nft.Entry{
Owner: owner.Address.String(),
Nfts: []*nft.NFT{
{
ClassId: classID,
Id: simtypes.RandStringOfLength(r, 10),
Uri: simtypes.RandStringOfLength(r, 10),
},
},
}
}
return entries
}
// RandomizedGenState generates a random GenesisState for nft.
func RandomizedGenState(simState *module.SimulationState) {
var classes []*nft.Class
simState.AppParams.GetOrGenerate(
simState.Cdc, "nft", &classes, simState.Rand,
func(r *rand.Rand) { classes = genClasses(r, simState.Accounts) },
)
var entries []*nft.Entry
simState.AppParams.GetOrGenerate(
simState.Cdc, "nft", &entries, simState.Rand,
func(r *rand.Rand) {
class := classes[r.Int63n(int64(len(classes)))]
entries = genNFT(r, class.Id, simState.Accounts)
},
)
nftGenesis := &nft.GenesisState{
Classes: classes,
Entries: entries,
}
simState.GenState[nft.ModuleName] = simState.Cdc.MustMarshalJSON(nftGenesis)
}