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

difftreelog

test(structure) refactor properties and nesting

Fahrrader2022-05-13parent: #1c4a2b3.patch.diff
in: master

7 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -33,7 +33,9 @@
     "loadTransfer": "ts-node src/transfer.nload.ts",
     "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
     "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",
-    "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
+    "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
+    "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
+    "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
     "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
     "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
     "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
modifiedtests/src/nesting/graphs.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -14,7 +14,7 @@
  * ```
  */
 async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {
-  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT'}));
+  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}}));
   const {collectionId} = getCreateCollectionResult(events);
 
   await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));
@@ -32,20 +32,26 @@
   return collectionId;
 }
 
-describe('graphs', () => {
-  it('ouroboros can\'t be created in graph', async () => {
+describe('Graphs', () => {
+  it('Ouroboros can\'t be created in a complex graph', async () => {
     await usingApi(async api => {
       const alice = privateKey('//Alice');
       const collection = await buildComplexObjectGraph(api, alice);
 
       // to self
-      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)))
-        .to.be.rejectedWith(/structure\.OuroborosDetected/);
+      await expect(
+        executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)),
+        'first transaction',  
+      ).to.be.rejectedWith(/structure\.OuroborosDetected/);
       // to nested part of graph
-      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)))
-        .to.be.rejectedWith(/structure\.OuroborosDetected/);
-      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)))
-        .to.be.rejectedWith(/structure\.OuroborosDetected/);
+      await expect(
+        executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)),
+        'second transaction',
+      ).to.be.rejectedWith(/structure\.OuroborosDetected/);
+      await expect(
+        executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)),
+        'third transaction',
+      ).to.be.rejectedWith(/structure\.OuroborosDetected/);
     });
   });
 });
modifiedtests/src/nesting/migration-check.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -18,7 +18,7 @@
     });
   });
 
-  it('Preserves collection settings', async () => {
+  it('Preserves collection settings after migration', async () => {
     let oldVersion: number;
     let collectionId: number;
     let collectionOld: any;
@@ -71,6 +71,7 @@
         });
       } catch (_) {
         connectionFailCounter++;
+        console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);
         await new Promise(resolve => setTimeout(resolve, 12000));
       }
     }
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -5,12 +5,12 @@
 import {
   addToAllowListExpectSuccess,
   createCollectionExpectSuccess,
-  createItemExpectFailure, 
   createItemExpectSuccess,
   enableAllowListExpectSuccess,
   enablePublicMintingExpectSuccess,
   getTokenOwner, 
   getTopmostTokenOwner, 
+  normalizeAccountId, 
   setCollectionLimitsExpectSuccess, 
   transferExpectFailure, 
   transferExpectSuccess, 
@@ -29,11 +29,7 @@
     });
   });
 
-  // ---------- Non-Fungible ----------
-
-  // todo refactor names
-  // todo remove excessive bundling, leave it for a single test
-  it('NFT: allows to nest/unnest token if nesting rule is Owner', async () => {
+  it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
@@ -49,8 +45,8 @@
       
       // Nest
       await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
-      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
-      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
+      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
+      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
 
       // Move bundle to different user
       await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});
@@ -63,10 +59,12 @@
     });
   });
 
-  it('NFT: allows to nest/unnest token if Owner-Restricted', async () => {
+  // ---------- Non-Fungible ----------
+
+  it('NFT: allows an Owner to nest/unnest their token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Create a nested token
@@ -74,28 +72,36 @@
       expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
       expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
 
-      // Create a token to be nested
+      // Create a token to be nested and nest
       const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
-      
-      // Nest
       await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
+      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
+      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
+    });
+  });
+
+  it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
+      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+
+      // Create a nested token
+      const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
       expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
       expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
 
-      // Move bundle to different user
-      await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});
-      expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});
-      expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
-      
-      // Unnest
-      await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});
-      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
+      // Create a token to be nested and nest
+      const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
+      await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
+      expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
+      expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
     });
   });
 
   // ---------- Fungible ----------
 
-  it('Fungible: allows to nest/unnest token if Owner', async () => {
+  it('Fungible: allows an Owner to nest/unnest their token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
@@ -111,18 +117,13 @@
         {Fungible: {Value: 10}},
       ))).to.not.be.rejected;
 
-      // Create a token to be nested
+      // Nest a new token
       const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
-      // Nest
       await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');
-      // Move bundle to different user
-      await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
-      // Unnest
-      await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');
     });
   });
 
-  it('Fungible: allows to nest/unnest token if Owner-Restricted', async () => {
+  it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
@@ -139,20 +140,15 @@
         {Fungible: {Value: 10}},
       ))).to.not.be.rejected;
 
-      // Create a token to be nested
+      // Nest a new token
       const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
-      // Nest
       await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');
-      // Move bundle to different user
-      await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
-      // Unnest
-      await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');
     });
   });
 
   // ---------- Re-Fungible ----------
 
-  it('ReFungible: allows to nest/unnest token if Owner', async () => {
+  it('ReFungible: allows an Owner to nest/unnest their token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
@@ -165,21 +161,16 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress, 
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.not.be.rejected;
 
-      // Create a token to be nested
+      // Nest a new token
       const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
-      // Nest
       await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');
-      // Move bundle to different user
-      await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
-      // Unnest
-      await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');
     });
   });
 
-  it('ReFungible: allows to nest/unnest token if Owner-Restricted', async () => {
+  it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
@@ -193,17 +184,12 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress,
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.not.be.rejected;
 
-      // Create a token to be nested
+      // Nest a new token
       const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
-      // Nest
       await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');
-      // Move bundle to different user
-      await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
-      // Unnest
-      await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');
     });
   });
 });
@@ -216,6 +202,29 @@
     });
   });
 
+  it('Disallows excessive token nesting', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+
+      // Create a nested-token matryoshka
+      const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
+      const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});
+      // The nesting depth is limited by 2
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collection, 
+          {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 
+          {nft: {const_data: [], variable_data: []}} as any,
+        ),
+      ), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/); // OuroborosDetected?
+
+      expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});
+    });
+  });
+
   // ---------- Non-Fungible ----------
 
   it('NFT: disallows to nest token if nesting is disabled', async () => {
@@ -225,22 +234,30 @@
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Try to create a nested token
-      await expect(executeTransaction(api, alice, api.tx.unique.createItem(
-        collection, 
-        {Ethereum: tokenIdToAddress(collection, targetToken)}, 
-        {nft: {const_data: [], variable_data: []}} as any,
-      ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collection, 
+          {Ethereum: tokenIdToAddress(collection, targetToken)}, 
+          {nft: {const_data: [], variable_data: []}} as any,
+        ),
+      ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
 
       // Create a token to be nested
       const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
       // Try to nest
-      await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)}); // todo to.be.rejected
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/); // todo to.be.rejected for all
       expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
       expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
     });
   });
 
-  it('NFT: disallows to nest token if not Owner', async () => {
+  it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
@@ -253,16 +270,28 @@
       const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
 
       // Try to create a nested token in the wrong collection
-      await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collection, 
+          {Ethereum: tokenIdToAddress(collection, targetToken)}, 
+          {nft: {const_data: [], variable_data: []}} as any,
+        ),
+      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/); // todo NestingIsDisabled?
 
       // Try to create and nest a token in the wrong collection
       const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
-      await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
       expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
     });
   });
 
-  it('NFT: disallows to nest token if not Owner (Restricted nesting)', async () => {
+  it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
@@ -275,16 +304,28 @@
       const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
 
       // Try to create a nested token in the wrong collection
-      await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collection, 
+          {Ethereum: tokenIdToAddress(collection, targetToken)}, 
+          {nft: {const_data: [], variable_data: []}} as any,
+        ),
+      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);
 
       // Try to create and nest a token in the wrong collection
       const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
-      await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
       expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
     });
   });
 
-  it('NFT: disallows to nest token to an unlisted collection', async () => {
+  it('NFT: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});
@@ -293,11 +334,23 @@
       const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
 
       // Try to create a nested token in the wrong collection
-      await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collection, 
+          {Ethereum: tokenIdToAddress(collection, targetToken)}, 
+          {nft: {const_data: [], variable_data: []}} as any,
+        ),
+      ), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
 
       // Try to create and nest a token in the wrong collection
       const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
-      await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
       expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
     });
   });
@@ -314,20 +367,28 @@
       const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
 
       // Try to create a nested token
-      await expect(executeTransaction(api, alice, api.tx.unique.createItem(
-        collectionFT, 
-        targetAddress, 
-        {Fungible: {Value: 10}},
-      ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collectionFT, 
+          targetAddress, 
+          {Fungible: {Value: 10}},
+        )
+      ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);
 
       // Create a token to be nested
       const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
       // Try to nest
-      await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);
     });
   });
 
-  it('Fungible: disallows to nest token if not Owner', async () => {
+  it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
@@ -343,22 +404,30 @@
       const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
 
       // Try to create a nested token in the wrong collection
-      await expect(executeTransaction(api, alice, api.tx.unique.createItem(
-        collectionFT, 
-        targetAddress, 
-        {Fungible: {Value: 10}},
-      ))).to.be.rejected;
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.createItem(
+          collectionFT, 
+          targetAddress, 
+          {Fungible: {Value: 10}},
+        )
+      ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);
 
       // Try to create and nest a token in the wrong collection
       const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
-      await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
+      await expect(executeTransaction(
+        api, alice, 
+        api.tx.unique.transfer(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,
+        ),
+      ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);
     });
   });
 
-  it('Fungible: disallows to nest token if not Owner (Restricted nesting)', async () => {
+  it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions
+      await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions?
 
       await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
       await enableAllowListExpectSuccess(alice, collectionNFT);
@@ -383,7 +452,7 @@
     });
   });
 
-  it('Fungible: disallows to nest token to an unlisted collection', async () => {
+  it('Fungible: disallows to nest token in an unlisted collection', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
@@ -422,7 +491,7 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress, 
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
 
       // Create a token to be nested
@@ -432,7 +501,7 @@
     });
   });
 
-  it('ReFungible: disallows to nest token if not Owner', async () => {
+  it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
@@ -451,7 +520,7 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress, 
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.be.rejected;
 
       // Try to create and nest a token in the wrong collection
@@ -460,7 +529,7 @@
     });
   });
 
-  it('ReFungible: disallows to nest token if not Owner (Restricted nesting)', async () => {
+  it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {
     await usingApi(async api => {
       const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});
@@ -479,7 +548,7 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress, 
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.be.rejected;
 
       // Try to create and nest a token in the wrong collection
@@ -503,7 +572,7 @@
       await expect(executeTransaction(api, alice, api.tx.unique.createItem(
         collectionRFT, 
         targetAddress, 
-        {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
+        {ReFungible: {const_data: [], pieces: 100}},
       ))).to.be.rejected;
 
       // Try to create and nest a token in the wrong collection
modifiedtests/src/nesting/properties.test.tsdiffbeforeafterboth
51 await expect(executeTransaction(51 await expect(executeTransaction(
52 api, 52 api,
53 alice, 53 alice,
54 api.tx.unique.setCollectionProperties(collectionId, [{key: 'black hole'}]), 54 api.tx.unique.setCollectionProperties(collectionId, [{key: 'black_hole'}]),
55 )).to.not.be.rejected;55 )).to.not.be.rejected;
5656
57 const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black hole'])).toJSON();57 const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black_hole'])).toHuman();
58 expect(properties).to.be.deep.equal([58 expect(properties).to.be.deep.equal([
59 {key: `0x${Buffer.from('electron').toString('hex')}`, value: `0x${Buffer.from('come bond').toString('hex')}`},59 {key: 'electron', value: 'come bond'},
60 {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('').toString('hex')}`},60 {key: 'black_hole', value: ''},
61 ]);61 ]);
62 });62 });
63 });63 });
69 await expect(executeTransaction(69 await expect(executeTransaction(
70 api, 70 api,
71 alice, 71 alice,
72 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole'}]), 72 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole'}]),
73 )).to.not.be.rejected;73 )).to.not.be.rejected;
7474
75 // Mutate the properties75 // Mutate the properties
76 await expect(executeTransaction(76 await expect(executeTransaction(
77 api, 77 api,
78 alice, 78 alice,
79 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black hole', value: 'LIGO'}]), 79 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black_hole', value: 'LIGO'}]),
80 )).to.not.be.rejected;80 )).to.not.be.rejected;
8181
82 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();82 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();
83 expect(properties).to.be.deep.equal([83 expect(properties).to.be.deep.equal([
84 {key: `0x${Buffer.from('electron').toString('hex')}`, value: `0x${Buffer.from('bonded').toString('hex')}`},84 {key: 'electron', value: 'bonded'},
85 {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('LIGO').toString('hex')}`},85 {key: 'black_hole', value: 'LIGO'},
86 ]);86 ]);
87 });87 });
88 });88 });
94 await expect(executeTransaction(94 await expect(executeTransaction(
95 api, 95 api,
96 alice, 96 alice,
97 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole', value: 'LIGO'}]), 97 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]),
98 )).to.not.be.rejected;98 )).to.not.be.rejected;
9999
100 await expect(executeTransaction(100 await expect(executeTransaction(
103 api.tx.unique.deleteCollectionProperties(collection, ['electron']), 103 api.tx.unique.deleteCollectionProperties(collection, ['electron']),
104 )).to.not.be.rejected;104 )).to.not.be.rejected;
105105
106 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();106 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();
107 expect(properties).to.be.deep.equal([107 expect(properties).to.be.deep.equal([
108 {key: `0x${Buffer.from('black hole').toString('hex')}`, value: `0x${Buffer.from('LIGO').toString('hex')}`},108 {key: 'black_hole', value: 'LIGO'},
109 ]);109 ]);
110 });110 });
111 });111 });
126 await expect(executeTransaction(126 await expect(executeTransaction(
127 api, 127 api,
128 bob, 128 bob,
129 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black hole', value: 'LIGO'}]), 129 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]),
130 )).to.be.rejectedWith(/common\.NoPermission/);130 )).to.be.rejectedWith(/common\.NoPermission/);
131 131
132 const properties = (await api.query.common.collectionProperties(collection)).toJSON();132 const properties = (await api.query.common.collectionProperties(collection)).toJSON();
158 alice, 158 alice,
159 api.tx.unique.setCollectionProperties(collection, [159 api.tx.unique.setCollectionProperties(collection, [
160 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))}, 160 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))},
161 {key: 'black hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))}, 161 {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))},
162 ]), 162 ]),
163 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);163 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);
164164
174 const propertiesToBeSet = [];174 const propertiesToBeSet = [];
175 for (let i = 0; i < 65; i++) {175 for (let i = 0; i < 65; i++) {
176 propertiesToBeSet.push({176 propertiesToBeSet.push({
177 key: 'electron ' + i,177 key: 'electron_' + i,
178 value: Math.random() > 0.5 ? 'high' : 'low',178 value: Math.random() > 0.5 ? 'high' : 'low',
179 });179 });
180 }180 }
191 });191 });
192 });192 });
193
194 it('Fails to set properties with invalid names', async () => {
195 await usingApi(async api => {
196 const collection = await createCollectionExpectSuccess();
197
198 const invalidProperties = [
199 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],
200 [{key: 'Mr.Sandman', value: 'Bring me a gene'}],
201 [{key: 'déjà vu', value: 'hmm...'}],
202 ];
203
204 for (let i = 0; i < invalidProperties.length; i++) {
205 await expect(executeTransaction(
206 api,
207 alice,
208 api.tx.unique.setCollectionProperties(collection, invalidProperties[i]),
209 ), `on rejecting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
210 }
211
212 await expect(executeTransaction(
213 api,
214 alice,
215 api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]),
216 ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
217
218 await expect(executeTransaction(
219 api,
220 alice,
221 api.tx.unique.setCollectionProperties(collection, [
222 {key: 'CRISPR-Cas9', value: 'rewriting nature!'}
223 ]),
224 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
225
226 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');
227
228 const properties = (await api.rpc.unique.collectionProperties(collection, keys)).toHuman();
229 expect(properties).to.be.deep.equal([
230 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},
231 ]);
232
233 for (let i = 0; i < invalidProperties.length; i++) {
234 await expect(executeTransaction(
235 api,
236 alice,
237 api.tx.unique.deleteCollectionProperties(collection, invalidProperties[i].map(propertySet => propertySet.key)),
238 ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
239 }
240 });
241 });
193});242});
194243
195// ---------- ACCESS RIGHTS244// ---------- ACCESS RIGHTS
228 api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]), 277 api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]),
229 )).to.not.be.rejected;278 )).to.not.be.rejected;
230279
231 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toJSON();280 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toHuman();
232 expect(propertyRights).to.be.deep.equal([281 expect(propertyRights).to.be.deep.equal([
233 {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},282 {key: 'skullduggery', permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},
234 {key: `0x${Buffer.from('mindgame').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},283 {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},
235 ]);284 ]);
236 });285 });
237 });286 });
252 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]), 301 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
253 )).to.not.be.rejected;302 )).to.not.be.rejected;
254303
255 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();304 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
256 expect(propertyRights).to.be.deep.equal([305 expect(propertyRights).to.be.deep.equal([
257 {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},306 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
258 ]);307 ]);
259 });308 });
260 });309 });
290 const constitution = [];339 const constitution = [];
291 for (let i = 0; i < 65; i++) {340 for (let i = 0; i < 65; i++) {
292 constitution.push({341 constitution.push({
293 key: 'property ' + i,342 key: 'property_' + i,
294 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},343 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},
295 });344 });
296 }345 }
322 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]), 371 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]),
323 )).to.be.rejectedWith(/common\.NoPermission/);372 )).to.be.rejectedWith(/common\.NoPermission/);
324373
325 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();374 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
326 expect(propertyRights).to.deep.equal([375 expect(propertyRights).to.deep.equal([
327 {key: `0x${Buffer.from('skullduggery').toString('hex')}`, permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},376 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
328 ]);377 ]);
329 });378 });
330 });379 });
380
381 it('Prevents adding properties with invalid names', async () => {
382 await usingApi(async api => {
383 const collection = await createCollectionExpectSuccess();
384
385 const invalidProperties = [
386 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],
387 [{key: 'G#4', permission: {tokenOwner: true}}],
388 [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],
389 ];
390
391 for (let i = 0; i < invalidProperties.length; i++) {
392 await expect(executeTransaction(
393 api,
394 alice,
395 api.tx.unique.setPropertyPermissions(collection, invalidProperties[i]),
396 ), `on setting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
397 }
398
399 await expect(executeTransaction(
400 api,
401 alice,
402 api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]),
403 ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);
404
405 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string
406 await expect(executeTransaction(
407 api,
408 alice,
409 api.tx.unique.setPropertyPermissions(collection, [
410 {key: correctKey, permission: {collectionAdmin: true}},
411 ]),
412 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
413
414 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');
415
416 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, keys)).toHuman();
417 expect(propertyRights).to.be.deep.equal([
418 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},
419 ]);
420 });
421 });
331});422});
332423
333// ---------- TOKEN PROPERTIES424// ---------- TOKEN PROPERTIES
361 await transferExpectSuccess(collection, token, alice, charlie);452 await transferExpectSuccess(collection, token, alice, charlie);
362 });453 });
363 454
364 it('Reads properties of a token', async () => {455 it('Reads yet empty properties of a token', async () => {
365 await usingApi(async api => {456 await usingApi(async api => {
366 const collection = await createCollectionExpectSuccess();457 const collection = await createCollectionExpectSuccess();
367 const token = await createItemExpectSuccess(alice, collection, 'NFT');458 const token = await createItemExpectSuccess(alice, collection, 'NFT');
381 let i = 0;472 let i = 0;
382 for (const permission of permissions) {473 for (const permission of permissions) {
383 for (const signer of permission.signers) {474 for (const signer of permission.signers) {
384 const key = i + ' ' + signer.address;475 const key = i + '_' + signer.address;
385 propertyKeys.push(key);476 propertyKeys.push(key);
386477
387 await expect(executeTransaction(478 await expect(executeTransaction(
400 i++;491 i++;
401 }492 }
402493
403 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];494 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];
404 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];495 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];
405 for (let i = 0; i < properties.length; i++) {496 for (let i = 0; i < properties.length; i++) {
406 expect(properties[i].value).to.be.equal(`0x${Buffer.from('Serotonin increase').toString('hex')}`);497 expect(properties[i].value).to.be.equal('Serotonin increase');
407 expect(tokensData[i].value).to.be.equal(`0x${Buffer.from('Serotonin increase').toString('hex')}`);498 expect(tokensData[i].value).to.be.equal('Serotonin increase');
408 }499 }
409 });500 });
410 });501 });
417 if (!permission.permission.mutable) continue;508 if (!permission.permission.mutable) continue;
418 509
419 for (const signer of permission.signers) {510 for (const signer of permission.signers) {
420 const key = i + ' ' + signer.address;511 const key = i + '_' + signer.address;
421 propertyKeys.push(key);512 propertyKeys.push(key);
422513
423 await expect(executeTransaction(514 await expect(executeTransaction(
442 i++;533 i++;
443 }534 }
444535
445 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];536 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];
446 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];537 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];
447 for (let i = 0; i < properties.length; i++) {538 for (let i = 0; i < properties.length; i++) {
448 expect(properties[i].value).to.be.equal(`0x${Buffer.from('Serotonin stable').toString('hex')}`);539 expect(properties[i].value).to.be.equal('Serotonin stable');
449 expect(tokensData[i].value).to.be.equal(`0x${Buffer.from('Serotonin stable').toString('hex')}`);540 expect(tokensData[i].value).to.be.equal('Serotonin stable');
450 }541 }
451 });542 });
452 });543 });
460 if (!permission.permission.mutable) continue;551 if (!permission.permission.mutable) continue;
461 552
462 for (const signer of permission.signers) {553 for (const signer of permission.signers) {
463 const key = i + ' ' + signer.address;554 const key = i + '_' + signer.address;
464 propertyKeys.push(key);555 propertyKeys.push(key);
465556
466 await expect(executeTransaction(557 await expect(executeTransaction(
532 await expect(executeTransaction(623 await expect(executeTransaction(
533 api, 624 api,
534 alice, 625 alice,
535 api.tx.unique.setPropertyPermissions(collection, [{key: i, permission: passage.permission}]), 626 api.tx.unique.setPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]),
536 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;627 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
537628
538 await expect(executeTransaction(629 await expect(executeTransaction(
539 api, 630 api,
540 signer, 631 signer,
541 api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin increase'}]), 632 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin increase'}]),
542 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;633 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;
543634
544 i++;635 i++;
558 await expect(executeTransaction(649 await expect(executeTransaction(
559 api, 650 api,
560 forbiddance.sinner, 651 forbiddance.sinner,
561 api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin down'}]), 652 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]),
562 ), `on failing to change property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);653 ), `on failing to change property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);
563654
564 await expect(executeTransaction(655 await expect(executeTransaction(
565 api, 656 api,
566 forbiddance.sinner, 657 forbiddance.sinner,
567 api.tx.unique.deleteTokenProperties(collection, token, [forbiddance.permission]), 658 api.tx.unique.deleteTokenProperties(collection, token, [`${i}`]),
568 ), `on failing to delete property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);659 ), `on failing to delete property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);
569 }660 }
570661
571 // todo RPC?
572 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();662 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
573 expect(properties.consumedSpace).to.be.equal(originalSpace);663 expect(properties.consumedSpace).to.be.equal(originalSpace);
574 });664 });
584 await expect(executeTransaction(674 await expect(executeTransaction(
585 api, 675 api,
586 permission.signers[0], 676 permission.signers[0],
587 api.tx.unique.setTokenProperties(collection, token, [{key: i, value: 'Serotonin down'}]), 677 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]),
588 ), `on failing to change property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);678 ), `on failing to change property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);
589679
590 await expect(executeTransaction(680 await expect(executeTransaction(
594 ), `on failing to delete property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);684 ), `on failing to delete property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);
595 }685 }
596686
597 // todo RPC?
598 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();687 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
599 expect(properties.consumedSpace).to.be.equal(originalSpace);688 expect(properties.consumedSpace).to.be.equal(originalSpace);
600 });689 });
632 api, 721 api,
633 alice, 722 alice,
634 api.tx.unique.setPropertyPermissions(collection, [723 api.tx.unique.setPropertyPermissions(collection, [
635 {key: 'a holy book', permission: {collectionAdmin: true, tokenOwner: true}}, 724 {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}},
636 {key: 'young years', permission: {collectionAdmin: true, tokenOwner: true}},725 {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},
637 ]), 726 ]),
638 ), 'on setting a new non-permitted property').to.not.be.rejected;727 ), 'on setting a new non-permitted property').to.not.be.rejected;
639728
643 await expect(executeTransaction(732 await expect(executeTransaction(
644 api, 733 api,
645 alice, 734 alice,
646 api.tx.unique.setCollectionProperties(collection, [{key: 'a holy book', value: 'word '.repeat(6554)}]), 735 api.tx.unique.setCollectionProperties(collection, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]),
647 )).to.be.rejected;736 )).to.be.rejected;
648 }737 }
649738
650 await expect(executeTransaction(739 await expect(executeTransaction(
651 api, 740 api,
652 alice, 741 alice,
653 api.tx.unique.setTokenProperties(collection, token, [742 api.tx.unique.setTokenProperties(collection, token, [
654 {key: 'a holy book', value: 'word '.repeat(3277)}, 743 {key: 'a_holy_book', value: 'word '.repeat(3277)},
655 {key: 'young years', value: 'neverending'.repeat(1490)},744 {key: 'young_years', value: 'neverending'.repeat(1490)},
656 ]), 745 ]),
657 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);746 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);
658747
659 expect((await api.rpc.unique.tokenProperties(collection, token, ['a holy book', 'young years'])).toJSON()).to.be.empty;748 expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young years'])).toJSON()).to.be.empty;
660 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();749 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
661 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);750 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);
662 });751 });
modifiedtests/src/nesting/unnest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -6,11 +6,13 @@
   createCollectionExpectSuccess,
   createItemExpectFailure,
   createItemExpectSuccess,
