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
29 const data = [29 const data = [
30 {30 {
31 owner: {substrate: alice.address},31 owner: {substrate: alice.address},
32 // constData: '0x0000',
33 }, {32 }, {
34 owner: {substrate: bob.address},33 owner: {substrate: bob.address},
35 // constData: '0x2222',
36 }, {34 }, {
37 owner: {substrate: charlie.address},35 owner: {substrate: charlie.address},
38 // constData: '0x4444',
39 },36 },
40 ];37 ];
4138
57 const data = [54 const data = [
58 {55 {
59 owner: {substrate: alice.address},56 owner: {substrate: alice.address},
60 // constData: '0x1111',
61 properties: [{key: 'k', value: 'v1'}],57 properties: [{key: 'k', value: 'v1'}],
62 }, {58 }, {
63 owner: {substrate: bob.address},59 owner: {substrate: bob.address},
64 // constData: '0x2222',
65 properties: [{key: 'k', value: 'v2'}],60 properties: [{key: 'k', value: 'v2'}],
66 }, {61 }, {
67 owner: {substrate: charlie.address},62 owner: {substrate: charlie.address},
68 // constData: '0x4444',
69 properties: [{key: 'k', value: 'v3'}],63 properties: [{key: 'k', value: 'v3'}],
70 },64 },
71 ];65 ];
88 const data = [82 const data = [
89 {83 {
90 owner: {substrate: alice.address},84 owner: {substrate: alice.address},
91 // constData: '0x0000',
92 properties: [{key: 'k', value: 'v1'}],85 properties: [{key: 'k', value: 'v1'}],
93 }, {86 }, {
94 owner: {substrate: bob.address},87 owner: {substrate: bob.address},
95 // constData: '0x2222',
96 properties: [{key: 'k', value: 'v2'}],88 properties: [{key: 'k', value: 'v2'}],
97 }, {89 }, {
98 owner: {substrate: charlie.address},90 owner: {substrate: charlie.address},
99 // constData: '0x4444',
100 properties: [{key: 'k', value: 'v3'}],91 properties: [{key: 'k', value: 'v3'}],
101 },92 },
102 ];93 ];
119 const data = [110 const data = [
120 {111 {
121 owner: {substrate: alice.address},112 owner: {substrate: alice.address},
122 // constData: '0x0000',
123 properties: [{key: 'k', value: 'v1'}],113 properties: [{key: 'k', value: 'v1'}],
124 }, {114 }, {
125 owner: {substrate: bob.address},115 owner: {substrate: bob.address},
126 // constData: '0x2222',
127 properties: [{key: 'k', value: 'v2'}],116 properties: [{key: 'k', value: 'v2'}],
128 }, {117 }, {
129 owner: {substrate: charlie.address},118 owner: {substrate: charlie.address},
130 // constData: '0x4444',
131 properties: [{key: 'k', value: 'v3'}],119 properties: [{key: 'k', value: 'v3'}],
132 },120 },
133 ];121 ];
272 const data = [260 const data = [
273 {261 {
274 owner: {substrate: alice.address},262 owner: {substrate: alice.address},
275 // constData: '0x0000',
276 }, {263 }, {
277 owner: {substrate: bob.address},264 owner: {substrate: bob.address},
278 // constData: '0x2222',
279 }, {265 }, {
280 owner: {substrate: charlie.address},266 owner: {substrate: charlie.address},
281 // constData: '0x4444',
282 },267 },
283 ];268 ];
284269
300 const data = [285 const data = [
301 {286 {
302 owner: {substrate: alice.address},287 owner: {substrate: alice.address},
303 // constData: '0x0000',
304 }, {288 }, {
305 owner: {substrate: bob.address},289 owner: {substrate: bob.address},
306 // constData: '0x2222',
307 }, {290 }, {
308 owner: {substrate: charlie.address},291 owner: {substrate: charlie.address},
309 // constData: '0x4444',
310 },292 },
311 ];293 ];
312294
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
--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -31,12 +31,12 @@
         name: strToUTF16('Mojave Pictures'),
         description: strToUTF16('$2.2 billion power plant!'),
         tokenPrefix: '0x0002030',
-        offchainSchema: '0x111111',
-        schemaVersion: 'Unique',
+        //offchainSchema: '0x111111',
+        //schemaVersion: 'Unique',
         limits: {
           accountTokenOwnershipLimit: 3,
         },
-        constOnChainSchema: '0x333333',
+        //constOnChainSchema: '0x333333',
       });
       const events = await submitTransactionAsync(alice, tx);
       const result = getCreateCollectionResult(events);
@@ -96,17 +96,17 @@
       const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;
 
       // Make sure the extra fields are what they should be
-      const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
-      const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
+      //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
+      //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
 
-      expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
-      expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
+      //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
+      //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
       expect(collectionNew).to.have.nested.property('limits.nestingRule');
 
       // Get rid of extra fields to perform comparison on the rest of the collection
       delete collectionNew.limits.nestingRule;
-      delete collectionOld.constOnChainSchema;
-      delete collectionOld.offchainSchema;
+      //delete collectionOld.constOnChainSchema;
+      //delete collectionOld.offchainSchema;
 
       expect(collectionNew).to.be.deep.equal(collectionOld);
     });
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,