1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '@unique/test-utils/util.js';19import {CrossAccountId} from '@unique-nft/playgrounds/unique.js';2021describe('Negative Test: Unnesting', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({url: import.meta.url});28 [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);29 });30 });3132 33 itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});35 36 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});37 await collection.addToAllowList(alice, {Substrate: bob.address});38 await collection.addToAllowList(alice, targetToken.nestingAccount());3940 41 const newToken = await collection.mintToken(bob);42 await expect(newToken.nest(alice, targetToken))43 .to.be.rejectedWith(/common\.NoPermission/);4445 46 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());47 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))48 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);4950 expect(await targetToken.getChildren()).to.be.length(1);51 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});52 expect(await nestedToken.getOwner()).to.be.deep.equal(CrossAccountId.toLowerCase(targetToken.nestingAccount()));53 });5455 [56 {mode: 'ft' as const},57 {mode: 'native ft' as const},58 ].map(md => [59 {mode: md.mode, restrictedMode: true},60 {mode: md.mode, restrictedMode: false},61 ].map(testCase => {62 itSub(`Fungible: disallows a non-Owner to unnest someone else's token [${testCase.mode}${testCase.restrictedMode ? ' (Restricted nesting)' : ''}]`, async ({helper}) => {63 const collectionNFT = await helper.nft.mintCollection(alice);64 const collectionFT = await (65 testCase.mode === 'ft'66 ? helper.ft.mintCollection(alice)67 : helper.ft.getCollectionObject(0)68 );69 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});7071 await collectionNFT.setPermissions(alice, {nesting: {72 collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,73 }});7475 76 await (77 testCase.mode === 'ft'78 ? collectionFT.mint(alice, 5n, targetToken.nestingAccount())79 : collectionFT.transfer(alice, targetToken.nestingAccount(), 5n)80 );8182 83 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))84 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);85 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);86 });87 }));88});