git.delta.rocks / unique-network / refs/commits / 7cf62e7cc906

difftreelog

Fixes for nesting and permissions tests

Andrey Kuznetsov2022-05-30parent: #fa5a068.patch.diff
in: master

3 files changed

modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
10 enablePublicMintingExpectSuccess,10 enablePublicMintingExpectSuccess,
11 getTokenOwner,11 getTokenOwner,
12 getTopmostTokenOwner,12 getTopmostTokenOwner,
13 setCollectionPermissionsExceptSuccess,13 setCollectionPermissionsExpectSuccess,
14 transferExpectFailure,14 transferExpectFailure,
15 transferExpectSuccess,15 transferExpectSuccess,
16 transferFromExpectSuccess,16 transferFromExpectSuccess,
31 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {31 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {
32 await usingApi(async api => {32 await usingApi(async api => {
33 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});33 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
34 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});34 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
35 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');35 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
3636
37 // Create a nested token37 // Create a nested token
63 it('NFT: allows an Owner to nest/unnest their token', async () => {63 it('NFT: allows an Owner to nest/unnest their token', async () => {
64 await usingApi(async api => {64 await usingApi(async api => {
65 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});65 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
66 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});66 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
67 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');67 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
6868
69 // Create a nested token69 // Create a nested token
82 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {82 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
83 await usingApi(async api => {83 await usingApi(async api => {
84 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});84 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
85 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});85 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
86 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');86 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
8787
88 // Create a nested token88 // Create a nested token
103 it('Fungible: allows an Owner to nest/unnest their token', async () => {103 it('Fungible: allows an Owner to nest/unnest their token', async () => {
104 await usingApi(async api => {104 await usingApi(async api => {
105 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});105 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
106 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});106 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
107 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});107 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
108 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};108 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
109109
130130
131 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});131 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
132132
133 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});133 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});
134134
135 // Create a nested token135 // Create a nested token
136 await expect(executeTransaction(api, alice, api.tx.unique.createItem(136 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
150 it('ReFungible: allows an Owner to nest/unnest their token', async () => {150 it('ReFungible: allows an Owner to nest/unnest their token', async () => {
151 await usingApi(async api => {151 await usingApi(async api => {
152 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});152 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
153 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});153 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
154 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});154 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
155 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};155 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
156156
177177
178 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});178 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
179179
180 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});180 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
181181
182 // Create a nested token182 // Create a nested token
183 await expect(executeTransaction(api, alice, api.tx.unique.createItem(183 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
204 it('Disallows excessive token nesting', async () => {204 it('Disallows excessive token nesting', async () => {
205 await usingApi(async api => {205 await usingApi(async api => {
206 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});206 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
207 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});207 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
208 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');208 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
209209
210 const maxNestingLevel = 5;210 const maxNestingLevel = 5;
238 it('NFT: disallows to nest token if nesting is disabled', async () => {238 it('NFT: disallows to nest token if nesting is disabled', async () => {
239 await usingApi(async api => {239 await usingApi(async api => {
240 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});240 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
241 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'});241 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});
242 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');242 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
243243
244 // Try to create a nested token244 // Try to create a nested token
260 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {260 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {
261 await usingApi(async api => {261 await usingApi(async api => {
262 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});262 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
263 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});263 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
264264
265 await addToAllowListExpectSuccess(alice, collection, bob.address);265 await addToAllowListExpectSuccess(alice, collection, bob.address);
266 await enableAllowListExpectSuccess(alice, collection);266 await enableAllowListExpectSuccess(alice, collection);
286 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {286 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
287 await usingApi(async api => {287 await usingApi(async api => {
288 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});288 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
289 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});289 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
290290
291 await addToAllowListExpectSuccess(alice, collection, bob.address);291 await addToAllowListExpectSuccess(alice, collection, bob.address);
292 await enableAllowListExpectSuccess(alice, collection);292 await enableAllowListExpectSuccess(alice, collection);
312 it('NFT: disallows to nest token in an unlisted collection', async () => {312 it('NFT: disallows to nest token in an unlisted collection', async () => {
313 await usingApi(async api => {313 await usingApi(async api => {
314 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});314 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
315 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});315 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
316316
317 // Create a token to attempt to be nested into317 // Create a token to attempt to be nested into
318 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');318 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
336 it('Fungible: disallows to nest token if nesting is disabled', async () => {336 it('Fungible: disallows to nest token if nesting is disabled', async () => {
337 await usingApi(async api => {337 await usingApi(async api => {
338 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});338 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
339 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});339 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
340 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');340 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
341 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};341 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
342342
364 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {364 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {
365 await usingApi(async api => {365 await usingApi(async api => {
366 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});366 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
367 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});367 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
368368
369 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);369 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
370 await enableAllowListExpectSuccess(alice, collectionNFT);370 await enableAllowListExpectSuccess(alice, collectionNFT);
401 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};401 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
402402
403 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});403 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
404 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});404 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
405405
406 // Try to create a nested token in the wrong collection406 // Try to create a nested token in the wrong collection
407 await expect(executeTransaction(api, alice, api.tx.unique.createItem(407 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
419 it('Fungible: disallows to nest token in an unlisted collection', async () => {419 it('Fungible: disallows to nest token in an unlisted collection', async () => {
420 await usingApi(async api => {420 await usingApi(async api => {
421 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});421 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
422 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});422 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
423423
424 // Create a token to attempt to be nested into424 // Create a token to attempt to be nested into
425 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');425 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
445 it('ReFungible: disallows to nest token if nesting is disabled', async () => {445 it('ReFungible: disallows to nest token if nesting is disabled', async () => {
446 await usingApi(async api => {446 await usingApi(async api => {
447 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});447 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
448 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});448 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
449 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');449 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
450 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};450 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
451451
475 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {475 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {
476 await usingApi(async api => {476 await usingApi(async api => {
477 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});477 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
478 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});478 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
479479
480 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);480 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
481 await enableAllowListExpectSuccess(alice, collectionNFT);481 await enableAllowListExpectSuccess(alice, collectionNFT);
512 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};512 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
513513
514 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});514 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
515 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});515 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
516516
517 // Try to create a nested token in the wrong collection517 // Try to create a nested token in the wrong collection
518 await expect(executeTransaction(api, alice, api.tx.unique.createItem(518 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
530 it('ReFungible: disallows to nest token to an unlisted collection', async () => {530 it('ReFungible: disallows to nest token to an unlisted collection', async () => {
531 await usingApi(async api => {531 await usingApi(async api => {
532 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});532 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
533 await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});533 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
534534
535 // Create a token to attempt to be nested into535 // Create a token to attempt to be nested into
536 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');536 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
modifiedtests/src/nesting/unnest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -8,7 +8,7 @@
   getBalance,
   getTokenOwner,
   normalizeAccountId,
-  setCollectionPermissionsExceptSuccess,
+  setCollectionPermissionsExpectSuccess,
   transferExpectSuccess,
   transferFromExpectSuccess,
 } from '../util/helpers';
@@ -28,7 +28,7 @@
   it('NFT: allows the owner to successfully unnest a token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
 
@@ -57,7 +57,7 @@
   it('Fungible: allows the owner to successfully unnest a token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
 
@@ -84,7 +84,7 @@
   it('ReFungible: allows the owner to successfully unnest a token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
 
@@ -119,7 +119,7 @@
   it('Disallows a non-owner to unnest/burn a token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
 
@@ -149,7 +149,7 @@
   // Recursive nesting
   it('Prevents Ouroboros creation', async () => {
     const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-    await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
+    await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
     const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
     // Create a nested token ouroboros
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -554,7 +554,7 @@
   });
 }
 
-export const setCollectionPermissionsExceptSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {
+export const setCollectionPermissionsExpectSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {
   await usingApi(async(api) => {
     const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions);
     const events = await submitTransactionAsync(sender, tx);
@@ -1298,7 +1298,7 @@
   await usingApi(async (api) => {
 
     // Run the transaction
-    const tx = api.tx.unique.setPublicAccessMode(collectionId, accessMode);
+    const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});
     const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
 
@@ -1319,7 +1319,7 @@
   await usingApi(async (api) => {
 
     // Run the transaction
-    const tx = api.tx.unique.setPublicAccessMode(collectionId, accessMode);
+    const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});
     const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
     const result = getGenericResult(events);
 
@@ -1345,7 +1345,7 @@
   await usingApi(async (api) => {
 
     // Run the transaction
-    const tx = api.tx.unique.setMintPermission(collectionId, enabled);
+    const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});
     const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
     expect(result.success).to.be.true;