git.delta.rocks / unique-network / refs/commits / c4efebc46da8

difftreelog

test transfer already nested token + destroy a non-empty collection + additional refactoring

Fahrrader2022-05-30parent: #b46fb6f.patch.diff
in: master

7 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -54,6 +54,7 @@
     "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
     "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
     "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+    "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",
     "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",
     "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",
     "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
modifiedtests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth
--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -29,13 +29,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
@@ -57,15 +54,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x1111',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -88,15 +82,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -119,15 +110,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -272,13 +260,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
@@ -300,13 +285,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -25,6 +25,7 @@
   setCollectionLimitsExpectSuccess,
   addCollectionAdminExpectSuccess,
   getCreatedCollectionCount,
+  createItemExpectSuccess,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -83,4 +84,10 @@
 
     await destroyCollectionExpectFailure(collectionId, '//Alice');
   });
+  it('fails when a collection still has a token', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await createItemExpectSuccess(alice, collectionId, 'NFT');
+
+    await destroyCollectionExpectFailure(collectionId, '//Alice');
+  });
 });
modifiedtests/src/nesting/migration-check.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -31,12 +31,12 @@
         name: strToUTF16('Mojave Pictures'),
         description: strToUTF16('$2.2 billion power plant!'),
         tokenPrefix: '0x0002030',
-        offchainSchema: '0x111111',
-        schemaVersion: 'Unique',
+        //offchainSchema: '0x111111',
+        //schemaVersion: 'Unique',
         limits: {
           accountTokenOwnershipLimit: 3,
         },
-        constOnChainSchema: '0x333333',
+        //constOnChainSchema: '0x333333',
       });
       const events = await submitTransactionAsync(alice, tx);
       const result = getCreateCollectionResult(events);
@@ -96,17 +96,17 @@
       const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;
 
       // Make sure the extra fields are what they should be
-      const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
-      const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
+      //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
+      //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
 
-      expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
-      expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
+      //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
+      //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
       expect(collectionNew).to.have.nested.property('limits.nestingRule');
 
       // Get rid of extra fields to perform comparison on the rest of the collection
       delete collectionNew.limits.nestingRule;
