difftreelog
test(structure) extra nesting + properties refactoring
in: master
7 files changed
tests/src/createItem.test.tsdiffbeforeafterboth144144145 it('User doesnt have editing rights', async () => {145 it('User doesnt have editing rights', async () => {146 await usingApi(async api => {146 await usingApi(async api => {147 const createMode = 'NFT';148 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});147 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});149 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');148 const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');150149tests/src/createMultipleItems.test.tsdiffbeforeafterboth146 const itemsListIndexBefore = await getLastTokenId(api, collectionId);146 const itemsListIndexBefore = await getLastTokenId(api, collectionId);147 expect(itemsListIndexBefore).to.be.equal(0);147 expect(itemsListIndexBefore).to.be.equal(0);148 const alice = privateKey('//Alice');148 const alice = privateKey('//Alice');149 const bob = privateKey('//Bob');150 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},149 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},151 {Nft: {const_data: '0x32', variable_data: '0x32'}},150 {Nft: {const_data: '0x32', variable_data: '0x32'}},152 {Nft: {const_data: '0x33', variable_data: '0x33'}}];151 {Nft: {const_data: '0x33', variable_data: '0x33'}}];182 const itemsListIndexBefore = await getLastTokenId(api, collectionId);181 const itemsListIndexBefore = await getLastTokenId(api, collectionId);183 expect(itemsListIndexBefore).to.be.equal(0);182 expect(itemsListIndexBefore).to.be.equal(0);184 const alice = privateKey('//Alice');183 const alice = privateKey('//Alice');185 const bob = privateKey('//Bob');186 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},184 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},187 {Nft: {const_data: '0x32', variable_data: '0x32'}},185 {Nft: {const_data: '0x32', variable_data: '0x32'}},188 {Nft: {const_data: '0x33', variable_data: '0x33'}}];186 {Nft: {const_data: '0x33', variable_data: '0x33'}}];218 const itemsListIndexBefore = await getLastTokenId(api, collectionId);216 const itemsListIndexBefore = await getLastTokenId(api, collectionId);219 expect(itemsListIndexBefore).to.be.equal(0);217 expect(itemsListIndexBefore).to.be.equal(0);220 const alice = privateKey('//Alice');218 const alice = privateKey('//Alice');221 const bob = privateKey('//Bob');222 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},219 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},223 {Nft: {const_data: '0x32', variable_data: '0x32'}},220 {Nft: {const_data: '0x32', variable_data: '0x32'}},224 {Nft: {const_data: '0x33', variable_data: '0x33'}}];221 {Nft: {const_data: '0x33', variable_data: '0x33'}}];tests/src/nesting/migration-check.test.tsdiffbeforeafterboth8// Used for polkadot-launch signalling8// Used for polkadot-launch signalling9import find from 'find-process';9import find from 'find-process';101011// todo skip11// todo un-skip for migrations12describe('Migration testing for pallet-common', () => {12describe.skip('Migration testing for pallet-common', () => {13 let alice: IKeyringPair;13 let alice: IKeyringPair;141415 before(async() => {15 before(async() => {63 });63 });646465 // And wait for the parachain upgrade65 // And wait for the parachain upgrade66 {67 // Catch warnings like 'RPC methods not decorated' and keep the 'waiting' message in front68 const stdlog = console.warn.bind(console);69 let warnCount = 0;70 console.warn = function(...args){71 if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {72 warnCount++;73 stdlog.apply(console, args as any);74 }75 };7677 let oldWarnCount = 0;66 while (newVersion == oldVersion! && connectionFailCounter < 2) {78 while (newVersion == oldVersion! && connectionFailCounter < 2) {67 try {79 try {68 await usingApi(async api => {80 await usingApi(async api => {69 await waitNewBlocks(api);81 await waitNewBlocks(api);70 newVersion = (api.consts.system.version.toJSON() as any).specVersion;82 newVersion = (api.consts.system.version.toJSON() as any).specVersion;83 if (warnCount > oldWarnCount) {84 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);85 oldWarnCount = warnCount;86 }87 await new Promise(resolve => setTimeout(resolve, 6000));71 });88 });72 } catch (_) {89 } catch (_) {73 connectionFailCounter++;90 connectionFailCounter++;74 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);75 await new Promise(resolve => setTimeout(resolve, 12000));91 await new Promise(resolve => setTimeout(resolve, 12000));76 }92 }77 }93 }94 }789579 await usingApi(async api => {96 await usingApi(async api => {80 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;97 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;tests/src/nesting/nest.test.tsdiffbeforeafterboth9 enableAllowListExpectSuccess,9 enableAllowListExpectSuccess,10 enablePublicMintingExpectSuccess,10 enablePublicMintingExpectSuccess,11 getTokenOwner, 11 getTokenOwner, 12 getTopmostTokenOwner, 12 getTopmostTokenOwner,13 normalizeAccountId, 14 setCollectionLimitsExpectSuccess, 13 setCollectionLimitsExpectSuccess, 15 transferExpectFailure, 14 transferExpectFailure, 16 transferExpectSuccess, 15 transferExpectSuccess, 232224describe('Integration Test: Nesting', () => {23describe('Integration Test: Nesting', () => {25 before(async () => {24 before(async () => {26 await usingApi(async api => {25 await usingApi(async () => {27 alice = privateKey('//Alice');26 alice = privateKey('//Alice');28 bob = privateKey('//Bob');27 bob = privateKey('//Bob');29 });28 });196195197describe('Negative Test: Nesting', async() => {196describe('Negative Test: Nesting', async() => {198 before(async () => {197 before(async () => {199 await usingApi(async api => {198 await usingApi(async () => {200 alice = privateKey('//Alice');199 alice = privateKey('//Alice');201 bob = privateKey('//Bob');200 bob = privateKey('//Bob');202 });201 });212 const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});211 const nestedToken1 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});213 const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});212 const nestedToken2 = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, nestedToken1)});214 // The nesting depth is limited by 2213 // The nesting depth is limited by 2215 await expect(executeTransaction(214 await expect(executeTransaction(api, alice, api.tx.unique.createItem(216 api, alice, 217 api.tx.unique.createItem(218 collection, 215 collection, 219 {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 216 {Ethereum: tokenIdToAddress(collection, nestedToken2)}, 220 {nft: {const_data: [], variable_data: []}} as any,217 {nft: {const_data: [], variable_data: []}} as any,221 ),218 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);222 ), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/); // OuroborosDetected?223219224 expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});220 expect(await getTopmostTokenOwner(api, collection, nestedToken2)).to.be.deep.equal({Substrate: alice.address});225 });221 });234 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');230 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');235231236 // Try to create a nested token232 // Try to create a nested token237 await expect(executeTransaction(233 await expect(executeTransaction(api, alice, api.tx.unique.createItem(238 api, alice, 239 api.tx.unique.createItem(240 collection, 234 collection, 241 {Ethereum: tokenIdToAddress(collection, targetToken)}, 235 {Ethereum: tokenIdToAddress(collection, targetToken)}, 242 {nft: {const_data: [], variable_data: []}} as any,236 {nft: {const_data: [], variable_data: []}} as any,243 ),237 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);244 ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);245238246 // Create a token to be nested239 // Create a token to be nested247 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');240 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');248 // Try to nest241 // Try to nest249 await expect(executeTransaction(242 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);250 api, alice, 251 api.tx.unique.transfer(252 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,253 ),254 ), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/); // todo to.be.rejected for all255 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});243 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});256 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});244 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});257 });245 });270 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');258 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');271259272 // Try to create a nested token in the wrong collection260 // Try to create a nested token in the wrong collection273 await expect(executeTransaction(261 await expect(executeTransaction(api, alice, api.tx.unique.createItem(274 api, alice, 275 api.tx.unique.createItem(276 collection, 262 collection, 277 {Ethereum: tokenIdToAddress(collection, targetToken)}, 263 {Ethereum: tokenIdToAddress(collection, targetToken)}, 278 {nft: {const_data: [], variable_data: []}} as any,264 {nft: {const_data: [], variable_data: []}} as any,279 ),265 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);280 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/); // todo NestingIsDisabled?281266282 // Try to create and nest a token in the wrong collection267 // Try to create and nest a token in the wrong collection283 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');268 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');284 await expect(executeTransaction(269 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);285 api, alice, 286 api.tx.unique.transfer(287 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,288 ),289 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);290 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});270 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});291 });271 });292 });272 });304 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');284 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');305285306 // Try to create a nested token in the wrong collection286 // Try to create a nested token in the wrong collection307 await expect(executeTransaction(287 await expect(executeTransaction(api, alice, api.tx.unique.createItem(308 api, alice, 309 api.tx.unique.createItem(310 collection, 288 collection, 311 {Ethereum: tokenIdToAddress(collection, targetToken)}, 289 {Ethereum: tokenIdToAddress(collection, targetToken)}, 312 {nft: {const_data: [], variable_data: []}} as any,290 {nft: {const_data: [], variable_data: []}} as any,313 ),291 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);314 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);315292316 // Try to create and nest a token in the wrong collection293 // Try to create and nest a token in the wrong collection317 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');294 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');318 await expect(executeTransaction(295 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);319 api, alice, 320 api.tx.unique.transfer(321 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,322 ),323 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);324 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});296 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});325 });297 });326 });298 });334 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');306 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');335307336 // Try to create a nested token in the wrong collection308 // Try to create a nested token in the wrong collection337 await expect(executeTransaction(309 await expect(executeTransaction(api, alice, api.tx.unique.createItem(338 api, alice, 339 api.tx.unique.createItem(340 collection, 310 collection, 341 {Ethereum: tokenIdToAddress(collection, targetToken)}, 311 {Ethereum: tokenIdToAddress(collection, targetToken)}, 342 {nft: {const_data: [], variable_data: []}} as any,312 {nft: {const_data: [], variable_data: []}} as any,343 ),313 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);344 ), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);345314346 // Try to create and nest a token in the wrong collection315 // Try to create and nest a token in the wrong collection347 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');316 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');348 await expect(executeTransaction(317 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);349 api, alice, 350 api.tx.unique.transfer(351 normalizeAccountId({Ethereum: tokenIdToAddress(collection, targetToken)}), collection, newToken, 1,352 ),353 ), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);354 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});318 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});355 });319 });356 });320 });367 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});331 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});368332369 // Try to create a nested token333 // Try to create a nested token370 await expect(executeTransaction(334 await expect(executeTransaction(api, alice, api.tx.unique.createItem(371 api, alice, 372 api.tx.unique.createItem(373 collectionFT, 335 collectionFT, 374 targetAddress, 336 targetAddress, 375 {Fungible: {Value: 10}},337 {Fungible: {Value: 10}},376 )338 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);377 ), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);339 378379 // Create a token to be nested340 // Create a token to be nested380 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');341 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');381 // Try to nest342 // Try to nest382 await expect(executeTransaction(343 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);383 api, alice, 344384 api.tx.unique.transfer(345 // Create another token to be nested385 normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,346 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');347 // Try to nest inside a fungible token386 ),348 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);387 ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);388 });349 });389 });350 });390351404 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});365 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});405366406 // Try to create a nested token in the wrong collection367 // Try to create a nested token in the wrong collection407 await expect(executeTransaction(368 await expect(executeTransaction(api, alice, api.tx.unique.createItem(408 api, alice, 409 api.tx.unique.createItem(410 collectionFT, 369 collectionFT, 411 targetAddress, 370 targetAddress, 412 {Fungible: {Value: 10}},371 {Fungible: {Value: 10}},413 )372 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);414 ), 'while creating nested token').to.be.rejectedWith(/structure\.DepthLimit/);415373416 // Try to create and nest a token in the wrong collection374 // Try to create and nest a token in the wrong collection417 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');375 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');418 await expect(executeTransaction(376 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);419 api, alice, 420 api.tx.unique.transfer(421 normalizeAccountId({Ethereum: tokenIdToAddress(collectionFT, targetToken)}), collectionFT, newToken, 1,422 ),423 ), 'while nesting new token').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);424 });377 });425 });378 });426379427 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {380 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {428 await usingApi(async api => {381 await usingApi(async api => {429 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});382 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});430 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions?431432 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);383 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);433 await enableAllowListExpectSuccess(alice, collectionNFT);384 await enableAllowListExpectSuccess(alice, collectionNFT);434 await enablePublicMintingExpectSuccess(alice, collectionNFT);385 await enablePublicMintingExpectSuccess(alice, collectionNFT);438 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};389 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};439390440 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});391 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});392 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});441393442 // Try to create a nested token in the wrong collection394 // Try to create a nested token in the wrong collection443 await expect(executeTransaction(api, alice, api.tx.unique.createItem(395 await expect(executeTransaction(api, alice, api.tx.unique.createItem(444 collectionFT, 396 collectionFT, 445 targetAddress, 397 targetAddress, 446 {Fungible: {Value: 10}},398 {Fungible: {Value: 10}},447 ))).to.be.rejected;399 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);448400449 // Try to create and nest a token in the wrong collection401 // Try to create and nest a token in the wrong collection450 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');402 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');451 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);403 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);452 });404 });453 });405 });454406468 collectionFT, 420 collectionFT, 469 targetAddress, 421 targetAddress, 470 {Fungible: {Value: 10}},422 {Fungible: {Value: 10}},471 ))).to.be.rejected;423 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);472424473 // Try to create and nest a token in the wrong collection425 // Try to create and nest a token in the wrong collection474 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');426 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');475 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);427 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);476 });428 });477 });429 });478430492 collectionRFT, 444 collectionRFT, 493 targetAddress, 445 targetAddress, 494 {ReFungible: {const_data: [], pieces: 100}},446 {ReFungible: {const_data: [], pieces: 100}},495 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);447 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);496448497 // Create a token to be nested449 // Create a token to be nested498 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');450 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');499 // Try to nest451 // Try to nest500 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);452 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);453 // Try to nest454 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);455456 // Create another token to be nested457 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');458 // Try to nest inside a fungible token459 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);501 });460 });502 });461 });503462521 collectionRFT, 480 collectionRFT, 522 targetAddress, 481 targetAddress, 523 {ReFungible: {const_data: [], pieces: 100}},482 {ReFungible: {const_data: [], pieces: 100}},524 ))).to.be.rejected;483 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);525484526 // Try to create and nest a token in the wrong collection485 // Try to create and nest a token in the wrong collection527 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');486 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');528 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);487 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);529 });488 });530 });489 });531490532 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {491 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {533 await usingApi(async api => {492 await usingApi(async api => {534 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});493 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});535 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});536537 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);494 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);538 await enableAllowListExpectSuccess(alice, collectionNFT);495 await enableAllowListExpectSuccess(alice, collectionNFT);539 await enablePublicMintingExpectSuccess(alice, collectionNFT);496 await enablePublicMintingExpectSuccess(alice, collectionNFT);543 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};500 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};544501545 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});502 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});503 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});546504547 // Try to create a nested token in the wrong collection505 // Try to create a nested token in the wrong collection548 await expect(executeTransaction(api, alice, api.tx.unique.createItem(506 await expect(executeTransaction(api, alice, api.tx.unique.createItem(549 collectionRFT, 507 collectionRFT, 550 targetAddress, 508 targetAddress, 551 {ReFungible: {const_data: [], pieces: 100}},509 {ReFungible: {const_data: [], pieces: 100}},552 ))).to.be.rejected;510 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);553511554 // Try to create and nest a token in the wrong collection512 // Try to create and nest a token in the wrong collection555 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');513 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');556 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);514 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);557 });515 });558 });516 });559517573 collectionRFT, 531 collectionRFT, 574 targetAddress, 532 targetAddress, 575 {ReFungible: {const_data: [], pieces: 100}},533 {ReFungible: {const_data: [], pieces: 100}},576 ))).to.be.rejected;534 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);577535578 // Try to create and nest a token in the wrong collection536 // Try to create and nest a token in the wrong collection579 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');537 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');580 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);538 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);581 });539 });582 });540 });583});541});tests/src/nesting/properties.test.tsdiffbeforeafterboth181819describe('Integration Test: Collection Properties', () => {19describe('Integration Test: Collection Properties', () => {20 before(async () => {20 before(async () => {21 await usingApi(async api => {21 await usingApi(async () => {22 alice = privateKey('//Alice');22 alice = privateKey('//Alice');23 bob = privateKey('//Bob');23 bob = privateKey('//Bob');24 });24 });113113114describe('Negative Integration Test: Collection Properties', () => {114describe('Negative Integration Test: Collection Properties', () => {115 before(async () => {115 before(async () => {116 await usingApi(async api => {116 await usingApi(async () => {117 alice = privateKey('//Alice');117 alice = privateKey('//Alice');118 bob = privateKey('//Bob');118 bob = privateKey('//Bob');119 });119 });213 api, 213 api, 214 alice, 214 alice, 215 api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]), 215 api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]), 216 ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);216 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);217217218 await expect(executeTransaction(218 await expect(executeTransaction(219 api, 219 api, 245245246describe('Integration Test: Access Rights to Token Properties', () => {246describe('Integration Test: Access Rights to Token Properties', () => {247 before(async () => {247 before(async () => {248 await usingApi(async api => {248 await usingApi(async () => {249 alice = privateKey('//Alice');249 alice = privateKey('//Alice');250 bob = privateKey('//Bob');250 bob = privateKey('//Bob');251 });251 });311311312describe('Negative Integration Test: Access Rights to Token Properties', () => {312describe('Negative Integration Test: Access Rights to Token Properties', () => {313 before(async () => {313 before(async () => {314 await usingApi(async api => {314 await usingApi(async () => {315 alice = privateKey('//Alice');315 alice = privateKey('//Alice');316 bob = privateKey('//Bob');316 bob = privateKey('//Bob');317 });317 });400 api, 400 api, 401 alice, 401 alice, 402 api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]), 402 api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]), 403 ), `on rejecting an unnamed property`).to.be.rejectedWith(/common\.EmptyPropertyKey/);403 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);404404405 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string405 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string406 await expect(executeTransaction(406 await expect(executeTransaction(429 let permissions: {permission: any, signers: IKeyringPair[]}[];429 let permissions: {permission: any, signers: IKeyringPair[]}[];430430431 before(async () => {431 before(async () => {432 await usingApi(async api => {432 await usingApi(async () => {433 alice = privateKey('//Alice');433 alice = privateKey('//Alice');434 bob = privateKey('//Bob');434 bob = privateKey('//Bob');435 charlie = privateKey('//Charlie');435 charlie = privateKey('//Charlie');445 });445 });446 });446 });447447448 beforeEach(async () => {448 beforeEach(async () => {449 await usingApi(async () => {449 collection = await createCollectionExpectSuccess();450 collection = await createCollectionExpectSuccess();450 token = await createItemExpectSuccess(alice, collection, 'NFT');451 token = await createItemExpectSuccess(alice, collection, 'NFT');451 await addCollectionAdminExpectSuccess(alice, collection, bob.address);452 await addCollectionAdminExpectSuccess(alice, collection, bob.address);452 await transferExpectSuccess(collection, token, alice, charlie);453 await transferExpectSuccess(collection, token, alice, charlie);453 });454 });454 455 });456 455 it('Reads yet empty properties of a token', async () => {457 it('Reads yet empty properties of a token', async () => {456 await usingApi(async api => {458 await usingApi(async api => {592 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];594 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];593595594 before(async () => {596 before(async () => {595 await usingApi(async api => {597 await usingApi(async () => {596 alice = privateKey('//Alice');598 alice = privateKey('//Alice');597 bob = privateKey('//Bob');599 bob = privateKey('//Bob');598 charlie = privateKey('//Charlie');600 charlie = privateKey('//Charlie');tests/src/nesting/unnest.test.tsdiffbeforeafterboth4import usingApi, {executeTransaction} from '../substrate/substrate-api';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {5import {6 createCollectionExpectSuccess,6 createCollectionExpectSuccess,7 createItemExpectFailure,8 createItemExpectSuccess,7 createItemExpectSuccess,9 getBalance,8 getBalance,10 getTokenOwner,9 getTokenOwner,11 getTopmostTokenOwner,12 normalizeAccountId,10 normalizeAccountId,13 setCollectionLimitsExpectSuccess,11 setCollectionLimitsExpectSuccess,14 transferExpectSuccess,12 transferExpectSuccess,211922describe('Integration Test: Unnesting', () => {20describe('Integration Test: Unnesting', () => {23 before(async () => {21 before(async () => {24 await usingApi(async api => {22 await usingApi(async () => {25 alice = privateKey('//Alice');23 alice = privateKey('//Alice');26 bob = privateKey('//Bob');24 bob = privateKey('//Bob');27 });25 });112110113describe('Negative Test: Unnesting', () => {111describe('Negative Test: Unnesting', () => {114 before(async () => {112 before(async () => {115 await usingApi(async api => {113 await usingApi(async () => {116 alice = privateKey('//Alice');114 alice = privateKey('//Alice');117 bob = privateKey('//Bob');115 bob = privateKey('//Bob');118 });116 });133 api,131 api,134 bob,132 bob,135 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),133 api.tx.unique.transferFrom(normalizeAccountId(targetAddress), normalizeAccountId(bob), collection, nestedToken, 1),136 ), 'while unnesting').to.be.rejectedWith(/^structure\.DepthLimit$/); // todo ApprovedValueTooLow?134 ), 'while unnesting').to.be.rejectedWith(/^common\.ApprovedValueTooLow$/);137 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});135 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});138136139 // Try to burn137 // Try to burntests/src/util/helpers.tsdiffbeforeafterboth427export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {427export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {428 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};428 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};429429430 const collectionId = 0;431 await usingApi(async (api) => {430 await usingApi(async (api) => {432 // Get number of collections before the transaction431 // Get number of collections before the transaction433 const collectionCountBefore = await getCreatedCollectionCount(api);432 const collectionCountBefore = await getCreatedCollectionCount(api);