1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';1920describe('Integration Test: Unnesting', () => {21 let alice: IKeyringPair;2223 before(async () => {24 await usingPlaygrounds(async (helper, privateKey) => {25 const donor = await privateKey({filename: __filename});26 [alice] = await helper.arrange.createAccounts([50n], donor);27 });28 });2930 itSub('NFT: allows the owner to successfully unnest a token', async ({helper}) => {31 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});32 const targetToken = await collection.mintToken(alice);3334 35 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());3637 38 await expect(nestedToken.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}), 'while unnesting').to.be.fulfilled;39 expect(await nestedToken.getOwner()).to.be.deep.equal({Substrate: alice.address});4041 42 await nestedToken.nest(alice, targetToken);43 await expect(nestedToken.burnFrom(alice, targetToken.nestingAccount()), 'while burning').to.be.fulfilled;44 await expect(nestedToken.getOwner()).to.be.rejected;45 });4647 itSub('Fungible: allows the owner to successfully unnest a token', async ({helper}) => {48 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});49 const targetToken = await collection.mintToken(alice);5051 const collectionFT = await helper.ft.mintCollection(alice);5253 54 await collectionFT.mint(alice, 10n, targetToken.nestingAccount());55 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;56 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(9n);57 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(1n);5859 60 await collectionFT.transfer(alice, targetToken.nestingAccount(), 5n);61 await expect(collectionFT.burnTokensFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;62 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(4n);63 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);64 expect(await targetToken.getChildren()).to.be.length(0);65 });66});6768describe('Negative Test: Unnesting', () => {69 let alice: IKeyringPair;70 let bob: IKeyringPair;7172 before(async () => {73 await usingPlaygrounds(async (helper, privateKey) => {74 const donor = await privateKey({filename: __filename});75 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);76 });77 });7879 itSub('Disallows a non-owner to unnest/burn a token', async ({helper}) => {80 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});81 const targetToken = await collection.mintToken(alice);8283 84 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());8586 87 await expect(nestedToken.unnest(bob, targetToken, {Substrate: alice.address})).to.be.rejectedWith(/common\.ApprovedValueTooLow/);88 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());8990 91 await expect(nestedToken.burnFrom(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);92 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());93 });9495 9697 98 itSub('Prevents Ouroboros creation', async ({helper}) => {99 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});100 const targetToken = await collection.mintToken(alice);101102 103 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());104 await expect(targetToken.nest(alice, nestedToken)).to.be.rejectedWith(/^structure\.OuroborosDetected$/);105 });106});