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

difftreelog

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

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

7 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -54,6 +54,7 @@
     "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
     "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
     "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+    "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",
     "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",
     "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",
     "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
modifiedtests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth
--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -29,13 +29,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
@@ -57,15 +54,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x1111',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -88,15 +82,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -119,15 +110,12 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
           properties: [{key: 'k', value: 'v1'}],
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
           properties: [{key: 'k', value: 'v2'}],
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
           properties: [{key: 'k', value: 'v3'}],
         },
       ];
@@ -272,13 +260,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
@@ -300,13 +285,10 @@
       const data = [
         {
           owner: {substrate: alice.address},
-          // constData: '0x0000',
         }, {
           owner: {substrate: bob.address},
-          // constData: '0x2222',
         }, {
           owner: {substrate: charlie.address},
-          // constData: '0x4444',
         },
       ];
 
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -25,6 +25,7 @@
   setCollectionLimitsExpectSuccess,
   addCollectionAdminExpectSuccess,
   getCreatedCollectionCount,
+  createItemExpectSuccess,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -83,4 +84,10 @@
 
     await destroyCollectionExpectFailure(collectionId, '//Alice');
   });
+  it('fails when a collection still has a token', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await createItemExpectSuccess(alice, collectionId, 'NFT');
+
+    await destroyCollectionExpectFailure(collectionId, '//Alice');
+  });
 });
modifiedtests/src/nesting/migration-check.test.tsdiffbeforeafterboth
31 name: strToUTF16('Mojave Pictures'),31 name: strToUTF16('Mojave Pictures'),
32 description: strToUTF16('$2.2 billion power plant!'),32 description: strToUTF16('$2.2 billion power plant!'),
33 tokenPrefix: '0x0002030',33 tokenPrefix: '0x0002030',
34 offchainSchema: '0x111111',34 //offchainSchema: '0x111111',
35 schemaVersion: 'Unique',35 //schemaVersion: 'Unique',
36 limits: {36 limits: {
37 accountTokenOwnershipLimit: 3,37 accountTokenOwnershipLimit: 3,
38 },38 },
39 constOnChainSchema: '0x333333',39 //constOnChainSchema: '0x333333',
40 });40 });
41 const events = await submitTransactionAsync(alice, tx);41 const events = await submitTransactionAsync(alice, tx);
42 const result = getCreateCollectionResult(events);42 const result = getCreateCollectionResult(events);
96 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;96 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;
9797
98 // Make sure the extra fields are what they should be98 // Make sure the extra fields are what they should be
99 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');99 //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
100 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');100 //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
101101
102 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);102 //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
103 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);103 //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
104 expect(collectionNew).to.have.nested.property('limits.nestingRule');104 expect(collectionNew).to.have.nested.property('limits.nestingRule');
105105
106 // Get rid of extra fields to perform comparison on the rest of the collection106 // Get rid of extra fields to perform comparison on the rest of the collection
107 delete collectionNew.limits.nestingRule;107 delete collectionNew.limits.nestingRule;
108 delete collectionOld.constOnChainSchema;108 //delete collectionOld.constOnChainSchema;
109 delete collectionOld.offchainSchema;109 //delete collectionOld.offchainSchema;
110110
111 expect(collectionNew).to.be.deep.equal(collectionOld);111 expect(collectionNew).to.be.deep.equal(collectionOld);
112 });112 });
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -10,6 +10,7 @@
   enablePublicMintingExpectSuccess,
   getTokenOwner,
   getTopmostTokenOwner,
+  normalizeAccountId,
   setCollectionPermissionsExpectSuccess,
   transferExpectFailure,
   transferExpectSuccess,
@@ -28,7 +29,7 @@
     });
   });
 
-  it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {
+  it('Performs the full suite: bundles a token, transfers, and unnests', async () => {
     await usingApi(async api => {
       const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
       await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
@@ -58,6 +59,33 @@
     });
   });
 
+  it('Transfers an already bundled token', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
+
+      const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');
+      const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');
+
+      // Create a nested token
+      const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});
+      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});
+      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});
+
+      // Transfer the nested token to another token
+      await expect(executeTransaction(
+        api,
+        alice,
+        api.tx.unique.transferFrom(
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), 
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), 
+          collection, tokenC, 1),
+      )).to.not.be.rejected;
+      expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});
+      expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});
+    });
+  });
+
   // ---------- Non-Fungible ----------
 
   it('NFT: allows an Owner to nest/unnest their token', async () => {
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setChainLimits.test.ts
+++ b/tests/src/setChainLimits.test.ts
@@ -43,8 +43,6 @@
         nftSponsorTransferTimeout: 1,
         fungibleSponsorTransferTimeout: 1,
         refungibleSponsorTransferTimeout: 1,
-        offchainSchemaLimit: 1,
-        constOnChainSchemaLimit: 1,
       };
     });
   });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -135,8 +135,8 @@
   nftSponsorTransferTimeout: number;
   fungibleSponsorTransferTimeout: number;
   refungibleSponsorTransferTimeout: number;
-  offchainSchemaLimit: number;
-  constOnChainSchemaLimit: number;
+  //offchainSchemaLimit: number;
+  //constOnChainSchemaLimit: number;
 }
 
 export interface IReFungibleTokenDataType {
@@ -310,7 +310,6 @@
   name: string,
   description: string,
   tokenPrefix: string,
-  schemaVersion: string,
   properties?: Array<Property>,
   propPerm?: Array<PropertyPermission>
 };
@@ -320,7 +319,6 @@
   mode: {type: 'NFT'},
   name: 'name',
   tokenPrefix: 'prefix',
-  schemaVersion: 'ImageURL',
 };
 
 export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
@@ -780,25 +778,8 @@
     const result = getGenericResult(events);
 
     expect(result.success).to.be.false;
-  });
-}
-
-/*export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {
-  await usingApi(async (api) => {
-    const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
-    const events = await submitTransactionAsync(sender, tx);
-    const result = getGenericResult(events);
-
-    expect(result.success).to.be.true;
   });
 }
-
-export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {
-  await usingApi(async (api) => {
-    const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
-    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
-  });
-}*/
 
 export interface CreateFungibleData {
   readonly Value: bigint;
@@ -1110,13 +1091,6 @@
 ): Promise<string[]> {
   return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;
 }
-/*export async function getConstMetadata(
-  api: ApiPromise,
-  collectionId: number,
-  tokenId: number,
-): Promise<number[]> {
-  return [...(await api.rpc.unique.constMetadata(collectionId, tokenId))];
-}*/
 export async function getTokenProperties(
   api: ApiPromise,
   collectionId: number,