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

difftreelog

fix add consumedSpace fns to playgrnds

Daniel Shiposha2022-12-14parent: #0d84ac0.patch.diff
in: master

3 files changed

modifiedtests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/collectionProperties.test.ts
+++ b/tests/src/nesting/collectionProperties.test.ts
@@ -25,7 +25,7 @@
   before(async () => {
     await usingPlaygrounds(async (helper, privateKey) => {
       const donor = await privateKey({filename: __filename});
-      [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);
+      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
     });
   });
   
@@ -149,16 +149,10 @@
       const makeNewPropData = () => {
         propDataChar = String.fromCharCode(propDataChar.charCodeAt(0) + 1);
         return `${propDataChar}`.repeat(propDataSize);
-      };
-
-      const getConsumedSpace = async () => {
-        const props = (await helper.getApi().query.common.collectionProperties(collection.collectionId)).toJSON();
-        
-        return (props! as any).consumedSpace;
       };
 
       await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
-      const originalSpace = await getConsumedSpace();
+      const originalSpace = await collection.getPropertiesConsumedSpace();
       expect(originalSpace).to.be.equal(propDataSize);
 
       const sameSizePropertiesPossibleNum = maxCollectionPropertiesSize / propDataSize;
@@ -167,7 +161,7 @@
       // It will not consume any additional space.
       for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
         await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
-        const consumedSpace = await getConsumedSpace();
+        const consumedSpace = await collection.getPropertiesConsumedSpace();
         expect(consumedSpace).to.be.equal(originalSpace);
       }
     }));
modifiedtests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth
353 : collection.mintToken(alice)353 : collection.mintToken(alice)
354 );354 );
355
356 const getConsumedSpace = async () => {
357 const props = (await helper.getApi().query[testCase.storage].tokenProperties(token.collectionId, token.tokenId)).toJSON();
358
359 return (props! as any).consumedSpace;
360 };
361355
362 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);356 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
363 const originalSpace = await getConsumedSpace();357 const originalSpace = await token.getTokenPropertiesConsumedSpace();
364 expect(originalSpace).to.be.equal(propDataSize);358 expect(originalSpace).to.be.equal(propDataSize);
365359
366 const sameSizePropertiesPossibleNum = maxTokenPropertiesSize / propDataSize;360 const sameSizePropertiesPossibleNum = maxTokenPropertiesSize / propDataSize;
369 // It will not consume any additional space.363 // It will not consume any additional space.
370 for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {364 for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
371 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);365 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
372 const consumedSpace = await getConsumedSpace();366 const consumedSpace = await token.getTokenPropertiesConsumedSpace();
373 expect(consumedSpace).to.be.equal(originalSpace);367 expect(consumedSpace).to.be.equal(originalSpace);
374 }368 }
375 }));369 }));
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1100,6 +1100,13 @@
     return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();
   }
 
+  async getPropertiesConsumedSpace(collectionId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.common.collectionProperties(collectionId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async getCollectionOptions(collectionId: number) {
     return (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();
   }
@@ -3035,6 +3042,10 @@
     return await this.helper.collection.getProperties(this.collectionId, propertyKeys);
   }
 
+  async getPropertiesConsumedSpace() {
+    return await this.helper.collection.getPropertiesConsumedSpace(this.collectionId);
+  }
+
   async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {
     return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);
   }
@@ -3158,6 +3169,13 @@
     return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.nonfungible.tokenProperties(this.collectionId, tokenId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId) {
     return await this.helper.nft.transferToken(signer, this.collectionId, tokenId, addressObj);
   }
@@ -3269,6 +3287,13 @@
     return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.refungible.tokenProperties(this.collectionId, tokenId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {
     return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);
   }
@@ -3421,6 +3446,10 @@
     return await this.collection.getTokenProperties(this.tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace() {
+    return await this.collection.getTokenPropertiesConsumedSpace(this.tokenId);
+  }
+
   async setProperties(signer: TSigner, properties: IProperty[]) {
     return await this.collection.setTokenProperties(signer, this.tokenId, properties);
   }