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
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -10,7 +10,7 @@
   enablePublicMintingExpectSuccess,
   getTokenOwner,
   getTopmostTokenOwner,
-  setCollectionPermissionsExceptSuccess,
+  setCollectionPermissionsExpectSuccess,
   transferExpectFailure,
   transferExpectSuccess,
   transferFromExpectSuccess,
@@ -31,7 +31,7 @@
   it('Performs the full suite: bundles a token, transfers, and allows to unnest', 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');
 
       // Create a nested token
@@ -63,7 +63,7 @@
   it('NFT: allows an Owner to nest/unnest their 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');
 
       // Create a nested token
@@ -82,7 +82,7 @@
   it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Create a nested token
@@ -103,7 +103,7 @@
   it('Fungible: allows an Owner to nest/unnest their token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -130,7 +130,7 @@
 
       const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
 
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});
 
       // Create a nested token
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -150,7 +150,7 @@
   it('ReFungible: allows an Owner to nest/unnest their token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -177,7 +177,7 @@
 
       const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
 
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
 
       // Create a nested token
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -204,7 +204,7 @@
   it('Disallows excessive token nesting', 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 maxNestingLevel = 5;
@@ -238,7 +238,7 @@
   it('NFT: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Try to create a nested token
@@ -260,7 +260,7 @@
   it('NFT: disallows a non-Owner to nest someone else\'s 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'});
 
       await addToAllowListExpectSuccess(alice, collection, bob.address);
       await enableAllowListExpectSuccess(alice, collection);
@@ -286,7 +286,7 @@
   it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
 
       await addToAllowListExpectSuccess(alice, collection, bob.address);
       await enableAllowListExpectSuccess(alice, collection);
@@ -312,7 +312,7 @@
   it('NFT: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -336,7 +336,7 @@
   it('Fungible: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -364,7 +364,7 @@
   it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
 
       await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
       await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -401,7 +401,7 @@
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
       const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
 
       // Try to create a nested token in the wrong collection
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -419,7 +419,7 @@
   it('Fungible: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
@@ -445,7 +445,7 @@
   it('ReFungible: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -475,7 +475,7 @@
   it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});
 
       await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
       await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -512,7 +512,7 @@
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
       const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
 
       // Try to create a nested token in the wrong collection
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -530,7 +530,7 @@
   it('ReFungible: disallows to nest token to an unlisted collection', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
modifiedtests/src/nesting/unnest.test.tsdiffbeforeafterboth
8 getBalance,8 getBalance,
9 getTokenOwner,9 getTokenOwner,
10 normalizeAccountId,10 normalizeAccountId,
11 setCollectionPermissionsExceptSuccess,11 setCollectionPermissionsExpectSuccess,
12 transferExpectSuccess,12 transferExpectSuccess,
13 transferFromExpectSuccess,13 transferFromExpectSuccess,
14} from '../util/helpers';14} from '../util/helpers';
28 it('NFT: allows the owner to successfully unnest a token', async () => {28 it('NFT: allows the owner to successfully unnest a token', async () => {
29 await usingApi(async api => {29 await usingApi(async api => {
30 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});30 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
31 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});31 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
32 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');32 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
33 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};33 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
3434
57 it('Fungible: allows the owner to successfully unnest a token', async () => {57 it('Fungible: allows the owner to successfully unnest a token', async () => {
58 await usingApi(async api => {58 await usingApi(async api => {
59 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});59 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
60 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});60 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
61 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');61 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
62 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};62 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
6363
84 it('ReFungible: allows the owner to successfully unnest a token', async () => {84 it('ReFungible: allows the owner to successfully unnest a token', async () => {
85 await usingApi(async api => {85 await usingApi(async api => {
86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});86 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
87 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});87 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
88 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');88 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
89 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};89 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
9090
119 it('Disallows a non-owner to unnest/burn a token', async () => {119 it('Disallows a non-owner to unnest/burn a token', async () => {
120 await usingApi(async api => {120 await usingApi(async api => {
121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});121 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
122 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});122 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
123 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');123 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
124 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};124 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
125125
149 // Recursive nesting149 // Recursive nesting
150 it('Prevents Ouroboros creation', async () => {150 it('Prevents Ouroboros creation', async () => {
151 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});151 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
152 await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});152 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
153 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');153 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
154154
155 // Create a nested token ouroboros155 // 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;