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

difftreelog

source

tests/src/sub/nesting/unnesting.negative.test.ts4.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('Negative Test: Unnesting', () => {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([100n, 50n], donor);28    });29  });3031  // TODO: make this test a bit more generic32  itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});34    //await collection.addAdmin(alice, {Substrate: bob.address});35    const targetToken = await collection.mintToken(alice, {Substrate: bob.address});36    await collection.addToAllowList(alice, {Substrate: bob.address});37    await collection.addToAllowList(alice, targetToken.nestingAccount());3839    // Try to nest somebody else's token40    const newToken = await collection.mintToken(bob);41    await expect(newToken.nest(alice, targetToken))42      .to.be.rejectedWith(/common\.NoPermission/);4344    // Try to unnest a token belonging to someone else as collection admin45    const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());46    await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))47      .to.be.rejectedWith(/common\.AddressNotInAllowlist/);4849    expect(await targetToken.getChildren()).to.be.length(1);50    expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());52  });5354  [55    {mode: 'ft' as const},56    {mode: 'native ft' as const},57  ].map(md => [58    {mode: md.mode, restrictedMode: true},59    {mode: md.mode, restrictedMode: false},60  ].map(testCase => {61    itSub(`Fungible: disallows a non-Owner to unnest someone else's token [${testCase.mode}${testCase.restrictedMode ? ' (Restricted nesting)' : ''}]`, async ({helper}) => {62      const collectionNFT = await helper.nft.mintCollection(alice);63      const collectionFT = await (64        testCase.mode === 'ft'65          ? helper.ft.mintCollection(alice)66          : helper.ft.getCollectionObject(0)67      );68      const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});6970      await collectionNFT.setPermissions(alice, {nesting: {71        collectionAdmin: true, tokenOwner: true, restricted: testCase.restrictedMode ? [collectionFT.collectionId] : null,72      }});7374      // Nest some tokens as Alice into Bob's token75      await (76        testCase.mode === 'ft'77          ? collectionFT.mint(alice, 5n, targetToken.nestingAccount())78          : collectionFT.transfer(alice, targetToken.nestingAccount(), 5n)79      );8081      // Try to pull it out as Alice still82      await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))83        .to.be.rejectedWith(/common\.ApprovedValueTooLow/);84      expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);85    });86  }));87});