git.delta.rocks / unique-network / refs/commits / 764dfd599fff

difftreelog

Quick fix for nesting tests

Andrey Kuznetsov2022-05-29parent: #e4d7343.patch.diff
in: master

5 files changed

modifiedtests/src/nesting/graphs.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -14,7 +14,7 @@
  * ```
  */
 async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {
-  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}}));
+  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', permissions: {nesting: 'Owner'}}));
   const {collectionId} = getCreateCollectionResult(events);
 
   await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -8,11 +8,11 @@
   createItemExpectSuccess,
   enableAllowListExpectSuccess,
   enablePublicMintingExpectSuccess,
-  getTokenOwner, 
+  getTokenOwner,
   getTopmostTokenOwner,
-  setCollectionLimitsExpectSuccess, 
-  transferExpectFailure, 
-  transferExpectSuccess, 
+  setCollectionPermissionsExceptSuccess,
+  transferExpectFailure,
+  transferExpectSuccess,
   transferFromExpectSuccess,
 } from '../util/helpers';
 import {IKeyringPair} from '@polkadot/types/types';
@@ -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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Create a nested-token matryoshka
@@ -226,7 +226,7 @@
   it('NFT: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});
+      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Try to create a nested token
@@ -248,7 +248,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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
 
       await addToAllowListExpectSuccess(alice, collection, bob.address);
       await enableAllowListExpectSuccess(alice, collection);
@@ -274,7 +274,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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});
 
       await addToAllowListExpectSuccess(alice, collection, bob.address);
       await enableAllowListExpectSuccess(alice, collection);
@@ -300,7 +300,7 @@
   it('NFT: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -324,7 +324,7 @@
   it('Fungible: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -352,7 +352,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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
 
       await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
       await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -389,7 +389,7 @@
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
       const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});
 
       // Try to create a nested token in the wrong collection
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -407,7 +407,7 @@
   it('Fungible: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
@@ -433,7 +433,7 @@
   it('ReFungible: disallows to nest token if nesting is disabled', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
@@ -463,7 +463,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 setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'});
 
       await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
       await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -500,7 +500,7 @@
       const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
 
       const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});
 
       // Try to create a nested token in the wrong collection
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
@@ -518,7 +518,7 @@
   it('ReFungible: disallows to nest token to an unlisted collection', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
+      await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});
 
       // Create a token to attempt to be nested into
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
modifiedtests/src/nesting/rules-smoke.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/rules-smoke.test.ts
+++ b/tests/src/nesting/rules-smoke.test.ts
@@ -14,8 +14,8 @@
       const bob = privateKey('//Bob');
       const events = await executeTransaction(api, alice, api.tx.unique.createCollectionEx({
         mode: 'NFT',
-        limits: {
-          nestingRule: {OwnerRestricted: []},
+        permissions: {
+          nesting: {OwnerRestricted: []},
         },
       }));
       const collection = getCreateCollectionResult(events).collectionId;
@@ -39,7 +39,7 @@
   it('called for nonfungible', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {ConstData: []}})))
+      await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {properties: []}})))
         .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);
 
       const token = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
@@ -51,7 +51,7 @@
   it('called for refungible', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
-      await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {ConstData: []}})))
+      await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {}})))
         .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);
 
       const token = await createItemExpectSuccess(alice, collection, 'ReFungible', {Substrate: alice.address});
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,
-  setCollectionLimitsExpectSuccess,
+  setCollectionPermissionsExceptSuccess,
   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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      await setCollectionPermissionsExceptSuccess(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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+    await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'});
     const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
     // Create a nested token ouroboros
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
325};325};
326326
327export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {327export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
328 const {name, description, mode, tokenPrefix, schemaVersion} = {...defaultCreateCollectionParams, ...params};328 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
329329
330 let collectionId = 0;330 let collectionId = 0;
331 await usingApi(async (api) => {331 await usingApi(async (api) => {
348 name: strToUTF16(name),348 name: strToUTF16(name),
349 description: strToUTF16(description),349 description: strToUTF16(description),
350 tokenPrefix: strToUTF16(tokenPrefix),350 tokenPrefix: strToUTF16(tokenPrefix),
351 mode: modeprm as any,351 mode: modeprm as any
352 schemaVersion: schemaVersion,
353 });352 });
354 const events = await submitTransactionAsync(alicePrivateKey, tx);353 const events = await submitTransactionAsync(alicePrivateKey, tx);
355 const result = getCreateCollectionResult(events);354 const result = getCreateCollectionResult(events);
555 });554 });
556}555}
556
557export const setCollectionPermissionsExceptSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {
558 await usingApi(async(api) => {
559 const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions);
560 const events = await submitTransactionAsync(sender, tx);
561 const result = getGenericResult(events);
562
563 expect(result.success).to.be.true;
564 });
565}
557566
558export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {567export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {
559 await usingApi(async (api) => {568 await usingApi(async (api) => {
1299 // What to expect1308 // What to expect
1300 // tslint:disable-next-line:no-unused-expression1309 // tslint:disable-next-line:no-unused-expression
1301 expect(result.success).to.be.true;1310 expect(result.success).to.be.true;
1302 expect(collection.access.toHuman()).to.be.equal(accessMode);1311 expect(collection.permissions.access.toHuman()).to.be.equal(accessMode);
1303 });1312 });
1304}1313}
13051314
1344 // Get the collection1353 // Get the collection
1345 const collection = await queryCollectionExpectSuccess(api, collectionId);1354 const collection = await queryCollectionExpectSuccess(api, collectionId);
13461355
1347 expect(collection.mintMode.toHuman()).to.be.equal(enabled);1356 expect(collection.permissions.mintMode.toHuman()).to.be.equal(enabled);
1348 });1357 });
1349}1358}
13501359