-
Notifications
You must be signed in to change notification settings - Fork 44
/
utils.go
187 lines (161 loc) · 6 KB
/
utils.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package simulation
// DONTCOVER
import (
"math/rand"
"time"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/v7/x/profiles/types"
)
var (
randomBios = []string{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Vestibulum a nulla sed purus pellentesque euismod quis ut risus.",
"Morbi nec magna interdum, rhoncus nisl ac, posuere sapien.",
"Duis vitae nisi efficitur, lobortis neque at, bibendum ipsum.",
"Donec semper nisi vel mollis cursus.",
"Curabitur quis massa id libero posuere venenatis ac ac erat.",
"Morbi dictum elit vitae libero lobortis luctus.",
"Nam sit amet velit venenatis est scelerisque egestas vitae nec turpis.",
"Duis commodo sapien id ligula volutpat tincidunt in et est.",
"Cras et magna cursus, volutpat purus at, dictum diam.",
"Phasellus in arcu euismod, accumsan urna quis, consectetur enim.",
"Morbi tincidunt urna sit amet vulputate bibendum.",
"Etiam vehicula eros vel libero sollicitudin elementum.",
"Pellentesque at nunc ac orci consequat varius.",
"Donec aliquam libero eu purus cursus, in congue magna tempor.",
"Vivamus a dolor scelerisque, posuere justo quis, pharetra nibh.",
}
randomProfilePics = []string{
"https://shorturl.at/adnX3",
"https://shorturl.at/adnX4",
}
randomProfileCovers = []string{
"https://shorturl.at/cgpyF",
"https://shorturl.at/cgpyG",
}
feeCoins = sdk.NewCoins(
sdk.NewCoin("band", sdk.NewInt(10)),
sdk.NewCoin("atom", sdk.NewInt(10)),
sdk.NewCoin("desmos", sdk.NewInt(10)),
sdk.NewCoin("akt", sdk.NewInt(10)),
sdk.NewCoin("dvpn", sdk.NewInt(10)),
sdk.NewCoin("daric", sdk.NewInt(10)),
sdk.NewCoin("osmo", sdk.NewInt(10)),
sdk.NewCoin("regen", sdk.NewInt(10)),
)
)
// NewRandomProfiles returns number random profiles
func NewRandomProfiles(r *rand.Rand, accounts []simtypes.Account, number int) []*types.Profile {
var profiles = make([]*types.Profile, number)
for index := range profiles {
account := accounts[index]
profiles[index] = NewRandomProfile(r, authtypes.NewBaseAccount(
account.Address,
account.PubKey,
0,
0,
))
}
return profiles
}
// NewRandomProfile return a random ProfileData from random data and the given account
//
//nolint:interfacer
func NewRandomProfile(r *rand.Rand, account authtypes.AccountI) *types.Profile {
profile, err := types.NewProfile(
RandomDTag(r),
RandomNickname(r),
RandomBio(r),
types.NewPictures(RandomProfilePic(r), RandomProfileCover(r)),
time.Now(),
account,
)
if err != nil {
panic(err)
}
return profile
}
// RandomProfile picks and returns a random profile from an array
func RandomProfile(r *rand.Rand, accounts []*types.Profile) *types.Profile {
idx := r.Intn(len(accounts))
return accounts[idx]
}
// RandomDTagTransferRequest picks and returns a random DTag transfer request from an array of requests
func RandomDTagTransferRequest(r *rand.Rand, requests []types.DTagTransferRequest) types.DTagTransferRequest {
idx := r.Intn(len(requests))
return requests[idx]
}
// RandomChainLink picks and returns a random chain link from an array of chain links
func RandomChainLink(r *rand.Rand, links []types.ChainLink) types.ChainLink {
idx := r.Intn(len(links))
return links[idx]
}
// RandomDTag return a random DTag
func RandomDTag(r *rand.Rand) string {
// DTag must be at least 3 characters and at most 30
return simtypes.RandStringOfLength(r, simtypes.RandIntBetween(r, 6, 30))
}
// RandomNickname return a random nickname
func RandomNickname(r *rand.Rand) string {
return simtypes.RandStringOfLength(r, 30)
}
// RandomBio return a random bio value from the list of randomBios given
func RandomBio(r *rand.Rand) string {
idx := r.Intn(len(randomBios))
return randomBios[idx]
}
// RandomProfilePic return a random profile pic value from the list of randomProfilePics given
func RandomProfilePic(r *rand.Rand) string {
idx := r.Intn(len(randomProfilePics))
return randomProfilePics[idx]
}
// RandomProfileCover return a random profile cover from the list of randomProfileCovers
func RandomProfileCover(r *rand.Rand) string {
idx := r.Intn(len(randomProfileCovers))
return randomProfileCovers[idx]
}
// GetSimAccount gets the profile having the given address from the accs list
func GetSimAccount(address sdk.Address, accs []simtypes.Account) *simtypes.Account {
for _, acc := range accs {
if acc.Address.Equals(address) {
return &acc
}
}
return nil
}
// RandomNicknameParams return a random set of nickname params
func RandomNicknameParams(r *rand.Rand) types.NicknameParams {
randomMin := sdk.NewInt(int64(simtypes.RandIntBetween(r, 2, 3)))
randomMax := sdk.NewInt(int64(simtypes.RandIntBetween(r, 30, 1000)))
return types.NewNicknameParams(randomMin, randomMax)
}
// RandomDTagParams return a random set of nickname params
func RandomDTagParams(r *rand.Rand) types.DTagParams {
randomMin := sdk.NewInt(int64(simtypes.RandIntBetween(r, 3, 4)))
randomMax := sdk.NewInt(int64(simtypes.RandIntBetween(r, 30, 50)))
return types.NewDTagParams("^[A-Za-z0-9_]+$", randomMin, randomMax)
}
// RandomBioParams return a random biography param
func RandomBioParams(r *rand.Rand) types.BioParams {
randomMax := sdk.NewInt(int64(simtypes.RandIntBetween(r, 500, 1000)))
return types.NewBioParams(randomMax)
}
// RandomOracleParams return a random oracle param
func RandomOracleParams(r *rand.Rand) types.OracleParams {
randomMinCount := uint64(simtypes.RandIntBetween(r, 1, 20))
return types.NewOracleParams(
r.Uint64(),
uint64(simtypes.RandIntBetween(r, int(randomMinCount), int(randomMinCount)+50)),
randomMinCount,
uint64(simtypes.RandIntBetween(r, 1, 10000)),
uint64(simtypes.RandIntBetween(r, 1, 10000)),
simtypes.RandSubsetCoins(r, feeCoins)...,
)
}
// RandomAppLinksParams return a random appLinks param
func RandomAppLinksParams(r *rand.Rand) types.AppLinksParams {
randomDuration := time.Duration(simtypes.RandIntBetween(r, 60*60*24*14, 60*60*24*7*4*6)) * time.Second
return types.NewAppLinksParams(randomDuration)
}