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

difftreelog

source

tests/src/nesting/nest.test.ts27.6 KiBsourcehistory
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  setCollectionLimitsExpectSuccess, 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 => {27      alice = privateKey('//Alice');28      bob = privateKey('//Bob');29    });30  });3132  it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {33    await usingApi(async api => {34      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});35      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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');45      46      // 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  // ---------- Non-Fungible ----------6364  it('NFT: allows an Owner to nest/unnest their token', async () => {65    await usingApi(async api => {66      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});67      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});68      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');6970      // Create a nested token71      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});72      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});73      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});7475      // Create a token to be nested and nest76      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');77      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});78      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});79      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});80    });81  });8283  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {84    await usingApi(async api => {85      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});86      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});87      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');8889      // Create a nested token90      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});91      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});92      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});9394      // Create a token to be nested and nest95      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');96      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});97      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});98      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});99    });100  });101102  // ---------- Fungible ----------103104  it('Fungible: allows an Owner to nest/unnest their token', async () => {105    await usingApi(async api => {106      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});107      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});108      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});109      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};110111      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});112113      // Create a nested token114      await expect(executeTransaction(api, alice, api.tx.unique.createItem(115        collectionFT, 116        targetAddress, 117        {Fungible: {Value: 10}},118      ))).to.not.be.rejected;119120      // Nest a new token121      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');122      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');123    });124  });125126  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {127    await usingApi(async api => {128      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});129      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});130      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};131132      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});133134      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});135136      // Create a nested token137      await expect(executeTransaction(api, alice, api.tx.unique.createItem(138        collectionFT, 139        targetAddress, 140        {Fungible: {Value: 10}},141      ))).to.not.be.rejected;142143      // Nest a new token144      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');145      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');146    });147  });148149  // ---------- Re-Fungible ----------150151  it('ReFungible: allows an Owner to nest/unnest their token', async () => {152    await usingApi(async api => {153      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});154      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});155      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});156      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};157158      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});159160      // Create a nested token161      await expect(executeTransaction(api, alice, api.tx.unique.createItem(162        collectionRFT, 163        targetAddress, 164        {ReFungible: {const_data: [], pieces: 100}},165      ))).to.not.be.rejected;166167      // Nest a new token168      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');169      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');170    });171  });172173  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {174    await usingApi(async api => {175      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});176      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});177      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};178179      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});180181      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});182183      // Create a nested token184      await expect(executeTransaction(api, alice, api.tx.unique.createItem(185        collectionRFT, 186        targetAddress,187        {ReFungible: {const_data: [], pieces: 100}},188      ))).to.not.be.rejected;189190      // Nest a new token191      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');192      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');193    });194  });195});196197describe('Negative Test: Nesting', async() => {198  before(async () => {199    await usingApi(async api => {200      alice = privateKey('//Alice');201      bob = privateKey('//Bob');202    });203  });204205  it('Disallows excessive token nesting', async () => {206    await usingApi(async api => {207      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});208      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});209      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');210211      // Create a nested-token matryoshka212      const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});213      const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});214      // The nesting depth is limited by 2215      await expect(executeTransaction(216        api, alice, 217        api.tx.unique.createItem(218          collection, 219          {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 220          {nft: {const_data: [], variable_data: []}} as any,221        ),222      ), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/); // OuroborosDetected?223224      expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});225    });226  });227228  // ---------- Non-Fungible ----------229230  it('NFT: disallows to nest token if nesting is disabled', async () => {231    await usingApi(async api => {232      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});233      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});234      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');235236      // Try to create a nested token237      await expect(executeTransaction(238        api, alice, 239        api.tx.unique.createItem(240          collection, 241          {Ethereum: tokenIdToAddress(collection, targetToken)}, 242          {nft: {const_data: [], variable_data: []}} as any,243        ),244      ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);245246      // Create a token to be nested247      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');248      // Try to nest249      await expect(executeTransaction(250        api, alice, 251        api.tx.unique.transfer(252          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,253        ),254      ), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/); // todo to.be.rejected for all255      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 setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: '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(274        api, alice, 275        api.tx.unique.createItem(276          collection, 277          {Ethereum: tokenIdToAddress(collection, targetToken)}, 278          {nft: {const_data: [], variable_data: []}} as any,279        ),280      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/); // todo NestingIsDisabled?281282      // Try to create and nest a token in the wrong collection283      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');284      await expect(executeTransaction(285        api, alice, 286        api.tx.unique.transfer(287          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,288        ),289      ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);290      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});291    });292  });293294  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {295    await usingApi(async api => {296      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});297      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});298299      await addToAllowListExpectSuccess(alice, collection, bob.address);300      await enableAllowListExpectSuccess(alice, collection);301      await enablePublicMintingExpectSuccess(alice, collection);302303      // Create a token to attempt to be nested into304      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');305306      // Try to create a nested token in the wrong collection307      await expect(executeTransaction(308        api, alice, 309        api.tx.unique.createItem(310          collection, 311          {Ethereum: tokenIdToAddress(collection, targetToken)}, 312          {nft: {const_data: [], variable_data: []}} as any,313        ),314      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);315316      // Try to create and nest a token in the wrong collection317      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');318      await expect(executeTransaction(319        api, alice, 320        api.tx.unique.transfer(321          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,322        ),323      ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);324      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});325    });326  });327328  it('NFT: disallows to nest token in an unlisted collection', async () => {329    await usingApi(async api => {330      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});331      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});332333      // Create a token to attempt to be nested into334      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');335336      // Try to create a nested token in the wrong collection337      await expect(executeTransaction(338        api, alice, 339        api.tx.unique.createItem(340          collection, 341          {Ethereum: tokenIdToAddress(collection, targetToken)}, 342          {nft: {const_data: [], variable_data: []}} as any,343        ),344      ), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);345346      // Try to create and nest a token in the wrong collection347      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');348      await expect(executeTransaction(349        api, alice, 350        api.tx.unique.transfer(351          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,352        ),353      ), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);354      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});355    });356  });357358  // ---------- Fungible ----------359360  it('Fungible: disallows to nest token if nesting is disabled', async () => {361    await usingApi(async api => {362      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});363      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});364      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');365      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};366367      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});368369      // Try to create a nested token370      await expect(executeTransaction(371        api, alice, 372        api.tx.unique.createItem(373          collectionFT, 374          targetAddress, 375          {Fungible: {Value: 10}},376        )377      ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);378379      // Create a token to be nested380      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');381      // Try to nest382      await expect(executeTransaction(383        api, alice, 384        api.tx.unique.transfer(385          normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,386        ),387      ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);388    });389  });390391  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {392    await usingApi(async api => {393      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});394      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});395396      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);397      await enableAllowListExpectSuccess(alice, collectionNFT);398      await enablePublicMintingExpectSuccess(alice, collectionNFT);399400      // Create a token to attempt to be nested into401      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');402      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};403404      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});405406      // Try to create a nested token in the wrong collection407      await expect(executeTransaction(408        api, alice, 409        api.tx.unique.createItem(410          collectionFT, 411          targetAddress, 412          {Fungible: {Value: 10}},413        )414      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);415416      // Try to create and nest a token in the wrong collection417      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');418      await expect(executeTransaction(419        api, alice, 420        api.tx.unique.transfer(421          normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,422        ),423      ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);424    });425  });426427  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {428    await usingApi(async api => {429      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});430      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions?431432      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);433      await enableAllowListExpectSuccess(alice, collectionNFT);434      await enablePublicMintingExpectSuccess(alice, collectionNFT);435436      // Create a token to attempt to be nested into437      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');438      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};439440      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});441442      // Try to create a nested token in the wrong collection443      await expect(executeTransaction(api, alice, api.tx.unique.createItem(444        collectionFT, 445        targetAddress, 446        {Fungible: {Value: 10}},447      ))).to.be.rejected;448449      // Try to create and nest a token in the wrong collection450      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');451      await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);452    });453  });454455  it('Fungible: disallows to nest token in an unlisted collection', async () => {456    await usingApi(async api => {457      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});458      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});459460      // Create a token to attempt to be nested into461      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');462      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};463464      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});465466      // Try to create a nested token in the wrong collection467      await expect(executeTransaction(api, alice, api.tx.unique.createItem(468        collectionFT, 469        targetAddress, 470        {Fungible: {Value: 10}},471      ))).to.be.rejected;472473      // Try to create and nest a token in the wrong collection474      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');475      await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);476    });477  });478479  // ---------- Re-Fungible ----------480481  it('ReFungible: disallows to nest token if nesting is disabled', async () => {482    await usingApi(async api => {483      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});484      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});485      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');486      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};487488      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});489490      // Create a nested token491      await expect(executeTransaction(api, alice, api.tx.unique.createItem(492        collectionRFT, 493        targetAddress, 494        {ReFungible: {const_data: [], pieces: 100}},495      ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);496497      // Create a token to be nested498      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');499      // Try to nest500      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);501    });502  });503504  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {505    await usingApi(async api => {506      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});507      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});508509      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);510      await enableAllowListExpectSuccess(alice, collectionNFT);511      await enablePublicMintingExpectSuccess(alice, collectionNFT);512513      // Create a token to attempt to be nested into514      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');515      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};516517      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});518519      // Try to create a nested token in the wrong collection520      await expect(executeTransaction(api, alice, api.tx.unique.createItem(521        collectionRFT, 522        targetAddress, 523        {ReFungible: {const_data: [], pieces: 100}},524      ))).to.be.rejected;525526      // Try to create and nest a token in the wrong collection527      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');528      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);529    });530  });531532  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {533    await usingApi(async api => {534      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});535      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});536537      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);538      await enableAllowListExpectSuccess(alice, collectionNFT);539      await enablePublicMintingExpectSuccess(alice, collectionNFT);540541      // Create a token to attempt to be nested into542      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');543      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};544545      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});546547      // Try to create a nested token in the wrong collection548      await expect(executeTransaction(api, alice, api.tx.unique.createItem(549        collectionRFT, 550        targetAddress, 551        {ReFungible: {const_data: [], pieces: 100}},552      ))).to.be.rejected;553554      // Try to create and nest a token in the wrong collection555      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');556      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);557    });558  });559560  it('ReFungible: disallows to nest token to an unlisted collection', async () => {561    await usingApi(async api => {562      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});563      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});564565      // Create a token to attempt to be nested into566      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');567      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};568569      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});570571      // Try to create a nested token in the wrong collection572      await expect(executeTransaction(api, alice, api.tx.unique.createItem(573        collectionRFT, 574        targetAddress, 575        {ReFungible: {const_data: [], pieces: 100}},576      ))).to.be.rejected;577578      // Try to create and nest a token in the wrong collection579      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');580      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);581    });582  });583});