git.delta.rocks / unique-network / refs/commits / 6b48a5a77b12

difftreelog

OwnerCanTransfer flag

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

10 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1164,6 +1164,7 @@
 		old_limit: &CollectionLimits,
 		mut new_limit: CollectionLimits,
 	) -> Result<CollectionLimits, DispatchError> {
+		let limits = old_limit;
 		limit_default!(old_limit, new_limit,
 			account_token_ownership_limit => ensure!(
 				new_limit <= MAX_TOKEN_OWNERSHIP,
@@ -1190,6 +1191,7 @@
 			),
 			sponsor_approve_timeout => {},
 			owner_can_transfer => ensure!(
+				!limits.owner_can_transfer_instaled() ||
 				old_limit || !new_limit,
 				<Error<T>>::OwnerPermissionsCantBeReverted,
 			),
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -409,7 +409,10 @@
 			.min(MAX_SPONSOR_TIMEOUT)
 	}
 	pub fn owner_can_transfer(&self) -> bool {
-		self.owner_can_transfer.unwrap_or(true)
+		self.owner_can_transfer.unwrap_or(false)
+	}
+	pub fn owner_can_transfer_instaled(&self) -> bool {
+		self.owner_can_transfer.is_some()
 	}
 	pub fn owner_can_destroy(&self) -> bool {
 		self.owner_can_destroy.unwrap_or(true)
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -28,7 +28,7 @@
   setCollectionLimitsExpectSuccess,
   transferExpectSuccess,
   addCollectionAdminExpectSuccess,
-  adminApproveFromExpectSuccess,
+  adminApproveFromExpectFail,
   getCreatedCollectionCount,
   transferFromExpectSuccess,
   transferFromExpectFail,
@@ -84,11 +84,11 @@
     await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
   });
 
-  it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
+  it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
     const collectionId = await createCollectionExpectSuccess();
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
 
-    await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);
+    await adminApproveFromExpectFail(collectionId, itemId, alice, bob.address, charlie.address);
   });
 });
 
@@ -292,7 +292,7 @@
   });
 });
 
-describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => {
+describe('Administrator and collection owner do not need approval in order to execute TransferFrom (with owner_can_transfer_flag = true):', () => {
   let alice: IKeyringPair;
   let bob: IKeyringPair;
   let charlie: IKeyringPair;
@@ -309,6 +309,7 @@
 
   it('NFT', async () => {
     const collectionId = await createCollectionExpectSuccess();
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);
     await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -317,6 +318,7 @@
 
   it('Fungible up to an approved amount', async () => {
     const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address); 
     await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -325,6 +327,7 @@
 
   it('ReFungible up to an approved amount', async () => {
     const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);
     await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -402,7 +405,7 @@
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
 
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-    await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
+    await adminApproveFromExpectFail(collectionId, itemId, bob, alice.address, charlie.address);
   });
 });
 
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -23,6 +23,7 @@
   normalizeAccountId,
   addCollectionAdminExpectSuccess,
   getBalance,
+  setCollectionLimitsExpectSuccess,
   isTokenExists,
 } from './util/helpers';
 
@@ -149,6 +150,7 @@
   it('Burn item in NFT collection', async () => {
     const createMode = 'NFT';
     const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
 
@@ -167,6 +169,7 @@
   it('Burn item in Fungible collection', async () => {
     const createMode = 'Fungible';
     const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
 
@@ -189,6 +192,7 @@
   it('Burn item in ReFungible collection', async () => {
     const createMode = 'ReFungible';
     const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
     await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
 
modifiedtests/src/eth/crossTransfer.test.tsdiffbeforeafterboth
--- a/tests/src/eth/crossTransfer.test.ts
+++ b/tests/src/eth/crossTransfer.test.ts
@@ -18,6 +18,7 @@
   createFungibleItemExpectSuccess,
   transferExpectSuccess,
   transferFromExpectSuccess,
+  setCollectionLimitsExpectSuccess,
   createItemExpectSuccess} from '../util/helpers';
 import {collectionIdToAddress,
   createEthAccountWithBalance,
@@ -35,6 +36,7 @@
     const alice = privateKeyWrapper('//Alice');
     const bob = privateKeyWrapper('//Bob');
     const charlie = privateKeyWrapper('//Charlie');
+    await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
     await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
     await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');
     await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
@@ -48,6 +50,7 @@
     });
     const alice = privateKeyWrapper('//Alice');
     const bob = privateKeyWrapper('//Bob');
+    await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
     const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
 
@@ -71,6 +74,7 @@
     const alice = privateKeyWrapper('//Alice');
     const bob = privateKeyWrapper('//Bob');
     const charlie = privateKeyWrapper('//Charlie');
+    await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
     const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
     await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');
     await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
@@ -85,6 +89,7 @@
     const alice = privateKeyWrapper('//Alice');
     const bob = privateKeyWrapper('//Bob');
     const charlie = privateKeyWrapper('//Charlie');
+    await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
     const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
modifiedtests/src/limits.test.tsdiffbeforeafterboth
--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -406,6 +406,7 @@
   it('Effective collection limits', async () => {
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
       
       { // Check that limits is undefined
         const collection = await api.rpc.unique.collectionById(collectionId);
@@ -419,7 +420,7 @@
         expect(limits.tokenLimit.toHuman()).to.be.null;
         expect(limits.sponsorTransferTimeout.toHuman()).to.be.null;
         expect(limits.sponsorApproveTimeout.toHuman()).to.be.null;
-        expect(limits.ownerCanTransfer.toHuman()).to.be.null;
+        expect(limits.ownerCanTransfer.toHuman()).to.be.true;
         expect(limits.ownerCanDestroy.toHuman()).to.be.null;
         expect(limits.transfersEnabled.toHuman()).to.be.null;
       }
modifiedtests/src/nesting/graphs.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -3,7 +3,7 @@
 import {expect} from 'chai';
 import {tokenIdToCross} from '../eth/util/helpers';
 import usingApi, {executeTransaction} from '../substrate/substrate-api';
-import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';
+import {getCreateCollectionResult, transferExpectSuccess, setCollectionLimitsExpectSuccess} from '../util/helpers';
 
 /**
  * ```dot
@@ -36,6 +36,7 @@
     await usingApi(async (api, privateKeyWrapper) => {
       const alice = privateKeyWrapper('//Alice');
       const collection = await buildComplexObjectGraph(api, alice);
+      await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});
 
       // to self
       await expect(
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  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  setCollectionLimitsExpectSuccess,19} from '../util/helpers';20import {IKeyringPair} from '@polkadot/types/types';2122let alice: IKeyringPair;23let bob: IKeyringPair;2425describe('Integration Test: Nesting', () => {26  before(async () => {27    await usingApi(async (api, 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 setCollectionLimitsExpectSuccess(alice, collectionA, {ownerCanTransfer: true});97      await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});98      const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});99100      const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');101      const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};102      let children = await getTokenChildren(api, collectionA, targetToken);103      expect(children.length).to.be.equal(0, 'Children length check at creation');104105      // Create a nested NFT token106      const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);107      children = await getTokenChildren(api, collectionA, targetToken);108      expect(children.length).to.be.equal(1, 'Children length check at nesting #1');109      expect(children).to.have.deep.members([110        {token: tokenA, collection: collectionA},111      ], 'Children contents check at nesting #1');112113      // Create then nest114      const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');115      await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);116      children = await getTokenChildren(api, collectionA, targetToken);117      expect(children.length).to.be.equal(2, 'Children length check at nesting #2');118      expect(children).to.have.deep.members([119        {token: tokenA, collection: collectionA},120        {token: tokenB, collection: collectionA},121      ], 'Children contents check at nesting #2');122123      // Move token B to a different user outside the nesting tree124      await transferExpectSuccess(collectionA, tokenB, alice, bob);125      children = await getTokenChildren(api, collectionA, targetToken);126      expect(children.length).to.be.equal(1, 'Children length check at unnesting');127      expect(children).to.be.have.deep.members([128        {token: tokenA, collection: collectionA},129      ], 'Children contents check at unnesting');130131      // Create a fungible token in another collection and then nest132      const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');133      await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');134      children = await getTokenChildren(api, collectionA, targetToken);135      expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');136      expect(children).to.be.have.deep.members([137        {token: tokenA, collection: collectionA},138        {token: tokenC, collection: collectionB},139      ], 'Children contents check at nesting #3 (from another collection)');140141      // Move the fungible token inside token A deeper in the nesting tree142      await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');143      children = await getTokenChildren(api, collectionA, targetToken);144      expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');145      expect(children).to.be.have.deep.members([146        {token: tokenA, collection: collectionA},147      ], 'Children contents check at deeper nesting');148    });149  });150151  // ---------- Non-Fungible ----------152153  it('NFT: allows an Owner to nest/unnest their token', async () => {154    await usingApi(async api => {155      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});156      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});157      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');158159      // Create a nested token160      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});161      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});162      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});163164      // Create a token to be nested and nest165      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');166      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});167      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});168      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});169    });170  });171172  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {173    await usingApi(async api => {174      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});176      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');177178      // Create a nested token179      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});180      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});181      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});182183      // Create a token to be nested and nest184      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');185      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});186      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});187      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});188    });189  });190191  // ---------- Fungible ----------192193  it('Fungible: allows an Owner to nest/unnest their token', async () => {194    await usingApi(async api => {195      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});196      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});197      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});198      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};199200      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});201202      // Create a nested token203      await expect(executeTransaction(api, alice, api.tx.unique.createItem(204        collectionFT,205        targetAddress,206        {Fungible: {Value: 10}},207      ))).to.not.be.rejected;208209      // Nest a new token210      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');211      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');212    });213  });214215  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {216    await usingApi(async api => {217      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});218      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});219      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};220221      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});222223      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted: [collectionFT]}});224225      // Create a nested token226      await expect(executeTransaction(api, alice, api.tx.unique.createItem(227        collectionFT,228        targetAddress,229        {Fungible: {Value: 10}},230      ))).to.not.be.rejected;231232      // Nest a new token233      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');234      await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');235    });236  });237238  // ---------- Re-Fungible ----------239240  it('ReFungible: allows an Owner to nest/unnest their token', async () => {241    await usingApi(async api => {242      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});243      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});244      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});245      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};246247      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});248249      // Create a nested token250      await expect(executeTransaction(api, alice, api.tx.unique.createItem(251        collectionRFT,252        targetAddress,253        {ReFungible: {const_data: [], pieces: 100}},254      ))).to.not.be.rejected;255256      // Nest a new token257      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');258      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');259    });260  });261262  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {263    await usingApi(async api => {264      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});265      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});266      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};267268      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});269270      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});271272      // Create a nested token273      await expect(executeTransaction(api, alice, api.tx.unique.createItem(274        collectionRFT,275        targetAddress,276        {ReFungible: {const_data: [], pieces: 100}},277      ))).to.not.be.rejected;278279      // Nest a new token280      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');281      await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');282    });283  });284});285286describe('Negative Test: Nesting', async() => {287  before(async () => {288    await usingApi(async (api, privateKeyWrapper) => {289      alice = privateKeyWrapper('//Alice');290      bob = privateKeyWrapper('//Bob');291    });292  });293294  it('Disallows excessive token nesting', async () => {295    await usingApi(async api => {296      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});297      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});298      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');299300      const maxNestingLevel = 5;301      let prevToken = targetToken;302303      // Create a nested-token matryoshka304      for (let i = 0; i < maxNestingLevel; i++) {305        const nestedToken = await createItemExpectSuccess(306          alice,307          collection,308          'NFT',309          {Ethereum: tokenIdToAddress(collection, prevToken)},310        );311312        prevToken = nestedToken;313      }314315      // The nesting depth is limited by `maxNestingLevel`316      await expect(executeTransaction(api, alice, api.tx.unique.createItem(317        collection,318        {Ethereum: tokenIdToAddress(collection, prevToken)},319          {nft: {const_data: [], variable_data: []}} as any,320      )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);321322      expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});323    });324  });325326  // ---------- Non-Fungible ----------327328  it('NFT: disallows to nest token if nesting is disabled', async () => {329    await usingApi(async api => {330      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});331      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {}});332      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');333334      // Try to create a nested token335      await expect(executeTransaction(api, alice, api.tx.unique.createItem(336        collection,337        {Ethereum: tokenIdToAddress(collection, targetToken)},338          {nft: {const_data: [], variable_data: []}} as any,339      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);340341      // Create a token to be nested342      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');343      // Try to nest344      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/);345      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});346      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});347    });348  });349350  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {351    await usingApi(async api => {352      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});353      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});354355      await addToAllowListExpectSuccess(alice, collection, bob.address);356      await enableAllowListExpectSuccess(alice, collection);357      await enablePublicMintingExpectSuccess(alice, collection);358359      // Create a token to attempt to be nested into360      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');361362      // Try to create a nested token in the wrong collection363      await expect(executeTransaction(api, alice, api.tx.unique.createItem(364        collection,365        {Ethereum: tokenIdToAddress(collection, targetToken)},366          {nft: {const_data: [], variable_data: []}} as any,367      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);368369      // Try to create and nest a token in the wrong collection370      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');371      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/);372      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});373    });374  });375376  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {377    await usingApi(async api => {378      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});379      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});380381      await addToAllowListExpectSuccess(alice, collection, bob.address);382      await enableAllowListExpectSuccess(alice, collection);383      await enablePublicMintingExpectSuccess(alice, collection);384385      // Create a token to attempt to be nested into386      const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');387388      // Try to create a nested token in the wrong collection389      await expect(executeTransaction(api, alice, api.tx.unique.createItem(390        collection,391        {Ethereum: tokenIdToAddress(collection, targetToken)},392          {nft: {const_data: [], variable_data: []}} as any,393      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);394395      // Try to create and nest a token in the wrong collection396      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');397      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/);398      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});399    });400  });401402  it('NFT: disallows to nest token in an unlisted collection', async () => {403    await usingApi(async api => {404      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});405      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[]}});406407      // Create a token to attempt to be nested into408      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');409410      // Try to create a nested token in the wrong collection411      await expect(executeTransaction(api, alice, api.tx.unique.createItem(412        collection,413        {Ethereum: tokenIdToAddress(collection, targetToken)},414          {nft: {const_data: [], variable_data: []}} as any,415      )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);416417      // Try to create and nest a token in the wrong collection418      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');419      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/);420      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});421    });422  });423424  // ---------- Fungible ----------425426  it('Fungible: disallows to nest token if nesting is disabled', async () => {427    await usingApi(async api => {428      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});429      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});430      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');431      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};432433      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});434435      // Try to create a nested token436      await expect(executeTransaction(api, alice, api.tx.unique.createItem(437        collectionFT,438        targetAddress,439        {Fungible: {Value: 10}},440      )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);441442      // Create a token to be nested443      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');444      // Try to nest445      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);446447      // Create another token to be nested448      const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');449      // Try to nest inside a fungible token450      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/);451    });452  });453454  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {455    await usingApi(async api => {456      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});457      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});458459      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);460      await enableAllowListExpectSuccess(alice, collectionNFT);461      await enablePublicMintingExpectSuccess(alice, collectionNFT);462463      // Create a token to attempt to be nested into464      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');465      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};466467      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});468469      // Try to create a nested token in the wrong collection470      await expect(executeTransaction(api, alice, api.tx.unique.createItem(471        collectionFT,472        targetAddress,473        {Fungible: {Value: 10}},474      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);475476      // Try to create and nest a token in the wrong collection477      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');478      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);479    });480  });481482  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {483    await usingApi(async api => {484      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});485      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);486      await enableAllowListExpectSuccess(alice, collectionNFT);487      await enablePublicMintingExpectSuccess(alice, collectionNFT);488489      // Create a token to attempt to be nested into490      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');491      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};492493      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});494      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionFT]}});495496      // Try to create a nested token in the wrong collection497      await expect(executeTransaction(api, alice, api.tx.unique.createItem(498        collectionFT,499        targetAddress,500        {Fungible: {Value: 10}},501      )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);502503      // Try to create and nest a token in the wrong collection504      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');505      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);506    });507  });508509  it('Fungible: disallows to nest token in an unlisted collection', async () => {510    await usingApi(async api => {511      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});512      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});513514      // Create a token to attempt to be nested into515      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');516      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};517518      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});519520      // Try to create a nested token in the wrong collection521      await expect(executeTransaction(api, alice, api.tx.unique.createItem(522        collectionFT,523        targetAddress,524        {Fungible: {Value: 10}},525      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);526527      // Try to create and nest a token in the wrong collection528      const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');529      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);530    });531  });532533  // ---------- Re-Fungible ----------534535  it('ReFungible: disallows to nest token if nesting is disabled', async () => {536    await usingApi(async api => {537      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});538      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});539      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');540      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};541542      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});543544      // Create a nested token545      await expect(executeTransaction(api, alice, api.tx.unique.createItem(546        collectionRFT,547        targetAddress,548        {ReFungible: {const_data: [], pieces: 100}},549      )), 'while creating a nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);550551      // Create a token to be nested552      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');553      // Try to nest554      await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);555      // Try to nest556      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);557558      // Create another token to be nested559      const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');560      // Try to nest inside a fungible token561      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/);562    });563  });564565  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {566    await usingApi(async api => {567      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});568      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});569570      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);571      await enableAllowListExpectSuccess(alice, collectionNFT);572      await enablePublicMintingExpectSuccess(alice, collectionNFT);573574      // Create a token to attempt to be nested into575      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');576      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};577578      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});579580      // Try to create a nested token in the wrong collection581      await expect(executeTransaction(api, alice, api.tx.unique.createItem(582        collectionRFT,583        targetAddress,584        {ReFungible: {const_data: [], pieces: 100}},585      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);586587      // Try to create and nest a token in the wrong collection588      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');589      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);590    });591  });592593  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {594    await usingApi(async api => {595      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});596      await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);597      await enableAllowListExpectSuccess(alice, collectionNFT);598      await enablePublicMintingExpectSuccess(alice, collectionNFT);599600      // Create a token to attempt to be nested into601      const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');602      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};603604      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});605      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});606607      // Try to create a nested token in the wrong collection608      await expect(executeTransaction(api, alice, api.tx.unique.createItem(609        collectionRFT,610        targetAddress,611        {ReFungible: {const_data: [], pieces: 100}},612      )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);613614      // Try to create and nest a token in the wrong collection615      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');616      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);617    });618  });619620  it('ReFungible: disallows to nest token to an unlisted collection', async () => {621    await usingApi(async api => {622      const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});623      await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});624625      // Create a token to attempt to be nested into626      const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');627      const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};628629      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});630631      // Try to create a nested token in the wrong collection632      await expect(executeTransaction(api, alice, api.tx.unique.createItem(633        collectionRFT,634        targetAddress,635        {ReFungible: {const_data: [], pieces: 100}},636      )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);637638      // Try to create and nest a token in the wrong collection639      const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');640      await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);641    });642  });643});
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -99,6 +99,7 @@
 
   it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
     const collectionId = await createCollectionExpectSuccess();
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
 
     await transferFromExpectSuccess(collectionId, itemId, alice, bob, charlie);
@@ -257,6 +258,7 @@
     await usingApi(async () => {
       // nft
       const nftCollectionId = await createCollectionExpectSuccess();
+      await setCollectionLimitsExpectSuccess(alice, nftCollectionId, {ownerCanTransfer: true});
       const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
       await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);
       await approveExpectFail(nftCollectionId, newNftTokenId, alice, bob);
@@ -266,6 +268,7 @@
   it('transferFrom burnt token before approve Fungible', async () => {
     await usingApi(async () => {
       const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      await setCollectionLimitsExpectSuccess(alice, fungibleCollectionId, {ownerCanTransfer: true});
       const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
       await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);
       await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
@@ -276,6 +279,7 @@
   it('transferFrom burnt token before approve ReFungible', async () => {
     await usingApi(async () => {
       const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+      await setCollectionLimitsExpectSuccess(alice, reFungibleCollectionId, {ownerCanTransfer: true});
       const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
       await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);
       await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, alice, bob);
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -921,6 +921,18 @@
   });
 }
 
+export async function adminApproveFromExpectFail(
+  collectionId: number,
+  tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,
+) {
+  await usingApi(async (api: ApiPromise) => {
+    const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);
+    const events = await expect(submitTransactionAsync(admin, approveUniqueTx)).to.be.rejected;
+    const result = getGenericResult(events);
+    expect(result.success).to.be.false;
+  });
+}
+
 export async function
 getFreeBalance(account: IKeyringPair): Promise<bigint> {
   let balance = 0n;