-      delete collectionOld.constOnChainSchema;
-      delete collectionOld.offchainSchema;
+      //delete collectionOld.constOnChainSchema;
+      //delete collectionOld.offchainSchema;
 
       expect(collectionNew).to.be.deep.equal(collectionOld);
     });
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
before · tests/src/nesting/nest.test.ts
1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6  addToAllowListExpectSuccess,7  createCollectionExpectSuccess,8  createItemExpectSuccess,9  enableAllowListExpectSuccess,10  enablePublicMintingExpectSuccess,11  getTokenOwner,12  getTopmostTokenOwner,13  setCollectionPermissionsExpectSuccess,14  transferExpectFailure,15  transferExpectSuccess,16  transferFromExpectSuccess,17} from '../util/helpers';18import {IKeyringPair} from '@polkadot/types/types';1920let alice: IKeyringPair;21let bob: IKeyringPair;2223describe('Integration Test: Nesting', () => {24  before(async () => {25    await usingApi(async () => {26      alice = privateKey('//Alice');27      bob = privateKey('//Bob');28    });29  });3031  it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {32    await usingApi(async api => {33      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});34      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});35      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3637      // Create a nested token38      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});39      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});40      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4142      // Create a token to be nested43      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4445      // Nest46      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});47      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});48      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4950      // Move bundle to different user51      await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});52      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});53      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5455      // Unnest56      await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});57      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});58    });59  });6061  // ---------- Non-Fungible ----------6263  it('NFT: allows an Owner to nest/unnest their token', async () => {64    await usingApi(async api => {65      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});67      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');6869      // Create a nested token70      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});71      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});72      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});7374      // Create a token to be nested and nest75      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');76      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});77      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});78      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});79    });80  });8182  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {83    await usingApi(async api => {84      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});85      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});86      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');8788      // Create a nested token89      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});90      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});91      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});9293      // Create a token to be nested and nest94      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');95      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});96      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});97      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});98    });99  });100101  // ---------- Fungible ----------102103  it('Fungible: allows an Owner to nest/unnest their token', async () => {104    await usingApi(async api => {105      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});106      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});107      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});108      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};109110      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});111112      // Create a nested token113      await expect(executeTransaction(api, alice, api.tx.unique.createItem(114        collectionFT,115        targetAddress,116        {Fungible: {Value: 10}},117      ))).to.not.be.rejected;118119      // Nest a new token120      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');121      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');122    });123  });124125  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {126    await usingApi(async api => {127      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});128      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});129      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};130131      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});132133      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});134135      // Create a nested token136      await expect(executeTransaction(api, alice, api.tx.unique.createItem(137        collectionFT,138        targetAddress,139        {Fungible: {Value: 10}},140      ))).to.not.be.rejected;141142      // Nest a new token143      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');144      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');145    });146  });147148  // ---------- Re-Fungible ----------149150  it('ReFungible: allows an Owner to nest/unnest their token', async () => {151    await usingApi(async api => {152      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});153      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});154      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});155      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};156157      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158159      // Create a nested token160      await expect(executeTransaction(api, alice, api.tx.unique.createItem(161        collectionRFT,162        targetAddress,163        {ReFungible: {const_data: [], pieces: 100}},164      ))).to.not.be.rejected;165166      // Nest a new token167      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');168      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');169    });170  });171172  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {173    await usingApi(async api => {174      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});176      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};177178      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179180      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});181182      // Create a nested token183      await expect(executeTransaction(api, alice, api.tx.unique.createItem(184        collectionRFT,185        targetAddress,186        {ReFungible: {const_data: [], pieces: 100}},187      ))).to.not.be.rejected;188189      // Nest a new token190      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');191      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');192    });193  });194});195196describe('Negative Test: Nesting', async() => {197  before(async () => {198    await usingApi(async () => {199      alice = privateKey('//Alice');200      bob = privateKey('//Bob');201    });202  });203204  it('Disallows excessive token nesting', async () => {205    await usingApi(async api => {206      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});207      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});208      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');209210      const maxNestingLevel = 5;211      let prevToken = targetToken;212213      // Create a nested-token matryoshka214      for (let i = 0; i < maxNestingLevel; i++) {215        const nestedToken = await createItemExpectSuccess(216          alice,217          collection,218          'NFT',219          {Ethereum: tokenIdToAddress(collection, prevToken)},220        );221222        prevToken = nestedToken;223      }224225      // The nesting depth is limited by `maxNestingLevel`226      await expect(executeTransaction(api, alice, api.tx.unique.createItem(227        collection,228        {Ethereum: tokenIdToAddress(collection, prevToken)},229          {nft: {const_data: [], variable_data: []}} as any,230      )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);231232      expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});233    });234  });235236  // ---------- Non-Fungible ----------237238  it('NFT: disallows to nest token if nesting is disabled', async () => {239    await usingApi(async api => {240      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});241      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});242      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');243244      // Try to create a nested token245      await expect(executeTransaction(api, alice, api.tx.unique.createItem(246        collection,247        {Ethereum: tokenIdToAddress(collection, targetToken)},248          {nft: {const_data: [], variable_data: []}} as any,249      )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);250251      // Create a token to be nested252      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');253      // Try to nest254      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);255      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});256      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});257    });258  });259260  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {261    await usingApi(async api => {262      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});263      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});264265      await addToAllowListExpectSuccess(alice, collection, bob.address);266      await enableAllowListExpectSuccess(alice, collection);267      await enablePublicMintingExpectSuccess(alice, collection);268269      // Create a token to attempt to be nested into270      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');271272      // Try to create a nested token in the wrong collection273      await expect(executeTransaction(api, alice, api.tx.unique.createItem(274        collection,275        {Ethereum: tokenIdToAddress(collection, targetToken)},276          {nft: {const_data: [], variable_data: []}} as any,277      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);278279      // Try to create and nest a token in the wrong collection280      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');281      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);282      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});283    });284  });285286  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {287    await usingApi(async api => {288      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});289      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});290291      await addToAllowListExpectSuccess(alice, collection, bob.address);292      await enableAllowListExpectSuccess(alice, collection);293      await enablePublicMintingExpectSuccess(alice, collection);294295      // Create a token to attempt to be nested into296      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');297298      // Try to create a nested token in the wrong collection299      await expect(executeTransaction(api, alice, api.tx.unique.createItem(300        collection,301        {Ethereum: tokenIdToAddress(collection, targetToken)},302          {nft: {const_data: [], variable_data: []}} as any,303      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);304305      // Try to create and nest a token in the wrong collection306      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');307      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);308      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});309    });310  });311312  it('NFT: disallows to nest token in an unlisted collection', async () => {313    await usingApi(async api => {314      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});315      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});316317      // Create a token to attempt to be nested into318      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');319320      // Try to create a nested token in the wrong collection321      await expect(executeTransaction(api, alice, api.tx.unique.createItem(322        collection,323        {Ethereum: tokenIdToAddress(collection, targetToken)},324          {nft: {const_data: [], variable_data: []}} as any,325      )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);326327      // Try to create and nest a token in the wrong collection328      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');329      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);330      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});331    });332  });333334  // ---------- Fungible ----------335336  it('Fungible: disallows to nest token if nesting is disabled', async () => {337    await usingApi(async api => {338      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});339      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});340      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');341      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};342343      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});344345      // Try to create a nested token346      await expect(executeTransaction(api, alice, api.tx.unique.createItem(347        collectionFT,348        targetAddress,349        {Fungible: {Value: 10}},350      )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);351352      // Create a token to be nested353      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');354      // Try to nest355      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);356357      // Create another token to be nested358      const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');359      // Try to nest inside a fungible token360      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);361    });362  });363364  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {365    await usingApi(async api => {366      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});367      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});368369      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);370      await enableAllowListExpectSuccess(alice, collectionNFT);371      await enablePublicMintingExpectSuccess(alice, collectionNFT);372373      // Create a token to attempt to be nested into374      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');375      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};376377      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});378379      // Try to create a nested token in the wrong collection380      await expect(executeTransaction(api, alice, api.tx.unique.createItem(381        collectionFT,382        targetAddress,383        {Fungible: {Value: 10}},384      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);385386      // Try to create and nest a token in the wrong collection387      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');388      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);389    });390  });391392  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {393    await usingApi(async api => {394      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});395      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);396      await enableAllowListExpectSuccess(alice, collectionNFT);397      await enablePublicMintingExpectSuccess(alice, collectionNFT);398399      // Create a token to attempt to be nested into400      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');401      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};402403      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});404      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});405406      // Try to create a nested token in the wrong collection407      await expect(executeTransaction(api, alice, api.tx.unique.createItem(408        collectionFT,409        targetAddress,410        {Fungible: {Value: 10}},411      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);412413      // Try to create and nest a token in the wrong collection414      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');415      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);416    });417  });418419  it('Fungible: disallows to nest token in an unlisted collection', async () => {420    await usingApi(async api => {421      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});422      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});423424      // Create a token to attempt to be nested into425      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');426      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};427428      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});429430      // Try to create a nested token in the wrong collection431      await expect(executeTransaction(api, alice, api.tx.unique.createItem(432        collectionFT,433        targetAddress,434        {Fungible: {Value: 10}},435      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);436437      // Try to create and nest a token in the wrong collection438      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');439      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);440    });441  });442443  // ---------- Re-Fungible ----------444445  it('ReFungible: disallows to nest token if nesting is disabled', async () => {446    await usingApi(async api => {447      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});448      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});449      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');450      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};451452      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});453454      // Create a nested token455      await expect(executeTransaction(api, alice, api.tx.unique.createItem(456        collectionRFT,457        targetAddress,458        {ReFungible: {const_data: [], pieces: 100}},459      )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);460461      // Create a token to be nested462      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');463      // Try to nest464      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);465      // Try to nest466      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);467468      // Create another token to be nested469      const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');470      // Try to nest inside a fungible token471      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);472    });473  });474475  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {476    await usingApi(async api => {477      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});478      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});479480      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);481      await enableAllowListExpectSuccess(alice, collectionNFT);482      await enablePublicMintingExpectSuccess(alice, collectionNFT);483484      // Create a token to attempt to be nested into485      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');486      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};487488      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});489490      // Try to create a nested token in the wrong collection491      await expect(executeTransaction(api, alice, api.tx.unique.createItem(492        collectionRFT,493        targetAddress,494        {ReFungible: {const_data: [], pieces: 100}},495      )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);496497      // Try to create and nest a token in the wrong collection498      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');499      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);500    });501  });502503  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {504    await usingApi(async api => {505      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});506      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);507      await enableAllowListExpectSuccess(alice, collectionNFT);508      await enablePublicMintingExpectSuccess(alice, collectionNFT);509510      // Create a token to attempt to be nested into511      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');512      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};513514      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});515      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});516517      // Try to create a nested token in the wrong collection518      await expect(executeTransaction(api, alice, api.tx.unique.createItem(519        collectionRFT,520        targetAddress,521        {ReFungible: {const_data: [], pieces: 100}},522      )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);523524      // Try to create and nest a token in the wrong collection525      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');526      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);527    });528  });529530  it('ReFungible: disallows to nest token to an unlisted collection', async () => {531    await usingApi(async api => {532      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});533      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});534535      // Create a token to attempt to be nested into536      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');537      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};538539      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});540541      // Try to create a nested token in the wrong collection542      await expect(executeTransaction(api, alice, api.tx.unique.createItem(543        collectionRFT,544        targetAddress,545        {ReFungible: {const_data: [], pieces: 100}},546      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);547548      // Try to create and nest a token in the wrong collection549      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');550      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);551    });552  });553});
after · tests/src/nesting/nest.test.ts
1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6  addToAllowListExpectSuccess,7  createCollectionExpectSuccess,8  createItemExpectSuccess,9  enableAllowListExpectSuccess,10  enablePublicMintingExpectSuccess,11  getTokenOwner,12  getTopmostTokenOwner,13  normalizeAccountId,14  setCollectionPermissionsExpectSuccess,15  transferExpectFailure,16  transferExpectSuccess,17  transferFromExpectSuccess,18} from '../util/helpers';19import {IKeyringPair} from '@polkadot/types/types';2021let alice: IKeyringPair;22let bob: IKeyringPair;2324describe('Integration Test: Nesting', () => {25  before(async () => {26    await usingApi(async () => {27      alice = privateKey('//Alice');28      bob = privateKey('//Bob');29    });30  });3132  it('Performs the full suite: bundles a token, transfers, and unnests', async () => {33    await usingApi(async api => {34      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});35      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});36      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3738      // Create a nested token39      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});40      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});41      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4243      // Create a token to be nested44      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4546      // Nest47      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});48      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});49      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5051      // Move bundle to different user52      await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});53      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});54      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5556      // Unnest57      await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});58      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});59    });60  });6162  it('Transfers an already bundled token', async () => {63    await usingApi(async api => {64      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});65      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});6667      const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');68      const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');6970      // Create a nested token71      const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});72      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});73      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});7475      // Transfer the nested token to another token76      await expect(executeTransaction(77        api,78        alice,79        api.tx.unique.transferFrom(80          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), 81          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), 82          collection, tokenC, 1),83      )).to.not.be.rejected;84      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});85      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});86    });87  });8889  // ---------- Non-Fungible ----------9091  it('NFT: allows an Owner to nest/unnest their token', async () => {92    await usingApi(async api => {93      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});94      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});95      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');9697      // Create a nested token98      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});99      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});100      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});101102      // Create a token to be nested and nest103      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');104      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});105      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});106      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});107    });108  });109110  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {111    await usingApi(async api => {112      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});113      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});114      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');115116      // Create a nested token117      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});118      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});119      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});120121      // Create a token to be nested and nest122      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');123      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});124      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});125      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});126    });127  });128129  // ---------- Fungible ----------130131  it('Fungible: allows an Owner to nest/unnest their token', async () => {132    await usingApi(async api => {133      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});134      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});135      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});136      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};137138      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});139140      // Create a nested token141      await expect(executeTransaction(api, alice, api.tx.unique.createItem(142        collectionFT,143        targetAddress,144        {Fungible: {Value: 10}},145      ))).to.not.be.rejected;146147      // Nest a new token148      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');149      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');150    });151  });152153  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {154    await usingApi(async api => {155      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});156      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});157      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};158159      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});160161      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});162163      // Create a nested token164      await expect(executeTransaction(api, alice, api.tx.unique.createItem(165        collectionFT,166        targetAddress,167        {Fungible: {Value: 10}},168      ))).to.not.be.rejected;169170      // Nest a new token171      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');172      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');173    });174  });175176  // ---------- Re-Fungible ----------177178  it('ReFungible: allows an Owner to nest/unnest their token', async () => {179    await usingApi(async api => {180      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});181      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});182      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});183      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};184185      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});186187      // Create a nested token188      await expect(executeTransaction(api, alice, api.tx.unique.createItem(189        collectionRFT,190        targetAddress,191        {ReFungible: {const_data: [], pieces: 100}},192      ))).to.not.be.rejected;193194      // Nest a new token195      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');196      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');197    });198  });199200  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {201    await usingApi(async api => {202      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});203      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});204      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};205206      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});207208      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});209210      // Create a nested token211      await expect(executeTransaction(api, alice, api.tx.unique.createItem(212        collectionRFT,213        targetAddress,214        {ReFungible: {const_data: [], pieces: 100}},215      ))).to.not.be.rejected;216217      // Nest a new token218      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');219      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');220    });221  });222});223224describe('Negative Test: Nesting', async() => {225  before(async () => {226    await usingApi(async () => {227      alice = privateKey('//Alice');228      bob = privateKey('//Bob');229    });230  });231232  it('Disallows excessive token nesting', async () => {233    await usingApi(async api => {234      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});235      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});236      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');237238      const maxNestingLevel = 5;239      let prevToken = targetToken;240241      // Create a nested-token matryoshka242      for (let i = 0; i < maxNestingLevel; i++) {243        const nestedToken = await createItemExpectSuccess(244          alice,245          collection,246          'NFT',247          {Ethereum: tokenIdToAddress(collection, prevToken)},248        );249250        prevToken = nestedToken;251      }252253      // The nesting depth is limited by `maxNestingLevel`254      await expect(executeTransaction(api, alice, api.tx.unique.createItem(255        collection,256        {Ethereum: tokenIdToAddress(collection, prevToken)},257          {nft: {const_data: [], variable_data: []}} as any,258      )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);259260      expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});261    });262  });263264  // ---------- Non-Fungible ----------265266  it('NFT: disallows to nest token if nesting is disabled', async () => {267    await usingApi(async api => {268      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});269      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});270      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');271272      // Try to create a nested token273      await expect(executeTransaction(api, alice, api.tx.unique.createItem(274        collection,275        {Ethereum: tokenIdToAddress(collection, targetToken)},276          {nft: {const_data: [], variable_data: []}} as any,277      )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);278279      // Create a token to be nested280      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');281      // Try to nest282      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);283      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});284      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});285    });286  });287288  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {289    await usingApi(async api => {290      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});291      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});292293      await addToAllowListExpectSuccess(alice, collection, bob.address);294      await enableAllowListExpectSuccess(alice, collection);295      await enablePublicMintingExpectSuccess(alice, collection);296297      // Create a token to attempt to be nested into298      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');299300      // Try to create a nested token in the wrong collection301      await expect(executeTransaction(api, alice, api.tx.unique.createItem(302        collection,303        {Ethereum: tokenIdToAddress(collection, targetToken)},304          {nft: {const_data: [], variable_data: []}} as any,305      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);306307      // Try to create and nest a token in the wrong collection308      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');309      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);310      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});311    });312  });313314  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {315    await usingApi(async api => {316      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});317      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});318319      await addToAllowListExpectSuccess(alice, collection, bob.address);320      await enableAllowListExpectSuccess(alice, collection);321      await enablePublicMintingExpectSuccess(alice, collection);322323      // Create a token to attempt to be nested into324      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');325326      // Try to create a nested token in the wrong collection327      await expect(executeTransaction(api, alice, api.tx.unique.createItem(328        collection,329        {Ethereum: tokenIdToAddress(collection, targetToken)},330          {nft: {const_data: [], variable_data: []}} as any,331      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);332333      // Try to create and nest a token in the wrong collection334      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');335      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);336      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});337    });338  });339340  it('NFT: disallows to nest token in an unlisted collection', async () => {341    await usingApi(async api => {342      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});343      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});344345      // Create a token to attempt to be nested into346      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');347348      // Try to create a nested token in the wrong collection349      await expect(executeTransaction(api, alice, api.tx.unique.createItem(350        collection,351        {Ethereum: tokenIdToAddress(collection, targetToken)},352          {nft: {const_data: [], variable_data: []}} as any,353      )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);354355      // Try to create and nest a token in the wrong collection356      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');357      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);358      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});359    });360  });361362  // ---------- Fungible ----------363364  it('Fungible: disallows to nest token if nesting is disabled', async () => {365    await usingApi(async api => {366      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});367      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});368      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');369      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};370371      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});372373      // Try to create a nested token374      await expect(executeTransaction(api, alice, api.tx.unique.createItem(375        collectionFT,376        targetAddress,377        {Fungible: {Value: 10}},378      )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);379380      // Create a token to be nested381      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');382      // Try to nest383      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);384385      // Create another token to be nested386      const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');387      // Try to nest inside a fungible token388      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);389    });390  });391392  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {393    await usingApi(async api => {394      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});395      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});396397      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);398      await enableAllowListExpectSuccess(alice, collectionNFT);399      await enablePublicMintingExpectSuccess(alice, collectionNFT);400401      // Create a token to attempt to be nested into402      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');403      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};404405      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});406407      // Try to create a nested token in the wrong collection408      await expect(executeTransaction(api, alice, api.tx.unique.createItem(409        collectionFT,410        targetAddress,411        {Fungible: {Value: 10}},412      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);413414      // Try to create and nest a token in the wrong collection415      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');416      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);417    });418  });419420  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {421    await usingApi(async api => {422      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});423      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);424      await enableAllowListExpectSuccess(alice, collectionNFT);425      await enablePublicMintingExpectSuccess(alice, collectionNFT);426427      // Create a token to attempt to be nested into428      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');429      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};430431      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});432      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});433434      // Try to create a nested token in the wrong collection435      await expect(executeTransaction(api, alice, api.tx.unique.createItem(436        collectionFT,437        targetAddress,438        {Fungible: {Value: 10}},439      )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);440441      // Try to create and nest a token in the wrong collection442      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');443      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);444    });445  });446447  it('Fungible: disallows to nest token in an unlisted collection', async () => {448    await usingApi(async api => {449      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});450      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});451452      // Create a token to attempt to be nested into453      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');454      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};455456      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});457458      // Try to create a nested token in the wrong collection459      await expect(executeTransaction(api, alice, api.tx.unique.createItem(460        collectionFT,461        targetAddress,462        {Fungible: {Value: 10}},463      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);464465      // Try to create and nest a token in the wrong collection466      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');467      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);468    });469  });470471  // ---------- Re-Fungible ----------472473  it('ReFungible: disallows to nest token if nesting is disabled', async () => {474    await usingApi(async api => {475      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});476      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});477      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');478      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};479480      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});481482      // Create a nested token483      await expect(executeTransaction(api, alice, api.tx.unique.createItem(484        collectionRFT,485        targetAddress,486        {ReFungible: {const_data: [], pieces: 100}},487      )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);488489      // Create a token to be nested490      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');491      // Try to nest492      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);493      // Try to nest494      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);495496      // Create another token to be nested497      const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');498      // Try to nest inside a fungible token499      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);500    });501  });502503  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {504    await usingApi(async api => {505      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});506      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});507508      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);509      await enableAllowListExpectSuccess(alice, collectionNFT);510      await enablePublicMintingExpectSuccess(alice, collectionNFT);511512      // Create a token to attempt to be nested into513      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');514      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};515516      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});517518      // Try to create a nested token in the wrong collection519      await expect(executeTransaction(api, alice, api.tx.unique.createItem(520        collectionRFT,521        targetAddress,522        {ReFungible: {const_data: [], pieces: 100}},523      )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);524525      // Try to create and nest a token in the wrong collection526      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');527      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);528    });529  });530531  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {532    await usingApi(async api => {533      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});534      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);535      await enableAllowListExpectSuccess(alice, collectionNFT);536      await enablePublicMintingExpectSuccess(alice, collectionNFT);537538      // Create a token to attempt to be nested into539      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');540      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};541542      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});543      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});544545      // Try to create a nested token in the wrong collection546      await expect(executeTransaction(api, alice, api.tx.unique.createItem(547        collectionRFT,548        targetAddress,549        {ReFungible: {const_data: [], pieces: 100}},550      )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);551552      // Try to create and nest a token in the wrong collection553      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');554      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);555    });556  });557558  it('ReFungible: disallows to nest token to an unlisted collection', async () => {559    await usingApi(async api => {560      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});561      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});562563      // Create a token to attempt to be nested into564      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');565      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};566567      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});568569      // Try to create a nested token in the wrong collection570      await expect(executeTransaction(api, alice, api.tx.unique.createItem(571        collectionRFT,572        targetAddress,573        {ReFungible: {const_data: [], pieces: 100}},574      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);575576      // Try to create and nest a token in the wrong collection577      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');578      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);579    });580  });581});
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setChainLimits.test.ts
+++ b/tests/src/setChainLimits.test.ts
@@ -43,8 +43,6 @@
         nftSponsorTransferTimeout: 1,
         fungibleSponsorTransferTimeout: 1,
         refungibleSponsorTransferTimeout: 1,
-        offchainSchemaLimit: 1,
-        constOnChainSchemaLimit: 1,
       };
     });
   });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -135,8 +135,8 @@
   nftSponsorTransferTimeout: number;
   fungibleSponsorTransferTimeout: number;
   refungibleSponsorTransferTimeout: number;
