/
genesis.go
103 lines (90 loc) · 2.62 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package simulation
import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/OmniFlix/omniflixhub/v2/x/onft/types"
)
const (
denomName1 = "denom1"
denomName2 = "denom2"
denomId1 = "onftdenom1"
denomId2 = "onftdenom2"
)
// RandomizedGenState generates a random GenesisState for nft
func RandomizedGenState(simState *module.SimulationState) {
collections := types.NewCollections(
types.NewCollection(
types.Denom{
Id: denomId1,
Name: denomName1,
Schema: "{}",
Creator: "",
Symbol: "denom1",
Description: simtypes.RandStringOfLength(simState.Rand, 45),
PreviewURI: simtypes.RandStringOfLength(simState.Rand, 45),
},
types.ONFTs{},
),
types.NewCollection(
types.Denom{
Id: denomId2,
Name: denomName2,
Schema: "{}",
Creator: "",
Symbol: "denom2",
Description: simtypes.RandStringOfLength(simState.Rand, 45),
PreviewURI: simtypes.RandStringOfLength(simState.Rand, 45),
},
types.ONFTs{}),
)
for i, acc := range simState.Accounts {
if simState.Rand.Intn(100) < 10 {
oNFT := types.NewONFT(
RandID(simState.Rand, "onft", 10),
RandMetadata(simState.Rand),
"{}",
genRandomBool(simState.Rand),
genRandomBool(simState.Rand),
acc.Address,
time.Time{},
genRandomBool(simState.Rand),
RandRoyaltyShare(simState.Rand),
)
if i < 50 {
collections[0].Denom.Creator = oNFT.Owner
collections[0] = collections[0].AddONFT(oNFT)
} else {
collections[1].Denom.Creator = oNFT.Owner
collections[1] = collections[1].AddONFT(oNFT)
}
}
}
nftGenesis := types.NewGenesisState(collections, types.DefaultParams())
bz, err := json.MarshalIndent(nftGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(nftGenesis)
}
func RandID(r *rand.Rand, prefix string, n int) string {
id := simtypes.RandStringOfLength(r, n)
return strings.ToLower(prefix + id)
}
func RandMetadata(r *rand.Rand) types.Metadata {
return types.Metadata{
Name: simtypes.RandStringOfLength(r, 10),
Description: simtypes.RandStringOfLength(r, 45),
PreviewURI: simtypes.RandStringOfLength(r, 45),
MediaURI: simtypes.RandStringOfLength(r, 45),
}
}
func RandRoyaltyShare(r *rand.Rand) sdk.Dec {
return simtypes.RandomDecAmount(r, sdk.NewDecWithPrec(999999999999999999, 18))
}