-
Notifications
You must be signed in to change notification settings - Fork 11
/
genesis.go
70 lines (62 loc) · 1.66 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
68
69
70
package simulation
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/UptickNetwork/uptick/x/collection/types"
)
const (
kitties = "kitties"
doggos = "doggos"
)
// RandomizedGenState generates a random GenesisState for nft
func RandomizedGenState(simState *module.SimulationState) {
collections := types.NewCollections(
types.NewCollection(
types.Denom{
Id: doggos,
Name: doggos,
Schema: "",
Creator: "",
Symbol: "dog",
},
types.NFTs{},
),
types.NewCollection(
types.Denom{
Id: kitties,
Name: kitties,
Schema: "",
Creator: "",
Symbol: "kit",
},
types.NFTs{}),
)
for _, acc := range simState.Accounts {
// 10% of accounts own an NFT
if simState.Rand.Intn(100) < 10 {
baseNFT := types.NewBaseNFT(
genNFTID(simState.Rand, 3, 128), // id
simtypes.RandStringOfLength(simState.Rand, 10),
acc.Address,
simtypes.RandStringOfLength(simState.Rand, 45), // tokenURI
simtypes.RandStringOfLength(simState.Rand, 32), // tokenURIHash
simtypes.RandStringOfLength(simState.Rand, 10),
)
// 50% doggos and 50% kitties
if simState.Rand.Intn(100) < 50 {
collections[0].Denom.Creator = baseNFT.Owner
collections[0] = collections[0].AddNFT(baseNFT)
} else {
collections[1].Denom.Creator = baseNFT.Owner
collections[1] = collections[1].AddNFT(baseNFT)
}
}
}
nftGenesis := types.NewGenesisState(collections)
_, err := json.MarshalIndent(nftGenesis, "", " ")
if err != nil {
panic(err)
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(nftGenesis)
}