+  getBalance,
   getTokenOwner,
   getTopmostTokenOwner,
   normalizeAccountId,
   setCollectionLimitsExpectSuccess,
   transferExpectSuccess,
+  transferFromExpectSuccess,
 } from '../util/helpers';
 import {IKeyringPair} from '@polkadot/types/types';
 
@@ -25,7 +27,7 @@
     });
   });
 
-  it('Allows the owner to successfully unnest a token', async () => {
+  it('NFT: allows the owner to successfully unnest a token', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
@@ -40,7 +42,7 @@
         api,
         alice,
         api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(alice), collection, nestedToken, 1),
-      )).to.not.be.rejected;
+      ), 'while unnesting').to.not.be.rejected;
       expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
 
       // Nest and burn
@@ -48,13 +50,64 @@
       await expect(executeTransaction(
         api,
         alice,
-        api.tx.unique.burnFrom(collection, normalizeAccountId(alice.address), nestedToken, 1),
-      )).to.not.be.rejected;
-      await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected; // 'owner == null'
+        api.tx.unique.burnFrom(collection, normalizeAccountId(targetAddress), nestedToken, 1),
+      ), 'while burning').to.not.be.rejected;
+      await expect(getTokenOwner(api, collection, nestedToken)).to.be.rejected;
     });
   });
 
