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
25 before(async () => {25 before(async () => {
26 await usingPlaygrounds(async (helper, privateKey) => {26 await usingPlaygrounds(async (helper, privateKey) => {
27 const donor = await privateKey({filename: __filename});27 const donor = await privateKey({filename: __filename});
28 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
29 });29 });
30 });30 });
31 31
151 return `${propDataChar}`.repeat(propDataSize);151 return `${propDataChar}`.repeat(propDataSize);
152 };152 };
153
154 const getConsumedSpace = async () => {
155 const props = (await helper.getApi().query.common.collectionProperties(collection.collectionId)).toJSON();
156
157 return (props! as any).consumedSpace;
158 };
159153
160 await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);154 await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
161 const originalSpace = await getConsumedSpace();155 const originalSpace = await collection.getPropertiesConsumedSpace();
162 expect(originalSpace).to.be.equal(propDataSize);156 expect(originalSpace).to.be.equal(propDataSize);
163157
164 const sameSizePropertiesPossibleNum = maxCollectionPropertiesSize / propDataSize;158 const sameSizePropertiesPossibleNum = maxCollectionPropertiesSize / propDataSize;
167 // It will not consume any additional space.161 // It will not consume any additional space.
168 for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {162 for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
169 await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);163 await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
170 const consumedSpace = await getConsumedSpace();164 const consumedSpace = await collection.getPropertiesConsumedSpace();
171 expect(consumedSpace).to.be.equal(originalSpace);165 expect(consumedSpace).to.be.equal(originalSpace);
172 }166 }
173 }));167 }));
modifiedtests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/tokenProperties.test.ts
+++ b/tests/src/nesting/tokenProperties.test.ts
@@ -353,14 +353,8 @@
           : collection.mintToken(alice)
       );
 
-      const getConsumedSpace = async () => {
-        const props = (await helper.getApi().query[testCase.storage].tokenProperties(token.collectionId, token.tokenId)).toJSON();
-        
-        return (props! as any).consumedSpace;
-      };
-
       await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
-      const originalSpace = await getConsumedSpace();
+      const originalSpace = await token.getTokenPropertiesConsumedSpace();
       expect(originalSpace).to.be.equal(propDataSize);
 
       const sameSizePropertiesPossibleNum = maxTokenPropertiesSize / propDataSize;
@@ -369,7 +363,7 @@
       // It will not consume any additional space.
       for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
         await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
-        const consumedSpace = await getConsumedSpace();
+        const consumedSpace = await token.getTokenPropertiesConsumedSpace();
         expect(consumedSpace).to.be.equal(originalSpace);
       }
     }));
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);
   }