git.delta.rocks / unique-network / refs/commits / 15d448e077f4

difftreelog

source

tests/src/sub/nesting/negative.test.ts7.6 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, Pallets, usingPlaygrounds} from '../../util';19import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';20import {itEth} from '../../eth/util';2122let alice: IKeyringPair;2324before(async () => {25  await usingPlaygrounds(async (helper, privateKey) => {26    const donor = await privateKey({filename: __filename});27    [alice] = await helper.arrange.createAccounts([50n], donor);28  });29});3031[32  {mode: 'nft' as const, requiredPallets: []},33  {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},34].map(testCase => {35  itSub.ifWithPallets(`Owner cannot nest ${testCase.mode.toUpperCase()} if nesting not allowed`, testCase.requiredPallets, async ({helper}) => {36    // Create default collection, permissions are not set:37    const aliceNFTCollection = await helper.nft.mintCollection(alice);38    const targetToken = await aliceNFTCollection.mintToken(alice);3940    const collectionForNesting = await helper[testCase.mode].mintCollection(alice);4142    // 1. Alice cannot create immediately nested tokens:43    const nestingTx = testCase.mode === 'nft'44      ? (collectionForNesting as UniqueNFTCollection).mintToken(alice, targetToken.nestingAccount())45      : (collectionForNesting as UniqueRFTCollection).mintToken(alice, 10n, targetToken.nestingAccount());46    await expect(nestingTx).to.be.rejectedWith('common.UserIsNotAllowedToNest');4748    // 2. Alice cannot mint and nest token:49    const nestedToken2 = await collectionForNesting.mintToken(alice);50    await expect(nestedToken2.nest(alice, targetToken)).to.be.rejectedWith('common.UserIsNotAllowedToNest');51  });52});5354itSub('Owner cannot nest FT if nesting not allowed', async ({helper}) => {55  // Create default collection, permissions are not set:56  const aliceNFTCollection = await helper.nft.mintCollection(alice);57  const targetToken = await aliceNFTCollection.mintToken(alice);5859  const collectionForNesting = await helper.ft.mintCollection(alice);6061  // 1. Alice cannot create immediately nested tokens:62  await expect(collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest');6364  // 2. Alice can mint and nest token:65  await collectionForNesting.mint(alice, 100n);66  await expect(collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');67});6869itSub.ifWithPallets('Cannot nest in non existing token', [Pallets.ReFungible], async ({helper}) => {70  const collection = await helper.nft.mintCollection(alice);71  // To avoid UserIsNotAllowedToNest error72  await helper.collection.setPermissions(alice, collection.collectionId, {nesting: {collectionAdmin: true}});7374  // The list of non-existing tokens:75  const tokenFromNonExistingCollection = helper.nft.getTokenObject(9999999, 1);76  const tokenBurnt = await collection.mintToken(alice);77  await tokenBurnt.burn(alice);78  const tokenNotMintedYet = helper.nft.getTokenObject(collection.collectionId, 2);7980  // The list of collections to nest tokens from:81  const nftCollectionForNesting = await helper.nft.mintCollection(alice);82  const rftCollectionForNesting = await helper.rft.mintCollection(alice);83  const ftCollectionForNesting = await helper.ft.mintCollection(alice);8485  const testCases = [86    {token: tokenFromNonExistingCollection, error: 'CollectionNotFound'},87    {token: tokenBurnt, error: 'TokenNotFound'},88    {token: tokenNotMintedYet, error: 'TokenNotFound'},89  ];9091  for(const testCase of testCases) {92    // 1. Alice cannot create nested token to non-existing token93    await expect(nftCollectionForNesting.mintToken(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);94    await expect(rftCollectionForNesting.mintToken(alice, 10n, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);95    await expect(ftCollectionForNesting.mint(alice, 10n, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);9697    // 2. Alice cannot mint and nest token:98    const nft = await nftCollectionForNesting.mintToken(alice);99    const rft = await rftCollectionForNesting.mintToken(alice, 100n);100    const _ft = await ftCollectionForNesting.mint(alice, 100n);101    await expect(nft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);102    await expect(rft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);103    await expect(ftCollectionForNesting.transfer(alice, testCase.token.nestingAccount(), 50n)).to.be.rejectedWith(testCase.error);104  }105});106107itEth.ifWithPallets('Cannot nest to collection address', [Pallets.ReFungible], async({helper}) => {108  const existingCollection = await helper.nft.mintCollection(alice);109  const existingCollectionAddress = helper.ethAddress.fromCollectionId(existingCollection.collectionId);110  const futureCollectionAddress = helper.ethAddress.fromCollectionId(99999999);111112  const nftCollectionForNesting = await helper.nft.mintCollection(alice);113114  // 1. Alice cannot create nested token to collection address115  await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');116  await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');117118  // 2. Alice cannot mint and nest token to collection address:119  const nft = await nftCollectionForNesting.mintToken(alice);120  await expect(nft.transfer(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');121  await expect(nft.transfer(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');122});123124itEth.ifWithPallets('Cannot nest in RFT or FT', [Pallets.ReFungible], async ({helper}) => {125  // Create default collection, permissions are not set:126  const rftCollection = await helper.rft.mintCollection(alice);127  const ftCollection = await helper.ft.mintCollection(alice);128129  const rftToken = await rftCollection.mintToken(alice);130  const _ftToken = await ftCollection.mint(alice, 100n);131132  const collectionForNesting = await helper.nft.mintCollection(alice);133134  // 1. Alice cannot create immediately nested tokens:135  await expect(collectionForNesting.mintToken(alice, rftToken.nestingAccount())).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');136  await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');137138  // 2. Alice cannot mint and nest token:139  const nestedToken2 = await collectionForNesting.mintToken(alice);140  await expect(nestedToken2.nest(alice, rftToken)).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');141  await expect(ftCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');142});