difftreelog
test multiple modified of token properties / minor fixes
in: master
1 file changed
tests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth321 expect(await targetToken.getProperties()).to.be.empty;321 expect(await targetToken.getProperties()).to.be.empty;322 });322 });323324 [325 {mode: 'nft' as const, storage: 'nonfungible' as const, pieces: undefined, requiredPallets: []},326 {mode: 'rft' as const, storage: 'refungible' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 327 ].map(testCase =>328 itSub.ifWithPallets(`Allows modifying a token property multiple times (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {329 const propKey = 'tok-prop';330331 const collection = await helper[testCase.mode].mintCollection(alice, {332 tokenPropertyPermissions: [333 {334 key: propKey,335 permission: {mutable: true, tokenOwner: true},336 },337 ],338 });339340 const maxTokenPropertiesSize = 32768;341342 const propDataSize = 4096;343344 let propDataChar = 'a';345 const makeNewPropData = () => {346 propDataChar = String.fromCharCode(propDataChar.charCodeAt(0) + 1);347 return `${propDataChar}`.repeat(propDataSize);348 };349350 const token = await (351 testCase.pieces352 ? collection.mintToken(alice, testCase.pieces)353 : collection.mintToken(alice)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 };361362 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);363 const originalSpace = await getConsumedSpace();364 expect(originalSpace).to.be.equal(propDataSize);365366 const sameSizePropertiesPossibleNum = maxTokenPropertiesSize / propDataSize;367368 // It is possible to modify a property as many times as needed.369 // It will not consume any additional space.370 for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {371 await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);372 const consumedSpace = await getConsumedSpace();373 expect(consumedSpace).to.be.equal(originalSpace);374 }375 }));323});376});324377325describe('Negative Integration Test: Token Properties', () => {378describe('Negative Integration Test: Token Properties', () => {476 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, amount);529 await testForbidsAddingPropertiesIfPropertyNotDeclared(token, amount);477 });530 });478531479 async function testForbidsAddingTooManyProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {532 async function testForbidsAddingTooLargeProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {480 const originalSpace = await prepare(token, pieces);533 const originalSpace = await prepare(token, pieces);481534482 await expect(535 await expect(504 expect(consumedSpace).to.be.equal(originalSpace);557 expect(consumedSpace).to.be.equal(originalSpace);505 }558 }506559507 itSub('Forbids adding too many properties to a token (NFT)', async ({helper}) => {560 itSub('Forbids adding too large properties to a token (NFT)', async ({helper}) => {508 const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'NFT');561 const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'NFT');509 await testForbidsAddingTooManyProperties(token, amount);562 await testForbidsAddingTooLargeProperties(token, amount);510 });563 });511564512 itSub.ifWithPallets('Forbids adding too many properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {565 itSub.ifWithPallets('Forbids adding too large properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {513 const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'RFT');566 const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'RFT');514 await testForbidsAddingTooManyProperties(token, amount);567 await testForbidsAddingTooLargeProperties(token, amount);515 });568 });569570 [571 {mode: 'nft' as const, requiredPallets: []},572 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 573 ].map(testCase =>574 itSub.ifWithPallets(`Forbids adding too many propeties to a token (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {575 const collection = await helper[testCase.mode].mintCollection(alice);576 const maxPropertiesPerItem = 64;577578 for (let i = 0; i < maxPropertiesPerItem; i++) {579 await collection.setTokenPropertyPermissions(alice, [{580 key: `${i+1}`,581 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},582 }]);583 }584585 await expect(collection.setTokenPropertyPermissions(alice, [{586 key: `${maxPropertiesPerItem}-th`,587 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},588 }])).to.be.rejectedWith(/common\.PropertyLimitReached/);589 }));516});590});517591518describe('ReFungible token properties permissions tests', () => {592describe('ReFungible token properties permissions tests', () => {