-  // todo refungible-fungible test just in case
+  it('Fungible: allows the owner to successfully unnest a token', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+      const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
+
+      const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      const nestedToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
+
+      // Nest and unnest
+      await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');
+      await transferFromExpectSuccess(collectionFT, nestedToken, alice, targetAddress, alice, 1, 'Fungible');
+
+      // Nest and burn
+      await transferExpectSuccess(collectionFT, nestedToken, alice, targetAddress, 1, 'Fungible');
+      const balanceBefore = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);
+      await expect(executeTransaction(
+        api,
+        alice,
+        api.tx.unique.burnFrom(collectionFT, normalizeAccountId(targetAddress), nestedToken, 1),
+      ), 'while burning').to.not.be.rejected;
+      const balanceAfter = await getBalance(api, collectionFT, normalizeAccountId(targetAddress), nestedToken);
+      expect(balanceAfter + BigInt(1)).to.be.equal(balanceBefore);
+    });
+  });
+
+  it('ReFungible: allows the owner to successfully unnest a token', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
+      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
+      const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)};
+
+      const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+      const nestedToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
+
+      // Nest and unnest
+      await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');
+      await transferFromExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, alice, 1, 'ReFungible');
+
+      // Nest and burn
+      await transferExpectSuccess(collectionRFT, nestedToken, alice, targetAddress, 1, 'ReFungible');
+      await expect(executeTransaction(
+        api,
+        alice,
+        api.tx.unique.burnFrom(collectionRFT, normalizeAccountId(targetAddress), nestedToken, 1),
+      ), 'while burning').to.not.be.rejected;
+      const balance = await getBalance(api, collectionRFT, normalizeAccountId(targetAddress), nestedToken);
+      expect(balance).to.be.equal(0n);
+    });
+  });
 });
 
 describe('Negative Test: Unnesting', () => {
@@ -80,8 +133,7 @@
         api,
         bob,
         api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),
-      )).to.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
-      //await transferFromExpectSuccess(collection, nestedToken, bob, targetAddress, {Substrate: bob.address});
+      ), 'while unnesting').to.be.rejectedWith(/^structure\.DepthLimit$/); // todo ApprovedValueTooLow?
       expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
 
       // Try to burn
