1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';1920describe('Negative Test: Unnesting', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);28 });29 });3031 32 itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {33 const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});34 35 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});36 await collection.addToAllowList(alice, {Substrate: bob.address});37 await collection.addToAllowList(alice, targetToken.nestingAccount());3839 40 const newToken = await collection.mintToken(bob);41 await expect(newToken.nest(alice, targetToken))42 .to.be.rejectedWith(/common\.NoPermission/);4344 45 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());46 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))47 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);4849 expect(await targetToken.getChildren()).to.be.length(1);50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());52 });5354 [55 {restrictedMode: true},56 {restrictedMode: false},57 ].map(testCase => {58 itSub(`Fungible: disallows a non-Owner to unnest someone else's token ${testCase.restrictedMode ? '(Restricted nesting)' : ''}`, async ({helper}) => {59 const collectionNFT = await helper.nft.mintCollection(alice);60 const collectionFT = await helper.ft.mintCollection(alice);61 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});6263 await collectionNFT.setPermissions(alice, {nesting: {64 collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,65 }});6667 68 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());6970 71 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))72 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);73 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);74 });75 });76});