difftreelog
fix add consumedSpace fns to playgrnds
in: master
3 files changed
tests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth25 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 };153154 const getConsumedSpace = async () => {155 const props = (await helper.getApi().query.common.collectionProperties(collection.collectionId)).toJSON();156 157 return (props! as any).consumedSpace;158 };159153160 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);163157164 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 }));tests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth353 : collection.mintToken(alice)353 : collection.mintToken(alice)354 );354 );355356 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 };361355362 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);365359366 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 }));tests/src/util/playgrounds/unique.tsdiffbeforeafterboth1100 return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();1100 return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();1101 }1101 }11021103 async getPropertiesConsumedSpace(collectionId: number): Promise<number> {1104 const api = this.helper.getApi();1105 const props = (await api.query.common.collectionProperties(collectionId)).toJSON();1106 1107 return (props! as any).consumedSpace;1108 }110211091103 async getCollectionOptions(collectionId: number) {1110 async getCollectionOptions(collectionId: number) {1104 return (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();1111 return (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();3035 return await this.helper.collection.getProperties(this.collectionId, propertyKeys);3042 return await this.helper.collection.getProperties(this.collectionId, propertyKeys);3036 }3043 }30443045 async getPropertiesConsumedSpace() {3046 return await this.helper.collection.getPropertiesConsumedSpace(this.collectionId);3047 }303730483038 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {3049 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {3039 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);3050 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);3158 return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);3169 return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);3159 }3170 }31713172 async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {3173 const api = this.helper.getApi();3174 const props = (await api.query.nonfungible.tokenProperties(this.collectionId, tokenId)).toJSON();3175 3176 return (props! as any).consumedSpace;3177 }316031783161 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId) {3179 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId) {3162 return await this.helper.nft.transferToken(signer, this.collectionId, tokenId, addressObj);3180 return await this.helper.nft.transferToken(signer, this.collectionId, tokenId, addressObj);3269 return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);3287 return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);3270 }3288 }32893290 async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {3291 const api = this.helper.getApi();3292 const props = (await api.query.refungible.tokenProperties(this.collectionId, tokenId)).toJSON();3293 3294 return (props! as any).consumedSpace;3295 }327132963272 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {3297 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {3273 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);3298 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);3421 return await this.collection.getTokenProperties(this.tokenId, propertyKeys);3446 return await this.collection.getTokenProperties(this.tokenId, propertyKeys);3422 }3447 }34483449 async getTokenPropertiesConsumedSpace() {3450 return await this.collection.getTokenPropertiesConsumedSpace(this.tokenId);3451 }342334523424 async setProperties(signer: TSigner, properties: IProperty[]) {3453 async setProperties(signer: TSigner, properties: IProperty[]) {3425 return await this.collection.setTokenProperties(signer, this.tokenId, properties);3454 return await this.collection.setTokenProperties(signer, this.tokenId, properties);