git.delta.rocks / unique-network / refs/commits / a663cc9dac43

difftreelog

source

tests/src/sub/nesting/e2e.test.ts6.5 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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({url: import.meta.url});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    // Create a nested NFT token40    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    // Create then nest46    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    // Move token B to a different user outside the nesting tree54    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    // Create a fungible token in another collection and then nest60    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    // Create a refungible token in another collection and then nest68    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    // Burn all nested pieces77    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    // Move part of the fungible token inside token A deeper in the nesting tree85    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    // Nested token also has children now:91    expect(await tokenA.getChildren()).to.have.deep.members([92      {tokenId: 0, collectionId: collectionB.collectionId},93    ]).and.has.length(1);9495    // Move the remaining part of the fungible token inside token A deeper in the nesting tree96    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  /// TODO review this test106  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    // Create an immediately nested token111    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    // Create a token to be nested116    const newToken = await collection.mintToken(alice);117118    // Nest119    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    // Move bundle to different user124    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    // Unnest131    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});