difftreelog
test modifying a property with different sizes
in: master
2 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([100n, 10n], donor);28 [alice, bob] = await helper.arrange.createAccounts([200n, 10n], donor);29 });29 });30 });30 });31 31 138 {mode: 'nft' as const, requiredPallets: []},138 {mode: 'nft' as const, requiredPallets: []},139 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 139 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 140 ].map(testCase =>140 ].map(testCase =>141 itSub.ifWithPallets(`Allows modifying a collection property multiple times (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {141 itSub.ifWithPallets(`Allows modifying a collection property multiple times with the same size (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {142 const propKey = 'tok-prop';142 const propKey = 'tok-prop';143143144 const collection = await helper[testCase.mode].mintCollection(alice);144 const collection = await helper[testCase.mode].mintCollection(alice);192 expect(consumedSpace).to.be.equal(originalSpace);192 expect(consumedSpace).to.be.equal(originalSpace);193 }));193 }));194195 [196 // TODO enable properties for FT collection in Substrate (release 040)197 // {mode: 'ft' as const, requiredPallets: []},198 {mode: 'nft' as const, requiredPallets: []},199 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 200 ].map(testCase =>201 itSub.ifWithPallets(`Modifying a collection property with different size correctly changes the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {202 const propKey = 'tok-prop';203204 const collection = await helper[testCase.mode].mintCollection(alice);205 const originalSpace = await collection.getPropertiesConsumedSpace();206207 const initPropDataSize = 4096;208 const biggerPropDataSize = 5000;209 const smallerPropDataSize = 4000;210211 const initPropData = 'a'.repeat(initPropDataSize);212 const biggerPropData = 'b'.repeat(biggerPropDataSize);213 const smallerPropData = 'b'.repeat(smallerPropDataSize);214215 let consumedSpace;216 let expectedConsumedSpaceDiff;217218 await collection.setProperties(alice, [{key: propKey, value: initPropData}]);219 consumedSpace = await collection.getPropertiesConsumedSpace();220 expectedConsumedSpaceDiff = initPropDataSize - originalSpace;221 expect(consumedSpace).to.be.equal(originalSpace + expectedConsumedSpaceDiff);222223 await collection.setProperties(alice, [{key: propKey, value: biggerPropData}]);224 consumedSpace = await collection.getPropertiesConsumedSpace();225 expectedConsumedSpaceDiff = biggerPropDataSize - initPropDataSize;226 expect(consumedSpace).to.be.equal(initPropDataSize + expectedConsumedSpaceDiff);227228 await collection.setProperties(alice, [{key: propKey, value: smallerPropData}]);229 consumedSpace = await collection.getPropertiesConsumedSpace();230 expectedConsumedSpaceDiff = biggerPropDataSize - smallerPropDataSize;231 expect(consumedSpace).to.be.equal(biggerPropDataSize - expectedConsumedSpaceDiff);232 }));194});233});195 234 196describe('Negative Integration Test: Collection Properties', () => {235describe('Negative Integration Test: Collection Properties', () => {tests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth435 expect(recomputedSpace).to.be.equal(originalSpace);435 expect(recomputedSpace).to.be.equal(originalSpace);436 }));436 }));437438 [439 {mode: 'nft' as const, pieces: undefined, requiredPallets: []},440 {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 441 ].map(testCase =>442 itSub.ifWithPallets(`Modifying a token property with different size correctly changes the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {443 const propKey = 'tok-prop';444445 const collection = await helper[testCase.mode].mintCollection(alice, {446 tokenPropertyPermissions: [447 {448 key: propKey,449 permission: {mutable: true, tokenOwner: true},450 },451 ],452 });453 const token = await (454 testCase.pieces455 ? collection.mintToken(alice, testCase.pieces)456 : collection.mintToken(alice)457 );458 const originalSpace = await token.getTokenPropertiesConsumedSpace();459460 const initPropDataSize = 4096;461 const biggerPropDataSize = 5000;462 const smallerPropDataSize = 4000;463464 const initPropData = 'a'.repeat(initPropDataSize);465 const biggerPropData = 'b'.repeat(biggerPropDataSize);466 const smallerPropData = 'b'.repeat(smallerPropDataSize);467468 let consumedSpace;469 let expectedConsumedSpaceDiff;470471 await token.setProperties(alice, [{key: propKey, value: initPropData}]);472 consumedSpace = await token.getTokenPropertiesConsumedSpace();473 expectedConsumedSpaceDiff = initPropDataSize - originalSpace;474 expect(consumedSpace).to.be.equal(originalSpace + expectedConsumedSpaceDiff);475476 await token.setProperties(alice, [{key: propKey, value: biggerPropData}]);477 consumedSpace = await token.getTokenPropertiesConsumedSpace();478 expectedConsumedSpaceDiff = biggerPropDataSize - initPropDataSize;479 expect(consumedSpace).to.be.equal(initPropDataSize + expectedConsumedSpaceDiff);480481 await token.setProperties(alice, [{key: propKey, value: smallerPropData}]);482 consumedSpace = await token.getTokenPropertiesConsumedSpace();483 expectedConsumedSpaceDiff = biggerPropDataSize - smallerPropDataSize;484 expect(consumedSpace).to.be.equal(biggerPropDataSize - expectedConsumedSpaceDiff);485 }));437});486});438487439describe('Negative Integration Test: Token Properties', () => {488describe('Negative Integration Test: Token Properties', () => {