From f780ed94ecfd7f414c8006a87699824e801e121e Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 14 Dec 2022 13:40:50 +0000 Subject: [PATCH] fix: add consumedSpace fns to playgrnds --- --- 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); } })); --- 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); } })); --- 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 { + 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 { + 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 { + 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); } -- gitstuff