-  offchainSchemaLimit: number;
-  constOnChainSchemaLimit: number;
+  //offchainSchemaLimit: number;
+  //constOnChainSchemaLimit: number;
 }
 
 export interface IReFungibleTokenDataType {
@@ -310,7 +310,6 @@
   name: string,
   description: string,
   tokenPrefix: string,
-  schemaVersion: string,
   properties?: Array<Property>,
   propPerm?: Array<PropertyPermission>
 };
@@ -320,7 +319,6 @@
   mode: {type: 'NFT'},
   name: 'name',
   tokenPrefix: 'prefix',
-  schemaVersion: 'ImageURL',
 };
 
 export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
@@ -780,25 +778,8 @@
     const result = getGenericResult(events);
 
     expect(result.success).to.be.false;
-  });
-}
-
-/*export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {
-  await usingApi(async (api) => {
-    const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
-    const events = await submitTransactionAsync(sender, tx);
-    const result = getGenericResult(events);
-
-    expect(result.success).to.be.true;
   });
 }
-
-export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {
-  await usingApi(async (api) => {
-    const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
-    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
-  });
-}*/
 
 export interface CreateFungibleData {
   readonly Value: bigint;
@@ -1110,13 +1091,6 @@
 ): Promise<string[]> {
   return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;
 }
-/*export async function getConstMetadata(
-  api: ApiPromise,
-  collectionId: number,
-  tokenId: number,
-): Promise<number[]> {
-  return [...(await api.rpc.unique.constMetadata(collectionId, tokenId))];
-}*/
 export async function getTokenProperties(
   api: ApiPromise,
   collectionId: number,