-
Notifications
You must be signed in to change notification settings - Fork 8
/
name_voucher_test.go
345 lines (310 loc) · 9.5 KB
/
name_voucher_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
335
336
337
338
339
340
341
342
343
344
345
package test_main
import (
"fmt"
"testing"
. "github.com/bjartek/overflow"
"github.com/hexops/autogold"
"github.com/stretchr/testify/assert"
)
func TestNameVoucher(t *testing.T) {
otu := NewOverflowTest(t).
setupFIND().
createUser(10.0, "user1")
initUser := func(s string) *OverflowTestUtils {
otu.O.Tx(
"initNameVoucher",
WithSigner(s),
).
AssertSuccess(otu.T)
return otu
}
var id uint64
var err error
// User 1 : have collection set up
// User 2 : does not have collection
t.Run("Should be able to mint NFT to User 1 with collection", func(t *testing.T) {
initUser("user1")
minCharLength := 4
id, err = otu.O.Tx(
"adminMintAndAirdropNameVoucher",
WithSigner("find-admin"),
WithAddresses("users", "user1"),
WithArg("minCharLength", minCharLength),
).
AssertSuccess(t).
AssertEvent(t, "Minted", map[string]interface{}{
"address": otu.O.Address("find"),
"minCharLength": minCharLength,
}).
AssertEvent(t, "Deposit", map[string]interface{}{
"to": otu.O.Address("user1"),
}).
GetIdFromEvent("Minted", "id")
assert.NoError(t, err)
})
t.Run("Should be able to use the name for register new name", func(t *testing.T) {
otu.O.Tx(
"redeemNameVoucher",
WithSigner("user1"),
WithArg("id", id),
WithArg("name", "test"),
).
AssertSuccess(t).
AssertEvent(t, "Redeemed", map[string]interface{}{
"id": id,
"address": otu.O.Address("user1"),
"minCharLength": 4,
"findName": "test",
"action": "register",
})
})
otu.createDapperUser("user2")
var ticketID uint64
t.Run("Should be able to mint NFT to User 1 without collection", func(t *testing.T) {
minCharLength := 5
res := otu.O.Tx(
"adminMintAndAirdropNameVoucher",
WithSigner("find-admin"),
WithAddresses("users", "user2"),
WithArg("minCharLength", minCharLength),
).
AssertSuccess(t).
AssertEvent(t, "Minted", map[string]interface{}{
"address": otu.O.Address("find"),
"minCharLength": minCharLength,
}).
AssertEvent(t, "AirdroppedToLostAndFound", map[string]interface{}{
"from": otu.O.Address("find"),
"to": otu.O.Address("user2"),
})
ticketID, err = res.GetIdFromEvent("AirdroppedToLostAndFound", "ticketID")
assert.NoError(t, err)
id, err = res.GetIdFromEvent("Minted", "id")
assert.NoError(t, err)
})
t.Run("Should be able to use the name for register new name in LostAndFound directly", func(t *testing.T) {
otu.O.Tx(
"redeemNameVoucher",
WithSigner("user2"),
WithArg("id", ticketID),
WithArg("name", "testingisgood"),
).
AssertSuccess(t).
AssertEvent(t, "NameVoucher.Redeemed", map[string]interface{}{
"id": id,
"address": otu.O.Address("user2"),
"minCharLength": 5,
"findName": "testingisgood",
"action": "register",
})
})
type TestCase struct {
NameVoucherLength uint64
Names map[bool][]string
ExpectedAction string
}
tcs := []TestCase{
{
NameVoucherLength: 3,
Names: map[bool][]string{
true: {"aaa", "aaaa", "aaaaa", "aaaaaaaaaaa"},
},
ExpectedAction: "register",
},
{
NameVoucherLength: 4,
Names: map[bool][]string{
false: {"bbb"},
true: {"bbbb", "bbbbb", "bbbbbbbbbbbbbb"},
},
ExpectedAction: "register",
},
{
NameVoucherLength: 5,
Names: map[bool][]string{
false: {"ccc", "cccc"},
true: {"ccccc", "ccccccc", "cccccccccccc"},
},
ExpectedAction: "register",
},
{
NameVoucherLength: 3,
Names: map[bool][]string{
true: {"aaa", "aaaa", "aaaaa", "aaaaaaaaaaa"},
},
ExpectedAction: "renew",
},
}
for _, tf := range tcs {
for success, names := range tf.Names {
for _, name := range names {
msg := "Should %sbe able to redeem a voucher and %s a %d character name. Name : %s"
var s string
if !success {
s = "not "
}
adminSigner := "find-admin"
user := "user1"
t.Run(fmt.Sprintf(msg, s, tf.ExpectedAction, tf.NameVoucherLength, name), func(t *testing.T) {
// send out the voucher and get prepared
id, err := otu.O.Tx(
"adminMintAndAirdropNameVoucher",
WithSigner(adminSigner),
WithAddresses("users", user),
WithArg("minCharLength", tf.NameVoucherLength),
).
AssertSuccess(t).
GetIdFromEvent("Minted", "id")
assert.NoError(t, err)
// redeem executes here
res := otu.O.Tx(
"redeemNameVoucher",
WithSigner(user),
WithArg("id", id),
WithArg("name", name),
)
if success {
res.AssertSuccess(t).
AssertEvent(t, "Redeemed", map[string]interface{}{
"id": id,
"address": otu.O.Address(user),
"minCharLength": tf.NameVoucherLength,
"findName": name,
"action": tf.ExpectedAction,
}).
AssertEvent(t, "Register", map[string]interface{}{
"owner": otu.O.Address(user),
"name": name,
})
return
}
res.AssertFailure(t, fmt.Sprintf("You are trying to register a %d character name, but the voucher can only support names with minimun character of %d", len(name), tf.NameVoucherLength))
})
}
}
}
nameVoucherLength := 4
id, err = otu.O.Tx(
"adminMintAndAirdropNameVoucher",
WithSigner("find-admin"),
WithAddresses("users", "user1"),
WithArg("minCharLength", nameVoucherLength),
).
AssertSuccess(t).
GetIdFromEvent("Minted", "id")
assert.NoError(t, err)
type PointerWant struct {
pointer string
expected autogold.Value
}
type ViewTestCase struct {
view string
cases []PointerWant
}
viewsTC := []ViewTestCase{
{
view: "Display",
cases: []PointerWant{
{
pointer: "/name",
expected: autogold.Want("display_name", fmt.Sprintf("%d-characters .find name voucher", nameVoucherLength)),
},
{
pointer: "/description",
expected: autogold.Want("display_description", `This voucher entitles the holder to claim or extend any available or owned .find name with 4 characters or more. It is valid for one-time use only and will be voided after the successful registration or extension of a .find name.
If you received this voucher via airdrop, check your inbox to claim it. Once claimed, it will be added to your collection. To use the voucher, follow these steps:
Log in to your account.
Navigate to the Collection page and locate the voucher you wish to use.
Click the “Use Voucher” button and follow the on-screen instructions to register a new .find name or extend an existing one.
Upon successful completion, the voucher will be invalidated, and the chosen .find name will be registered or extended under your account.`),
},
{
pointer: "/thumbnail/cid",
expected: autogold.Want("display_thumbnail", "QmWpQRvGudYrkZw6rKKTrkghkYKs4wt3KQGzxcXJ8JmuSc"),
},
},
},
{
view: "ExternalURL",
cases: []PointerWant{
{
pointer: "/url",
expected: autogold.Want("ExternalURL_url", fmt.Sprintf("https://find.xyz/%s/collection/nameVoucher/%d", otu.O.Address("user1"), id)),
},
},
},
{
view: "Royalties",
cases: []PointerWant{
{
pointer: "/cutInfos/0/cut",
expected: autogold.Want("Royalties_cut", 0.025),
},
{
pointer: "/cutInfos/0/description",
expected: autogold.Want("Royalties_description", "network"),
},
},
},
{
view: "NFTCollectionDisplay",
cases: []PointerWant{
{
pointer: "/name",
expected: autogold.Want("NFTCollectionDisplay_name", "NameVoucher"),
},
{
pointer: "/description",
expected: autogold.Want("NFTCollectionDisplay_description", "Name Vouchers can be used to claim or extend any available .find name of 3-characters or more, depending on voucher rarity. Vouchers can be used only once and will be destroyed after use. Enjoy!"),
},
{
pointer: "/externalURL",
expected: autogold.Want("NFTCollectionDisplay_externalURL", map[string]interface{}{"url": "https://find.xyz/"}),
},
{
pointer: "/squareImage",
expected: autogold.Want("NFTCollectionDisplay_squareImage", map[string]interface{}{
"file": map[string]interface{}{"url": "https://pbs.twimg.com/profile_images/1467546091780550658/R1uc6dcq_400x400.jpg"},
"mediaType": "image",
}),
},
{
pointer: "/bannerImage",
expected: autogold.Want("NFTCollectionDisplay_bannerImage", map[string]interface{}{
"file": map[string]interface{}{"url": "https://pbs.twimg.com/profile_banners/1448245049666510848/1674733461/1500x500"},
"mediaType": "image",
}),
},
{
pointer: "/socials",
expected: autogold.Want("NFTCollectionDisplay_socials", map[string]interface{}{"discord": map[string]interface{}{"url": "https://discord.gg/findonflow"}, "twitter": map[string]interface{}{"url": "https://twitter.com/findonflow"}}),
},
},
},
{
view: "Traits",
cases: []PointerWant{
{
pointer: "/traits/0",
expected: autogold.Want("Traits_first", map[string]interface{}{"displayType": "number", "name": "Minimum number of characters", "value": nameVoucherLength}),
},
},
},
}
for _, tc := range viewsTC {
for _, p := range tc.cases {
t.Run(fmt.Sprintf("should get %s view with %s", tc.view, p.expected.Name()), func(t *testing.T) {
iden, err := otu.O.QualifiedIdentifier("MetadataViews", tc.view)
assert.NoError(t, err)
otu.O.Script(
"view",
WithArg("user", "user1"),
WithArg("path", "/public/nameVoucher"),
WithArg("id", id),
WithArg("identifier", iden),
).
AssertWithPointerWant(t, p.pointer, p.expected)
})
}
}
}