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({url: import.meta.url});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 {mode: 'ft' as const},56 {mode: 'native ft' as const},57 ].map(md => [58 {mode: md.mode, restrictedMode: true},59 {mode: md.mode, restrictedMode: false},60 ].map(testCase => {61 itSub(`Fungible: disallows a non-Owner to unnest someone else's token [${testCase.mode}${testCase.restrictedMode ? ' (Restricted nesting)' : ''}]`, async ({helper}) => {62 const collectionNFT = await helper.nft.mintCollection(alice);63 const collectionFT = await (64 testCase.mode === 'ft'65 ? helper.ft.mintCollection(alice)66 : helper.ft.getCollectionObject(0)67 );68 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});6970 await collectionNFT.setPermissions(alice, {nesting: {71 collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,72 }});7374 75 await (76 testCase.mode === 'ft'77 ? collectionFT.mint(alice, 5n, targetToken.nestingAccount())78 : collectionFT.transfer(alice, targetToken.nestingAccount(), 5n)79 );8081 82 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))83 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);84 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);85 });86 }));87});