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

difftreelog

test(nesting) collection admin test suite

Fahrrader2022-06-14parent: #681a5b7.patch.diff
in: master

2 files changed

modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -98,7 +98,7 @@
     ...encodeIntBE(collection),
     ...encodeIntBE(token),
   ]);
-  return Web3.utils.toChecksumAddress('0x' + buf.toString('hex'));
+  return Web3.utils.toChecksumAddress('0x' + buf.toString('hex')).toLowerCase();
 }
 export function tokenIdToCross(collection: number, token: number): CrossAccountId {
   return {
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
before · tests/src/nesting/nest.test.ts
1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {5  addToAllowListExpectSuccess,6  createCollectionExpectSuccess,7  createItemExpectSuccess,8  enableAllowListExpectSuccess,9  enablePublicMintingExpectSuccess,10  getTokenChildren,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 (api, privateKeyWrapper) => {27      alice = privateKeyWrapper('//Alice');28      bob = privateKeyWrapper('//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: {tokenOwner: true}});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: {tokenOwner: true}});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,83          tokenC,84          1,85        ),86      )).to.not.be.rejected;87      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});88      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});89    });90  });9192  it('Checks token children', async () => {93    await usingApi(async api => {94      const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});95      await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});96      const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});9798      const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');99      const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};100      let children = await getTokenChildren(api, collectionA, targetToken);101      expect(children.length).to.be.equal(0, 'Children length check at creation');102103      // Create a nested NFT token104      const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);105      children = await getTokenChildren(api, collectionA, targetToken);106      expect(children.length).to.be.equal(1, 'Children length check at nesting #1');107      expect(children).to.have.deep.members([108        {token: tokenA, collection: collectionA},109      ], 'Children contents check at nesting #1');110111      // Create then nest112      const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');113      await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);114      children = await getTokenChildren(api, collectionA, targetToken);115      expect(children.length).to.be.equal(2, 'Children length check at nesting #2');116      expect(children).to.have.deep.members([117        {token: tokenA, collection: collectionA},118        {token: tokenB, collection: collectionA},119      ], 'Children contents check at nesting #2');120121      // Move token B to a different user outside the nesting tree122      await transferExpectSuccess(collectionA, tokenB, alice, bob);123      children = await getTokenChildren(api, collectionA, targetToken);124      expect(children.length).to.be.equal(1, 'Children length check at unnesting');125      expect(children).to.be.have.deep.members([126        {token: tokenA, collection: collectionA},127      ], 'Children contents check at unnesting');128129      // Create a fungible token in another collection and then nest130      const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');131      await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');132      children = await getTokenChildren(api, collectionA, targetToken);133      expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');134      expect(children).to.be.have.deep.members([135        {token: tokenA, collection: collectionA},136        {token: tokenC, collection: collectionB},137      ], 'Children contents check at nesting #3 (from another collection)');138139      // Move the fungible token inside token A deeper in the nesting tree140      await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');141      children = await getTokenChildren(api, collectionA, targetToken);142      expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');143      expect(children).to.be.have.deep.members([144        {token: tokenA, collection: collectionA},145      ], 'Children contents check at deeper nesting');146    });147  });148149  // ---------- Non-Fungible ----------150151  it('NFT: allows an Owner to nest/unnest their token', async () => {152    await usingApi(async api => {153      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});154      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});155      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');156157      // Create a nested token158      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});159      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});160      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});161162      // Create a token to be nested and nest163      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');164      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});165      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});166      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});167    });168  });169170  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {171    await usingApi(async api => {172      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});173      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});174      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');175176      // Create a nested token177      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});178      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});179      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});180181      // Create a token to be nested and nest182      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');183      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});184      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});185      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});186    });187  });188189  // ---------- Fungible ----------190191  it('Fungible: allows an Owner to nest/unnest their token', async () => {192    await usingApi(async api => {193      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});194      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});195      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});196      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};197198      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});199200      // Create a nested token201      await expect(executeTransaction(api, alice, api.tx.unique.createItem(202        collectionFT,203        targetAddress,204        {Fungible: {Value: 10}},205      ))).to.not.be.rejected;206207      // Nest a new token208      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');209      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');210    });211  });212213  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {214    await usingApi(async api => {215      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});216      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});217      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};218219      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});220221      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted: [collectionFT]}});222223      // Create a nested token224      await expect(executeTransaction(api, alice, api.tx.unique.createItem(225        collectionFT,226        targetAddress,227        {Fungible: {Value: 10}},228      ))).to.not.be.rejected;229230      // Nest a new token231      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');232      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');233    });234  });235236  // ---------- Re-Fungible ----------237238  it('ReFungible: allows an Owner to nest/unnest their token', async () => {239    await usingApi(async api => {240      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});241      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});242      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});243      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};244245      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});246247      // Create a nested token248      await expect(executeTransaction(api, alice, api.tx.unique.createItem(249        collectionRFT,250        targetAddress,251        {ReFungible: {const_data: [], pieces: 100}},252      ))).to.not.be.rejected;253254      // Nest a new token255      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');256      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');257    });258  });259260  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {261    await usingApi(async api => {262      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});263      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});264      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};265266      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});267268      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});269270      // Create a nested token271      await expect(executeTransaction(api, alice, api.tx.unique.createItem(272        collectionRFT,273        targetAddress,274        {ReFungible: {const_data: [], pieces: 100}},275      ))).to.not.be.rejected;276277      // Nest a new token278      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');279      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');280    });281  });282});283284describe('Negative Test: Nesting', async() => {285  before(async () => {286    await usingApi(async (api, privateKeyWrapper) => {287      alice = privateKeyWrapper('//Alice');288      bob = privateKeyWrapper('//Bob');289    });290  });291292  it('Disallows excessive token nesting', async () => {293    await usingApi(async api => {294      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});295      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});296      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');297298      const maxNestingLevel = 5;299      let prevToken = targetToken;300301      // Create a nested-token matryoshka302      for (let i = 0; i < maxNestingLevel; i++) {303        const nestedToken = await createItemExpectSuccess(304          alice,305          collection,306          'NFT',307          {Ethereum: tokenIdToAddress(collection, prevToken)},308        );309310        prevToken = nestedToken;311      }312313      // The nesting depth is limited by `maxNestingLevel`314      await expect(executeTransaction(api, alice, api.tx.unique.createItem(315        collection,316        {Ethereum: tokenIdToAddress(collection, prevToken)},317          {nft: {const_data: [], variable_data: []}} as any,318      )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);319320      expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});321    });322  });323324  // ---------- Non-Fungible ----------325326  it('NFT: disallows to nest token if nesting is disabled', async () => {327    await usingApi(async api => {328      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});329      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {}});330      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');331332      // Try to create a nested token333      await expect(executeTransaction(api, alice, api.tx.unique.createItem(334        collection,335        {Ethereum: tokenIdToAddress(collection, targetToken)},336          {nft: {const_data: [], variable_data: []}} as any,337      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);338339      // Create a token to be nested340      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');341      // Try to nest342      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);343      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});344      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});345    });346  });347348  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {349    await usingApi(async api => {350      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});351      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});352353      await addToAllowListExpectSuccess(alice, collection, bob.address);354      await enableAllowListExpectSuccess(alice, collection);355      await enablePublicMintingExpectSuccess(alice, collection);356357      // Create a token to attempt to be nested into358      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');359360      // Try to create a nested token in the wrong collection361      await expect(executeTransaction(api, alice, api.tx.unique.createItem(362        collection,363        {Ethereum: tokenIdToAddress(collection, targetToken)},364          {nft: {const_data: [], variable_data: []}} as any,365      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);366367      // Try to create and nest a token in the wrong collection368      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');369      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/);370      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});371    });372  });373374  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {375    await usingApi(async api => {376      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});377      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});378379      await addToAllowListExpectSuccess(alice, collection, bob.address);380      await enableAllowListExpectSuccess(alice, collection);381      await enablePublicMintingExpectSuccess(alice, collection);382383      // Create a token to attempt to be nested into384      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');385386      // Try to create a nested token in the wrong collection387      await expect(executeTransaction(api, alice, api.tx.unique.createItem(388        collection,389        {Ethereum: tokenIdToAddress(collection, targetToken)},390          {nft: {const_data: [], variable_data: []}} as any,391      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);392393      // Try to create and nest a token in the wrong collection394      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');395      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/);396      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});397    });398  });399400  it('NFT: disallows to nest token in an unlisted collection', async () => {401    await usingApi(async api => {402      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});403      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[]}});404405      // Create a token to attempt to be nested into406      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');407408      // Try to create a nested token in the wrong collection409      await expect(executeTransaction(api, alice, api.tx.unique.createItem(410        collection,411        {Ethereum: tokenIdToAddress(collection, targetToken)},412          {nft: {const_data: [], variable_data: []}} as any,413      )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);414415      // Try to create and nest a token in the wrong collection416      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');417      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/);418      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});419    });420  });421422  // ---------- Fungible ----------423424  it('Fungible: disallows to nest token if nesting is disabled', async () => {425    await usingApi(async api => {426      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});427      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});428      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');429      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};430431      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});432433      // Try to create a nested token434      await expect(executeTransaction(api, alice, api.tx.unique.createItem(435        collectionFT,436        targetAddress,437        {Fungible: {Value: 10}},438      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);439440      // Create a token to be nested441      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');442      // Try to nest443      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);444445      // Create another token to be nested446      const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');447      // Try to nest inside a fungible token448      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/);449    });450  });451452  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {453    await usingApi(async api => {454      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});455      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});456457      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);458      await enableAllowListExpectSuccess(alice, collectionNFT);459      await enablePublicMintingExpectSuccess(alice, collectionNFT);460461      // Create a token to attempt to be nested into462      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');463      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};464465      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});466467      // Try to create a nested token in the wrong collection468      await expect(executeTransaction(api, alice, api.tx.unique.createItem(469        collectionFT,470        targetAddress,471        {Fungible: {Value: 10}},472      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);473474      // Try to create and nest a token in the wrong collection475      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');476      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);477    });478  });479480  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {481    await usingApi(async api => {482      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});483      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);484      await enableAllowListExpectSuccess(alice, collectionNFT);485      await enablePublicMintingExpectSuccess(alice, collectionNFT);486487      // Create a token to attempt to be nested into488      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');489      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};490491      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});492      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionFT]}});493494      // Try to create a nested token in the wrong collection495      await expect(executeTransaction(api, alice, api.tx.unique.createItem(496        collectionFT,497        targetAddress,498        {Fungible: {Value: 10}},499      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);500501      // Try to create and nest a token in the wrong collection502      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');503      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);504    });505  });506507  it('Fungible: disallows to nest token in an unlisted collection', async () => {508    await usingApi(async api => {509      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});510      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});511512      // Create a token to attempt to be nested into513      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');514      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};515516      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});517518      // Try to create a nested token in the wrong collection519      await expect(executeTransaction(api, alice, api.tx.unique.createItem(520        collectionFT,521        targetAddress,522        {Fungible: {Value: 10}},523      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);524525      // Try to create and nest a token in the wrong collection526      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');527      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);528    });529  });530531  // ---------- Re-Fungible ----------532533  it('ReFungible: disallows to nest token if nesting is disabled', async () => {534    await usingApi(async api => {535      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});536      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});537      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');538      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};539540      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});541542      // Create a nested token543      await expect(executeTransaction(api, alice, api.tx.unique.createItem(544        collectionRFT,545        targetAddress,546        {ReFungible: {const_data: [], pieces: 100}},547      )), 'while creating a nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);548549      // Create a token to be nested550      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');551      // Try to nest552      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);553      // Try to nest554      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);555556      // Create another token to be nested557      const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');558      // Try to nest inside a fungible token559      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/);560    });561  });562563  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {564    await usingApi(async api => {565      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});566      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});567568      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);569      await enableAllowListExpectSuccess(alice, collectionNFT);570      await enablePublicMintingExpectSuccess(alice, collectionNFT);571572      // Create a token to attempt to be nested into573      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');574      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};575576      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});577578      // Try to create a nested token in the wrong collection579      await expect(executeTransaction(api, alice, api.tx.unique.createItem(580        collectionRFT,581        targetAddress,582        {ReFungible: {const_data: [], pieces: 100}},583      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);584585      // Try to create and nest a token in the wrong collection586      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');587      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);588    });589  });590591  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {592    await usingApi(async api => {593      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});594      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);595      await enableAllowListExpectSuccess(alice, collectionNFT);596      await enablePublicMintingExpectSuccess(alice, collectionNFT);597598      // Create a token to attempt to be nested into599      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');600      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};601602      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});603      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});604605      // Try to create a nested token in the wrong collection606      await expect(executeTransaction(api, alice, api.tx.unique.createItem(607        collectionRFT,608        targetAddress,609        {ReFungible: {const_data: [], pieces: 100}},610      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);611612      // Try to create and nest a token in the wrong collection613      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');614      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);615    });616  });617618  it('ReFungible: disallows to nest token to an unlisted collection', async () => {619    await usingApi(async api => {620      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});621      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});622623      // Create a token to attempt to be nested into624      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');625      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};626627      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});628629      // Try to create a nested token in the wrong collection630      await expect(executeTransaction(api, alice, api.tx.unique.createItem(631        collectionRFT,632        targetAddress,633        {ReFungible: {const_data: [], pieces: 100}},634      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);635636      // Try to create and nest a token in the wrong collection637      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');638      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);639    });640  });641});
after · tests/src/nesting/nest.test.ts
1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {5  addCollectionAdminExpectSuccess,6  addToAllowListExpectSuccess,7  createCollectionExpectSuccess,8  createItemExpectSuccess,9  enableAllowListExpectSuccess,10  enablePublicMintingExpectSuccess,11  getTokenChildren,12  getTokenOwner,13  getTopmostTokenOwner,14  normalizeAccountId,15  setCollectionPermissionsExpectSuccess,16  transferExpectFailure,17  transferExpectSuccess,18  transferFromExpectSuccess,19} from '../util/helpers';20import {IKeyringPair} from '@polkadot/types/types';2122let alice: IKeyringPair;23let bob: IKeyringPair;2425describe('Integration Test: Composite nesting tests', () => {26  before(async () => {27    await usingApi(async (_, privateKeyWrapper) => {28      alice = privateKeyWrapper('//Alice');29      bob = privateKeyWrapper('//Bob');30    });31  });3233  it('Performs the full suite: bundles a token, transfers, and unnests', async () => {34    await usingApi(async api => {35      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});36      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});37      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3839      // Create a nested token40      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});41      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});42      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4344      // Create a token to be nested45      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4647      // Nest48      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});49      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});50      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5152      // Move bundle to different user53      await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});54      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});55      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5657      // Unnest58      await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});59      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});60    });61  });6263  it('Transfers an already bundled token', async () => {64    await usingApi(async api => {65      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});6768      const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');69      const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');7071      // Create a nested token72      const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});73      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});74      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});7576      // Transfer the nested token to another token77      await expect(executeTransaction(78        api,79        alice,80        api.tx.unique.transferFrom(81          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}),82          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}),83          collection,84          tokenC,85          1,86        ),87      )).to.not.be.rejected;88      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});89      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});90    });91  });9293  it('Checks token children', async () => {94    await usingApi(async api => {95      const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});96      await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});97      const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});9899      const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');100      const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};101      let children = await getTokenChildren(api, collectionA, targetToken);102      expect(children.length).to.be.equal(0, 'Children length check at creation');103104      // Create a nested NFT token105      const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);106      children = await getTokenChildren(api, collectionA, targetToken);107      expect(children.length).to.be.equal(1, 'Children length check at nesting #1');108      expect(children).to.have.deep.members([109        {token: tokenA, collection: collectionA},110      ], 'Children contents check at nesting #1');111112      // Create then nest113      const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');114      await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);115      children = await getTokenChildren(api, collectionA, targetToken);116      expect(children.length).to.be.equal(2, 'Children length check at nesting #2');117      expect(children).to.have.deep.members([118        {token: tokenA, collection: collectionA},119        {token: tokenB, collection: collectionA},120      ], 'Children contents check at nesting #2');121122      // Move token B to a different user outside the nesting tree123      await transferExpectSuccess(collectionA, tokenB, alice, bob);124      children = await getTokenChildren(api, collectionA, targetToken);125      expect(children.length).to.be.equal(1, 'Children length check at unnesting');126      expect(children).to.be.have.deep.members([127        {token: tokenA, collection: collectionA},128      ], 'Children contents check at unnesting');129130      // Create a fungible token in another collection and then nest131      const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');132      await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');133      children = await getTokenChildren(api, collectionA, targetToken);134      expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');135      expect(children).to.be.have.deep.members([136        {token: tokenA, collection: collectionA},137        {token: tokenC, collection: collectionB},138      ], 'Children contents check at nesting #3 (from another collection)');139140      // Move the fungible token inside token A deeper in the nesting tree141      await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');142      children = await getTokenChildren(api, collectionA, targetToken);143      expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');144      expect(children).to.be.have.deep.members([145        {token: tokenA, collection: collectionA},146      ], 'Children contents check at deeper nesting');147    });148  });149});150151describe('Integration Test: Various token type nesting', async () => {152  before(async () => {153    await usingApi(async (_, privateKeyWrapper) => {154      alice = privateKeyWrapper('//Alice');155      bob = privateKeyWrapper('//Bob');156    });157  });158159  it('Admin (NFT): allows an Admin to nest a token', async () => {160    await usingApi(async api => {161      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});162      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});163      await addCollectionAdminExpectSuccess(alice, collection, bob.address);164      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');165166      // Create a nested token167      const nestedToken = await createItemExpectSuccess(bob, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});168      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});169      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});170171      // Create a token to be nested and nest172      const newToken = await createItemExpectSuccess(bob, collection, 'NFT');173      await transferExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)});174      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});175      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});176    });177  });178179  it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {180    await usingApi(async api => {181      const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});182      await addCollectionAdminExpectSuccess(alice, collectionA, bob.address);183      const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});184      await addCollectionAdminExpectSuccess(alice, collectionB, bob.address);185      await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {admin: true, restricted:[collectionA, collectionB]}});186      const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');187188      // Create a nested token189      const nestedToken = await createItemExpectSuccess(bob, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});190      expect(await getTopmostTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Substrate: alice.address});191      expect(await getTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});192193      // Create a token to be nested and nest194      const newToken = await createItemExpectSuccess(bob, collectionB, 'NFT');195      await transferExpectSuccess(collectionB, newToken, bob, {Ethereum: tokenIdToAddress(collectionA, targetToken)});196      expect(await getTopmostTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});197      expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});198    });199  });200201  // ---------- Non-Fungible ----------202203  it('NFT: allows an Owner to nest/unnest their token', async () => {204    await usingApi(async api => {205      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});206      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});207      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');208209      // Create a nested token210      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});211      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});212      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});213214      // Create a token to be nested and nest215      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');216      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});217      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});218      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});219    });220  });221222  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {223    await usingApi(async api => {224      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});225      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});226      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');227228      // Create a nested token229      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});230      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});231      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});232233      // Create a token to be nested and nest234      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');235      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});236      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});237      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});238    });239  });240241  // ---------- Fungible ----------242243  it('Fungible: allows an Owner to nest/unnest their token', async () => {244    await usingApi(async api => {245      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});246      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});247      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});248      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};249250      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});251252      // Create a nested token253      await expect(executeTransaction(api, alice, api.tx.unique.createItem(254        collectionFT,255        targetAddress,256        {Fungible: {Value: 10}},257      ))).to.not.be.rejected;258259      // Nest a new token260      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');261      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');262    });263  });264265  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {266    await usingApi(async api => {267      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});268      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});269      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};270271      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});272273      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted: [collectionFT]}});274275      // Create a nested token276      await expect(executeTransaction(api, alice, api.tx.unique.createItem(277        collectionFT,278        targetAddress,279        {Fungible: {Value: 10}},280      ))).to.not.be.rejected;281282      // Nest a new token283      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');284      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');285    });286  });287288  // ---------- Re-Fungible ----------289290  it('ReFungible: allows an Owner to nest/unnest their token', async () => {291    await usingApi(async api => {292      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});293      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});294      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});295      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};296297      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});298299      // Create a nested token300      await expect(executeTransaction(api, alice, api.tx.unique.createItem(301        collectionRFT,302        targetAddress,303        {ReFungible: {const_data: [], pieces: 100}},304      ))).to.not.be.rejected;305306      // Nest a new token307      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');308      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');309    });310  });311312  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {313    await usingApi(async api => {314      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});315      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});316      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};317318      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});319320      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});321322      // Create a nested token323      await expect(executeTransaction(api, alice, api.tx.unique.createItem(324        collectionRFT,325        targetAddress,326        {ReFungible: {const_data: [], pieces: 100}},327      ))).to.not.be.rejected;328329      // Nest a new token330      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');331      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');332    });333  });334});335336describe('Negative Test: Nesting', async() => {337  before(async () => {338    await usingApi(async (_, privateKeyWrapper) => {339      alice = privateKeyWrapper('//Alice');340      bob = privateKeyWrapper('//Bob');341    });342  });343344  it('Disallows excessive token nesting', async () => {345    await usingApi(async api => {346      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});347      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});348      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');349350      const maxNestingLevel = 5;351      let prevToken = targetToken;352353      // Create a nested-token matryoshka354      for (let i = 0; i < maxNestingLevel; i++) {355        const nestedToken = await createItemExpectSuccess(356          alice,357          collection,358          'NFT',359          {Ethereum: tokenIdToAddress(collection, prevToken)},360        );361362        prevToken = nestedToken;363      }364365      // The nesting depth is limited by `maxNestingLevel`366      await expect(executeTransaction(api, alice, api.tx.unique.createItem(367        collection,368        {Ethereum: tokenIdToAddress(collection, prevToken)},369          {nft: {const_data: [], variable_data: []}} as any,370      )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);371372      expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});373    });374  });375376  // ---------- Admin ------------377378  it('Admin (NFT): disallows an Admin to operate nesting when only TokenOwner is allowed', async () => {379    await usingApi(async api => {380      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});381      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});382      await addCollectionAdminExpectSuccess(alice, collection, bob.address);383      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');384385      // Try to create a nested token as collection admin when it's disallowed386      await expect(executeTransaction(api, bob, api.tx.unique.createItem(387        collection,388        {Ethereum: tokenIdToAddress(collection, targetToken)},389          {nft: {const_data: [], variable_data: []}} as any,390      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);391392      // Try to create and nest a token in the wrong collection393      const newToken = await createItemExpectSuccess(bob, collection, 'NFT');394      await expect(executeTransaction(api, bob, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);395      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});396    });397  });398399  it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {400    await usingApi(async api => {401      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});402      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});403      await addToAllowListExpectSuccess(alice, collection, bob.address);404      await enableAllowListExpectSuccess(alice, collection);405      await enablePublicMintingExpectSuccess(alice, collection);406      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');407408      // Try to create a nested token as collection admin when it's disallowed409      await expect(executeTransaction(api, bob, api.tx.unique.createItem(410        collection,411        {Ethereum: tokenIdToAddress(collection, targetToken)},412          {nft: {const_data: [], variable_data: []}} as any,413      )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?414415      // Try to create and nest a token in the wrong collection416      const newToken = await createItemExpectSuccess(bob, collection, 'NFT');417      await expect(executeTransaction(api, bob, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);418      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});419    });420  });421422  it('Admin (NFT): disallows an Admin to nest and unnest someone else\'s token', async () => {423    await usingApi(async api => {424      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});425      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {admin: true}});426427      await addToAllowListExpectSuccess(alice, collection, bob.address);428      await enableAllowListExpectSuccess(alice, collection);429      await enablePublicMintingExpectSuccess(alice, collection);430431      // Create a token to attempt to be nested into432      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');433      const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};434435      // Try to nest somebody else's token436      const newToken = await createItemExpectSuccess(bob, collection, 'NFT');437      await expect(executeTransaction(438        api, 439        alice, 440        api.tx.unique.transfer(targetAddress, collection, newToken, 1),441      ), 'while nesting another\'s token token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);442      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});443444      // Nest a token as admin and try to unnest it, now belonging to someone else445      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);446      await expect(executeTransaction(447        api, 448        alice, 449        api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),450      ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);451      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal(targetAddress);452      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});453    });454  });455456  it('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async () => {457    await usingApi(async api => {458      const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});459      const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});460      await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {admin: true, restricted:[collectionA]}});461462      // Create a token to attempt to be nested into463      const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');464465      // Try to create and nest a token in the wrong collection466      const newToken = await createItemExpectSuccess(alice, collectionB, 'NFT');467      await expect(executeTransaction(468        api, 469        alice, 470        api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionA, targetToken)}, collectionB, newToken, 1),471      ), 'while nesting a foreign token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);472      expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});473    });474  });475476  // ---------- Non-Fungible ----------477478  it('NFT: disallows to nest token if nesting is disabled', async () => {479    await usingApi(async api => {480      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});481      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {}});482      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');483484      // Try to create a nested token485      await expect(executeTransaction(api, alice, api.tx.unique.createItem(486        collection,487        {Ethereum: tokenIdToAddress(collection, targetToken)},488          {nft: {const_data: [], variable_data: []}} as any,489      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);490491      // Create a token to be nested492      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');493      // Try to nest494      await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);495      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});496      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});497    });498  });499500  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {501    await usingApi(async api => {502      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});503      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});504505      await addToAllowListExpectSuccess(alice, collection, bob.address);506      await enableAllowListExpectSuccess(alice, collection);507      await enablePublicMintingExpectSuccess(alice, collection);508509      // Create a token to attempt to be nested into510      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');511512      // Try to create a nested token in the wrong collection513      await expect(executeTransaction(api, alice, api.tx.unique.createItem(514        collection,515        {Ethereum: tokenIdToAddress(collection, targetToken)},516          {nft: {const_data: [], variable_data: []}} as any,517      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);518519      // Try to create and nest a token in the wrong collection520      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');521      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/);522      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});523    });524  });525526  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {527    await usingApi(async api => {528      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});529      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});530531      await addToAllowListExpectSuccess(alice, collection, bob.address);532      await enableAllowListExpectSuccess(alice, collection);533      await enablePublicMintingExpectSuccess(alice, collection);534535      // Create a token to attempt to be nested into536      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');537538      // Try to create a nested token in the wrong collection539      await expect(executeTransaction(api, alice, api.tx.unique.createItem(540        collection,541        {Ethereum: tokenIdToAddress(collection, targetToken)},542          {nft: {const_data: [], variable_data: []}} as any,543      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);544545      // Try to create and nest a token in the wrong collection546      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');547      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/);548      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});549    });550  });551552  it('NFT: disallows to nest token in an unlisted collection', async () => {553    await usingApi(async api => {554      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});555      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[]}});556557      // Create a token to attempt to be nested into558      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');559560      // Try to create a nested token in the wrong collection561      await expect(executeTransaction(api, alice, api.tx.unique.createItem(562        collection,563        {Ethereum: tokenIdToAddress(collection, targetToken)},564          {nft: {const_data: [], variable_data: []}} as any,565      )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);566567      // Try to create and nest a token in the wrong collection568      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');569      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/);570      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});571    });572  });573574  // ---------- Fungible ----------575576  it('Fungible: disallows to nest token if nesting is disabled', async () => {577    await usingApi(async api => {578      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});579      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});580      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');581      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};582583      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});584585      // Try to create a nested token586      await expect(executeTransaction(api, alice, api.tx.unique.createItem(587        collectionFT,588        targetAddress,589        {Fungible: {Value: 10}},590      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);591592      // Create a token to be nested593      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');594      // Try to nest595      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);596597      // Create another token to be nested598      const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');599      // Try to nest inside a fungible token600      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/);601    });602  });603604  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {605    await usingApi(async api => {606      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});607      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});608609      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);610      await enableAllowListExpectSuccess(alice, collectionNFT);611      await enablePublicMintingExpectSuccess(alice, collectionNFT);612613      // Create a token to attempt to be nested into614      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');615      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};616617      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});618619      // Try to create a nested token in the wrong collection620      await expect(executeTransaction(api, alice, api.tx.unique.createItem(621        collectionFT,622        targetAddress,623        {Fungible: {Value: 10}},624      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);625626      // Try to create and nest a token in the wrong collection627      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');628      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);629    });630  });631632  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {633    await usingApi(async api => {634      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});635      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);636      await enableAllowListExpectSuccess(alice, collectionNFT);637      await enablePublicMintingExpectSuccess(alice, collectionNFT);638639      // Create a token to attempt to be nested into640      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');641      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};642643      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});644      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionFT]}});645646      // Try to create a nested token in the wrong collection647      await expect(executeTransaction(api, alice, api.tx.unique.createItem(648        collectionFT,649        targetAddress,650        {Fungible: {Value: 10}},651      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);652653      // Try to create and nest a token in the wrong collection654      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');655      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);656    });657  });658659  it('Fungible: disallows to nest token in an unlisted collection', async () => {660    await usingApi(async api => {661      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});662      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});663664      // Create a token to attempt to be nested into665      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');666      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};667668      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});669670      // Try to create a nested token in the wrong collection671      await expect(executeTransaction(api, alice, api.tx.unique.createItem(672        collectionFT,673        targetAddress,674        {Fungible: {Value: 10}},675      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);676677      // Try to create and nest a token in the wrong collection678      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');679      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);680    });681  });682683  // ---------- Re-Fungible ----------684685  it('ReFungible: disallows to nest token if nesting is disabled', async () => {686    await usingApi(async api => {687      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});688      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});689      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');690      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};691692      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});693694      // Create a nested token695      await expect(executeTransaction(api, alice, api.tx.unique.createItem(696        collectionRFT,697        targetAddress,698        {ReFungible: {const_data: [], pieces: 100}},699      )), 'while creating a nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);700701      // Create a token to be nested702      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');703      // Try to nest704      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);705      // Try to nest706      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);707708      // Create another token to be nested709      const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');710      // Try to nest inside a fungible token711      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/);712    });713  });714715  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {716    await usingApi(async api => {717      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});718      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});719720      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);721      await enableAllowListExpectSuccess(alice, collectionNFT);722      await enablePublicMintingExpectSuccess(alice, collectionNFT);723724      // Create a token to attempt to be nested into725      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');726      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};727728      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});729730      // Try to create a nested token in the wrong collection731      await expect(executeTransaction(api, alice, api.tx.unique.createItem(732        collectionRFT,733        targetAddress,734        {ReFungible: {const_data: [], pieces: 100}},735      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);736737      // Try to create and nest a token in the wrong collection738      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');739      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);740    });741  });742743  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {744    await usingApi(async api => {745      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});746      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);747      await enableAllowListExpectSuccess(alice, collectionNFT);748      await enablePublicMintingExpectSuccess(alice, collectionNFT);749750      // Create a token to attempt to be nested into751      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');752      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};753754      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});755      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});756757      // Try to create a nested token in the wrong collection758      await expect(executeTransaction(api, alice, api.tx.unique.createItem(759        collectionRFT,760        targetAddress,761        {ReFungible: {const_data: [], pieces: 100}},762      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);763764      // Try to create and nest a token in the wrong collection765      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');766      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);767    });768  });769770  it('ReFungible: disallows to nest token to an unlisted collection', async () => {771    await usingApi(async api => {772      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});773      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});774775      // Create a token to attempt to be nested into776      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');777      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};778779      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});780781      // Try to create a nested token in the wrong collection782      await expect(executeTransaction(api, alice, api.tx.unique.createItem(783        collectionRFT,784        targetAddress,785        {ReFungible: {const_data: [], pieces: 100}},786      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);787788      // Try to create and nest a token in the wrong collection789      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');790      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);791    });792  });793});