-
Notifications
You must be signed in to change notification settings - Fork 8
/
find_forge_test.go
487 lines (437 loc) · 15.3 KB
/
find_forge_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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
package test_main
import (
"context"
"fmt"
"os"
"testing"
. "github.com/bjartek/overflow"
"github.com/hexops/autogold"
"github.com/onflow/cadence"
"github.com/stretchr/testify/assert"
)
func TestFindForge(t *testing.T) {
otu := NewOverflowTest(t)
otu.setupFIND().
createUser(10000.0, "user1").
registerUser("user1").
buyForge("user1")
t.Run("Should be able to mint Example NFT and then get it by script", func(t *testing.T) {
exampleNFTIdentifier := exampleNFTType(otu)
otu.O.Tx("adminAddNFTCatalog",
WithSigner("find-admin"),
WithArg("collectionIdentifier", exampleNFTIdentifier),
WithArg("contractName", exampleNFTIdentifier),
WithArg("contractAddress", "find"),
WithArg("addressWithNFT", "find"),
WithArg("nftID", 0),
WithArg("publicPathIdentifier", "exampleNFTCollection"),
).
AssertSuccess(t)
otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertSuccess(t)
extraIDs, err := otu.O.Script(
`
import ExampleNFT from "../contracts/standard/ExampleNFT.cdc"
pub fun main() : UInt64 {return ExampleNFT.totalSupply - 1}
`,
).GetAsInterface()
assert.NoError(t, err)
otu.O.Script("getNFTCatalogIDs",
WithArg("user", "user1"),
WithArg("collections", `[]`),
).AssertWant(t,
autogold.Want("collection", map[string]interface{}{exampleNFTIdentifier: map[string]interface{}{
"collectionName": "The Example Collection",
"extraIDs": []interface{}{extraIDs},
"extraIDsIdentifier": exampleNFTIdentifier,
"length": 1,
"shard": "NFTCatalog",
}}),
)
})
exampleNFTForge := otu.identifier("ExampleNFT", "Forge")
t.Run("Should be able to add allowed names to private forges", func(t *testing.T) {
otu.O.Tx("adminRemoveForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
).AssertSuccess(t)
otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertFailure(t, fmt.Sprintf("This forge type is not supported. type : %s", exampleNFTForge))
otu.O.Tx("adminAddForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
WithArg("name", "user1"),
).AssertSuccess(t)
otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertSuccess(t)
otu.createUser(10000.0, "user2").
registerUser("user2").
buyForge("user2")
otu.O.Tx("devMintExampleNFT",
WithSigner("user2"),
WithArg("name", "user2"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertFailure(t, fmt.Sprintf("This forge is not supported publicly. Forge Type : %s", exampleNFTForge))
otu.O.Tx("adminAddForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
WithArg("name", "user2"),
).AssertSuccess(t)
otu.O.Tx("devMintExampleNFT",
WithSigner("user2"),
WithArg("name", "user2"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertSuccess(t)
})
t.Run("Should be able to add allowed names to private forges", func(t *testing.T) {
otu.O.Tx("adminRemoveForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
).AssertSuccess(t)
otu.O.Tx("adminAddForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
WithArg("name", "user1"),
).AssertSuccess(t)
price := 1000.0 / 0.42
otu.O.Tx("buyAddon",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("addon", "premiumForge"),
WithArg("maxAmount", price),
).AssertSuccess(t).
AssertEvent(t, otu.identifier("FIND", "AddonActivated"),
map[string]interface{}{
"name": "user1",
"addon": "premiumForge",
},
)
id, err := otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).AssertSuccess(t).
GetIdFromEvent("FindForge.Minted", "id")
if err != nil {
panic(err)
}
otu.O.Script("getNFTView",
WithArg("user", "user1"),
WithArg("aliasOrIdentifier", exampleNFTType(otu)),
WithArg("id", id),
WithArg("identifier", otu.identifier("MetadataViews", "Royalties")),
).AssertWant(t,
autogold.Want("royalty", map[string]interface{}{"cutInfos": []interface{}{map[string]interface{}{"cut": 0.05, "description": "creator", "receiver": fmt.Sprintf("Capability<&AnyResource{%s}>(address: %s, path: /public/findProfileReceiver)", otu.identifier("FungibleToken", "Receiver"), otu.O.Address("user1"))}}}),
)
})
t.Run("Should not be able to mint Example NFTs with non-exist traits", func(t *testing.T) {
otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3, 4}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).
Print().
AssertFailure(t, "This trait does not exist ID :4")
})
t.Run("Should be able register traits to Example NFT and then mint", func(t *testing.T) {
otu.O.Tx("devAddTraitsExampleNFT",
WithSigner("find-admin"),
WithArg("lease", "user1"),
).
AssertSuccess(t)
otu.O.Tx("devMintExampleNFT",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3, 4}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).
AssertSuccess(t)
})
t.Run("Should be able to add addon and mint for users as admin", func(t *testing.T) {
otu.registerUserWithName("user1", "testingname")
otu.O.Tx("adminAddAddon",
WithSigner("find-admin"),
WithArg("name", "testingname"),
WithArg("addon", "premiumForge"),
).
AssertSuccess(t).
AssertEvent(t, "AddonActivated", map[string]interface{}{
"name": "testingname",
"addon": "premiumForge",
})
otu.O.Tx("adminAddForge",
WithSigner("find-admin"),
WithArg("type", exampleNFTForge),
WithArg("name", "testingname"),
).AssertSuccess(t)
otu.O.Tx("devadminMintExampleNFT",
WithSigner("find-admin"),
WithArg("name", "testingname"),
WithArg("artist", "Bam"),
WithArg("nftName", "ExampleNFT"),
WithArg("nftDescription", "This is an ExampleNFT"),
WithArg("nftUrl", "This is an exampleNFT url"),
WithArg("traits", []uint64{1, 2, 3, 4}),
WithArg("collectionDescription", "Example NFT FIND"),
WithArg("collectionExternalURL", "Example NFT external url"),
WithArg("collectionSquareImage", "Example NFT square image"),
WithArg("collectionBannerImage", "Example NFT banner image"),
).
AssertSuccess(t)
})
type MetadataViews_NFTCollectionDisplay struct {
Socials map[string]MetadataViews_ExternalURL
SquareImage MetadataViews_Media_IPFS `cadence:"squareImage"`
BannerImage MetadataViews_Media_IPFS `cadence:"bannerImage"`
Name string
Description string
ExternalURL MetadataViews_ExternalURL `cadence:"externalURL"`
}
collectionDisplay := MetadataViews_NFTCollectionDisplay{
Name: "notSet",
Description: "testing",
ExternalURL: MetadataViews_ExternalURL{Url: "testing url"},
SquareImage: MetadataViews_Media_IPFS{
File: MetadataViews_IPFSFile{
Cid: "testing square",
Path: nil,
},
},
BannerImage: MetadataViews_Media_IPFS{
File: MetadataViews_IPFSFile{
Cid: "testing banner",
Path: nil,
},
},
Socials: map[string]MetadataViews_ExternalURL{
"twitter": {Url: "testing twitter"},
"discord": {Url: "testing discord"},
},
}
t.Run("Should be able to order Forges for contract", func(t *testing.T) {
testingName := "foo"
mintType := "DIM"
otu.O.Tx("register",
WithSigner("user1"),
WithArg("name", testingName),
WithArg("maxAmount", 500.0/0.42),
).AssertSuccess(t)
otu.O.Tx("buyAddon",
WithSigner("user1"),
WithArg("name", testingName),
WithArg("addon", "forge"),
WithArg("maxAmount", 50.0/0.42),
).
AssertSuccess(t).
AssertEvent(t, "AddonActivated", map[string]interface{}{
"name": testingName,
"addon": "forge",
})
otu.O.Tx("adminAddForgeMintType",
WithSigner("find-admin"),
WithArg("mintType", mintType),
).
AssertSuccess(t)
collectionDisplay.Name = testingName
otu.O.Tx("orderForge",
WithSigner("user1"),
WithArg("name", testingName),
WithArg("mintType", mintType),
WithArg("minterCut", 0.05),
WithArg("collectionDisplay", collectionDisplay),
).
Print().
AssertSuccess(t).
AssertEvent(t, "ForgeOrdered", map[string]interface{}{
"lease": testingName,
"mintType": mintType,
})
})
t.Run("Should be able to remove order as Admin", func(t *testing.T) {
testingName := "foo"
mintType := "DIM"
collectionDisplay.Name = testingName
otu.O.Tx("adminCancelForgeOrder",
WithSigner("find-admin"),
WithArg("name", testingName),
WithArg("mintType", mintType),
).
Print().
AssertSuccess(t).
AssertEvent(t, "ForgeOrderCancelled", map[string]interface{}{
"lease": testingName,
"mintType": mintType,
})
})
t.Run("Should be able to order as Admin", func(t *testing.T) {
testingName := "foo"
mintType := "DIM"
collectionDisplay.Name = testingName
otu.O.Tx("adminOrderForge",
WithSigner("find-admin"),
WithArg("name", testingName),
WithArg("mintType", mintType),
WithArg("minterCut", 0.05),
WithArg("collectionDisplay", collectionDisplay),
).
Print().
AssertSuccess(t).
AssertEvent(t, "ForgeOrdered", map[string]interface{}{
"lease": testingName,
"mintType": mintType,
})
})
// set User4 as admin, the account as find-forge on emulator (for deploying contracts)
otu.O.Tx("setup_fin_1_create_client", WithSigner("find-forge")).
AssertSuccess(otu.T).AssertNoEvents(otu.T)
// link in the server in the versus client
otu.O.Tx("setup_fin_2_register_client",
findSigner,
WithArg("ownerAddress", "find-forge"),
).AssertSuccess(otu.T).AssertNoEvents(otu.T)
t.Run("Should be able to deploy Forge recipe contract and fulfill the order", func(t *testing.T) {
file, err := os.ReadFile("./contracts/FindFooDIM.cdc")
assert.NoError(t, err)
err = otu.O.AddContract(context.Background(), "find-forge", file, []cadence.Value{}, "./contracts/FindFooDIM.cdc", false)
assert.NoError(t, err)
})
t.Run("Should be able to mint Foo NFT as user 1", func(t *testing.T) {
type FindForgeStruct_FindDIM struct {
Name string `cadence:"name"`
Description string `cadence:"description"`
ThumbnailHash string `cadence:"thumbnailHash"`
ExternalURL string `cadence:"externalURL"`
Edition uint64 `cadence:"edition"`
MaxEdition uint64 `cadence:"maxEdition"`
Descriptions map[string]string `cadence:"descriptions"`
Scalars map[string]float64 `cadence:"scalars"`
Boosts map[string]float64 `cadence:"boosts"`
BoostPercents map[string]float64 `cadence:"boostPercents"`
Levels map[string]float64 `cadence:"levels"`
Traits map[string]string `cadence:"traits"`
Dates map[string]float64 `cadence:"dates"`
Medias map[string]string `cadence:"medias"`
Extras map[string]interface{} `cadence:"extras"`
}
data := FindForgeStruct_FindDIM{
Name: "Name",
Description: "Description",
ThumbnailHash: "ThumbnailHash",
ExternalURL: "ExternalURL",
Edition: 1,
MaxEdition: 2,
Descriptions: map[string]string{
"Descriptions": "Descriptions",
},
Scalars: map[string]float64{
"Scalars": 1.0,
},
Boosts: map[string]float64{
"Boosts": 1.0,
},
BoostPercents: map[string]float64{
"BoostPercents": 1.0,
},
Levels: map[string]float64{
"Levels": 1.0,
},
Traits: map[string]string{
"Traits": "Traits",
},
Dates: map[string]float64{
"Dates": 1.0,
},
Medias: map[string]string{
"Traits": "Traits",
},
Extras: map[string]interface{}{},
}
otu.O.Tx("devmintFooDIMNFT",
WithSigner("user1"),
WithArg("name", "foo"),
WithArg("receivers", []string{"user1"}),
WithArg("data", []FindForgeStruct_FindDIM{
data,
}),
).
AssertSuccess(t).
AssertEvent(t, "FindFooDIM.Minted", map[string]interface{}{
"name": data.Name,
"description": data.Description,
"edition": data.Edition,
"maxEdition": data.MaxEdition,
})
})
}