-
Notifications
You must be signed in to change notification settings - Fork 8
/
find_verifier_test.go
334 lines (266 loc) · 10.9 KB
/
find_verifier_test.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package test_main
import (
"fmt"
"testing"
. "github.com/bjartek/overflow"
"github.com/hexops/autogold"
"github.com/stretchr/testify/assert"
)
func TestFindVerifier(t *testing.T) {
user := "user1"
otu := NewOverflowTest(t).
setupFIND().
createUser(10000.0, "user1").
registerUser("user1")
// Has One FLOAT
t.Run("Should return false if user have no float", func(t *testing.T) {
floatID := otu.createFloatEvent("find")
otu.O.Script("devFindVerifierHasOneFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{floatID, 0}),
).
AssertWant(t, autogold.Want("Has no float, false", map[string]interface{}{
"description": fmt.Sprintf("User with one of these FLOATs are verified : %d, %d", floatID, 0),
"result": false,
}))
})
t.Run("Should panic if no float is specified", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierHasOneFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{}),
).
GetAsInterface()
assert.Error(t, err)
})
t.Run("Should return true if user has one of the float", func(t *testing.T) {
floatID := otu.createFloatEvent("find")
otu.claimFloat("find", user, floatID)
otu.O.Script("devFindVerifierHasOneFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{floatID, 0}),
).
AssertWant(t, autogold.Want("Has one float, true", map[string]interface{}{
"description": fmt.Sprintf("User with one of these FLOATs are verified : %d, %d", floatID, 0),
"result": true,
}))
})
t.Run("Should return false if user doesn't have float contained", func(t *testing.T) {
claimedFloatID := otu.createFloatEvent("find")
notClaimedFloatID := otu.createFloatEvent("find")
otu.claimFloat("find", user, claimedFloatID)
otu.O.Script("devFindVerifierHasOneFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{notClaimedFloatID, 0}),
).
AssertWant(t, autogold.Want("Has one float, false", map[string]interface{}{
"description": fmt.Sprintf("User with one of these FLOATs are verified : %d, %d", notClaimedFloatID, 0),
"result": false,
}))
})
// Has All FLOAT
t.Run("Should return true if user has all of the float", func(t *testing.T) {
floatID := otu.createFloatEvent("find")
floatID2 := otu.createFloatEvent("find")
otu.claimFloat("find", user, floatID)
otu.claimFloat("find", user, floatID2)
otu.O.Script("devFindVerifierHasAllFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{floatID, floatID2}),
).
AssertWant(t, autogold.Want("Has all float, true", map[string]interface{}{
"description": fmt.Sprintf("User with all of these FLOATs are verified : %d, %d", floatID, floatID2),
"result": true,
}))
})
t.Run("Should return false if user doesn't have all float contained", func(t *testing.T) {
floatID := otu.createFloatEvent("find")
floatID2 := otu.createFloatEvent("find")
otu.claimFloat("find", user, floatID)
otu.claimFloat("find", user, floatID2)
otu.O.Script("devFindVerifierHasAllFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{floatID, floatID2, 0}),
).
AssertWant(t, autogold.Want("Has all float, false", map[string]interface{}{
"description": fmt.Sprintf("User with all of these FLOATs are verified : %d, %d, %d", floatID, floatID2, 0),
"result": false,
}))
})
t.Run("Should panic if no float is specified", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierHasAllFLOAT",
WithArg("user", otu.O.Address(user)),
WithArg("floatIDs", []uint64{}),
).
GetAsInterface()
assert.Error(t, err)
})
// WhiteLabel
t.Run("Should return true if user is in whiteLabel", func(t *testing.T) {
otu.O.Script("devFindVerifierIsInWhiteList",
WithArg("user", otu.O.Address(user)),
WithAddresses("addresses", user, "user2", "user3"),
).
AssertWant(t, autogold.Want("whitelabel, true", map[string]interface{}{
"description": fmt.Sprintf("Only these wallet addresses are verified : %s, %s, %s", otu.O.Address(user), otu.O.Address("user2"), otu.O.Address("user3")),
"result": true,
}))
})
t.Run("Should return true if user is not in whiteLabel", func(t *testing.T) {
otu.O.Script("devFindVerifierIsInWhiteList",
WithArg("user", otu.O.Address(user)),
WithAddresses("addresses", "user2", "user3"),
).
AssertWant(t, autogold.Want("whitelabel, false", map[string]interface{}{
"description": fmt.Sprintf("Only these wallet addresses are verified : %s, %s", otu.O.Address("user2"), otu.O.Address("user3")),
"result": false,
}))
})
t.Run("Should panic if no one is not in whiteLabel", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierIsInWhiteList",
WithArg("user", otu.O.Address(user)),
WithArg("addresses", "[]"),
).
GetAsInterface()
assert.Error(t, err)
})
// Has Find Name
t.Run("Should return true if user has the find name", func(t *testing.T) {
otu.O.Script("devFindVerifierHasFindName",
WithArg("user", otu.O.Address(user)),
WithArg("findNames", []string{"user1", "user2"}),
).
AssertWant(t, autogold.Want("HasFindName, true", map[string]interface{}{
"description": "Users with one of these find names are verified : user1, user2",
"result": true,
}))
})
t.Run("Should return false if user does not have the find name", func(t *testing.T) {
otu.O.Script("devFindVerifierHasFindName",
WithArg("user", otu.O.Address(user)),
WithArg("findNames", []string{"user2", "user3"}),
).
AssertWant(t, autogold.Want("HasFindName, false", map[string]interface{}{
"description": "Users with one of these find names are verified : user2, user3",
"result": false,
}))
})
t.Run("Should panic if no find name is specified", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierHasFindName",
WithArg("user", otu.O.Address(user)),
WithArg("findNames", "[]"),
).
GetAsInterface()
assert.Error(t, err)
})
t.Run("Should return false if user has no lease collection", func(t *testing.T) {
otu.O.Script("devFindVerifierHasFindName",
WithArg("user", otu.O.Address("user2")),
WithArg("findNames", []string{"user2", "user3"}),
).
AssertWant(t, autogold.Want("HasFindName user no lease collection, false", map[string]interface{}{
"description": "Users with one of these find names are verified : user2, user3",
"result": false,
}))
})
// Has No. of NFTs in Path
t.Run("Should return true if user has no of NFTs equal to threshold", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsInPath",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("threshold", 2),
).
AssertWant(t, autogold.Want("Has no. of NFT equal to threshold, true", map[string]interface{}{
"description": "Users with at least 2 nos. of NFT in path /public/exampleNFTCollection are verified",
"result": true,
}))
})
t.Run("Should return true if user has no of NFTs more than threshold", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsInPath",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("threshold", 1),
).
AssertWant(t, autogold.Want("Has no. of NFT more than threshold, true", map[string]interface{}{
"description": "Users with at least 1 nos. of NFT in path /public/exampleNFTCollection are verified",
"result": true,
}))
})
t.Run("Should return false if user has no of NFTs less than threshold", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsInPath",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("threshold", 100),
).
AssertWant(t, autogold.Want("Has no. of NFT less than threshold, false", map[string]interface{}{
"description": "Users with at least 100 nos. of NFT in path /public/exampleNFTCollection are verified",
"result": false,
}))
})
t.Run("Should panic if 0 threshold is specified", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierHasNFTsInPath",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("threshold", 0),
).
GetAsInterface()
assert.Error(t, err)
})
t.Run("Should return false if user has no collection", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsInPath",
WithArg("user", otu.O.Address("user3")),
WithArg("path", "exampleNFTCollection"),
WithArg("threshold", 3),
).
AssertWant(t, autogold.Want("Has no collection, false", map[string]interface{}{
"description": "Users with at least 3 nos. of NFT in path /public/exampleNFTCollection are verified",
"result": false,
}))
})
// HasNFTWithRarities
t.Run("Should return true if user has nft with specified rarity", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsWithRarity",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("rarityA", true),
WithArg("rarityB", true),
).
AssertWant(t, autogold.Want("has nft with specified rarity, true", map[string]interface{}{
"description": "Users with at least 1 NFT in path /public/exampleNFTCollection with one of these rarities are verified : description : rarity description, score : 1.00000000, max score : 2.00000000; description : fake rarity, score : 1.00000000, max score : 2.00000000; ",
"result": true,
}))
})
t.Run("Should return false if user does not have nft with specified rarity", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsWithRarity",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("rarityA", false),
WithArg("rarityB", true),
).
AssertWant(t, autogold.Want("does not have nft with specified rarity, false", map[string]interface{}{
"description": "Users with at least 1 NFT in path /public/exampleNFTCollection with one of these rarities are verified : description : fake rarity, score : 1.00000000, max score : 2.00000000; ",
"result": false,
}))
})
t.Run("Should panic if no rarity is specified", func(t *testing.T) {
_, err := otu.O.Script("devFindVerifierHasNFTsWithRarity",
WithArg("user", otu.O.Address("find")),
WithArg("path", "exampleNFTCollection"),
WithArg("rarityA", false),
WithArg("rarityB", false),
).
GetAsInterface()
assert.Error(t, err)
})
t.Run("Should return false if user has no collection specified for rarity", func(t *testing.T) {
otu.O.Script("devFindVerifierHasNFTsWithRarity",
WithArg("user", otu.O.Address("user3")),
WithArg("path", "exampleNFTCollection"),
WithArg("rarityA", true),
WithArg("rarityB", false),
).
AssertWant(t, autogold.Want("user has no collection, false", map[string]interface{}{
"description": "Users with at least 1 NFT in path /public/exampleNFTCollection with one of these rarities are verified : description : rarity description, score : 1.00000000, max score : 2.00000000; ",
"result": false,
}))
})
}