git.delta.rocks / unique-network / refs/commits / 0a7dd513e470

difftreelog

yarn fix

Daniel Shiposha2022-07-04parent: #86d26e3.patch.diff
in: master

23 files changed

modifiedtests/src/rmrk/acceptNft.test.tsdiffbeforeafterboth
1import { expect } from "chai";1import {expect} from 'chai';
2import { getApiConnection } from "../substrate/substrate-api";2import {getApiConnection} from '../substrate/substrate-api';
3import {3import {
4 createCollection,4 createCollection,
5 mintNft,5 mintNft,
6 sendNft,6 sendNft,
7 acceptNft7 acceptNft,
8} from "./util/tx";8} from './util/tx';
9import { NftIdTuple } from "./util/fetch";9import {NftIdTuple} from './util/fetch';
10import { isNftChildOfAnother, expectTxFailure } from "./util/helpers";10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
1111
12describe("integration test: accept NFT", () => {12describe('integration test: accept NFT', () => {
13 let api: any;13 let api: any;
14 before(async () => { api = await getApiConnection(); });14 before(async () => { api = await getApiConnection(); });
1515
16 const alice = "//Alice";16 const alice = '//Alice';
17 const bob = "//Bob";17 const bob = '//Bob';
1818
19 const createTestCollection = async (issuerUri: string) => {19 const createTestCollection = async (issuerUri: string) => {
20 return await createCollection(20 return await createCollection(
21 api,21 api,
22 issuerUri,22 issuerUri,
23 "accept-metadata",23 'accept-metadata',
24 null,24 null,
25 "acpt"25 'acpt',
26 );26 );
27 }27 };
2828
29 it("accept NFT", async () => {29 it('accept NFT', async () => {
30 const ownerAlice = alice;30 const ownerAlice = alice;
31 const ownerBob = bob;31 const ownerBob = bob;
3232
33 const aliceCollectionId = await createTestCollection(alice);33 const aliceCollectionId = await createTestCollection(alice);
34 const bobCollectionId = await createTestCollection(bob);34 const bobCollectionId = await createTestCollection(bob);
3535
36 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");36 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
37 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");37 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
3838
39 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];39 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
4040
41 await sendNft(api, "pending", ownerBob, bobCollectionId, childNftId, newOwnerNFT);41 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);
42 await acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);42 await acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);
4343
44 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);44 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);
45 expect(isChild).to.be.true;45 expect(isChild).to.be.true;
46 });46 });
4747
48 it("[negative] unable to accept NFT by a not-an-owner", async () => {48 it('[negative] unable to accept NFT by a not-an-owner', async () => {
49 const ownerAlice = alice;49 const ownerAlice = alice;
50 const ownerBob = bob;50 const ownerBob = bob;
5151
52 const aliceCollectionId = await createTestCollection(alice);52 const aliceCollectionId = await createTestCollection(alice);
53 const bobCollectionId = await createTestCollection(bob);53 const bobCollectionId = await createTestCollection(bob);
5454
55 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");55 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
56 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");56 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
5757
58 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];58 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
5959
60 await sendNft(api, "pending", ownerBob, bobCollectionId, childNftId, newOwnerNFT);60 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);
61 const tx = acceptNft(api, bob, bobCollectionId, childNftId, newOwnerNFT);61 const tx = acceptNft(api, bob, bobCollectionId, childNftId, newOwnerNFT);
6262
63 await expectTxFailure(/rmrkCore\.NoPermission/, tx);63 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
64 });64 });
6565
66 it("[negative] unable to accept non-existing NFT", async () => {66 it('[negative] unable to accept non-existing NFT', async () => {
67 const collectionId = 0;67 const collectionId = 0;
68 const maxNftId = 0xFFFFFFFF;68 const maxNftId = 0xFFFFFFFF;
6969
70 const owner = alice;70 const owner = alice;
71 const aliceCollectionId = await createTestCollection(alice);71 const aliceCollectionId = await createTestCollection(alice);
7272
73 const parentNftId = await mintNft(api, alice, owner, aliceCollectionId, "parent-nft-metadata");73 const parentNftId = await mintNft(api, alice, owner, aliceCollectionId, 'parent-nft-metadata');
7474
75 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];75 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
7676
79 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);79 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
80 });80 });
8181
82 it("[negative] unable to accept NFT which is not sent", async () => {82 it('[negative] unable to accept NFT which is not sent', async () => {
83 const ownerAlice = alice;83 const ownerAlice = alice;
84 const ownerBob = bob;84 const ownerBob = bob;
8585
86 const aliceCollectionId = await createTestCollection(alice);86 const aliceCollectionId = await createTestCollection(alice);
87 const bobCollectionId = await createTestCollection(bob);87 const bobCollectionId = await createTestCollection(bob);
8888
89 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");89 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
90 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");90 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
9191
92 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];92 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
9393
modifiedtests/src/rmrk/addResource.test.tsdiffbeforeafterboth
1import { expect } from "chai";1import {expect} from 'chai';
2import { getApiConnection } from "../substrate/substrate-api";2import {getApiConnection} from '../substrate/substrate-api';
3import { NftIdTuple } from "./util/fetch";3import {NftIdTuple} from './util/fetch';
4import { expectTxFailure, getResourceById } from "./util/helpers";4import {expectTxFailure, getResourceById} from './util/helpers';
5import {5import {
6 addNftBasicResource,6 addNftBasicResource,
7 acceptNftResource,7 acceptNftResource,
10 sendNft,10 sendNft,
11 addNftSlotResource,11 addNftSlotResource,
12 addNftComposableResource,12 addNftComposableResource,
13} from "./util/tx";13} from './util/tx';
14import {RmrkTraitsResourceResourceInfo as ResourceInfo} from "@polkadot/types/lookup";14import {RmrkTraitsResourceResourceInfo as ResourceInfo} from '@polkadot/types/lookup';
1515
16describe("integration test: add NFT resource", () => {16describe('integration test: add NFT resource', () => {
17 const Alice = "//Alice";17 const Alice = '//Alice';
18 const Bob = "//Bob";18 const Bob = '//Bob';
19 const src = "test-res-src";19 const src = 'test-res-src';
20 const metadata = "test-res-metadata";20 const metadata = 'test-res-metadata';
21 const license = "test-res-license";21 const license = 'test-res-license';
22 const thumb = "test-res-thumb";22 const thumb = 'test-res-thumb';
2323
24 const nonexistentId = 99999;24 const nonexistentId = 99999;
2525
28 api = await getApiConnection();28 api = await getApiConnection();
29 });29 });
3030
31 it("add resource", async () => {31 it('add resource', async () => {
32 const collectionIdAlice = await createCollection(32 const collectionIdAlice = await createCollection(
33 api,33 api,
34 Alice,34 Alice,
35 "test-metadata",35 'test-metadata',
36 null,36 null,
37 "test-symbol"37 'test-symbol',
38 );38 );
3939
40 const nftAlice = await mintNft(40 const nftAlice = await mintNft(
41 api,41 api,
42 Alice,42 Alice,
43 Alice,43 Alice,
44 collectionIdAlice,44 collectionIdAlice,
45 "nft-metadata"45 'nft-metadata',
46 );46 );
4747
48 await addNftBasicResource(48 await addNftBasicResource(
49 api,49 api,
50 Alice,50 Alice,
51 "added",51 'added',
52 collectionIdAlice,52 collectionIdAlice,
53 nftAlice,53 nftAlice,
54 src,54 src,
55 metadata,55 metadata,
56 license,56 license,
57 thumb57 thumb,
58 );58 );
59 });59 });
6060
61 it('add a resource to the nested NFT', async () => {61 it('add a resource to the nested NFT', async () => {
62 const collectionIdAlice = await createCollection(62 const collectionIdAlice = await createCollection(
63 api,63 api,
64 Alice,64 Alice,
65 "test-metadata",65 'test-metadata',
66 null,66 null,
67 "test-symbol"67 'test-symbol',
68 );68 );
6969
70 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "parent-nft-metadata");70 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'parent-nft-metadata');
71 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "child-nft-metadata");71 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'child-nft-metadata');
7272
73 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];73 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];
7474
75 await sendNft(api, "sent", Alice, collectionIdAlice, childNftId, newOwnerNFT);75 await sendNft(api, 'sent', Alice, collectionIdAlice, childNftId, newOwnerNFT);
7676
77 await addNftBasicResource(77 await addNftBasicResource(
78 api,78 api,
79 Alice,79 Alice,
80 "added",80 'added',
81 collectionIdAlice,81 collectionIdAlice,
82 childNftId,82 childNftId,
83 src,83 src,
84 metadata,84 metadata,
85 license,85 license,
86 thumb86 thumb,
87 );87 );
88 });88 });
8989
90 it('add multiple resources', async () => {90 it('add multiple resources', async () => {
91 const collectionIdAlice = await createCollection(91 const collectionIdAlice = await createCollection(
92 api,92 api,
93 Alice,93 Alice,
94 "test-metadata",94 'test-metadata',
95 null,95 null,
96 "test-symbol"96 'test-symbol',
97 );97 );
9898
99 const nftAlice = await mintNft(99 const nftAlice = await mintNft(
100 api,100 api,
101 Alice,101 Alice,
102 Alice,102 Alice,
103 collectionIdAlice,103 collectionIdAlice,
104 "nft-metadata"104 'nft-metadata',
105 );105 );
106106
107 const baseId = 42;107 const baseId = 42;
108 const slotId = 10;108 const slotId = 10;
109 const parts = [0, 5, 2];109 const parts = [0, 5, 2];
110110
111 let resourcesInfo = [];111 const resourcesInfo = [];
112 const resourceNum = 4;112 const resourceNum = 4;
113113
114 const checkResource = async (resource: ResourceInfo, resType: string, expectedId: number, expected: {114 const checkResource = async (resource: ResourceInfo, resType: string, expectedId: number, expected: {
151 const firstBasicResourceId = await addNftBasicResource(151 const firstBasicResourceId = await addNftBasicResource(
152 api,152 api,
153 Alice,153 Alice,
154 "added",154 'added',
155 collectionIdAlice,155 collectionIdAlice,
156 nftAlice,156 nftAlice,
157 resourcesInfo[0].src,157 resourcesInfo[0].src,
158 resourcesInfo[0].metadata,158 resourcesInfo[0].metadata,
159 resourcesInfo[0].license,159 resourcesInfo[0].license,
160 resourcesInfo[0].thumb160 resourcesInfo[0].thumb,
161 );161 );
162162
163 const secondBasicResourceId = await addNftBasicResource(163 const secondBasicResourceId = await addNftBasicResource(
164 api,164 api,
165 Alice,165 Alice,
166 "added",166 'added',
167 collectionIdAlice,167 collectionIdAlice,
168 nftAlice,168 nftAlice,
169 resourcesInfo[1].src,169 resourcesInfo[1].src,
170 resourcesInfo[1].metadata,170 resourcesInfo[1].metadata,
171 resourcesInfo[1].license,171 resourcesInfo[1].license,
172 resourcesInfo[1].thumb172 resourcesInfo[1].thumb,
173 );173 );
174174
175 const composableResourceId = await addNftComposableResource(175 const composableResourceId = await addNftComposableResource(
176 api,176 api,
177 Alice,177 Alice,
178 "added",178 'added',
179 collectionIdAlice,179 collectionIdAlice,
180 nftAlice,180 nftAlice,
181 parts,181 parts,
189 const slotResourceId = await addNftSlotResource(189 const slotResourceId = await addNftSlotResource(
190 api,190 api,
191 Alice,191 Alice,
192 "added",192 'added',
193 collectionIdAlice,193 collectionIdAlice,
194 nftAlice,194 nftAlice,
195 baseId,195 baseId,
196 slotId,196 slotId,
197 resourcesInfo[3].src,197 resourcesInfo[3].src,
198 resourcesInfo[3].metadata,198 resourcesInfo[3].metadata,
199 resourcesInfo[3].license,199 resourcesInfo[3].license,
200 resourcesInfo[3].thumb200 resourcesInfo[3].thumb,
201 );201 );
202202
203 const firstResource = await getResourceById(api, collectionIdAlice, nftAlice, firstBasicResourceId);203 const firstResource = await getResourceById(api, collectionIdAlice, nftAlice, firstBasicResourceId);
217 const collectionIdAlice = await createCollection(217 const collectionIdAlice = await createCollection(
218 api,218 api,
219 Alice,219 Alice,
220 "test-metadata",220 'test-metadata',
221 null,221 null,
222 "test-symbol"222 'test-symbol',
223 );223 );
224224
225 const tx = addNftBasicResource(225 const tx = addNftBasicResource(
226 api,226 api,
227 Alice,227 Alice,
228 "added",228 'added',
229 collectionIdAlice,229 collectionIdAlice,
230 nonexistentId,230 nonexistentId,
231 src,231 src,
232 metadata,232 metadata,
233 license,233 license,
234 thumb234 thumb,
235 );235 );
236 236
237 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);237 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
241 const collectionIdAlice = await createCollection(241 const collectionIdAlice = await createCollection(
242 api,242 api,
243 Alice,243 Alice,
244 "test-metadata",244 'test-metadata',
245 null,245 null,
246 "test-symbol"246 'test-symbol',
247 );247 );
248248
249 const nftAlice = await mintNft(249 const nftAlice = await mintNft(
250 api,250 api,
251 Alice,251 Alice,
252 Alice,252 Alice,
253 collectionIdAlice,253 collectionIdAlice,
254 "nft-metadata"254 'nft-metadata',
255 );255 );
256256
257 const tx = addNftBasicResource(257 const tx = addNftBasicResource(
258 api,258 api,
259 Bob,259 Bob,
260 "added",260 'added',
261 collectionIdAlice,261 collectionIdAlice,
262 nftAlice,262 nftAlice,
263 src,263 src,
264 metadata,264 metadata,
265 license,265 license,
266 thumb266 thumb,
267 );267 );
268 268
269 await expectTxFailure(/rmrkCore\.NoPermission/, tx);269 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
273 const collectionIdAlice = await createCollection(273 const collectionIdAlice = await createCollection(
274 api,274 api,
275 Alice,275 Alice,
276 "test-metadata",276 'test-metadata',
277 null,277 null,
278 "test-symbol"278 'test-symbol',
279 );279 );
280280
281 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "parent-nft-metadata");281 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'parent-nft-metadata');
282 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "child-nft-metadata");282 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'child-nft-metadata');
283283
284 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];284 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];
285285
286 await sendNft(api, "sent", Alice, collectionIdAlice, childNftId, newOwnerNFT);286 await sendNft(api, 'sent', Alice, collectionIdAlice, childNftId, newOwnerNFT);
287287
288 const tx = addNftBasicResource(288 const tx = addNftBasicResource(
289 api,289 api,
290 Bob,290 Bob,
291 "added",291 'added',
292 collectionIdAlice,292 collectionIdAlice,
293 childNftId,293 childNftId,
294 src,294 src,
295 metadata,295 metadata,
296 license,296 license,
297 thumb297 thumb,
298 );298 );
299 299
300 await expectTxFailure(/rmrkCore\.NoPermission/, tx);300 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
301 });301 });
302302
303 it("accept resource", async () => {303 it('accept resource', async () => {
304 const collectionIdBob = await createCollection(304 const collectionIdBob = await createCollection(
305 api,305 api,
306 Bob,306 Bob,
307 "test-metadata",307 'test-metadata',
308 null,308 null,
309 "test-symbol"309 'test-symbol',
310 );310 );
311311
312 const nftAlice = await mintNft(312 const nftAlice = await mintNft(
313 api,313 api,
314 Bob,314 Bob,
315 Alice,315 Alice,
316 collectionIdBob,316 collectionIdBob,
317 "nft-metadata"317 'nft-metadata',
318 );318 );
319319
320 const resourceId = await addNftBasicResource(320 const resourceId = await addNftBasicResource(
321 api,321 api,
322 Bob,322 Bob,
323 "pending",323 'pending',
324 collectionIdBob,324 collectionIdBob,
325 nftAlice,325 nftAlice,
326 src,326 src,
327 metadata,327 metadata,
328 license,328 license,
329 thumb329 thumb,
330 );330 );
331331
332 await acceptNftResource(api, Alice, collectionIdBob, nftAlice, resourceId);332 await acceptNftResource(api, Alice, collectionIdBob, nftAlice, resourceId);
333 });333 });
334334
335 it("[negative]: unable to accept a non-existing resource", async () => {335 it('[negative]: unable to accept a non-existing resource', async () => {
336 const collectionIdBob = await createCollection(336 const collectionIdBob = await createCollection(
337 api,337 api,
338 Bob,338 Bob,
339 "test-metadata",339 'test-metadata',
340 null,340 null,
341 "test-symbol"341 'test-symbol',
342 );342 );
343343
344 const nftAlice = await mintNft(344 const nftAlice = await mintNft(
345 api,345 api,
346 Bob,346 Bob,
347 Alice,347 Alice,
348 collectionIdBob,348 collectionIdBob,
349 "nft-metadata"349 'nft-metadata',
350 );350 );
351351
352 const tx = acceptNftResource(api, Alice, collectionIdBob, nftAlice, nonexistentId);352 const tx = acceptNftResource(api, Alice, collectionIdBob, nftAlice, nonexistentId);
353 await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);353 await expectTxFailure(/rmrkCore\.ResourceDoesntExist/, tx);
354 });354 });
355355
356 it("[negative]: unable to accept a resource by a not-an-NFT-owner user", async () => {356 it('[negative]: unable to accept a resource by a not-an-NFT-owner user', async () => {
357 const collectionIdBob = await createCollection(357 const collectionIdBob = await createCollection(
358 api,358 api,
359 Bob,359 Bob,
360 "test-metadata",360 'test-metadata',
361 null,361 null,
362 "test-symbol"362 'test-symbol',
363 );363 );
364364
365 const nftAlice = await mintNft(365 const nftAlice = await mintNft(
366 api,366 api,
367 Bob,367 Bob,
368 Alice,368 Alice,
369 collectionIdBob,369 collectionIdBob,
370 "nft-metadata"370 'nft-metadata',
371 );371 );
372372
373 const resourceId = await addNftBasicResource(373 const resourceId = await addNftBasicResource(
374 api,374 api,
375 Bob,375 Bob,
376 "pending",376 'pending',
377 collectionIdBob,377 collectionIdBob,
378 nftAlice,378 nftAlice,
379 src,379 src,
380 metadata,380 metadata,
381 license,381 license,
382 thumb382 thumb,
383 );383 );
384384
385 const tx = acceptNftResource(api, Bob, collectionIdBob, nftAlice, resourceId);385 const tx = acceptNftResource(api, Bob, collectionIdBob, nftAlice, resourceId);
386386
387 await expectTxFailure(/rmrkCore\.NoPermission/, tx);387 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
388 });388 });
389389
390 it("[negative]: unable to accept a resource to a non-target NFT", async () => {390 it('[negative]: unable to accept a resource to a non-target NFT', async () => {
391 const collectionIdBob = await createCollection(391 const collectionIdBob = await createCollection(
392 api,392 api,
393 Bob,393 Bob,
394 "test-metadata",394 'test-metadata',
395 null,395 null,
396 "test-symbol"396 'test-symbol',
397 );397 );
398398
399 const nftAlice = await mintNft(399 const nftAlice = await mintNft(
400 api,400 api,
401 Bob,401 Bob,
402 Alice,402 Alice,
403 collectionIdBob,403 collectionIdBob,
404 "nft-metadata"404 'nft-metadata',
405 );405 );
406406
407 const wrongNft = await mintNft(407 const wrongNft = await mintNft(
408 api,408 api,
409 Bob,409 Bob,
410 Alice,410 Alice,
411 collectionIdBob,411 collectionIdBob,
412 "nft-metadata"412 'nft-metadata',
413 );413 );
414 414
415 const resourceId = await addNftBasicResource(415 const resourceId = await addNftBasicResource(
416 api,416 api,
417 Bob,417 Bob,
418 "pending",418 'pending',
419 collectionIdBob,419 collectionIdBob,
420 nftAlice,420 nftAlice,
421 src,421 src,
422 metadata,422 metadata,
423 license,423 license,
424 thumb424 thumb,
425 );425 );
426426
427 const tx = acceptNftResource(api, Bob, collectionIdBob, wrongNft, resourceId);427 const tx = acceptNftResource(api, Bob, collectionIdBob, wrongNft, resourceId);
modifiedtests/src/rmrk/addTheme.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import { getApiConnection } from '../substrate/substrate-api';2import {getApiConnection} from '../substrate/substrate-api';
3import { createBase, addTheme } from "./util/tx";3import {createBase, addTheme} from './util/tx';
4import { expectTxFailure } from './util/helpers';4import {expectTxFailure} from './util/helpers';
5import { getThemeNames } from './util/fetch';5import {getThemeNames} from './util/fetch';
66
7describe("integration test: add Theme to Base", () => {7describe('integration test: add Theme to Base', () => {
8 let api: any;8 let api: any;
9 before(async () => { api = await getApiConnection(); });9 before(async () => { api = await getApiConnection(); });
1010
11 const alice = "//Alice";11 const alice = '//Alice';
12 const bob = "//Bob";12 const bob = '//Bob';
1313
14 it("add default theme", async () => {14 it('add default theme', async () => {
15 const baseId = await createBase(api, alice, "default-themed-base", "DTBase", []);15 const baseId = await createBase(api, alice, 'default-themed-base', 'DTBase', []);
16 await addTheme(api, alice, baseId, {16 await addTheme(api, alice, baseId, {
17 name: "default",17 name: 'default',
18 properties: [18 properties: [
19 {19 {
20 key: "some-key",20 key: 'some-key',
21 value: "some-key-value"21 value: 'some-key-value',
22 },22 },
23 {23 {
24 key: "another-key",24 key: 'another-key',
25 value: "another-key-value"25 value: 'another-key-value',
26 }26 },
27 ]27 ],
28 });28 });
29 });29 });
3030
31 it("add default theme and a custom one", async () => {31 it('add default theme and a custom one', async () => {
32 const baseId = await createBase(api, alice, "2-themed-base", "2TBase", []);32 const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);
33 await addTheme(api, alice, baseId, {33 await addTheme(api, alice, baseId, {
34 name: "default",34 name: 'default',
35 properties: [35 properties: [
36 {36 {
37 key: "default-key",37 key: 'default-key',
38 value: "default-key-value"38 value: 'default-key-value',
39 }39 },
40 ]40 ],
41 });41 });
42 await addTheme(api, alice, baseId, {42 await addTheme(api, alice, baseId, {
43 name: "custom-theme",43 name: 'custom-theme',
44 properties: [44 properties: [
45 {45 {
46 key: "custom-key-0",46 key: 'custom-key-0',
47 value: "custom-key-value-0"47 value: 'custom-key-value-0',
48 },48 },
49 {49 {
50 key: "custom-key-1",50 key: 'custom-key-1',
51 value: "custom-key-value-1"51 value: 'custom-key-value-1',
52 }52 },
53 ]53 ],
54 })54 });
55 });55 });
5656
57 it("fetch filtered theme keys", async () => {57 it('fetch filtered theme keys', async () => {
58 const baseId = await createBase(api, alice, "2-themed-base", "2TBase", []);58 const baseId = await createBase(api, alice, '2-themed-base', '2TBase', []);
59 await addTheme(api, alice, baseId, {59 await addTheme(api, alice, baseId, {
60 name: "default",60 name: 'default',
61 properties: [61 properties: [
62 {62 {
63 key: "first-key",63 key: 'first-key',
64 value: "first-key-value"64 value: 'first-key-value',
65 },65 },
66 {66 {
67 key: "second-key",67 key: 'second-key',
68 value: "second-key-value"68 value: 'second-key-value',
69 }69 },
70 ]70 ],
71 }, ["second-key"]);71 }, ['second-key']);
72 });72 });
7373
74 it("fetch theme names", async() => {74 it('fetch theme names', async() => {
75 const baseId = await createBase(api, alice, "3-themed-base", "3TBase", []);75 const baseId = await createBase(api, alice, '3-themed-base', '3TBase', []);
76 const names = [76 const names = [
77 "default",77 'default',
78 "first-theme",78 'first-theme',
79 "second-theme"79 'second-theme',
80 ];80 ];
8181
82 for (var i = 0; i < names.length; i++) {82 for (var i = 0; i < names.length; i++) {
90 (name) => name === names[i]
91 ) !== undefined;
9290
93 expect(isFound, "Error: invalid theme names").to.be.true;91 expect(isFound, 'Error: invalid theme names').to.be.true;
94 }92 }
95 });93 });
9694
97 it("[negative] unable to add theme to non-existing base", async () => {95 it('[negative] unable to add theme to non-existing base', async () => {
98 const maxBaseId = 0xFFFFFFFF;96 const maxBaseId = 0xFFFFFFFF;
99 const tx = addTheme(api, alice, maxBaseId, {97 const tx = addTheme(api, alice, maxBaseId, {
100 name: "default",98 name: 'default',
101 properties: []99 properties: [],
102 });100 });
103101
104 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);102 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);
105 });103 });
106104
107 it("[negative] unable to add custom theme if no default theme", async () => {105 it('[negative] unable to add custom theme if no default theme', async () => {
108 const baseId = await createBase(api, alice, "no-default-themed-base", "NDTBase", []);106 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);
109 const tx = addTheme(api, alice, baseId, {107 const tx = addTheme(api, alice, baseId, {
110 name: "custom-theme",108 name: 'custom-theme',
111 properties: []109 properties: [],
112 });110 });
113111
114 await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);112 await expectTxFailure(/rmrkEquip\.NeedsDefaultThemeFirst/, tx);
115 });113 });
116114
117 it("[negative] unable to add theme by a not-an-owner", async () => {115 it('[negative] unable to add theme by a not-an-owner', async () => {
118 const baseId = await createBase(api, alice, "no-default-themed-base", "NDTBase", []);116 const baseId = await createBase(api, alice, 'no-default-themed-base', 'NDTBase', []);
119 const tx = addTheme(api, bob, baseId, {117 const tx = addTheme(api, bob, baseId, {
120 name: "default",118 name: 'default',
121 properties: []119 properties: [],
122 });120 });
123121
124 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);122 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);
modifiedtests/src/rmrk/burnNft.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from "./util/helpers";2import {expectTxFailure} from './util/helpers';
3import { NftIdTuple, getChildren } from './util/fetch';3import {NftIdTuple, getChildren} from './util/fetch';
4import { burnNft, createCollection, sendNft, mintNft } from "./util/tx";4import {burnNft, createCollection, sendNft, mintNft} from './util/tx';
55
6import chai from 'chai';6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
88
9chai.use(chaiAsPromised);9chai.use(chaiAsPromised);
10const expect = chai.expect;10const expect = chai.expect;
1111
12describe("integration test: burn nft", () => {12describe('integration test: burn nft', () => {
13 const Alice = "//Alice";13 const Alice = '//Alice';
14 const Bob = "//Bob";14 const Bob = '//Bob';
1515
16 let api: any;16 let api: any;
17 before(async () => {17 before(async () => {
18 api = await getApiConnection();18 api = await getApiConnection();
19 });19 });
2020
21 it("burn nft", async () => {21 it('burn nft', async () => {
22 await createCollection(22 await createCollection(
23 api,23 api,
24 Alice,24 Alice,
25 "test-metadata",25 'test-metadata',
26 null,26 null,
27 "test-symbol"27 'test-symbol',
28 ).then(async (collectionId) => {28 ).then(async (collectionId) => {
29 const nftId = await mintNft(29 const nftId = await mintNft(
30 api,30 api,
31 Alice,31 Alice,
32 Alice,32 Alice,
33 collectionId,33 collectionId,
34 "nft-metadata"34 'nft-metadata',
35 );35 );
36 await burnNft(api, Alice, collectionId, nftId);36 await burnNft(api, Alice, collectionId, nftId);
37 });37 });
38 });38 });
3939
40 it("burn nft with children", async () => {40 it('burn nft with children', async () => {
41 const collectionId = await createCollection(41 const collectionId = await createCollection(
42 api,42 api,
43 Alice,43 Alice,
44 "test-metadata",44 'test-metadata',
45 null,45 null,
46 "test-symbol"46 'test-symbol',
47 );47 );
4848
49 const parentNftId = await mintNft(49 const parentNftId = await mintNft(
50 api,50 api,
51 Alice,51 Alice,
52 Alice,52 Alice,
53 collectionId,53 collectionId,
54 "nft-metadata"54 'nft-metadata',
55 );55 );
5656
57 const childNftId = await mintNft(57 const childNftId = await mintNft(
58 api,58 api,
59 Alice,59 Alice,
60 Alice,60 Alice,
61 collectionId,61 collectionId,
62 "nft-metadata"62 'nft-metadata',
63 );63 );
6464
65 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];65 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
6666
67 await sendNft(api, "sent", Alice, collectionId, childNftId, newOwnerNFT);67 await sendNft(api, 'sent', Alice, collectionId, childNftId, newOwnerNFT);
6868
69 const childrenBefore = await getChildren(api, collectionId, parentNftId);69 const childrenBefore = await getChildren(api, collectionId, parentNftId);
70 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')70 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')
71 .to.be.true;71 .to.be.true;
7272
73 let child = childrenBefore[0];73 const child = childrenBefore[0];
74 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')74 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')
75 .to.be.true;75 .to.be.true;
7676
84 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;84 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;
85 });85 });
8686
87 it("burn child nft", async () => {87 it('burn child nft', async () => {
88 const collectionId = await createCollection(88 const collectionId = await createCollection(
89 api,89 api,
90 Alice,90 Alice,
91 "test-metadata",91 'test-metadata',
92 null,92 null,
93 "test-symbol"93 'test-symbol',
94 );94 );
9595
96 const parentNftId = await mintNft(96 const parentNftId = await mintNft(
97 api,97 api,
98 Alice,98 Alice,
99 Alice,99 Alice,
100 collectionId,100 collectionId,
101 "nft-metadata"101 'nft-metadata',
102 );102 );
103103
104 const childNftId = await mintNft(104 const childNftId = await mintNft(
105 api,105 api,
106 Alice,106 Alice,
107 Alice,107 Alice,
108 collectionId,108 collectionId,
109 "nft-metadata"109 'nft-metadata',
110 );110 );
111111
112 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];112 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
113113
114 await sendNft(api, "sent", Alice, collectionId, childNftId, newOwnerNFT);114 await sendNft(api, 'sent', Alice, collectionId, childNftId, newOwnerNFT);
115115
116 const childrenBefore = await getChildren(api, collectionId, parentNftId);116 const childrenBefore = await getChildren(api, collectionId, parentNftId);
117 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')117 expect(childrenBefore.length === 1, 'Error: parent NFT should have children')
118 .to.be.true;118 .to.be.true;
119119
120 let child = childrenBefore[0];120 const child = childrenBefore[0];
121 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')121 expect(child.collectionId.eq(collectionId), 'Error: invalid child collection Id')
122 .to.be.true;122 .to.be.true;
123123
131 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;131 expect(childrenAfter.length === 0, 'Error: children should be burned').to.be.true;
132 });132 });
133133
134 it("[negative] burn non-existing NFT", async () => {134 it('[negative] burn non-existing NFT', async () => {
135 await createCollection(135 await createCollection(
136 api,136 api,
137 Alice,137 Alice,
138 "test-metadata",138 'test-metadata',
139 null,139 null,
140 "test-symbol"140 'test-symbol',
141 ).then(async (collectionId) => {141 ).then(async (collectionId) => {
142 const tx = burnNft(api, Alice, collectionId, 99999);142 const tx = burnNft(api, Alice, collectionId, 99999);
143 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);143 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
144 });144 });
145 });145 });
146146
147 it("[negative] burn not an owner NFT user", async () => {147 it('[negative] burn not an owner NFT user', async () => {
148 await createCollection(148 await createCollection(
149 api,149 api,
150 Alice,150 Alice,
151 "test-metadata",151 'test-metadata',
152 null,152 null,
153 "test-symbol"153 'test-symbol',
154 ).then(async (collectionId) => {154 ).then(async (collectionId) => {
155 const nftId = await mintNft(155 const nftId = await mintNft(
156 api,156 api,
157 Alice,157 Alice,
158 Alice,158 Alice,
159 collectionId,159 collectionId,
160 "nft-metadata"160 'nft-metadata',
161 );161 );
162 const tx = burnNft(api, Bob, collectionId, nftId);162 const tx = burnNft(api, Bob, collectionId, nftId);
163 await expectTxFailure(/rmrkCore\.NoPermission/, tx);163 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
modifiedtests/src/rmrk/changeCollectionIssuer.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from "./util/helpers";2import {expectTxFailure} from './util/helpers';
3import {3import {
4 changeIssuer,4 changeIssuer,
5 createCollection,5 createCollection,
6} from "./util/tx";6} from './util/tx';
77
8describe("integration test: collection issuer", () => {8describe('integration test: collection issuer', () => {
9 const Alice = "//Alice";9 const Alice = '//Alice';
10 const Bob = "//Bob";10 const Bob = '//Bob';
1111
12 let api: any;12 let api: any;
13 before(async () => {13 before(async () => {
14 api = await getApiConnection();14 api = await getApiConnection();
15 });15 });
1616
17 it("change collection issuer", async () => {17 it('change collection issuer', async () => {
18 await createCollection(18 await createCollection(
19 api,19 api,
20 Alice,20 Alice,
21 "test-metadata",21 'test-metadata',
22 null,22 null,
23 "test-symbol"23 'test-symbol',
24 ).then(async (collectionId) => {24 ).then(async (collectionId) => {
25 await changeIssuer(api, Alice, collectionId, Bob);25 await changeIssuer(api, Alice, collectionId, Bob);
26 });26 });
27 });27 });
2828
29 it("[negative] change not an owner NFT collection issuer", async () => {29 it('[negative] change not an owner NFT collection issuer', async () => {
30 await createCollection(api, Bob, "test-metadata", null, "test-symbol").then(30 await createCollection(api, Bob, 'test-metadata', null, 'test-symbol').then(async (collectionId) => {
31 async (collectionId) => {
32 const tx = changeIssuer(api, Alice, collectionId, Bob);31 const tx = changeIssuer(api, Alice, collectionId, Bob);
33 await expectTxFailure(/rmrkCore\.NoPermission/, tx);32 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
34 }33 });
35 );
36 });34 });
3735
38 it("[negative] change non-existigit NFT collection issuer", async () => {36 it('[negative] change non-existigit NFT collection issuer', async () => {
39 await createCollection(37 await createCollection(
40 api,38 api,
41 Alice,39 Alice,
42 "test-metadata",40 'test-metadata',
43 null,41 null,
44 "test-symbol"42 'test-symbol',
45 ).then(async () => {43 ).then(async () => {
46 const tx = changeIssuer(api, Alice, 99999, Bob);44 const tx = changeIssuer(api, Alice, 99999, Bob);
47 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);45 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);
modifiedtests/src/rmrk/createBase.test.tsdiffbeforeafterboth
1import { getApiConnection } from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import { createCollection, createBase } from "./util/tx";2import {createCollection, createBase} from './util/tx';
33
4describe("integration test: create new Base", () => {4describe('integration test: create new Base', () => {
5 let api: any;5 let api: any;
6 before(async () => { api = await getApiConnection(); });6 before(async () => { api = await getApiConnection(); });
77
8 const alice = '//Alice';8 const alice = '//Alice';
99
10 it("create empty Base", async () => {10 it('create empty Base', async () => {
11 await createBase(api, alice, 'empty-base-type', 'EBase', []);11 await createBase(api, alice, 'empty-base-type', 'EBase', []);
12 });12 });
1313
14 it("create Base with fixed part", async () => {14 it('create Base with fixed part', async () => {
15 await createBase(api, alice, 'fixedpart-base-type', 'FPBase', [15 await createBase(api, alice, 'fixedpart-base-type', 'FPBase', [
16 {16 {
17 "FixedPart": {17 'FixedPart': {
18 id: 42,18 id: 42,
19 z: 0,19 z: 0,
20 src: "some-fixed-url"20 src: 'some-fixed-url',
21 }21 },
22 }22 },
23 ]);23 ]);
24 });24 });
2525
26 it("create Base with slot part (no collection)", async () => {26 it('create Base with slot part (no collection)', async () => {
27 await createBase(api, alice, 'slotpart-base-type', 'SPBase', [27 await createBase(api, alice, 'slotpart-base-type', 'SPBase', [
28 {28 {
29 "SlotPart": {29 'SlotPart': {
30 id: 112,30 id: 112,
31 equippable: "Empty",31 equippable: 'Empty',
32 z: 0,32 z: 0,
33 src: "some-fallback-slot-url"33 src: 'some-fallback-slot-url',
34 }34 },
35 }35 },
36 ]);36 ]);
37 });37 });
3838
39 it("create Base with slot part (any collection)", async () => {39 it('create Base with slot part (any collection)', async () => {
40 await createBase(api, alice, 'slotpartany-base-type', 'SPABase', [40 await createBase(api, alice, 'slotpartany-base-type', 'SPABase', [
41 {41 {
42 "SlotPart": {42 'SlotPart': {
43 id: 222,43 id: 222,
44 equippable: "All",44 equippable: 'All',
45 z: 1,45 z: 1,
46 src: "some-fallback-slot-url"46 src: 'some-fallback-slot-url',
47 }47 },
48 }48 },
49 ]);49 ]);
50 });50 });
5151
52 it("create Base with slot part (custom collections)", async () => {52 it('create Base with slot part (custom collections)', async () => {
53 const firstCollectionId = await createCollection(53 const firstCollectionId = await createCollection(
54 api,54 api,
55 alice,55 alice,
56 "first-collection-meta",56 'first-collection-meta',
57 null,57 null,
58 "first-collection"58 'first-collection',
59 );59 );
6060
61 const secondCollectionId = await createCollection(61 const secondCollectionId = await createCollection(
62 api,62 api,
63 alice,63 alice,
64 "first-collection-meta",64 'first-collection-meta',
65 null,65 null,
66 "first-collection"66 'first-collection',
67 );67 );
6868
69 await createBase(api, alice, "slotpartcustom-base-type", "SPCBase", [69 await createBase(api, alice, 'slotpartcustom-base-type', 'SPCBase', [
70 {70 {
71 "SlotPart": {71 'SlotPart': {
72 id: 1024,72 id: 1024,
73 equippable: {73 equippable: {
74 "Custom": [firstCollectionId, secondCollectionId]74 'Custom': [firstCollectionId, secondCollectionId],
75 },75 },
76 z: 2,76 z: 2,
77 src: "some-fallback-slot-url"77 src: 'some-fallback-slot-url',
78 }78 },
79 }79 },
80 ]);80 ]);
81 });81 });
8282
modifiedtests/src/rmrk/createCollection.test.tsdiffbeforeafterboth

no syntactic changes

modifiedtests/src/rmrk/deleteCollection.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from "./util/helpers";2import {expectTxFailure} from './util/helpers';
3import { createCollection, deleteCollection } from "./util/tx";3import {createCollection, deleteCollection} from './util/tx';
44
5describe("integration test: delete collection", () => {5describe('integration test: delete collection', () => {
6 let api: any;6 let api: any;
7 before(async () => {7 before(async () => {
8 api = await getApiConnection();8 api = await getApiConnection();
9 });9 });
1010
11 const Alice = "//Alice";11 const Alice = '//Alice';
12 const Bob = "//Bob";12 const Bob = '//Bob';
1313
14 it("delete NFT collection", async () => {14 it('delete NFT collection', async () => {
15 await createCollection(15 await createCollection(
16 api,16 api,
17 Alice,17 Alice,
18 "test-metadata",18 'test-metadata',
19 null,19 null,
20 "test-symbol"20 'test-symbol',
21 ).then(async (collectionId) => {21 ).then(async (collectionId) => {
22 await deleteCollection(api, Alice, collectionId.toString());22 await deleteCollection(api, Alice, collectionId.toString());
23 });23 });
24 });24 });
2525
26 it("[negative] delete non-existing NFT collection", async () => {26 it('[negative] delete non-existing NFT collection', async () => {
27 const tx = deleteCollection(api, Alice, "99999");27 const tx = deleteCollection(api, Alice, '99999');
28 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);28 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);
29 });29 });
3030
31 it("[negative] delete not an owner NFT collection", async () => {31 it('[negative] delete not an owner NFT collection', async () => {
32 await createCollection(32 await createCollection(
33 api,33 api,
34 Alice,34 Alice,
35 "test-metadata",35 'test-metadata',
36 null,36 null,
37 "test-symbol"37 'test-symbol',
38 ).then(async (collectionId) => {38 ).then(async (collectionId) => {
39 const tx = deleteCollection(api, Bob, collectionId.toString());39 const tx = deleteCollection(api, Bob, collectionId.toString());
40 await expectTxFailure(/uniques.NoPermission/, tx);40 await expectTxFailure(/uniques.NoPermission/, tx);
modifiedtests/src/rmrk/equipNft.test.tsdiffbeforeafterboth
1import { ApiPromise } from "@polkadot/api";1import {ApiPromise} from '@polkadot/api';
2import { expect } from "chai";2import {expect} from 'chai';
3import { getApiConnection } from "../substrate/substrate-api";3import {getApiConnection} from '../substrate/substrate-api';
4import { getNft, getParts, NftIdTuple } from "./util/fetch";4import {getNft, getParts, NftIdTuple} from './util/fetch';
5import { expectTxFailure } from "./util/helpers";5import {expectTxFailure} from './util/helpers';
6import {6import {
7 addNftComposableResource,7 addNftComposableResource,
8 addNftSlotResource,8 addNftSlotResource,
11 equipNft,11 equipNft,
12 mintNft,12 mintNft,
13 sendNft,13 sendNft,
14 unequipNft14 unequipNft,
15} from "./util/tx";15} from './util/tx';
1616
17const Alice = "//Alice";17const Alice = '//Alice';
18const Bob = "//Bob";18const Bob = '//Bob';
1919
20const composableParts: number[] = [5, 2, 7];20const composableParts: number[] = [5, 2, 7];
21const composableSrc = 'test-cmp-src';21const composableSrc = 'test-cmp-src';
34 return createCollection(34 return createCollection(
35 api,35 api,
36 Alice,36 Alice,
37 "test-metadata",37 'test-metadata',
38 null,38 null,
39 "test-symbol"39 'test-symbol',
40 );40 );
41}41}
4242
46 Alice,46 Alice,
47 Alice,47 Alice,
48 collectionId,48 collectionId,
49 "nft-metadata"49 'nft-metadata',
50 );50 );
51}51}
5252
5555
56 const parentNFT: NftIdTuple = [collectionId, parentNftId];56 const parentNFT: NftIdTuple = [collectionId, parentNftId];
5757
58 await sendNft(api, "sent", Alice, collectionId, nftChildId, parentNFT);58 await sendNft(api, 'sent', Alice, collectionId, nftChildId, parentNFT);
5959
60 return nftChildId;60 return nftChildId;
61}61}
6262
63async function createTestBase(api: ApiPromise): Promise<number> {63async function createTestBase(api: ApiPromise): Promise<number> {
64 return createBase(api, Alice, "test-base", "DTBase", [64 return createBase(api, Alice, 'test-base', 'DTBase', [
65 {65 {
66 SlotPart: {66 SlotPart: {
67 id: slotId,67 id: slotId,
68 equippable: "All",68 equippable: 'All',
69 z: 1,69 z: 1,
70 src: slotSrc,70 src: slotSrc,
71 },71 },
77 await addNftComposableResource(77 await addNftComposableResource(
78 api,78 api,
79 Alice,79 Alice,
80 "added",80 'added',
81 collectionId,81 collectionId,
82 nftId,82 nftId,
83 composableParts,83 composableParts,
84 baseId,84 baseId,
85 composableSrc,85 composableSrc,
86 composableMetadata,86 composableMetadata,
87 composableLicense,87 composableLicense,
88 composableThumb88 composableThumb,
89 );89 );
90}90}
9191
92async function addTestSlot(api: ApiPromise, collectionId: number, nftId: number, baseId: number, slotId: number): Promise<number> {92async function addTestSlot(api: ApiPromise, collectionId: number, nftId: number, baseId: number, slotId: number): Promise<number> {
93 return await addNftSlotResource(93 return await addNftSlotResource(
94 api,94 api,
95 Alice,95 Alice,
96 "added",96 'added',
97 collectionId,97 collectionId,
98 nftId,98 nftId,
99 baseId,99 baseId,
100 slotId,100 slotId,
101 slotSrc,101 slotSrc,
102 slotMetadata,102 slotMetadata,
103 slotLicense,103 slotLicense,
104 slotThumb104 slotThumb,
105 );105 );
106}106}
107107
108async function checkEquipStatus(108async function checkEquipStatus(
109 api: ApiPromise,109 api: ApiPromise,
110 expectedStatus: "equipped" | "unequipped",110 expectedStatus: 'equipped' | 'unequipped',
111 collectionId: number,111 collectionId: number,
112 nftId: number112 nftId: number,
113) {113) {
114 const itemNftDataOpt = await getNft(api, collectionId, nftId);114 const itemNftDataOpt = await getNft(api, collectionId, nftId);
115 expect(itemNftDataOpt.isSome, 'Error: unable to fetch item NFT data');115 expect(itemNftDataOpt.isSome, 'Error: unable to fetch item NFT data');
116116
117 const itemNftData = itemNftDataOpt.unwrap();117 const itemNftData = itemNftDataOpt.unwrap();
118 expect(itemNftData.equipped.isTrue, `Error: item NFT should be ${expectedStatus}`)118 expect(itemNftData.equipped.isTrue, `Error: item NFT should be ${expectedStatus}`)
119 .to.be.equal(expectedStatus === "equipped");119 .to.be.equal(expectedStatus === 'equipped');
120}120}
121121
122describe("integration test: Equip NFT", () => {122describe('integration test: Equip NFT', () => {
123123
124 let api: any;124 let api: any;
125 before(async () => {125 before(async () => {
126 api = await getApiConnection();126 api = await getApiConnection();
127 });127 });
128128
129 it("equip nft", async () => {129 it('equip nft', async () => {
130 const collectionId = await createTestCollection(api);130 const collectionId = await createTestCollection(api);
131 const nftParentId = await mintTestNft(api, collectionId);131 const nftParentId = await mintTestNft(api, collectionId);
132 const nftChildId = await mintChildNft(api, collectionId, nftParentId);132 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
141141
142 await equipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);142 await equipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);
143143
144 await checkEquipStatus(api, "equipped", collectionId, nftChildId);144 await checkEquipStatus(api, 'equipped', collectionId, nftChildId);
145 });145 });
146146
147 it("unequip nft", async () => {147 it('unequip nft', async () => {
148 const collectionId = await createTestCollection(api);148 const collectionId = await createTestCollection(api);
149 const nftParentId = await mintTestNft(api, collectionId);149 const nftParentId = await mintTestNft(api, collectionId);
150 const nftChildId = await mintChildNft(api, collectionId, nftParentId);150 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
159159
160 await equipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);160 await equipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);
161161
162 await checkEquipStatus(api, "equipped", collectionId, nftChildId);162 await checkEquipStatus(api, 'equipped', collectionId, nftChildId);
163163
164 await unequipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);164 await unequipNft(api, Alice, itemNFT, equipperNFT, resourceId, baseId, slotId);
165 await checkEquipStatus(api, "unequipped", collectionId, nftChildId);165 await checkEquipStatus(api, 'unequipped', collectionId, nftChildId);
166 });166 });
167167
168 it("[negative] equip NFT onto non-existing NFT", async () => {168 it('[negative] equip NFT onto non-existing NFT', async () => {
169 const collectionId = await createTestCollection(api);169 const collectionId = await createTestCollection(api);
170170
171 const nftChildId = await mintNft(171 const nftChildId = await mintNft(
172 api,172 api,
173 Alice,173 Alice,
174 Alice,174 Alice,
175 collectionId,175 collectionId,
176 "nft-metadata"176 'nft-metadata',
177 );177 );
178178
179 const itemNFT: NftIdTuple = [collectionId, nftChildId];179 const itemNFT: NftIdTuple = [collectionId, nftChildId];
186 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);186 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
187 });187 });
188188
189 it("[negative] equip non-existing NFT", async () => {189 it('[negative] equip non-existing NFT', async () => {
190 const collectionId = await createTestCollection(api);190 const collectionId = await createTestCollection(api);
191 const nftParentId = await mintNft(191 const nftParentId = await mintNft(
192 api,192 api,
193 Alice,193 Alice,
194 Alice,194 Alice,
195 collectionId,195 collectionId,
196 "nft-metadata"196 'nft-metadata',
197 );197 );
198198
199 const baseId = await createTestBase(api);199 const baseId = await createTestBase(api);
209 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);209 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
210 });210 });
211211
212 it("[negative] equip NFT by a not-an-owner user", async () => {212 it('[negative] equip NFT by a not-an-owner user', async () => {
213 const collectionId = await createTestCollection(api);213 const collectionId = await createTestCollection(api);
214 const nftParentId = await mintTestNft(api, collectionId);214 const nftParentId = await mintTestNft(api, collectionId);
215 const nftChildId = await mintChildNft(api, collectionId, nftParentId);215 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
227 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);227 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);
228 });228 });
229229
230 it("[negative] unable to equip NFT onto indirect parent NFT", async () => {230 it('[negative] unable to equip NFT onto indirect parent NFT', async () => {
231 const collectionId = await createTestCollection(api);231 const collectionId = await createTestCollection(api);
232 const nftParentId = await mintTestNft(api, collectionId);232 const nftParentId = await mintTestNft(api, collectionId);
233 const nftChildId = await mintChildNft(api, collectionId, nftParentId);233 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
245 await expectTxFailure(/rmrkEquip\.MustBeDirectParent/, tx);245 await expectTxFailure(/rmrkEquip\.MustBeDirectParent/, tx);
246 });246 });
247247
248 it("[negative] unable to equip NFT onto parent NFT with another base", async () => {248 it('[negative] unable to equip NFT onto parent NFT with another base', async () => {
249 const collectionId = await createTestCollection(api);249 const collectionId = await createTestCollection(api);
250 const nftParentId = await mintTestNft(api, collectionId);250 const nftParentId = await mintTestNft(api, collectionId);
251 const nftChildId = await mintChildNft(api, collectionId, nftParentId);251 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
264 await expectTxFailure(/rmrkEquip\.NoResourceForThisBaseFoundOnNft/, tx);264 await expectTxFailure(/rmrkEquip\.NoResourceForThisBaseFoundOnNft/, tx);
265 });265 });
266266
267 it("[negative] unable to equip NFT into slot with another id", async () => {267 it('[negative] unable to equip NFT into slot with another id', async () => {
268 const collectionId = await createTestCollection(api);268 const collectionId = await createTestCollection(api);
269 const nftParentId = await mintTestNft(api, collectionId);269 const nftParentId = await mintTestNft(api, collectionId);
270 const nftChildId = await mintChildNft(api, collectionId, nftParentId);270 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
282 await expectTxFailure(/rmrkEquip\.ItemHasNoResourceToEquipThere/, tx);282 await expectTxFailure(/rmrkEquip\.ItemHasNoResourceToEquipThere/, tx);
283 });283 });
284284
285 it("[negative] unable to equip NFT with incorrect slot (fixed part)", async () => {285 it('[negative] unable to equip NFT with incorrect slot (fixed part)', async () => {
286 const collectionId = await createTestCollection(api);286 const collectionId = await createTestCollection(api);
287 const nftParentId = await mintTestNft(api, collectionId);287 const nftParentId = await mintTestNft(api, collectionId);
288 const nftChildId = await mintChildNft(api, collectionId, nftParentId);288 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
289289
290 const baseId = await createBase(api, Alice, "test-base", "DTBase", [290 const baseId = await createBase(api, Alice, 'test-base', 'DTBase', [
291 {291 {
292 FixedPart: {292 FixedPart: {
293 id: slotId,293 id: slotId,
294 equippable: "All",294 equippable: 'All',
295 z: 1,295 z: 1,
296 src: slotSrc,296 src: slotSrc,
297 },297 },
308 await expectTxFailure(/rmrkEquip\.CantEquipFixedPart/, tx);308 await expectTxFailure(/rmrkEquip\.CantEquipFixedPart/, tx);
309 });309 });
310310
311 it("[negative] unable to equip NFT from a collection that is not allowed by the slot", async () => {311 it('[negative] unable to equip NFT from a collection that is not allowed by the slot', async () => {
312 const collectionId = await createTestCollection(api);312 const collectionId = await createTestCollection(api);
313 const nftParentId = await mintTestNft(api, collectionId);313 const nftParentId = await mintTestNft(api, collectionId);
314 const nftChildId = await mintChildNft(api, collectionId, nftParentId);314 const nftChildId = await mintChildNft(api, collectionId, nftParentId);
315315
316 const baseId = await createBase(api, Alice, "test-base", "DTBase", [316 const baseId = await createBase(api, Alice, 'test-base', 'DTBase', [
317 {317 {
318 SlotPart: {318 SlotPart: {
319 id: 1,319 id: 1,
320 z: 1,320 z: 1,
321 equippable: "Empty",321 equippable: 'Empty',
322 src: slotSrc,322 src: slotSrc,
323 },323 },
324 },324 },
modifiedtests/src/rmrk/getOwnedNfts.test.tsdiffbeforeafterboth
3import { getOwnedNfts } from './util/fetch';3import {getOwnedNfts} from './util/fetch';
4import { mintNft, createCollection } from './util/tx';4import {mintNft, createCollection} from './util/tx';
55
6describe("integration test: get owned NFTs", () => {6describe('integration test: get owned NFTs', () => {
7 let api: any;7 let api: any;
8 before(async () => { api = await getApiConnection(); });8 before(async () => { api = await getApiConnection(); });
99
10 const alice = '//Alice';10 const alice = '//Alice';
1111
12 it("fetch all NFTs owned by a user", async () => {12 it('fetch all NFTs owned by a user', async () => {
13 const owner = alice;13 const owner = alice;
14 const collectionMetadata = 'aliceCollectionMetadata';14 const collectionMetadata = 'aliceCollectionMetadata';
15 const collectionMax = null;15 const collectionMax = null;
18 const royalty = null;18 const royalty = null;
19 const nftMetadata = 'alice-NFT-metadata';19 const nftMetadata = 'alice-NFT-metadata';
2020
21 let collectionId = await createCollection(21 const collectionId = await createCollection(
22 api,22 api,
23 alice,23 alice,
24 collectionMetadata,24 collectionMetadata,
6060
61 const isFound = (nftId: number) => {61 const isFound = (nftId: number) => {
62 return ownedNfts.find((ownedNftId) => {62 return ownedNfts.find((ownedNftId) => {
63 return ownedNftId === nftId63 return ownedNftId === nftId;
64 }) !== undefined;64 }) !== undefined;
65 };65 };
6666
67 nftIds.forEach((nftId) => {67 nftIds.forEach((nftId) => {
68 expect(isFound(nftId), `NFT ${nftId} should be owned by ${alice}`)68 expect(isFound(nftId), `NFT ${nftId} should be owned by ${alice}`)
69 .to.be.true69 .to.be.true;
70 });70 });
71 });71 });
7272
modifiedtests/src/rmrk/lockCollection.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from "./util/helpers";2import {expectTxFailure} from './util/helpers';
3import { createCollection, lockCollection, mintNft } from "./util/tx";3import {createCollection, lockCollection, mintNft} from './util/tx';
44
5describe("integration test: lock collection", () => {5describe('integration test: lock collection', () => {
6 const Alice = "//Alice";6 const Alice = '//Alice';
7 const Bob = "//Bob";7 const Bob = '//Bob';
8 const Max = 5;8 const Max = 5;
99
10 let api: any;10 let api: any;
11 before(async () => {11 before(async () => {
12 api = await getApiConnection();12 api = await getApiConnection();
13 });13 });
1414
15 it("lock collection", async () => {15 it('lock collection', async () => {
16 await createCollection(16 await createCollection(
17 api,17 api,
18 Alice,18 Alice,
19 "test-metadata",19 'test-metadata',
20 null,20 null,
21 "test-symbol"21 'test-symbol',
22 ).then(async (collectionId) => {22 ).then(async (collectionId) => {
23 await lockCollection(api, Alice, collectionId);23 await lockCollection(api, Alice, collectionId);
24 });24 });
25 });25 });
2626
27 it("[negative] lock non-existing NFT collection", async () => {27 it('[negative] lock non-existing NFT collection', async () => {
28 const tx = lockCollection(api, Alice, 99999);28 const tx = lockCollection(api, Alice, 99999);
29 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);29 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);
30 });30 });
3131
32 it("[negative] lock not an owner NFT collection issuer", async () => {32 it('[negative] lock not an owner NFT collection issuer', async () => {
33 await createCollection(33 await createCollection(
34 api,34 api,
35 Alice,35 Alice,
36 "test-metadata",36 'test-metadata',
37 null,37 null,
38 "test-symbol"38 'test-symbol',
39 ).then(async (collectionId) => {39 ).then(async (collectionId) => {
40 const tx = lockCollection(api, Bob, collectionId);40 const tx = lockCollection(api, Bob, collectionId);
41 await expectTxFailure(/rmrkCore\.NoPermission/, tx);41 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
42 });42 });
43 });43 });
4444
45 it("lock collection with minting", async () => {45 it('lock collection with minting', async () => {
46 await createCollection(46 await createCollection(
47 api,47 api,
48 Alice,48 Alice,
49 "test-metadata",49 'test-metadata',
50 Max,50 Max,
51 "test-symbol"51 'test-symbol',
52 ).then(async (collectionId) => {52 ).then(async (collectionId) => {
53 for (let i = 0; i < 5; i++) {53 for (let i = 0; i < 5; i++) {
54 await mintNft(54 await mintNft(
55 api,55 api,
56 Alice,56 Alice,
57 Alice,57 Alice,
58 collectionId,58 collectionId,
59 "test-metadata",59 'test-metadata',
60 null,60 null,
61 null61 null,
62 );62 );
63 }63 }
64 await lockCollection(api, Alice, collectionId, Max);64 await lockCollection(api, Alice, collectionId, Max);
65 });65 });
66 });66 });
6767
68 it("[negative] unable to mint NFT inside a locked collection", async () => {68 it('[negative] unable to mint NFT inside a locked collection', async () => {
69 await createCollection(69 await createCollection(
70 api,70 api,
71 Alice,71 Alice,
72 "test-metadata",72 'test-metadata',
73 Max,73 Max,
74 "test-symbol"74 'test-symbol',
75 ).then(async (collectionId) => {75 ).then(async (collectionId) => {
76 await lockCollection(api, Alice, collectionId);76 await lockCollection(api, Alice, collectionId);
77 const tx = mintNft(77 const tx = mintNft(
78 api,78 api,
79 Alice,79 Alice,
80 Alice,80 Alice,
81 collectionId,81 collectionId,
82 "test-metadata",82 'test-metadata',
83 null,83 null,
84 null84 null,
85 );85 );
86 await expectTxFailure(/rmrkCore\.CollectionFullOrLocked/, tx);86 await expectTxFailure(/rmrkCore\.CollectionFullOrLocked/, tx);
87 });87 });
88 });88 });
8989
90 it("[negative] unable to mint NFT inside a full collection", async () => {90 it('[negative] unable to mint NFT inside a full collection', async () => {
91 await createCollection(api, Alice, "test-metadata", 1, "test-symbol").then(91 await createCollection(api, Alice, 'test-metadata', 1, 'test-symbol').then(async (collectionId) => {
92 async (collectionId) => {
93 await mintNft(92 await mintNft(
94 api,93 api,
95 Alice,94 Alice,
96 Alice,95 Alice,
97 collectionId,96 collectionId,
98 "test-metadata",97 'test-metadata',
99 null,98 null,
100 null99 null,
101 );100 );
102 const tx = mintNft(101 const tx = mintNft(
103 api,102 api,
104 Alice,103 Alice,
105 Alice,104 Alice,
106 collectionId,105 collectionId,
107 "test-metadata",106 'test-metadata',
108 null,107 null,
109 null108 null,
110 );109 );
111 await expectTxFailure(/rmrkCore\.CollectionFullOrLocked/, tx);110 await expectTxFailure(/rmrkCore\.CollectionFullOrLocked/, tx);
112 }111 });
modifiedtests/src/rmrk/mintNft.test.tsdiffbeforeafterboth
4import { expectTxFailure } from './util/helpers';4import {expectTxFailure} from './util/helpers';
5import { createCollection, mintNft } from './util/tx';5import {createCollection, mintNft} from './util/tx';
66
7describe("integration test: mint new NFT", () => {7describe('integration test: mint new NFT', () => {
8 let api: any;8 let api: any;
9 before(async () => { api = await getApiConnection(); });9 before(async () => { api = await getApiConnection(); });
1010
13 const maxCollectionId = 0xFFFFFFFF;13 const maxCollectionId = 0xFFFFFFFF;
14 const maxNftId = 0xFFFFFFFF;14 const maxNftId = 0xFFFFFFFF;
1515
16 it("mint NFT", async () => {16 it('mint NFT', async () => {
17 const owner = null;17 const owner = null;
18 const collectionMetadata = 'mintingCollectionMetadata';18 const collectionMetadata = 'mintingCollectionMetadata';
19 const collectionMax = null;19 const collectionMax = null;
22 const royalty = null;22 const royalty = null;
23 const nftMetadata = 'NFT-test-metadata';23 const nftMetadata = 'NFT-test-metadata';
2424
25 let collectionId = await createCollection(25 const collectionId = await createCollection(
26 api,26 api,
27 alice,27 alice,
28 collectionMetadata,28 collectionMetadata,
41 );41 );
42 });42 });
4343
44 it("mint NFT and set another owner", async () => {44 it('mint NFT and set another owner', async () => {
45 const owner = bob;45 const owner = bob;
46 const collectionMetadata = 'setOwnerCollectionMetadata';46 const collectionMetadata = 'setOwnerCollectionMetadata';
47 const collectionMax = null;47 const collectionMax = null;
50 const royalty = null;50 const royalty = null;
51 const nftMetadata = 'setOwner-NFT-metadata';51 const nftMetadata = 'setOwner-NFT-metadata';
5252
53 let collectionId = await createCollection(53 const collectionId = await createCollection(
54 api,54 api,
55 alice,55 alice,
56 collectionMetadata,56 collectionMetadata,
69 );69 );
70 });70 });
7171
72 it("mint NFT with recipient and roalty", async () => {72 it('mint NFT with recipient and roalty', async () => {
73 const owner = alice;73 const owner = alice;
74 const collectionMetadata = 'mintingCollectionMetadata';74 const collectionMetadata = 'mintingCollectionMetadata';
75 const collectionMax = null;75 const collectionMax = null;
78 const royalty = 70000;78 const royalty = 70000;
79 const nftMetadata = 'recipient-royalty-NFT-test-metadata';79 const nftMetadata = 'recipient-royalty-NFT-test-metadata';
8080
81 let collectionId = await createCollection(81 const collectionId = await createCollection(
82 api,82 api,
83 alice,83 alice,
84 collectionMetadata,84 collectionMetadata,
97 );97 );
98 });98 });
9999
100 it("mint NFT with resources", async () => {100 it('mint NFT with resources', async () => {
101 const owner = alice;101 const owner = alice;
102 const collectionMetadata = 'mintingCollectionMetadata';102 const collectionMetadata = 'mintingCollectionMetadata';
103 const collectionMax = null;103 const collectionMax = null;
127 }127 },
128 ];128 ];
129129
130 let collectionId = await createCollection(130 const collectionId = await createCollection(
131 api,131 api,
132 alice,132 alice,
133 collectionMetadata,133 collectionMetadata,
146 );148 );
147 });149 });
148150
149 it("[negative] unable to mint NFT within non-existing collection", async () => {151 it('[negative] unable to mint NFT within non-existing collection', async () => {
150 const owner = alice;152 const owner = alice;
151 const recipientUri = null;153 const recipientUri = null;
152 const royalty = null;154 const royalty = null;
153 const nftMetadata = "NFT-test-metadata";155 const nftMetadata = 'NFT-test-metadata';
154156
155 const tx = mintNft(157 const tx = mintNft(
156 api,158 api,
167169
168 it("[negative] unable to mint NFT by a user that isn't the owner of the collection", async () => {170 it("[negative] unable to mint NFT by a user that isn't the owner of the collection", async () => {
169 const owner = alice;171 const owner = alice;
170 const collectionMetadata = "mintingCollectionMetadata";172 const collectionMetadata = 'mintingCollectionMetadata';
171 const collectionMax = null;173 const collectionMax = null;
172 const collectionSymbol = "MCS";174 const collectionSymbol = 'MCS';
173 const recipientUri = null;175 const recipientUri = null;
174 const royalty = null;176 const royalty = null;
175 const nftMetadata = "NFT-test-metadata";177 const nftMetadata = 'NFT-test-metadata';
176178
177 let collectionId = await createCollection(179 const collectionId = await createCollection(
178 api,180 api,
179 alice,181 alice,
180 collectionMetadata,182 collectionMetadata,
195 await expectTxFailure(/rmrkCore\.NoPermission/, tx);197 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
196 });198 });
197199
198 it("[negative] unable to fetch non-existing NFT", async () => {200 it('[negative] unable to fetch non-existing NFT', async () => {
199 const nft = await getNft(api, maxCollectionId, maxNftId);201 const nft = await getNft(api, maxCollectionId, maxNftId);
200 expect(nft.isSome).to.be.false;202 expect(nft.isSome).to.be.false;
201 });203 });
modifiedtests/src/rmrk/rejectNft.test.tsdiffbeforeafterboth
1import { expect } from "chai";1import {expect} from 'chai';
2import { getApiConnection } from "../substrate/substrate-api";2import {getApiConnection} from '../substrate/substrate-api';
3import {3import {
4 createCollection,4 createCollection,
5 mintNft,5 mintNft,
6 sendNft,6 sendNft,
7 rejectNft7 rejectNft,
8} from "./util/tx";8} from './util/tx';
9import { getChildren, NftIdTuple } from "./util/fetch";9import {getChildren, NftIdTuple} from './util/fetch';
10import { isNftChildOfAnother, expectTxFailure } from "./util/helpers";10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
1111
12describe("integration test: reject NFT", () => {12describe('integration test: reject NFT', () => {
13 let api: any;13 let api: any;
14 before(async () => { api = await getApiConnection(); });14 before(async () => { api = await getApiConnection(); });
1515
16 const alice = "//Alice";16 const alice = '//Alice';
17 const bob = "//Bob";17 const bob = '//Bob';
1818
19 const createTestCollection = async (issuerUri: string) => {19 const createTestCollection = async (issuerUri: string) => {
20 return await createCollection(20 return await createCollection(
21 api,21 api,
22 issuerUri,22 issuerUri,
23 "reject-metadata",23 'reject-metadata',
24 null,24 null,
25 "rjct"25 'rjct',
26 );26 );
27 }27 };
2828
29 it("reject NFT", async () => {29 it('reject NFT', async () => {
30 const ownerAlice = alice;30 const ownerAlice = alice;
31 const ownerBob = bob;31 const ownerBob = bob;
3232
33 const aliceCollectionId = await createTestCollection(alice);33 const aliceCollectionId = await createTestCollection(alice);
34 const bobCollectionId = await createTestCollection(bob);34 const bobCollectionId = await createTestCollection(bob);
3535
36 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");36 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
37 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");37 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
3838
39 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];39 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
4040
41 await sendNft(api, "pending", ownerBob, bobCollectionId, childNftId, newOwnerNFT);41 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);
42 await rejectNft(api, alice, bobCollectionId, childNftId);42 await rejectNft(api, alice, bobCollectionId, childNftId);
4343
44 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);44 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);
45 expect(isChild, 'Error: rejected NFT is still a child of the target NFT').to.be.false;45 expect(isChild, 'Error: rejected NFT is still a child of the target NFT').to.be.false;
46 });46 });
4747
48 it("[negative] unable to reject NFT by a not-an-owner", async () => {48 it('[negative] unable to reject NFT by a not-an-owner', async () => {
49 const ownerAlice = alice;49 const ownerAlice = alice;
50 const ownerBob = bob;50 const ownerBob = bob;
5151
52 const aliceCollectionId = await createTestCollection(alice);52 const aliceCollectionId = await createTestCollection(alice);
53 const bobCollectionId = await createTestCollection(bob);53 const bobCollectionId = await createTestCollection(bob);
5454
55 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");55 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
56 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");56 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
5757
58 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];58 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
5959
60 await sendNft(api, "pending", ownerBob, bobCollectionId, childNftId, newOwnerNFT);60 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);
61 const tx = rejectNft(api, bob, bobCollectionId, childNftId);61 const tx = rejectNft(api, bob, bobCollectionId, childNftId);
6262
63 await expectTxFailure(/rmrkCore\.CannotRejectNonOwnedNft/, tx);63 await expectTxFailure(/rmrkCore\.CannotRejectNonOwnedNft/, tx);
64 });64 });
6565
66 it("[negative] unable to reject non-existing NFT", async () => {66 it('[negative] unable to reject non-existing NFT', async () => {
67 const maxNftId = 0xFFFFFFFF;67 const maxNftId = 0xFFFFFFFF;
6868
69 const collectionId = await createTestCollection(alice);69 const collectionId = await createTestCollection(alice);
73 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);73 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
74 });74 });
7575
76 it("[negative] unable to reject NFT which is not sent", async () => {76 it('[negative] unable to reject NFT which is not sent', async () => {
77 const ownerAlice = alice;77 const ownerAlice = alice;
7878
79 const collectionId = await createTestCollection(alice);79 const collectionId = await createTestCollection(alice);
8080
81 const nftId = await mintNft(api, alice, ownerAlice, collectionId, "parent-nft-metadata");81 const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'parent-nft-metadata');
8282
83 const tx = rejectNft(api, alice, collectionId, nftId);83 const tx = rejectNft(api, alice, collectionId, nftId);
8484
modifiedtests/src/rmrk/removeResource.test.tsdiffbeforeafterboth
1import { expect } from 'chai';1import {expect} from 'chai';
2import privateKey from "../substrate/privateKey";2import privateKey from '../substrate/privateKey';
3import { executeTransaction, getApiConnection } from '../substrate/substrate-api';3import {executeTransaction, getApiConnection} from '../substrate/substrate-api';
4import { getNft, NftIdTuple } from './util/fetch';4import {getNft, NftIdTuple} from './util/fetch';
5import { expectTxFailure } from './util/helpers';5import {expectTxFailure} from './util/helpers';
6import {6import {
7 acceptNft, acceptResourceRemoval, addNftBasicResource,7 acceptNft, acceptResourceRemoval, addNftBasicResource,
8 createBase,8 createBase,
9 createCollection,9 createCollection,
10 mintNft, removeNftResource, sendNft10 mintNft, removeNftResource, sendNft,
11} from "./util/tx";11} from './util/tx';
1212
1313
1414
21 ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;21 ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
22 });22 });
2323
24 const Alice = "//Alice";24 const Alice = '//Alice';
25 const Bob = "//Bob";25 const Bob = '//Bob';
26 const src = "test-basic-src";26 const src = 'test-basic-src';
27 const metadata = "test-basic-metadata";27 const metadata = 'test-basic-metadata';
28 const license = "test-basic-license";28 const license = 'test-basic-license';
29 const thumb = "test-basic-thumb";29 const thumb = 'test-basic-thumb';
3030
31 it('deleting a resource directly by the NFT owner', async () => {31 it('deleting a resource directly by the NFT owner', async () => {
32 const collectionIdAlice = await createCollection(32 const collectionIdAlice = await createCollection(
33 api,33 api,
34 Alice,34 Alice,
35 "test-metadata",35 'test-metadata',
36 null,36 null,
37 "test-symbol"37 'test-symbol',
38 );38 );
3939
40 const nftAlice = await mintNft(40 const nftAlice = await mintNft(
41 api,41 api,
42 Alice,42 Alice,
43 Alice,43 Alice,
44 collectionIdAlice,44 collectionIdAlice,
45 "nft-metadata"45 'nft-metadata',
46 );46 );
4747
48 const resourceId = await addNftBasicResource(48 const resourceId = await addNftBasicResource(
49 api,49 api,
50 Alice,50 Alice,
51 "added",51 'added',
52 collectionIdAlice,52 collectionIdAlice,
53 nftAlice,53 nftAlice,
54 src,54 src,
55 metadata,55 metadata,
56 license,56 license,
57 thumb57 thumb,
58 );58 );
5959
60 await removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, resourceId);60 await removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, resourceId);
64 const collectionIdAlice = await createCollection(64 const collectionIdAlice = await createCollection(
65 api,65 api,
66 Alice,66 Alice,
67 "test-metadata",67 'test-metadata',
68 null,68 null,
69 "test-symbol"69 'test-symbol',
70 );70 );
7171
72 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "parent-nft-metadata");72 const parentNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'parent-nft-metadata');
73 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, "child-nft-metadata");73 const childNftId = await mintNft(api, Alice, Alice, collectionIdAlice, 'child-nft-metadata');
7474
75 const resourceId = await addNftBasicResource(75 const resourceId = await addNftBasicResource(
76 api,76 api,
77 Alice,77 Alice,
78 "added",78 'added',
79 collectionIdAlice,79 collectionIdAlice,
80 childNftId,80 childNftId,
81 src,81 src,
82 metadata,82 metadata,
83 license,83 license,
84 thumb84 thumb,
85 );85 );
8686
87 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];87 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];
8888
89 await sendNft(api, "sent", Alice, collectionIdAlice, childNftId, newOwnerNFT);89 await sendNft(api, 'sent', Alice, collectionIdAlice, childNftId, newOwnerNFT);
9090
91 await removeNftResource(api, 'removed', Alice, collectionIdAlice, childNftId, resourceId);91 await removeNftResource(api, 'removed', Alice, collectionIdAlice, childNftId, resourceId);
92 });92 });
95 const collectionIdAlice = await createCollection(95 const collectionIdAlice = await createCollection(
96 api,96 api,
97 Alice,97 Alice,
98 "test-metadata",98 'test-metadata',
99 null,99 null,
100 "test-symbol"100 'test-symbol',
101 );101 );
102102
103 const nftBob = await mintNft(103 const nftBob = await mintNft(
104 api,104 api,
105 Alice,105 Alice,
106 Bob,106 Bob,
107 collectionIdAlice,107 collectionIdAlice,
108 "nft-metadata"108 'nft-metadata',
109 );109 );
110110
111 const resourceId = await addNftBasicResource(111 const resourceId = await addNftBasicResource(
112 api,112 api,
113 Alice,113 Alice,
114 "pending",114 'pending',
115 collectionIdAlice,115 collectionIdAlice,
116 nftBob,116 nftBob,
117 src,117 src,
118 metadata,118 metadata,
119 license,119 license,
120 thumb120 thumb,
121 );121 );
122122
123 await removeNftResource(api, 'pending', Alice, collectionIdAlice, nftBob, resourceId);123 await removeNftResource(api, 'pending', Alice, collectionIdAlice, nftBob, resourceId);
128 const collectionIdAlice = await createCollection(128 const collectionIdAlice = await createCollection(
129 api,129 api,
130 Alice,130 Alice,
131 "test-metadata",131 'test-metadata',
132 null,132 null,
133 "test-symbol"133 'test-symbol',
134 );134 );
135135
136 const parentNftId = await mintNft(136 const parentNftId = await mintNft(
137 api,137 api,
138 Alice,138 Alice,
139 Bob,139 Bob,
140 collectionIdAlice,140 collectionIdAlice,
141 "parent-nft-metadata"141 'parent-nft-metadata',
142 );142 );
143 const childNftId = await mintNft(143 const childNftId = await mintNft(
144 api,144 api,
145 Alice,145 Alice,
146 Bob,146 Bob,
147 collectionIdAlice,147 collectionIdAlice,
148 "child-nft-metadata"148 'child-nft-metadata',
149 );149 );
150150
151 const resourceId = await addNftBasicResource(151 const resourceId = await addNftBasicResource(
152 api,152 api,
153 Alice,153 Alice,
154 "pending",154 'pending',
155 collectionIdAlice,155 collectionIdAlice,
156 childNftId,156 childNftId,
157 src,157 src,
158 metadata,158 metadata,
159 license,159 license,
160 thumb160 thumb,
161 );161 );
162162
163 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];163 const newOwnerNFT: NftIdTuple = [collectionIdAlice, parentNftId];
164164
165 await sendNft(api, "sent", Bob, collectionIdAlice, childNftId, newOwnerNFT);165 await sendNft(api, 'sent', Bob, collectionIdAlice, childNftId, newOwnerNFT);
166166
167 await removeNftResource(api, 'pending', Alice, collectionIdAlice, childNftId, resourceId);167 await removeNftResource(api, 'pending', Alice, collectionIdAlice, childNftId, resourceId);
168 await acceptResourceRemoval(api, Bob, collectionIdAlice, childNftId, resourceId);168 await acceptResourceRemoval(api, Bob, collectionIdAlice, childNftId, resourceId);
172 const collectionIdAlice = await createCollection(172 const collectionIdAlice = await createCollection(
173 api,173 api,
174 Alice,174 Alice,
175 "test-metadata",175 'test-metadata',
176 null,176 null,
177 "test-symbol"177 'test-symbol',
178 );178 );
179179
180 const nftAlice = await mintNft(180 const nftAlice = await mintNft(
181 api,181 api,
182 Alice,182 Alice,
183 Alice,183 Alice,
184 collectionIdAlice,184 collectionIdAlice,
185 "nft-metadata"185 'nft-metadata',
186 );186 );
187187
188 const resourceId = await addNftBasicResource(188 const resourceId = await addNftBasicResource(
189 api,189 api,
190 Alice,190 Alice,
191 "added",191 'added',
192 collectionIdAlice,192 collectionIdAlice,
193 nftAlice,193 nftAlice,
194 src,194 src,
195 metadata,195 metadata,
196 license,196 license,
197 thumb197 thumb,
198 );198 );
199199
200 const tx = removeNftResource(api, 'removed', Alice, 0xFFFFFFFF, nftAlice, resourceId);200 const tx = removeNftResource(api, 'removed', Alice, 0xFFFFFFFF, nftAlice, resourceId);
205 const collectionIdAlice = await createCollection(205 const collectionIdAlice = await createCollection(
206 api,206 api,
207 Alice,207 Alice,
208 "test-metadata",208 'test-metadata',
209 null,209 null,
210 "test-symbol"210 'test-symbol',
211 );211 );
212212
213 const nftAlice = await mintNft(213 const nftAlice = await mintNft(
214 api,214 api,
215 Alice,215 Alice,
216 Alice,216 Alice,
217 collectionIdAlice,217 collectionIdAlice,
218 "nft-metadata"218 'nft-metadata',
219 );219 );
220220
221 const resourceId = await addNftBasicResource(221 const resourceId = await addNftBasicResource(
222 api,222 api,
223 Alice,223 Alice,
224 "added",224 'added',
225 collectionIdAlice,225 collectionIdAlice,
226 nftAlice,226 nftAlice,
227 src,227 src,
228 metadata,228 metadata,
229 license,229 license,
230 thumb230 thumb,
231 );231 );
232232
233 const tx = removeNftResource(api, 'removed', Bob, collectionIdAlice, nftAlice, resourceId);233 const tx = removeNftResource(api, 'removed', Bob, collectionIdAlice, nftAlice, resourceId);
238 const collectionIdAlice = await createCollection(238 const collectionIdAlice = await createCollection(
239 api,239 api,
240 Alice,240 Alice,
241 "test-metadata",241 'test-metadata',
242 null,242 null,
243 "test-symbol"243 'test-symbol',
244 );244 );
245245
246 const nftAlice = await mintNft(246 const nftAlice = await mintNft(
247 api,247 api,
248 Alice,248 Alice,
249 Alice,249 Alice,
250 collectionIdAlice,250 collectionIdAlice,
251 "nft-metadata"251 'nft-metadata',
252 );252 );
253253
254 const tx = removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, 127);254 const tx = removeNftResource(api, 'removed', Alice, collectionIdAlice, nftAlice, 127);
259 const collectionIdAlice = await createCollection(259 const collectionIdAlice = await createCollection(
260 api,260 api,
261 Alice,261 Alice,
262 "test-metadata",262 'test-metadata',
263 null,263 null,
264 "test-symbol"264 'test-symbol',
265 );265 );
266266
267 const nftBob = await mintNft(267 const nftBob = await mintNft(
268 api,268 api,
269 Alice,269 Alice,
270 Bob,270 Bob,
271 collectionIdAlice,271 collectionIdAlice,
272 "nft-metadata"272 'nft-metadata',
273 );273 );
274274
275 const resourceId = await addNftBasicResource(275 const resourceId = await addNftBasicResource(
276 api,276 api,
277 Alice,277 Alice,
278 "pending",278 'pending',
279 collectionIdAlice,279 collectionIdAlice,
280 nftBob,280 nftBob,
281 src,281 src,
282 metadata,282 metadata,
283 license,283 license,
284 thumb284 thumb,
285 );285 );
286286
287 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);287 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, resourceId);
292 const collectionIdAlice = await createCollection(292 const collectionIdAlice = await createCollection(
293 api,293 api,
294 Alice,294 Alice,
295 "test-metadata",295 'test-metadata',
296 null,296 null,
297 "test-symbol"297 'test-symbol',
298 );298 );
299299
300 const nftBob = await mintNft(300 const nftBob = await mintNft(
301 api,301 api,
302 Alice,302 Alice,
303 Bob,303 Bob,
304 collectionIdAlice,304 collectionIdAlice,
305 "nft-metadata"305 'nft-metadata',
306 );306 );
307307
308 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, 127);308 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftBob, 127);
313 const collectionIdAlice = await createCollection(313 const collectionIdAlice = await createCollection(
314 api,314 api,
315 Alice,315 Alice,
316 "test-metadata",316 'test-metadata',
317 null,317 null,
318 "test-symbol"318 'test-symbol',
319 );319 );
320320
321 const nftAlice = await mintNft(321 const nftAlice = await mintNft(
322 api,322 api,
323 Alice,323 Alice,
324 Alice,324 Alice,
325 collectionIdAlice,325 collectionIdAlice,
326 "nft-metadata"326 'nft-metadata',
327 );327 );
328328
329 const resourceId = await addNftBasicResource(329 const resourceId = await addNftBasicResource(
330 api,330 api,
331 Alice,331 Alice,
332 "added",332 'added',
333 collectionIdAlice,333 collectionIdAlice,
334 nftAlice,334 nftAlice,
335 src,335 src,
336 metadata,336 metadata,
337 license,337 license,
338 thumb338 thumb,
339 );339 );
340340
341 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftAlice, resourceId);341 const tx = acceptResourceRemoval(api, Bob, collectionIdAlice, nftAlice, resourceId);
modifiedtests/src/rmrk/sendNft.test.tsdiffbeforeafterboth
1import { expect } from "chai";1import {expect} from 'chai';
2import { getApiConnection } from "../substrate/substrate-api";2import {getApiConnection} from '../substrate/substrate-api';
3import { createCollection, mintNft, sendNft } from "./util/tx";3import {createCollection, mintNft, sendNft} from './util/tx';
4import { NftIdTuple } from "./util/fetch";4import {NftIdTuple} from './util/fetch';
5import { isNftChildOfAnother, expectTxFailure } from "./util/helpers";5import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
66
7describe("integration test: send NFT", () => {7describe('integration test: send NFT', () => {
8 let api: any;8 let api: any;
9 before(async () => { api = await getApiConnection(); });9 before(async () => { api = await getApiConnection(); });
1010
11 const maxNftId = 0xFFFFFFFF;11 const maxNftId = 0xFFFFFFFF;
1212
13 const alice = "//Alice";13 const alice = '//Alice';
14 const bob = "//Bob";14 const bob = '//Bob';
1515
16 const createTestCollection = async (issuerUri: string) => {16 const createTestCollection = async (issuerUri: string) => {
17 return await createCollection(17 return await createCollection(
18 api,18 api,
19 issuerUri,19 issuerUri,
20 "nft-collection-metadata",20 'nft-collection-metadata',
21 null,21 null,
22 "nft-collection"22 'nft-collection',
23 );23 );
24 };24 };
2525
2626
27 it("send NFT to another user", async () => {27 it('send NFT to another user', async () => {
28 const originalOwnerUri = alice;28 const originalOwnerUri = alice;
29 const newOwnerUri = bob;29 const newOwnerUri = bob;
3030
31 const collectionId = await createTestCollection(alice);31 const collectionId = await createTestCollection(alice);
3232
33 const nftId = await mintNft(api, alice, originalOwnerUri, collectionId, "nft-metadata");33 const nftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'nft-metadata');
3434
35 await sendNft(api, "sent", originalOwnerUri, collectionId, nftId, newOwnerUri);35 await sendNft(api, 'sent', originalOwnerUri, collectionId, nftId, newOwnerUri);
36 });36 });
3737
38 it("[negative] unable to send non-existing NFT", async () => {38 it('[negative] unable to send non-existing NFT', async () => {
39 const originalOwnerUri = alice;39 const originalOwnerUri = alice;
40 const newOwnerUri = bob;40 const newOwnerUri = bob;
4141
42 const collectionId = 0;42 const collectionId = 0;
43 const tx = sendNft(api, "sent", originalOwnerUri, collectionId, maxNftId, newOwnerUri);43 const tx = sendNft(api, 'sent', originalOwnerUri, collectionId, maxNftId, newOwnerUri);
4444
45 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);45 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
46 });46 });
4747
48 it("[negative] unable to send NFT by a not-an-owner", async () => {48 it('[negative] unable to send NFT by a not-an-owner', async () => {
49 const originalOwnerUri = alice;49 const originalOwnerUri = alice;
50 const newOwnerUri = bob;50 const newOwnerUri = bob;
5151
52 const collectionId = await createTestCollection(alice);52 const collectionId = await createTestCollection(alice);
5353
54 const nftId = await mintNft(api, alice, originalOwnerUri, collectionId, "nft-metadata");54 const nftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'nft-metadata');
5555
56 const tx = sendNft(api, "sent", newOwnerUri, collectionId, nftId, newOwnerUri);56 const tx = sendNft(api, 'sent', newOwnerUri, collectionId, nftId, newOwnerUri);
57 await expectTxFailure(/rmrkCore\.NoPermission/, tx);57 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
58 });58 });
5959
60 it("send NFT to another NFT (same owner)", async () => {60 it('send NFT to another NFT (same owner)', async () => {
61 const originalOwnerUri = alice;61 const originalOwnerUri = alice;
6262
63 const collectionId = await createTestCollection(alice);63 const collectionId = await createTestCollection(alice);
6464
65 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "parent-nft-metadata");65 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'parent-nft-metadata');
66 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "child-nft-metadata");66 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'child-nft-metadata');
6767
68 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];68 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
6969
70 await sendNft(api, "sent", alice, collectionId, childNftId, newOwnerNFT);70 await sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);
7171
72 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);72 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);
73 expect(isChild).to.be.true;73 expect(isChild).to.be.true;
74 });74 });
7575
76 it("[negative] send non-existing NFT to another NFT", async () => {76 it('[negative] send non-existing NFT to another NFT', async () => {
77 const originalOwnerUri = alice;77 const originalOwnerUri = alice;
7878
79 const collectionId = await createTestCollection(alice);79 const collectionId = await createTestCollection(alice);
8080
81 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "parent-nft-metadata");81 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'parent-nft-metadata');
82 const childNftId = maxNftId;82 const childNftId = maxNftId;
8383
84 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];84 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
8585
86 const tx = sendNft(api, "sent", alice, collectionId, childNftId, newOwnerNFT);86 const tx = sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);
8787
88 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);88 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
8989
90 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);90 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);
91 expect(isChild).to.be.false;91 expect(isChild).to.be.false;
92 });92 });
9393
94 it("send NFT to another NFT (by not-an-owner)", async () => {94 it('send NFT to another NFT (by not-an-owner)', async () => {
95 const originalOwnerUri = alice;95 const originalOwnerUri = alice;
9696
97 const collectionId = await createTestCollection(alice);97 const collectionId = await createTestCollection(alice);
9898
99 const author = alice;99 const author = alice;
100 const attacker = bob;100 const attacker = bob;
101101
102 const parentNftId = await mintNft(api, author, originalOwnerUri, collectionId, "parent-nft-metadata");102 const parentNftId = await mintNft(api, author, originalOwnerUri, collectionId, 'parent-nft-metadata');
103 const childNftId = await mintNft(api, author, originalOwnerUri, collectionId, "child-nft-metadata");103 const childNftId = await mintNft(api, author, originalOwnerUri, collectionId, 'child-nft-metadata');
104104
105 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];105 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
106106
107 const tx = sendNft(api, "sent", attacker, collectionId, childNftId, newOwnerNFT);107 const tx = sendNft(api, 'sent', attacker, collectionId, childNftId, newOwnerNFT);
108108
109 await expectTxFailure(/rmrkCore\.NoPermission/, tx);109 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
110110
111 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);111 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);
112 expect(isChild).to.be.false;112 expect(isChild).to.be.false;
113 });113 });
114114
115 it("[negative] send NFT to non-existing NFT", async () => {115 it('[negative] send NFT to non-existing NFT', async () => {
116 const originalOwnerUri = alice;116 const originalOwnerUri = alice;
117117
118 const collectionId = await createTestCollection(alice);118 const collectionId = await createTestCollection(alice);
119119
120 const parentNftId = maxNftId;120 const parentNftId = maxNftId;
121 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "child-nft-metadata");121 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'child-nft-metadata');
122122
123 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];123 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
124124
125 const tx = sendNft(api, "sent", alice, collectionId, childNftId, newOwnerNFT);125 const tx = sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);
126126
127 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);127 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
128128
129 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);129 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);
130 expect(isChild).to.be.false;130 expect(isChild).to.be.false;
131 });131 });
132132
133 it("send NFT to another NFT owned by another user", async () => {133 it('send NFT to another NFT owned by another user', async () => {
134 const ownerAlice = alice;134 const ownerAlice = alice;
135 const ownerBob = bob;135 const ownerBob = bob;
136136
137 const aliceCollectionId = await createTestCollection(alice);137 const aliceCollectionId = await createTestCollection(alice);
138 const bobCollectionId = await createTestCollection(bob);138 const bobCollectionId = await createTestCollection(bob);
139139
140 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, "parent-nft-metadata");140 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');
141 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, "child-nft-metadata");141 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');
142142
143 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];143 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];
144144
145 await sendNft(api, "pending", bob, bobCollectionId, childNftId, newOwnerNFT);145 await sendNft(api, 'pending', bob, bobCollectionId, childNftId, newOwnerNFT);
146 });146 });
147147
148 it("[negative] unable to send NFT to itself", async () => {148 it('[negative] unable to send NFT to itself', async () => {
149 const nftOwner = alice;149 const nftOwner = alice;
150 const collectionId = await createTestCollection(alice);150 const collectionId = await createTestCollection(alice);
151151
152 const nftId = await mintNft(api, alice, nftOwner, collectionId, "ouroboros-nft-metadata");152 const nftId = await mintNft(api, alice, nftOwner, collectionId, 'ouroboros-nft-metadata');
153153
154 const newOwnerNFT: NftIdTuple = [collectionId, nftId];154 const newOwnerNFT: NftIdTuple = [collectionId, nftId];
155155
156 const tx = sendNft(api, "sent", alice, collectionId, nftId, newOwnerNFT);156 const tx = sendNft(api, 'sent', alice, collectionId, nftId, newOwnerNFT);
157157
158 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);158 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);
159159
160 const isChild = await isNftChildOfAnother(api, collectionId, nftId, newOwnerNFT);160 const isChild = await isNftChildOfAnother(api, collectionId, nftId, newOwnerNFT);
161 expect(isChild).to.be.false;161 expect(isChild).to.be.false;
162 });162 });
163163
164 it("[negative] unable to send NFT to child NFT", async () => {164 it('[negative] unable to send NFT to child NFT', async () => {
165 const originalOwnerUri = alice;165 const originalOwnerUri = alice;
166166
167 const collectionId = await createTestCollection(alice);167 const collectionId = await createTestCollection(alice);
168168
169 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "parent-nft-metadata");169 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'parent-nft-metadata');
170 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "child-nft-metadata");170 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'child-nft-metadata');
171171
172 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];172 const newOwnerNFT: NftIdTuple = [collectionId, parentNftId];
173173
174 await sendNft(api, "sent", alice, collectionId, childNftId, newOwnerNFT);174 await sendNft(api, 'sent', alice, collectionId, childNftId, newOwnerNFT);
175175
176 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);176 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, newOwnerNFT);
177 expect(isChild).to.be.true;177 expect(isChild).to.be.true;
178178
179 const descendentOwner: NftIdTuple = [collectionId, childNftId];179 const descendentOwner: NftIdTuple = [collectionId, childNftId];
180 const tx = sendNft(api, "sent", alice, collectionId, parentNftId, descendentOwner);180 const tx = sendNft(api, 'sent', alice, collectionId, parentNftId, descendentOwner);
181181
182 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);182 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);
183 const isOuroboros = await isNftChildOfAnother(api, collectionId, parentNftId, descendentOwner);183 const isOuroboros = await isNftChildOfAnother(api, collectionId, parentNftId, descendentOwner);
184 expect(isOuroboros).to.be.false;184 expect(isOuroboros).to.be.false;
185 });185 });
186186
187 it("[negative] unable to send NFT to descendent NFT", async () => {187 it('[negative] unable to send NFT to descendent NFT', async () => {
188 const originalOwnerUri = alice;188 const originalOwnerUri = alice;
189189
190 const collectionId = await createTestCollection(alice);190 const collectionId = await createTestCollection(alice);
191191
192 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "parent-nft-metadata");192 const parentNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'parent-nft-metadata');
193 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "child-nft-metadata");193 const childNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'child-nft-metadata');
194 const grandsonNftId = await mintNft(api, alice, originalOwnerUri, collectionId, "grandson-nft-metadata");194 const grandsonNftId = await mintNft(api, alice, originalOwnerUri, collectionId, 'grandson-nft-metadata');
195195
196 const ownerParentNFT: NftIdTuple = [collectionId, parentNftId];196 const ownerParentNFT: NftIdTuple = [collectionId, parentNftId];
197197
198 await sendNft(api, "sent", alice, collectionId, childNftId, ownerParentNFT);198 await sendNft(api, 'sent', alice, collectionId, childNftId, ownerParentNFT);
199199
200 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, ownerParentNFT);200 const isChild = await isNftChildOfAnother(api, collectionId, childNftId, ownerParentNFT);
201 expect(isChild).to.be.true;201 expect(isChild).to.be.true;
202202
203 const ownerChildNFT: NftIdTuple = [collectionId, childNftId];203 const ownerChildNFT: NftIdTuple = [collectionId, childNftId];
204 await sendNft(api, "sent", alice, collectionId, grandsonNftId, ownerChildNFT);204 await sendNft(api, 'sent', alice, collectionId, grandsonNftId, ownerChildNFT);
205205
206 const isGrandson = await isNftChildOfAnother(api, collectionId, grandsonNftId, ownerChildNFT);206 const isGrandson = await isNftChildOfAnother(api, collectionId, grandsonNftId, ownerChildNFT);
207 expect(isGrandson).to.be.true;207 expect(isGrandson).to.be.true;
208208
209 const ownerGrandsonNFT: NftIdTuple = [collectionId, grandsonNftId];209 const ownerGrandsonNFT: NftIdTuple = [collectionId, grandsonNftId];
210 const tx = sendNft(api, "sent", alice, collectionId, parentNftId, ownerGrandsonNFT);210 const tx = sendNft(api, 'sent', alice, collectionId, parentNftId, ownerGrandsonNFT);
211211
212 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);212 await expectTxFailure(/rmrkCore\.CannotSendToDescendentOrSelf/, tx);
213 const isOuroboros = await isNftChildOfAnother(api, collectionId, parentNftId, ownerGrandsonNFT);213 const isOuroboros = await isNftChildOfAnother(api, collectionId, parentNftId, ownerGrandsonNFT);
214 expect(isOuroboros).to.be.false;214 expect(isOuroboros).to.be.false;
215 });215 });
216216
217 it("send nested NFT to another user", async () => {217 it('send nested NFT to another user', async () => {
218 const originalOwner = alice;218 const originalOwner = alice;
219 const newOwner = bob;219 const newOwner = bob;
220220
221 const collectionId = await createTestCollection(alice);221 const collectionId = await createTestCollection(alice);
222222
223 const parentNftId = await mintNft(api, alice, originalOwner, collectionId, "parent-nft-metadata");223 const parentNftId = await mintNft(api, alice, originalOwner, collectionId, 'parent-nft-metadata');
224 const childNftId = await mintNft(api, alice, originalOwner, collectionId, "child-nft-metadata");224 const childNftId = await mintNft(api, alice, originalOwner, collectionId, 'child-nft-metadata');
225225
226 const parentNftTuple: NftIdTuple = [collectionId, parentNftId];226 const parentNftTuple: NftIdTuple = [collectionId, parentNftId];
227227
228 await sendNft(api, "sent", originalOwner, collectionId, childNftId, parentNftTuple);228 await sendNft(api, 'sent', originalOwner, collectionId, childNftId, parentNftTuple);
229229
230 await sendNft(api, "sent", originalOwner, collectionId, childNftId, newOwner);230 await sendNft(api, 'sent', originalOwner, collectionId, childNftId, newOwner);
231 });231 });
232232
233 it("[negative] send nested NFT to another user (by a not-root-owner)", async () => {233 it('[negative] send nested NFT to another user (by a not-root-owner)', async () => {
234 const originalOwner = alice;234 const originalOwner = alice;
235 const newOwner = bob;235 const newOwner = bob;
236236
237 const collectionId = await createTestCollection(alice);237 const collectionId = await createTestCollection(alice);
238238
239 const parentNftId = await mintNft(api, alice, originalOwner, collectionId, "parent-nft-metadata");239 const parentNftId = await mintNft(api, alice, originalOwner, collectionId, 'parent-nft-metadata');
240 const childNftId = await mintNft(api, alice, originalOwner, collectionId, "child-nft-metadata");240 const childNftId = await mintNft(api, alice, originalOwner, collectionId, 'child-nft-metadata');
241241
242 const parentNftTuple: NftIdTuple = [collectionId, parentNftId];242 const parentNftTuple: NftIdTuple = [collectionId, parentNftId];
243243
244 await sendNft(api, "sent", originalOwner, collectionId, childNftId, parentNftTuple);244 await sendNft(api, 'sent', originalOwner, collectionId, childNftId, parentNftTuple);
245245
246 const tx = sendNft(api, "sent", newOwner, collectionId, childNftId, newOwner);246 const tx = sendNft(api, 'sent', newOwner, collectionId, childNftId, newOwner);
247247
248 await expectTxFailure(/rmrkCore\.NoPermission/, tx);248 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
249 });249 });
modifiedtests/src/rmrk/setCollectionProperty.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from "./util/helpers";2import {expectTxFailure} from './util/helpers';
3import { createCollection, setPropertyCollection } from "./util/tx";3import {createCollection, setPropertyCollection} from './util/tx';
44
5describe("integration test: set collection property", () => {5describe('integration test: set collection property', () => {
6 const Alice = "//Alice";6 const Alice = '//Alice';
7 const Bob = "//Bob";7 const Bob = '//Bob';
88
9 let api: any;9 let api: any;
10 before(async () => {10 before(async () => {
11 api = await getApiConnection();11 api = await getApiConnection();
12 });12 });
1313
14 it("set collection property", async () => {14 it('set collection property', async () => {
15 await createCollection(15 await createCollection(
16 api,16 api,
17 Alice,17 Alice,
18 "test-metadata",18 'test-metadata',
19 null,19 null,
20 "test-symbol"20 'test-symbol',
21 ).then(async (collectionId) => {21 ).then(async (collectionId) => {
22 await setPropertyCollection(api, Alice, collectionId, "test_key", "42");22 await setPropertyCollection(api, Alice, collectionId, 'test_key', '42');
23 await setPropertyCollection(api, Alice, collectionId, "test_key", "10");23 await setPropertyCollection(api, Alice, collectionId, 'test_key', '10');
24 await setPropertyCollection(24 await setPropertyCollection(
25 api,25 api,
26 Alice,26 Alice,
27 collectionId,27 collectionId,
28 "second_test_key",28 'second_test_key',
29 "111"29 '111',
30 );30 );
31 });31 });
32 });32 });
3333
34 it("[negative] set non-existing collection property", async () => {34 it('[negative] set non-existing collection property', async () => {
35 const tx = setPropertyCollection(35 const tx = setPropertyCollection(
36 api,36 api,
37 Alice,37 Alice,
38 9999,38 9999,
39 "test_key",39 'test_key',
40 "42"40 '42',
41 );41 );
42 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);42 await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);
43 });43 });
4444
45 it("[negative] set property not an owner NFT collection issuer", async () => {45 it('[negative] set property not an owner NFT collection issuer', async () => {
46 await createCollection(46 await createCollection(
47 api,47 api,
48 Bob,48 Bob,
49 "test-metadata",49 'test-metadata',
50 null,50 null,
51 "test-symbol"51 'test-symbol',
52 ).then(async (collectionId) => {52 ).then(async (collectionId) => {
53 const tx = setPropertyCollection(53 const tx = setPropertyCollection(
54 api,54 api,
55 Alice,55 Alice,
56 collectionId,56 collectionId,
57 "test_key",57 'test_key',
58 "42"58 '42',
59 );59 );
60 await expectTxFailure(/rmrkCore\.NoPermission/, tx);60 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
61 });61 });
modifiedtests/src/rmrk/setEquippableList.test.tsdiffbeforeafterboth
1import { getApiConnection } from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import { expectTxFailure } from './util/helpers';2import {expectTxFailure} from './util/helpers';
3import { createCollection, createBase, setEquippableList } from "./util/tx";3import {createCollection, createBase, setEquippableList} from './util/tx';
44
5describe("integration test: set slot's Equippable List", () => {5describe("integration test: set slot's Equippable List", () => {
6 let api: any;6 let api: any;
14 await createCollection(14 await createCollection(
15 api,15 api,
16 alice,16 alice,
17 "equiplist-collection-metadata",17 'equiplist-collection-metadata',
18 null,18 null,
19 "equiplist-0"19 'equiplist-0',
20 ),20 ),
21 await createCollection(21 await createCollection(
22 api,22 api,
23 alice,23 alice,
24 "equiplist-collection-metadata",24 'equiplist-collection-metadata',
25 null,25 null,
26 "equiplist-1"26 'equiplist-1',
27 )27 ),
28 ]28 ];
2929
30 const slotId = 202;30 const slotId = 202;
3131
32 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [32 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [
33 {33 {
34 "SlotPart": {34 'SlotPart': {
35 id: slotId,35 id: slotId,
36 equippable: "All",36 equippable: 'All',
37 z: 1,37 z: 1,
38 src: "some-fallback-slot-url"38 src: 'some-fallback-slot-url',
39 }39 },
40 }40 },
41 ]);41 ]);
4242
43 await setEquippableList(api, alice, baseId, slotId, "All");43 await setEquippableList(api, alice, baseId, slotId, 'All');
44 await setEquippableList(api, alice, baseId, slotId, "Empty");44 await setEquippableList(api, alice, baseId, slotId, 'Empty');
45 await setEquippableList(api, alice, baseId, slotId, { "Custom": collectionIds });45 await setEquippableList(api, alice, baseId, slotId, {'Custom': collectionIds});
46 });46 });
4747
48 it("[negative] unable to set equippable list of a slot of non-existing base", async () => {48 it('[negative] unable to set equippable list of a slot of non-existing base', async () => {
49 const maxBaseId = 0xFFFFFFFF;49 const maxBaseId = 0xFFFFFFFF;
50 const slotId = 0;50 const slotId = 0;
5151
52 const tx = setEquippableList(api, alice, maxBaseId, slotId, "All");52 const tx = setEquippableList(api, alice, maxBaseId, slotId, 'All');
53 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);53 await expectTxFailure(/rmrkEquip\.BaseDoesntExist/, tx);
54 });54 });
5555
56 it("[negative] unable to set equippable list by a not-an-owner", async () => {56 it('[negative] unable to set equippable list by a not-an-owner', async () => {
57 const slotId = 42;57 const slotId = 42;
5858
59 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [59 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [
60 {60 {
61 "SlotPart": {61 'SlotPart': {
62 id: slotId,62 id: slotId,
63 equippable: "All",63 equippable: 'All',
64 z: 1,64 z: 1,
65 src: "some-fallback-slot-url"65 src: 'some-fallback-slot-url',
66 }66 },
67 }67 },
68 ]);68 ]);
6969
70 const tx = setEquippableList(api, bob, baseId, slotId, "All");70 const tx = setEquippableList(api, bob, baseId, slotId, 'All');
71 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);71 await expectTxFailure(/rmrkEquip\.PermissionError/, tx);
72 });72 });
7373
74 it("[negative] unable to set equippable list to a fixed part", async () => {74 it('[negative] unable to set equippable list to a fixed part', async () => {
75 const fixedPartId = 42;75 const fixedPartId = 42;
7676
77 const baseId = await createBase(api, alice, 'fixedpart-base-type', 'fixedpart', [77 const baseId = await createBase(api, alice, 'fixedpart-base-type', 'fixedpart', [
78 {78 {
79 "FixedPart": {79 'FixedPart': {
80 id: fixedPartId,80 id: fixedPartId,
81 z: 0,81 z: 0,
82 src: "fixed-part-url"82 src: 'fixed-part-url',
83 }83 },
84 }84 },
85 ]);85 ]);
8686
87 const tx = setEquippableList(api, alice, baseId, fixedPartId, "All");87 const tx = setEquippableList(api, alice, baseId, fixedPartId, 'All');
88 await expectTxFailure(/rmrkEquip\.NoEquippableOnFixedPart/, tx);88 await expectTxFailure(/rmrkEquip\.NoEquippableOnFixedPart/, tx);
89 });89 });
9090
91 it("[negative] unable to set equippable list to non-existing slot", async () => {91 it('[negative] unable to set equippable list to non-existing slot', async () => {
92 const slotId = 77792 const slotId = 777;
93 const maxSlotId = 0xFFFFFFFF;93 const maxSlotId = 0xFFFFFFFF;
9494
95 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [95 const baseId = await createBase(api, alice, 'slotpartany-base-type', 'slotpartany', [
96 {96 {
97 "SlotPart": {97 'SlotPart': {
98 id: slotId,98 id: slotId,
99 equippable: "All",99 equippable: 'All',
100 z: 1,100 z: 1,
101 src: "some-fallback-slot-url"101 src: 'some-fallback-slot-url',
102 }102 },
103 }103 },
104 ]);104 ]);
105105
106 const tx = setEquippableList(api, alice, baseId, maxSlotId, "All");106 const tx = setEquippableList(api, alice, baseId, maxSlotId, 'All');
107 await expectTxFailure(/rmrkEquip\.PartDoesntExist/, tx);107 await expectTxFailure(/rmrkEquip\.PartDoesntExist/, tx);
108 })108 });
109109
110 after(() => { api.disconnect(); });110 after(() => { api.disconnect(); });
111});111});
modifiedtests/src/rmrk/setNftProperty.test.tsdiffbeforeafterboth
1import { getApiConnection } from "../substrate/substrate-api";1import {getApiConnection} from '../substrate/substrate-api';
2import { NftIdTuple } from "./util/fetch";2import {NftIdTuple} from './util/fetch';
3import { expectTxFailure } from "./util/helpers";3import {expectTxFailure} from './util/helpers';
4import { createCollection, mintNft, sendNft, setNftProperty } from "./util/tx";4import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';
55
6describe("integration test: set NFT property", () => {6describe('integration test: set NFT property', () => {
7 let api: any;7 let api: any;
8 before(async () => { api = await getApiConnection(); });8 before(async () => { api = await getApiConnection(); });
99
10 const alice = "//Alice";10 const alice = '//Alice';
11 const bob = "//Bob";11 const bob = '//Bob';
1212
13 const createTestCollection = async (issuerUri: string) => {13 const createTestCollection = async (issuerUri: string) => {
14 return await createCollection(14 return await createCollection(
15 api,15 api,
16 issuerUri,16 issuerUri,
17 "setprop-nft-collection-metadata",17 'setprop-nft-collection-metadata',
18 null,18 null,
19 "setprop"19 'setprop',
20 );20 );
21 };21 };
2222
23 it("set NFT property", async () => {23 it('set NFT property', async () => {
24 const ownerAlice = alice;24 const ownerAlice = alice;
2525
26 const collectionId = await createTestCollection(alice);26 const collectionId = await createTestCollection(alice);
27 const nftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-nft");27 const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-nft');
2828
29 await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'test-key-value');29 await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'test-key-value');
30 await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'updated-key-value');30 await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'updated-key-value');
31 await setNftProperty(api, alice, collectionId, nftId, 'second-test-key', 'second-test-key-value');31 await setNftProperty(api, alice, collectionId, nftId, 'second-test-key', 'second-test-key-value');
32 });32 });
3333
34 it("[negative] unable to set a property of non-existing NFT", async () => {34 it('[negative] unable to set a property of non-existing NFT', async () => {
35 const collectionId = 0;35 const collectionId = 0;
36 const maxNftId = 0xFFFFFFFF;36 const maxNftId = 0xFFFFFFFF;
3737
40 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);40 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);
41 });41 });
4242
43 it("[negative] unable to set a property by not-an-owner", async () => {43 it('[negative] unable to set a property by not-an-owner', async () => {
44 const ownerAlice = alice;44 const ownerAlice = alice;
4545
46 const collectionId = await createTestCollection(alice);46 const collectionId = await createTestCollection(alice);
47 const nftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-nft");47 const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-nft');
4848
49 const tx = setNftProperty(api, bob, collectionId, nftId, 'test-key', 'test-key-value');49 const tx = setNftProperty(api, bob, collectionId, nftId, 'test-key', 'test-key-value');
5050
51 await expectTxFailure(/rmrkCore\.NoPermission/, tx);51 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
52 });52 });
5353
54 it("set a property to nested NFT", async () => {54 it('set a property to nested NFT', async () => {
55 const ownerAlice = alice;55 const ownerAlice = alice;
5656
57 const collectionId = await createTestCollection(alice);57 const collectionId = await createTestCollection(alice);
58 const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-parent-nft");58 const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-parent-nft');
59 const childNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-child-nft");59 const childNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-child-nft');
6060
61 const ownerNft: NftIdTuple = [collectionId, parentNftId];61 const ownerNft: NftIdTuple = [collectionId, parentNftId];
6262
63 await sendNft(api, "sent", ownerAlice, collectionId, childNftId, ownerNft);63 await sendNft(api, 'sent', ownerAlice, collectionId, childNftId, ownerNft);
6464
65 await setNftProperty(api, alice, collectionId, childNftId, 'test-key', 'test-key-value');65 await setNftProperty(api, alice, collectionId, childNftId, 'test-key', 'test-key-value');
66 });66 });
6767
68 it("[negative] set a property to nested NFT (by not-root-owner)", async () => {68 it('[negative] set a property to nested NFT (by not-root-owner)', async () => {
69 const ownerAlice = alice;69 const ownerAlice = alice;
7070
71 const collectionId = await createTestCollection(alice);71 const collectionId = await createTestCollection(alice);
72 const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-parent-nft");72 const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-parent-nft');
73 const childNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-child-nft");73 const childNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-child-nft');
7474
75 const ownerNft: NftIdTuple = [collectionId, parentNftId];75 const ownerNft: NftIdTuple = [collectionId, parentNftId];
7676
77 await sendNft(api, "sent", ownerAlice, collectionId, childNftId, ownerNft);77 await sendNft(api, 'sent', ownerAlice, collectionId, childNftId, ownerNft);
7878
79 const tx = setNftProperty(api, bob, collectionId, childNftId, 'test-key', 'test-key-value');79 const tx = setNftProperty(api, bob, collectionId, childNftId, 'test-key', 'test-key-value');
8080
modifiedtests/src/rmrk/setResourcePriorities.test.tsdiffbeforeafterboth
2import { expectTxFailure } from './util/helpers';2import {expectTxFailure} from './util/helpers';
3import { mintNft, createCollection, setResourcePriorities } from './util/tx';3import {mintNft, createCollection, setResourcePriorities} from './util/tx';
44
5describe("integration test: set NFT resource priorities", () => {5describe('integration test: set NFT resource priorities', () => {
6 let api: any;6 let api: any;
7 before(async () => { api = await getApiConnection(); });7 before(async () => { api = await getApiConnection(); });
88
19 );19 );
20 };20 };
2121
22 it("set NFT resource priorities", async () => {22 it('set NFT resource priorities', async () => {
23 const owner = alice;23 const owner = alice;
2424
25 const collectionId = await createTestCollection(alice);25 const collectionId = await createTestCollection(alice);
28 await setResourcePriorities(api, alice, collectionId, nftId, [10, 42]);28 await setResourcePriorities(api, alice, collectionId, nftId, [10, 42]);
29 });29 });
3030
31 it("[negative] set NFT resource priorities by a not-an-owner", async () => {31 it('[negative] set NFT resource priorities by a not-an-owner', async () => {
32 const owner = alice;32 const owner = alice;
33 const attacker = bob;33 const attacker = bob;
3434
40 await expectTxFailure(/rmrkCore\.NoPermission/, tx);40 await expectTxFailure(/rmrkCore\.NoPermission/, tx);
41 });41 });
4242
43 it("[negative] set NFT resource priorities to non-existing NFT", async () => {43 it('[negative] set NFT resource priorities to non-existing NFT', async () => {
44 const owner = alice;44 const owner = alice;
4545
46 const collectionId = 0;46 const collectionId = 0;
modifiedtests/src/rmrk/util/fetch.tsdiffbeforeafterboth
33 const owner = privateKey(ownerUri, Number(ss58Format));33 const owner = privateKey(ownerUri, Number(ss58Format));
3434
35 return (await api.rpc.rmrk.accountTokens(owner.address, collectionId))35 return (await api.rpc.rmrk.accountTokens(owner.address, collectionId))
36 .map((value) => value.toNumber())36 .map((value) => value.toNumber());
37}37}
3838
39export async function getNft(api: ApiPromise, collectionId: number, nftId: number): Promise<Option<Nft>> {39export async function getNft(api: ApiPromise, collectionId: number, nftId: number): Promise<Option<Nft>> {
68 api: ApiPromise,68 api: ApiPromise,
69 baseId: number,69 baseId: number,
70 slotId: number70 slotId: number,
71): Promise<"All" | "Empty" | { "Custom": number[] } | null> {71): Promise<'All' | 'Empty' | { 'Custom': number[] } | null> {
72 const parts = await getParts(api, baseId);72 const parts = await getParts(api, baseId);
7373
74 const part = parts.find((part) => {74 const part = parts.find((part) => {
83 const slot = part.asSlotPart;83 const slot = part.asSlotPart;
84 if (slot.equippable.isCustom) {84 if (slot.equippable.isCustom) {
85 return {85 return {
86 "Custom": slot.equippable.asCustom86 'Custom': slot.equippable.asCustom
87 .toArray()87 .toArray()
88 .map((collectionId) => collectionId.toNumber())88 .map((collectionId) => collectionId.toNumber()),
89 };89 };
90 } else if (slot.equippable.isAll) {90 } else if (slot.equippable.isAll) {
91 return "All";91 return 'All';
92 } else {92 } else {
93 return "Empty";93 return 'Empty';
94 }94 }
95 } else {95 } else {
96 return null;96 return null;
modifiedtests/src/rmrk/util/helpers.tsdiffbeforeafterboth
1import { ApiPromise } from "@polkadot/api";1import {ApiPromise} from '@polkadot/api';
2import {2import {
3 RmrkTraitsNftAccountIdOrCollectionNftTuple as NftOwner,3 RmrkTraitsNftAccountIdOrCollectionNftTuple as NftOwner,
4 RmrkTraitsPropertyPropertyInfo as Property,4 RmrkTraitsPropertyPropertyInfo as Property,
5 RmrkTraitsResourceResourceInfo as ResourceInfo,5 RmrkTraitsResourceResourceInfo as ResourceInfo,
6} from "@polkadot/types/lookup";6} from '@polkadot/types/lookup';
7import type { EventRecord } from '@polkadot/types/interfaces';7import type {EventRecord} from '@polkadot/types/interfaces';
8import type { GenericEventData } from '@polkadot/types';8import type {GenericEventData} from '@polkadot/types';
9import privateKey from "../../substrate/privateKey";9import privateKey from '../../substrate/privateKey';
10import { NftIdTuple, getChildren, getOwnedNfts, getCollectionProperties, getNftProperties, getResources } from './fetch';10import {NftIdTuple, getChildren, getOwnedNfts, getCollectionProperties, getNftProperties, getResources} from './fetch';
11import chaiAsPromised from 'chai-as-promised';11import chaiAsPromised from 'chai-as-promised';
12import chai from 'chai';12import chai from 'chai';
20}20}
2121
22export function makeNftOwner(api: ApiPromise, owner: string | NftIdTuple): NftOwner {22export function makeNftOwner(api: ApiPromise, owner: string | NftIdTuple): NftOwner {
23 const isNftSending = (typeof owner !== "string");23 const isNftSending = (typeof owner !== 'string');
2424
25 if (isNftSending) {25 if (isNftSending) {
26 return api.createType("RmrkTraitsNftAccountIdOrCollectionNftTuple", {26 return api.createType('RmrkTraitsNftAccountIdOrCollectionNftTuple', {
27 "CollectionAndNftTuple": owner27 'CollectionAndNftTuple': owner,
28 });28 });
29 } else {29 } else {
30 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;30 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
31 return api.createType("RmrkTraitsNftAccountIdOrCollectionNftTuple", {31 return api.createType('RmrkTraitsNftAccountIdOrCollectionNftTuple', {
32 AccountId: privateKey(owner, Number(ss58Format)).address,32 AccountId: privateKey(owner, Number(ss58Format)).address,
33 });33 });
34 }34 }
40 collectionId: number,40 collectionId: number,
41 nftId: number41 nftId: number,
42): Promise<boolean> {42): Promise<boolean> {
43 if (typeof owner === "string") {43 if (typeof owner === 'string') {
44 return (await getOwnedNfts(api, owner, collectionId))44 return (await getOwnedNfts(api, owner, collectionId))
45 .find(ownedNftId => {45 .find(ownedNftId => {
46 return ownedNftId === nftId;46 return ownedNftId === nftId;
60 props: Property[]60 props: Property[],
61): boolean {61): boolean {
62 let isPropFound = false;62 let isPropFound = false;
63 for (var i = 0; i < props.length && !isPropFound; i++) {63 for (let i = 0; i < props.length && !isPropFound; i++) {
64 const fetchedProp = props[i];64 const fetchedProp = props[i];
6565
66 isPropFound = fetchedProp.key.eq(key)66 isPropFound = fetchedProp.key.eq(key)
200200
201export function checkResourceStatus(201export function checkResourceStatus(
202 resource: ResourceInfo,202 resource: ResourceInfo,
203 expectedStatus: "pending" | "added"203 expectedStatus: 'pending' | 'added',
204) {204) {
205 expect(resource.pending.isTrue, `Error: added resource should be ${expectedStatus}`)205 expect(resource.pending.isTrue, `Error: added resource should be ${expectedStatus}`)
206 .to.be.equal(expectedStatus === "pending");206 .to.be.equal(expectedStatus === 'pending');
207}207}
208208
modifiedtests/src/rmrk/util/tx.tsdiffbeforeafterboth
1import { ApiPromise } from "@polkadot/api";1import {ApiPromise} from '@polkadot/api';
2import { Bytes, Option, u32, Vec } from '@polkadot/types-codec';2import {Bytes, Option, u32, Vec} from '@polkadot/types-codec';
3import {3import {
4 RmrkTraitsNftAccountIdOrCollectionNftTuple as NftOwner, RmrkTraitsPartEquippableList as EquippableList,4 RmrkTraitsNftAccountIdOrCollectionNftTuple as NftOwner, RmrkTraitsPartEquippableList as EquippableList,
5 RmrkTraitsPartPartType as PartType, RmrkTraitsResourceBasicResource as BasicResource,5 RmrkTraitsPartPartType as PartType, RmrkTraitsResourceBasicResource as BasicResource,
6 RmrkTraitsResourceComposableResource as ComposableResource, RmrkTraitsResourceResourceInfo as ResourceInfo, RmrkTraitsResourceSlotResource as SlotResource, RmrkTraitsTheme as Theme6 RmrkTraitsResourceComposableResource as ComposableResource, RmrkTraitsResourceResourceInfo as ResourceInfo, RmrkTraitsResourceSlotResource as SlotResource, RmrkTraitsTheme as Theme,
7} from "@polkadot/types/lookup";7} from '@polkadot/types/lookup';
8import { IKeyringPair } from "@polkadot/types/types";8import {IKeyringPair} from '@polkadot/types/types';
9import chai from 'chai';9import chai from 'chai';
10import chaiAsPromised from 'chai-as-promised';10import chaiAsPromised from 'chai-as-promised';
11import '../../interfaces/augment-api';11import '../../interfaces/augment-api';
12import privateKey from "../../substrate/privateKey";12import privateKey from '../../substrate/privateKey';
13import { executeTransaction } from "../../substrate/substrate-api";13import {executeTransaction} from '../../substrate/substrate-api';
14import {14import {
15 getBase,15 getBase,
16 getCollection,16 getCollection,
21 getResources, 21 getResources,
22 getResourcePriority, 22 getResourcePriority,
23 getTheme,23 getTheme,
24 NftIdTuple24 NftIdTuple,
25} from "./fetch";25} from './fetch';
26import {26import {
27 extractRmrkCoreTxResult,27 extractRmrkCoreTxResult,
28 extractRmrkEquipTxResult, isCollectionPropertyExists, isNftOwnedBy, isNftPropertyExists, isTxResultSuccess, makeNftOwner,28 extractRmrkEquipTxResult, isCollectionPropertyExists, isNftOwnedBy, isNftPropertyExists, isTxResultSuccess, makeNftOwner,
29 findResourceById, getResourceById, checkResourceStatus29 findResourceById, getResourceById, checkResourceStatus,
30} from "./helpers";30} from './helpers';
3131
32chai.use(chaiAsPromised);32chai.use(chaiAsPromised);
33const expect = chai.expect;33const expect = chai.expect;
5050
51 const collectionResult = extractRmrkCoreTxResult(51 const collectionResult = extractRmrkCoreTxResult(events, 'CollectionCreated', (data) => {
52 events, 'CollectionCreated', (data) => {
53 return parseInt(data[1].toString(), 10)52 return parseInt(data[1].toString(), 10);
54 }53 });
55 );
56 expect(collectionResult.success, 'Error: unable to create a collection').to.be.true;54 expect(collectionResult.success, 'Error: unable to create a collection').to.be.true;
6563
66 const collection = collectionOption.unwrap();64 const collection = collectionOption.unwrap();
6765
68 expect(collection.metadata.toUtf8()).to.be.equal(metadata, "Error: Invalid NFT collection metadata");66 expect(collection.metadata.toUtf8()).to.be.equal(metadata, 'Error: Invalid NFT collection metadata');
69 expect(collection.max.isSome).to.be.equal(max !== null, "Error: Invalid NFT collection max");67 expect(collection.max.isSome).to.be.equal(max !== null, 'Error: Invalid NFT collection max');
7068
71 if (collection.max.isSome) {69 if (collection.max.isSome) {
72 expect(collection.max.unwrap().toNumber()).to.be.equal(max, "Error: Invalid NFT collection max");70 expect(collection.max.unwrap().toNumber()).to.be.equal(max, 'Error: Invalid NFT collection max');
73 }71 }
74 expect(collection.symbol.toUtf8()).to.be.equal(symbol, "Error: Invalid NFT collection's symbol");72 expect(collection.symbol.toUtf8()).to.be.equal(symbol, "Error: Invalid NFT collection's symbol");
75 expect(collection.nftsCount.toNumber()).to.be.equal(0, "Error: NFT collection shoudn't have any tokens");73 expect(collection.nftsCount.toNumber()).to.be.equal(0, "Error: NFT collection shoudn't have any tokens");
76 expect(collection.issuer.toString()).to.be.equal(issuer.address, "Error: Invalid NFT collection issuer");74 expect(collection.issuer.toString()).to.be.equal(issuer.address, 'Error: Invalid NFT collection issuer');
7775
78 return collectionId;76 return collectionId;
79}77}
125121
126 const collectionTxResult = extractRmrkCoreTxResult(122 const collectionTxResult = extractRmrkCoreTxResult(
127 events,123 events,
128 "CollectionDestroy",124 'CollectionDestroy',
129 (data) => {125 (data) => {
130 return parseInt(data[1].toString(), 10);126 return parseInt(data[1].toString(), 10);
131 }127 },
132 );128 );
133 expect(collectionTxResult.success, 'Error: Unable to delete NFT collection').to.be.true;129 expect(collectionTxResult.success, 'Error: Unable to delete NFT collection').to.be.true;
134130
214 metadata: string,208 metadata: string,
215 recipientUri: string | null = null,209 recipientUri: string | null = null,
216 royalty: number | null = null,210 royalty: number | null = null,
217 transferable: boolean = true,211 transferable = true,
218 resources: {basic?: any, composable?: any, slot?: any}[] | null = null212 resources: {basic?: any, composable?: any, slot?: any}[] | null = null,
219): Promise<number> {213): Promise<number> {
220 let nftId = 0;214 let nftId = 0;
221 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;215 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
269 const nft = nftOption.unwrap();261 const nft = nftOption.unwrap();
270262
271 expect(nft.owner.isAccountId, 'Error: NFT owner should be some user').to.be.true;263 expect(nft.owner.isAccountId, 'Error: NFT owner should be some user').to.be.true;
272 expect(nft.owner.asAccountId.toString()).to.be.equal(actualOwnerAddress, "Error: Invalid NFT owner");264 expect(nft.owner.asAccountId.toString()).to.be.equal(actualOwnerAddress, 'Error: Invalid NFT owner');
273265
274 const isOwnedInUniques = await isNftOwnedBy(api, actualOwnerUri, collectionId, nftId);266 const isOwnedInUniques = await isNftOwnedBy(api, actualOwnerUri, collectionId, nftId);
275 expect(isOwnedInUniques, `Error: created NFT is not actually owned by ${ownerUri}`)267 expect(isOwnedInUniques, `Error: created NFT is not actually owned by ${ownerUri}`)
290 .to.be.true;282 .to.be.true;
291 }283 }
292284
293 expect(nft.metadata.toUtf8()).to.be.equal(metadata, "Error: Invalid NFT metadata");285 expect(nft.metadata.toUtf8()).to.be.equal(metadata, 'Error: Invalid NFT metadata');
294 286
295 const nftResources = await getResources(api, collectionId, nftId);287 const nftResources = await getResources(api, collectionId, nftId);
296 if (resources == null) {288 if (resources == null) {
311 let typedResource = null;303 let typedResource = null;
312 let typedNftResource = null;304 let typedNftResource = null;
313305
314 if (resource.basic && nftResource.hasOwnProperty("Basic")) {306 if (resource.basic && nftResource.hasOwnProperty('Basic')) {
315 typedResource = resource.basic!;307 typedResource = resource.basic!;
316 typedNftResource = nftResource["Basic" as NftResourceKey]!;308 typedNftResource = nftResource['Basic' as NftResourceKey]!;
317 } else if (resource.composable && nftResource.hasOwnProperty("Composable")) {309 } else if (resource.composable && nftResource.hasOwnProperty('Composable')) {
318 typedResource = resource.composable!;310 typedResource = resource.composable!;
319 typedNftResource = nftResource["Composable" as NftResourceKey]! as any;311 typedNftResource = nftResource['Composable' as NftResourceKey]! as any;
320 if (typedResource.parts != undefined && typedResource.parts.toString() != typedNftResource.parts.toString()312 if (typedResource.parts != undefined && typedResource.parts.toString() != typedNftResource.parts.toString()
321 || typedResource.base != typedNftResource.base && typedResource.base != undefined) {313 || typedResource.base != typedNftResource.base && typedResource.base != undefined) {
322 continue;314 continue;
323 }315 }
324 } else if (resource.slot && nftResource.hasOwnProperty("Slot")) {316 } else if (resource.slot && nftResource.hasOwnProperty('Slot')) {
325 typedResource = resource.slot!;317 typedResource = resource.slot!;
326 typedNftResource = nftResource["Slot" as NftResourceKey]! as any;318 typedNftResource = nftResource['Slot' as NftResourceKey]! as any;
327 if (typedResource.slot != typedNftResource.slot && typedResource.slot != undefined 319 if (typedResource.slot != typedNftResource.slot && typedResource.slot != undefined
328 || typedResource.base != typedNftResource.base && typedResource.base != undefined) {320 || typedResource.base != typedNftResource.base && typedResource.base != undefined) {
329 continue;321 continue;
347 // remove the matching resource from the resources we check339 // remove the matching resource from the resources we check
348 nftResources.splice(j, 1);340 nftResources.splice(j, 1);
349 successFindingResource = true;341 successFindingResource = true;
350 };342 }
351343
352 expect(successFindingResource, `Error: Couldn't find resource #${i}'s counterpart among the returned`).to.be.true;344 expect(successFindingResource, `Error: Couldn't find resource #${i}'s counterpart among the returned`).to.be.true;
353 }345 }
358350
359export async function sendNft(351export async function sendNft(
360 api: ApiPromise,352 api: ApiPromise,
361 expectedStatus: "pending" | "sent",353 expectedStatus: 'pending' | 'sent',
362 originalOwnerUri: string,354 originalOwnerUri: string,
363 collectionId: number,355 collectionId: number,
364 nftId: number,356 nftId: number,
365 newOwner: string | NftIdTuple357 newOwner: string | NftIdTuple,
366) {358) {
367 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;359 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
368 const originalOwner = privateKey(originalOwnerUri, Number(ss58Format));360 const originalOwner = privateKey(originalOwnerUri, Number(ss58Format));
373 const tx = api.tx.rmrkCore.send(collectionId, nftId, newOwnerObj);365 const tx = api.tx.rmrkCore.send(collectionId, nftId, newOwnerObj);
374 const events = await executeTransaction(api, originalOwner, tx);366 const events = await executeTransaction(api, originalOwner, tx);
375367
376 const sendResult = extractRmrkCoreTxResult(events, "NFTSent", (data) => {368 const sendResult = extractRmrkCoreTxResult(events, 'NFTSent', (data) => {
377 return {369 return {
378 dstOwner: data[1] as NftOwner,370 dstOwner: data[1] as NftOwner,
379 collectionId: parseInt(data[2].toString(), 10),371 collectionId: parseInt(data[2].toString(), 10),
403 const nftAfterSending = nftAfterSendingOpt.unwrap();395 const nftAfterSending = nftAfterSendingOpt.unwrap();
404396
405 const isOwnedByNewOwner = await isNftOwnedBy(api, newOwner, collectionId, nftId);397 const isOwnedByNewOwner = await isNftOwnedBy(api, newOwner, collectionId, nftId);
406 const isPending = expectedStatus === "pending";398 const isPending = expectedStatus === 'pending';
407399
408 expect(400 expect(
409 isOwnedByNewOwner,401 isOwnedByNewOwner,
434 const issuer = privateKey(issuerUri, Number(ss58Format));426 const issuer = privateKey(issuerUri, Number(ss58Format));
435 const newOwnerObj = makeNftOwner(api, newOwner);427 const newOwnerObj = makeNftOwner(api, newOwner);
436428
437 let nftBeforeOpt = await getNft(api, collectionId, nftId);429 const nftBeforeOpt = await getNft(api, collectionId, nftId);
438430
439 const tx = api.tx.rmrkCore.acceptNft(collectionId, nftId, newOwnerObj);431 const tx = api.tx.rmrkCore.acceptNft(collectionId, nftId, newOwnerObj);
440 const events = await executeTransaction(api, issuer, tx);432 const events = await executeTransaction(api, issuer, tx);
441433
442 const acceptResult = extractRmrkCoreTxResult(events, "NFTAccepted", (data) => {434 const acceptResult = extractRmrkCoreTxResult(events, 'NFTAccepted', (data) => {
443 return {435 return {
444 recipient: data[1] as NftOwner,436 recipient: data[1] as NftOwner,
445 collectionId: parseInt(data[2].toString(), 10),437 collectionId: parseInt(data[2].toString(), 10),
485) {477) {
486 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;478 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
487 const issuer = privateKey(issuerUri, Number(ss58Format));479 const issuer = privateKey(issuerUri, Number(ss58Format));
488 let nftBeforeOpt = await getNft(api, collectionId, nftId);480 const nftBeforeOpt = await getNft(api, collectionId, nftId);
489481
490 const tx = api.tx.rmrkCore.rejectNft(collectionId, nftId);482 const tx = api.tx.rmrkCore.rejectNft(collectionId, nftId);
491 const events = await executeTransaction(api, issuer, tx);483 const events = await executeTransaction(api, issuer, tx);
492 const rejectResult = extractRmrkCoreTxResult(events, "NFTRejected", (data) => {484 const rejectResult = extractRmrkCoreTxResult(events, 'NFTRejected', (data) => {
493 return {485 return {
494 collectionId: parseInt(data[1].toString(), 10),486 collectionId: parseInt(data[1].toString(), 10),
495 nftId: parseInt(data[2].toString(), 10)487 nftId: parseInt(data[2].toString(), 10),
528 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;520 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
529 const issuer = privateKey(issuerUri, Number(ss58Format));521 const issuer = privateKey(issuerUri, Number(ss58Format));
530522
531 const partTypes = api.createType("Vec<RmrkTraitsPartPartType>", parts) as Vec<PartType>;523 const partTypes = api.createType('Vec<RmrkTraitsPartPartType>', parts) as Vec<PartType>;
532524
533 const tx = api.tx.rmrkEquip.createBase(baseType, symbol, partTypes);525 const tx = api.tx.rmrkEquip.createBase(baseType, symbol, partTypes);
534 const events = await executeTransaction(api, issuer, tx);526 const events = await executeTransaction(api, issuer, tx);
551 const base = baseOptional.unwrap();541 const base = baseOptional.unwrap();
552 const baseParts = await getParts(api, baseId);542 const baseParts = await getParts(api, baseId);
553543
554 expect(base.issuer.toString()).to.be.equal(issuer.address, "Error: Invalid Base issuer");544 expect(base.issuer.toString()).to.be.equal(issuer.address, 'Error: Invalid Base issuer');
555 expect(base.baseType.toUtf8()).to.be.equal(baseType, "Error: Invalid Base type");545 expect(base.baseType.toUtf8()).to.be.equal(baseType, 'Error: Invalid Base type');
556 expect(base.symbol.toUtf8()).to.be.equal(symbol, "Error: Invalid Base symbol");546 expect(base.symbol.toUtf8()).to.be.equal(symbol, 'Error: Invalid Base symbol');
557 expect(partTypes.eq(baseParts), "Error: Received invalid base parts").to.be.true;547 expect(partTypes.eq(baseParts), 'Error: Received invalid base parts').to.be.true;
558548
559 return baseId;549 return baseId;
560}550}
588578
589 expect(eventData.nftId).to.be.equal(nftId, 'Error: Invalid NFT ID (set priorities event data');579 expect(eventData.nftId).to.be.equal(nftId, 'Error: Invalid NFT ID (set priorities event data');
590580
591 for (var i = 0; i < priorities.length; i++) {581 for (let i = 0; i < priorities.length; i++) {
592 const resourceId = priorities[i];582 const resourceId = priorities[i];
593583
594 const fetchedPrio = await getResourcePriority(api, collectionId, nftId, resourceId);584 const fetchedPrio = await getResourcePriority(api, collectionId, nftId, resourceId);
602 issuerUri: string,592 issuerUri: string,
603 baseId: number,593 baseId: number,
604 slotId: number,594 slotId: number,
605 equippableList: "All" | "Empty" | { 'Custom': number[] }595 equippableList: 'All' | 'Empty' | { 'Custom': number[] },
606) {596) {
607 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;597 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
608 const issuer = privateKey(issuerUri, Number(ss58Format));598 const issuer = privateKey(issuerUri, Number(ss58Format));
660650
661 expect(theme.name.eq(fetchedTheme.name), 'Error: Invalid theme name').to.be.true;651 expect(theme.name.eq(fetchedTheme.name), 'Error: Invalid theme name').to.be.true;
662652
663 for (var i = 0; i < theme.properties.length; i++) {653 for (let i = 0; i < theme.properties.length; i++) {
664 const property = theme.properties[i];654 const property = theme.properties[i];
665 const propertyKey = property.key.toUtf8();655 const propertyKey = property.key.toUtf8();
666656
692 api: ApiPromise,678 api: ApiPromise,
693 issuerUri: string,679 issuerUri: string,
694 collectionId: number,680 collectionId: number,
695 max: number = 0681 max = 0,
696) {682) {
697 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;683 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
698 const issuer = privateKey(issuerUri, Number(ss58Format));684 const issuer = privateKey(issuerUri, Number(ss58Format));
804 nftId: parseInt(data[0].toString(), 10),783 nftId: parseInt(data[0].toString(), 10),
805 resourceId: parseInt(data[1].toString(), 10)784 resourceId: parseInt(data[1].toString(), 10),
806 };785 };
807 }786 });
808 )
809787
810 expect(acceptResult.success, 'Error: Unable to accept a resource').to.be.true;788 expect(acceptResult.success, 'Error: Unable to accept a resource').to.be.true;
814 .to.be.eq(resourceId);792 .to.be.eq(resourceId);
815793
816 const resource = await getResourceById(api, collectionId, nftId, resourceId);794 const resource = await getResourceById(api, collectionId, nftId, resourceId);
817 checkResourceStatus(resource, "added");795 checkResourceStatus(resource, 'added');
818}796}
819797
820async function executeResourceCreation(798async function executeResourceCreation(
823 tx: any,801 tx: any,
824 collectionId: number,802 collectionId: number,
825 nftId: number,803 nftId: number,
826 expectedStatus: "pending" | "added"804 expectedStatus: 'pending' | 'added',
827): Promise<ResourceInfo> {805): Promise<ResourceInfo> {
828 const events = await executeTransaction(api, issuer, tx);806 const events = await executeTransaction(api, issuer, tx);
829807
844export async function addNftBasicResource(820export async function addNftBasicResource(
845 api: ApiPromise,821 api: ApiPromise,
846 issuerUri: string,822 issuerUri: string,
847 expectedStatus: "pending" | "added",823 expectedStatus: 'pending' | 'added',
848 collectionId: number,824 collectionId: number,
849 nftId: number,825 nftId: number,
850 src: string | null,826 src: string | null,
851 metadata: string | null,827 metadata: string | null,
852 license: string | null,828 license: string | null,
853 thumb: string | null829 thumb: string | null,
854): Promise<number> {830): Promise<number> {
855 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;831 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
856 const issuer = privateKey(issuerUri, Number(ss58Format));832 const issuer = privateKey(issuerUri, Number(ss58Format));
898export async function addNftComposableResource(874export async function addNftComposableResource(
899 api: ApiPromise,875 api: ApiPromise,
900 issuerUri: string,876 issuerUri: string,
901 expectedStatus: "pending" | "added",877 expectedStatus: 'pending' | 'added',
902 collectionId: number,878 collectionId: number,
903 nftId: number,879 nftId: number,
904 parts: number[],880 parts: number[],
905 baseId: number,881 baseId: number,
906 src: string | null,882 src: string | null,
907 metadata: string | null,883 metadata: string | null,
908 license: string | null,884 license: string | null,
909 thumb: string | null885 thumb: string | null,
910): Promise<number> {886): Promise<number> {
911 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;887 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
912 const issuer = privateKey(issuerUri, Number(ss58Format));888 const issuer = privateKey(issuerUri, Number(ss58Format));
960export async function addNftSlotResource(936export async function addNftSlotResource(
961 api: ApiPromise,937 api: ApiPromise,
962 issuerUri: string,938 issuerUri: string,
963 expectedStatus: "pending" | "added",939 expectedStatus: 'pending' | 'added',
964 collectionId: number,940 collectionId: number,
965 nftId: number,941 nftId: number,
966 baseId: number,942 baseId: number,
967 slotId: number,943 slotId: number,
968 src: string | null,944 src: string | null,
969 metadata: string | null,945 metadata: string | null,
970 license: string | null,946 license: string | null,
971 thumb: string | null947 thumb: string | null,
972): Promise<number> {948): Promise<number> {
973 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;949 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
974 const issuer = privateKey(issuerUri, Number(ss58Format));950 const issuer = privateKey(issuerUri, Number(ss58Format));
1040 base_id: parseInt(data[2].toString(), 10),1015 base_id: parseInt(data[2].toString(), 10),
1041 slot_id: parseInt(data[3].toString(), 10),1016 slot_id: parseInt(data[3].toString(), 10),
1042 };1017 };
1043 }1018 });
1044 )
1045 expect(equipResult.success, 'Error: Unable to equip an item').to.be.true;1019 expect(equipResult.success, 'Error: Unable to equip an item').to.be.true;
1046 expect(equipResult.successData!.item_collection, 'Error: Invalid item collection id')1020 expect(equipResult.successData!.item_collection, 'Error: Invalid item collection id')
10691043
1070 const unEquipResult = extractRmrkEquipTxResult(1044 const unEquipResult = extractRmrkEquipTxResult(
1071 events,1045 events,
1072 "SlotUnequipped",1046 'SlotUnequipped',
1073 (data) => {1047 (data) => {
1074 return {1048 return {
1075 item_collection: parseInt(data[0].toString(), 10),1049 item_collection: parseInt(data[0].toString(), 10),
1076 item_nft: parseInt(data[1].toString(), 10),1050 item_nft: parseInt(data[1].toString(), 10),
1077 base_id: parseInt(data[2].toString(), 10),1051 base_id: parseInt(data[2].toString(), 10),
1078 slot_id: parseInt(data[3].toString(), 10),1052 slot_id: parseInt(data[3].toString(), 10),
1079 };1053 };
1080 }1054 },
1081 );1055 );
10821056
1083 expect(unEquipResult.success, 'Error: Unable to unequip an item').to.be.true;1057 expect(unEquipResult.success, 'Error: Unable to unequip an item').to.be.true;
10931067
1094export async function removeNftResource(1068export async function removeNftResource(
1095 api: ApiPromise,1069 api: ApiPromise,
1096 expectedStatus: "pending" | "removed",1070 expectedStatus: 'pending' | 'removed',
1097 issuerUri: string,1071 issuerUri: string,
1098 collectionId: number,1072 collectionId: number,
1099 nftId: number,1073 nftId: number,
1100 resourceId: number1074 resourceId: number,
1101) {1075) {
1102 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;1076 const ss58Format = api.registry.getChainProperties()!.toJSON().ss58Format;
1103 const issuer = privateKey(issuerUri, Number(ss58Format));1077 const issuer = privateKey(issuerUri, Number(ss58Format));
1110 nftId: parseInt(data[0].toString(), 10),1083 nftId: parseInt(data[0].toString(), 10),
1111 resourceId: parseInt(data[1].toString(), 10)1084 resourceId: parseInt(data[1].toString(), 10),
1112 };1085 };
1113 }1086 });
1114 )
1115 expect(removeResult.success, 'Error: Unable to remove a resource').to.be.true;1087 expect(removeResult.success, 'Error: Unable to remove a resource').to.be.true;
1116 expect(removeResult.successData!.nftId, 'Error: Invalid NFT Id while removing a resource')1088 expect(removeResult.successData!.nftId, 'Error: Invalid NFT Id while removing a resource')
1117 .to.be.eq(nftId);1089 .to.be.eq(nftId);
1118 expect(removeResult.successData!.resourceId, 'Error: Invalid resource Id while removing a resource')1090 expect(removeResult.successData!.resourceId, 'Error: Invalid resource Id while removing a resource')
1119 .to.be.eq(resourceId);1091 .to.be.eq(resourceId);
11201092
1121 let afterDeleting = await findResourceById(api, collectionId, nftId, resourceId);1093 const afterDeleting = await findResourceById(api, collectionId, nftId, resourceId);
11221094
1123 if (expectedStatus === 'pending') {1095 if (expectedStatus === 'pending') {
1124 expect(afterDeleting).not.to.be.null;1096 expect(afterDeleting).not.to.be.null;
1146 nftId: parseInt(data[0].toString(), 10),1117 nftId: parseInt(data[0].toString(), 10),
1147 resourceId: parseInt(data[1].toString(), 10)1118 resourceId: parseInt(data[1].toString(), 10),
1148 };1119 };
1149 }1120 });
1150 )
1151 expect(acceptResult.success, 'Error: Unable to accept a resource').to.be.true;1121 expect(acceptResult.success, 'Error: Unable to accept a resource').to.be.true;
1152 expect(acceptResult.successData!.nftId, 'Error: Invalid NFT Id while accepting a resource')1122 expect(acceptResult.successData!.nftId, 'Error: Invalid NFT Id while accepting a resource')
1153 .to.be.eq(nftId);1123 .to.be.eq(nftId);
1154 expect(acceptResult.successData!.resourceId, 'Error: Invalid resource Id while accepting a resource')1124 expect(acceptResult.successData!.resourceId, 'Error: Invalid resource Id while accepting a resource')
1155 .to.be.eq(resourceId);1125 .to.be.eq(resourceId);
11561126
1157 let afterDeleting = await findResourceById(api, collectionId, nftId, resourceId);1127 const afterDeleting = await findResourceById(api, collectionId, nftId, resourceId);
1158 expect(afterDeleting, 'Error: resource deleting failed').to.be.null;1128 expect(afterDeleting, 'Error: resource deleting failed').to.be.null;
1159}1129}
11601130
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
6161
62export async function getApiConnection(settings: ApiOptions | undefined = undefined): Promise<ApiPromise> {62export async function getApiConnection(settings: ApiOptions | undefined = undefined): Promise<ApiPromise> {
63 settings = settings || defaultApiOptions();63 settings = settings || defaultApiOptions();
64 let api = new ApiPromise(settings);64 const api = new ApiPromise(settings);
6565
66 if (api) {66 if (api) {
67 await api.isReadyOrError;67 await api.isReadyOrError;