@@ -89,31 +141,15 @@
         api,
         bob,
         api.tx.unique.burnFrom(collection, normalizeAccountId(bob.address), nestedToken, 1),
-      )).to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
+      ), 'while burning').to.not.be.rejectedWith(/^common\.ApprovedValueTooLow$/);
       expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
     });
   });
 
-  it('Disallows excessive token nesting', async () => {
-    await usingApi(async api => {
-      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
-      const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
-
-      // Create a nested token matryoshka
-      const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
-      const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});
-      // The nesting depth is limited by 2
-      await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken2)});
+  // todo another test for creating excessive depth matryoshka with Ethereum?
 
-      expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});
-    });
-  });
-
-  // todo another test for creating excessive depth matryoshka with Ethereum, move this one to nest ^
-
   // Recursive nesting
-  it('Prevents ouroboros creation', async () => {
+  it('Prevents Ouroboros creation', async () => {
     const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
     await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
     const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -903,7 +903,7 @@
     const from = normalizeAccountId(accountFrom);
     const to = normalizeAccountId(accountTo);
     let balanceBefore = 0n;
-    if (type === 'Fungible') {
+    if (type === 'Fungible' || type === 'ReFungible') {
       balanceBefore = await getBalance(api, collectionId, to, tokenId);
     }
     const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
@@ -923,7 +923,7 @@
       }
     }
     if (type === 'ReFungible') {
-      expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(BigInt(value));
+      expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(balanceBefore + BigInt(value));
     }
   });
 }