git.delta.rocks / unique-network / refs/commits / 2df3f6b6e145

difftreelog

source

tests/src/sub/nesting/e2e.test.ts7.0 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);35    const collectionNative = helper.ft.getCollectionObject(0);3637    const targetToken = await collectionA.mintToken(alice);38    expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');3940    // Create a nested NFT token41    const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());42    expect(await targetToken.getChildren()).to.have.deep.members([43      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},44    ]).and.has.length(1);4546    // Create then nest47    const tokenB = await collectionA.mintToken(alice);48    await tokenB.nest(alice, targetToken);49    expect(await targetToken.getChildren()).to.have.deep.members([50      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},51      {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},52    ]).and.has.length(2);5354    // Move token B to a different user outside the nesting tree55    await tokenB.unnest(alice, targetToken, {Substrate: bob.address});56    expect(await targetToken.getChildren()).to.have.deep.members([57      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},58    ]).and.has.length(1);5960    // Create a fungible token in another collection and then nest61    await collectionB.mint(alice, 10n);62    await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);63    expect(await targetToken.getChildren()).to.have.deep.members([64      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},65      {tokenId: 0, collectionId: collectionB.collectionId},66    ]).and.has.length(2);6768    // Create a refungible token in another collection and then nest69    const tokenC = await collectionC.mintToken(alice, 10n);70    await tokenC.transfer(alice, targetToken.nestingAccount(), 2n);71    expect(await targetToken.getChildren()).to.have.deep.members([72      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},73      {tokenId: 0, collectionId: collectionB.collectionId},74      {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},75    ]).and.has.length(3);7677    // Nest native fungible token into another collection78    await collectionNative.transfer(alice, targetToken.nestingAccount(), 2n);79    expect(await targetToken.getChildren()).to.have.deep.members([80      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},81      {tokenId: 0, collectionId: collectionB.collectionId},82      {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},83    ]).and.has.length(3);8485    // Burn all nested pieces86    await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);87    expect(await targetToken.getChildren()).to.have.deep.members([88      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},89      {tokenId: 0, collectionId: collectionB.collectionId},90    ])91      .and.has.length(2);9293    // Move part of the fungible token inside token A deeper in the nesting tree94    await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);95    expect(await targetToken.getChildren()).to.be.have.deep.members([96      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},97      {tokenId: 0, collectionId: collectionB.collectionId},98    ]).and.has.length(2);99    // Nested token also has children now:100    expect(await tokenA.getChildren()).to.have.deep.members([101      {tokenId: 0, collectionId: collectionB.collectionId},102    ]).and.has.length(1);103104    // Move the remaining part of the fungible token inside token A deeper in the nesting tree105    await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);106    expect(await targetToken.getChildren()).to.have.deep.members([107      {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108    ]).and.has.length(1);109    expect(await tokenA.getChildren()).to.have.deep.members([110      {tokenId: 0, collectionId: collectionB.collectionId},111    ]).and.has.length(1);112  });113114  /// TODO review this test115  itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {116    const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});117    const targetToken = await collection.mintToken(alice);118119    // Create an immediately nested token120    const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());121    expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});122    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());123124    // Create a token to be nested125    const newToken = await collection.mintToken(alice);126127    // Nest128    await newToken.nest(alice, targetToken);129    expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});130    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());131132    // Move bundle to different user133    await targetToken.transfer(alice, {Substrate: bob.address});134    expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});135    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());136    expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});137    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());138139    // Unnest140    await newToken.unnest(bob, targetToken, {Substrate: bob.address});141    expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});142    expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});143  });144});