1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';1920describe('Composite nesting tests', () => {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([50n, 10n], donor);28 });29 });3031 itSub('Checks token children e2e', async ({helper}) => {32 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const collectionB = await helper.ft.mintCollection(alice);34 const collectionC = await helper.rft.mintCollection(alice);3536 const targetToken = await collectionA.mintToken(alice);37 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');3839 40 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());41 expect(await targetToken.getChildren()).to.have.deep.members([42 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},43 ]).and.has.length(1);4445 46 const tokenB = await collectionA.mintToken(alice);47 await tokenB.nest(alice, targetToken);48 expect(await targetToken.getChildren()).to.have.deep.members([49 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},50 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},51 ]).and.has.length(2);5253 54 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});55 expect(await targetToken.getChildren()).to.have.deep.members([56 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},57 ]).and.has.length(1);5859 60 await collectionB.mint(alice, 10n);61 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);62 expect(await targetToken.getChildren()).to.have.deep.members([63 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},64 {tokenId: 0, collectionId: collectionB.collectionId},65 ]).and.has.length(2);6667 68 const tokenC = await collectionC.mintToken(alice, 10n);69 await tokenC.transfer(alice, targetToken.nestingAccount(), 2n);70 expect(await targetToken.getChildren()).to.have.deep.members([71 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},72 {tokenId: 0, collectionId: collectionB.collectionId},73 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},74 ]).and.has.length(3);7576 77 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);78 expect(await targetToken.getChildren()).to.have.deep.members([79 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},80 {tokenId: 0, collectionId: collectionB.collectionId},81 ])82 .and.has.length(2);8384 85 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);86 expect(await targetToken.getChildren()).to.be.have.deep.members([87 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},88 {tokenId: 0, collectionId: collectionB.collectionId},89 ]).and.has.length(2);90 91 expect(await tokenA.getChildren()).to.have.deep.members([92 {tokenId: 0, collectionId: collectionB.collectionId},93 ]).and.has.length(1);9495 96 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);97 expect(await targetToken.getChildren()).to.have.deep.members([98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},99 ]).and.has.length(1);100 expect(await tokenA.getChildren()).to.have.deep.members([101 {tokenId: 0, collectionId: collectionB.collectionId},102 ]).and.has.length(1);103 });104105 106 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {107 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});108 const targetToken = await collection.mintToken(alice);109110 111 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());112 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});113 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());114115 116 const newToken = await collection.mintToken(alice);117118 119 await newToken.nest(alice, targetToken);120 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});121 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());122123 124 await targetToken.transfer(alice, {Substrate: bob.address});125 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});126 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());127 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});128 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());129130 131 await newToken.unnest(bob, targetToken, {Substrate: bob.address});132 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});133 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});134 });135});