git.delta.rocks / unique-network / refs/commits / 2203d0f0ed69

difftreelog

Tests: refactor fractionalizer tests to playgrounds

Andrey2022-10-03parent: #239c99e.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -30,6 +30,7 @@
     "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",
     "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",
     "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",
+    "testEthFractionalizer": "mocha --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",
     "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
     "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
     "loadTransfer": "ts-node src/transfer.nload.ts",
modifiedtests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth
before · tests/src/eth/fractionalizer/fractionalizer.test.ts
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/>.161718import Web3 from 'web3';19import {ApiPromise} from '@polkadot/api';20import {evmToAddress} from '@polkadot/util-crypto';21import {readFile} from 'fs/promises';22import {executeTransaction, submitTransactionAsync} from '../../substrate/substrate-api';23import {getCreateCollectionResult, getCreateItemResult, UNIQUE, requirePallets, Pallets} from '../../util/helpers';24import {collectionIdToAddress, CompiledContract, createEthAccountWithBalance, createNonfungibleCollection, createRFTCollection, GAS_ARGS, itWeb3, tokenIdFromAddress, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from '../util/helpers';25import {Contract} from 'web3-eth-contract';26import * as solc from 'solc';2728import chai from 'chai';29import chaiLike from 'chai-like';30import {IKeyringPair} from '@polkadot/types/types';31chai.use(chaiLike);32const expect = chai.expect;33let fractionalizer: CompiledContract;3435async function compileFractionalizer() {36  if (!fractionalizer) {37    const input = {38      language: 'Solidity',39      sources: {40        ['Fractionalizer.sol']: {41          content: (await readFile(`${__dirname}/Fractionalizer.sol`)).toString(),42        },43      },44      settings: {45        outputSelection: {46          '*': {47            '*': ['*'],48          },49        },50      },51    };52    const json = JSON.parse(solc.compile(JSON.stringify(input), {import: await findImports()}));53    const out = json.contracts['Fractionalizer.sol']['Fractionalizer'];5455    fractionalizer = {56      abi: out.abi,57      object: '0x' + out.evm.bytecode.object,58    };59  }60  return fractionalizer;61}6263async function findImports() {64  const collectionHelpers = (await readFile(`${__dirname}/../api/CollectionHelpers.sol`)).toString();65  const contractHelpers = (await readFile(`${__dirname}/../api/ContractHelpers.sol`)).toString();66  const uniqueRefungibleToken = (await readFile(`${__dirname}/../api/UniqueRefungibleToken.sol`)).toString();67  const uniqueRefungible = (await readFile(`${__dirname}/../api/UniqueRefungible.sol`)).toString();68  const uniqueNFT = (await readFile(`${__dirname}/../api/UniqueNFT.sol`)).toString();6970  return function(path: string) {71    switch (path) {72      case 'api/CollectionHelpers.sol': return {contents: `${collectionHelpers}`};73      case 'api/ContractHelpers.sol': return {contents: `${contractHelpers}`};74      case 'api/UniqueRefungibleToken.sol': return {contents: `${uniqueRefungibleToken}`};75      case 'api/UniqueRefungible.sol': return {contents: `${uniqueRefungible}`};76      case 'api/UniqueNFT.sol': return {contents: `${uniqueNFT}`};77      default: return {error: 'File not found'};78    }79  };80}8182async function deployFractionalizer(web3: Web3, owner: string) {83  const compiled = await compileFractionalizer();84  const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {85    data: compiled.object,86    from: owner,87    ...GAS_ARGS,88  });89  return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});90}9192async function initFractionalizer(api: ApiPromise, web3: Web3, privateKeyWrapper: (account: string) => IKeyringPair, owner: string) {93  const fractionalizer = await deployFractionalizer(web3, owner);94  const amount = 10n * UNIQUE;95  await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS});96  const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({value: Number(2n * UNIQUE)});97  const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;98  return {fractionalizer, rftCollectionAddress};99}100101async function createRFTToken(api: ApiPromise, web3: Web3, owner: string, fractionalizer: Contract, amount: bigint) {102  const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);103  const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);104  const nftTokenId = await nftContract.methods.nextTokenId().call();105  await nftContract.methods.mint(owner, nftTokenId).send();106107  await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();108  await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();109  const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, amount).send();110  const {_collection, _tokenId, _rftToken} = result.events.Fractionalized.returnValues;111  return {112    nftCollectionAddress: _collection,113    nftTokenId: _tokenId,114    rftTokenAddress: _rftToken,115  };116}117118describe('Fractionalizer contract usage', () => {119  before(async function() {120    await requirePallets(this, [Pallets.ReFungible]);121  });122123  itWeb3('Set RFT collection', async ({api, web3, privateKeyWrapper}) => {124    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125    const fractionalizer = await deployFractionalizer(web3, owner);126    const {collectionIdAddress} = await createRFTCollection(api, web3, owner);127    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);128    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();129    const result = await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();130    expect(result.events).to.be.like({131      RFTCollectionSet: {132        returnValues: {133          _collection: collectionIdAddress,134        },135      },136    });137  });138139  itWeb3('Mint RFT collection', async ({api, web3, privateKeyWrapper}) => {140    const alice = privateKeyWrapper('//Alice');141    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);142    const fractionalizer = await deployFractionalizer(web3, owner);143    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);144    await executeTransaction(api, alice, tx);145146    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});147    expect(result.events).to.be.like({148      RFTCollectionSet: {},149    });150    expect(result.events.RFTCollectionSet.returnValues._collection).to.be.ok;151  });152153  itWeb3('Set Allowlist', async ({api, web3, privateKeyWrapper}) => {154    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);155    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);156    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);157    const result1 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send({from: owner});158    expect(result1.events).to.be.like({159      AllowListSet: {160        returnValues: {161          _collection: nftCollectionAddress,162          _status: true,163        },164      },165    });166    const result2 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, false).send({from: owner});167    expect(result2.events).to.be.like({168      AllowListSet: {169        returnValues: {170          _collection: nftCollectionAddress,171          _status: false,172        },173      },174    });175  });176177  itWeb3('NFT to RFT', async ({api, web3, privateKeyWrapper}) => {178    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);179180    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);181    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);182    const nftTokenId = await nftContract.methods.nextTokenId().call();183    await nftContract.methods.mint(owner, nftTokenId).send();184185    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);186187    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();188    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();189    const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send();190    expect(result.events).to.be.like({191      Fractionalized: {192        returnValues: {193          _collection: nftCollectionAddress,194          _tokenId: nftTokenId,195          _amount: '100',196        },197      },198    });199    const rftTokenAddress = result.events.Fractionalized.returnValues._rftToken;200    const rftTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);201    expect(await rftTokenContract.methods.balanceOf(owner).call()).to.equal('100');202  });203204  itWeb3('RFT to NFT', async ({api, web3, privateKeyWrapper}) => {205    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);206207    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);208    const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await createRFTToken(api, web3, owner, fractionalizer, 100n);209210    const {collectionId, tokenId} = tokenIdFromAddress(rftTokenAddress);211    const refungibleAddress = collectionIdToAddress(collectionId);212    expect(rftCollectionAddress).to.be.equal(refungibleAddress);213    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);214    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send();215    const result = await fractionalizer.methods.rft2nft(refungibleAddress, tokenId).send();216    expect(result.events).to.be.like({217      Defractionalized: {218        returnValues: {219          _rftToken: rftTokenAddress,220          _nftCollection: nftCollectionAddress,221          _nftTokenId: nftTokenId,222        },223      },224    });225  });226227  itWeb3('Test fractionalizer NFT <-> RFT mapping ', async ({api, web3, privateKeyWrapper}) => {228    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);229230    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);231    const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await createRFTToken(api, web3, owner, fractionalizer, 100n);232233    const {collectionId, tokenId} = tokenIdFromAddress(rftTokenAddress);234    const refungibleAddress = collectionIdToAddress(collectionId);235    expect(rftCollectionAddress).to.be.equal(refungibleAddress);236    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);237    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send();238239    const rft2nft = await fractionalizer.methods.rft2nftMapping(rftTokenAddress).call();240    expect(rft2nft).to.be.like({241      _collection: nftCollectionAddress,242      _tokenId: nftTokenId,243    });244245    const nft2rft = await fractionalizer.methods.nft2rftMapping(nftCollectionAddress, nftTokenId).call();246    expect(nft2rft).to.be.eq(tokenId.toString());247  });248});249250251252describe('Negative Integration Tests for fractionalizer', () => {253  before(async function() {254    await requirePallets(this, [Pallets.ReFungible]);255  });256257  itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {258    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);259    const {collectionIdAddress} = await createRFTCollection(api, web3, owner);260    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);261262    const fractionalizer = await deployFractionalizer(web3, owner);263    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();264    await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();265266    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())267      .to.be.rejectedWith(/RFT collection is already set$/g);268  });269270  itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {271    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);272    const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);273    const nftContract = uniqueNFT(web3, collectionIdAddress, owner);274275    const fractionalizer = await deployFractionalizer(web3, owner);276    await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send();277278    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())279      .to.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);280  });281282  itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {283    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);284    const fractionalizer = await deployFractionalizer(web3, owner);285    const {collectionIdAddress} = await createRFTCollection(api, web3, owner);286287    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())288      .to.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);289  });290291  itWeb3('call setRFTCollection after createAndSetRFTCollection', async ({api, web3, privateKeyWrapper}) => {292    const alice = privateKeyWrapper('//Alice');293    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);294    const fractionalizer = await deployFractionalizer(web3, owner);295    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);296    await submitTransactionAsync(alice, tx);297298    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});299    const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;300301    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())302      .to.be.rejectedWith(/RFT collection is already set$/g);303  });304305  itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {306    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);307308    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);309    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);310    const nftTokenId = await nftContract.methods.nextTokenId().call();311    await nftContract.methods.mint(owner, nftTokenId).send();312313    const fractionalizer = await deployFractionalizer(web3, owner);314315    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())316      .to.be.rejectedWith(/RFT collection is not set$/g);317  });318319  itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {320    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);321    const nftOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);322323    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);324    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);325    const nftTokenId = await nftContract.methods.nextTokenId().call();326    await nftContract.methods.mint(owner, nftTokenId).send();327    await nftContract.methods.transfer(nftOwner, 1).send();328329330    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);331    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();332333    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())334      .to.be.rejectedWith(/Only token owner could fractionalize it$/g);335  });336337  itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {338    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);339340    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);341    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);342    const nftTokenId = await nftContract.methods.nextTokenId().call();343    await nftContract.methods.mint(owner, nftTokenId).send();344345    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);346347    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();348    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())349      .to.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);350  });351352  itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {353    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);354355    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);356    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);357    const nftTokenId = await nftContract.methods.nextTokenId().call();358    await nftContract.methods.mint(owner, nftTokenId).send();359360    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);361362    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();363    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())364      .to.be.rejectedWith(/ApprovedValueTooLow$/g);365  });366367  itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {368    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);369370    const fractionalizer = await deployFractionalizer(web3, owner);371    const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);372    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);373    const rftTokenId = await refungibleContract.methods.nextTokenId().call();374    await refungibleContract.methods.mint(owner, rftTokenId).send();375    376    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())377      .to.be.rejectedWith(/RFT collection is not set$/g);378  });379380  itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {381    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);382383    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);384    const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);385    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);386    const rftTokenId = await refungibleContract.methods.nextTokenId().call();387    await refungibleContract.methods.mint(owner, rftTokenId).send();388    389    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())390      .to.be.rejectedWith(/Wrong RFT collection$/g);391  });392393  itWeb3('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({api, web3, privateKeyWrapper}) => {394    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);395    const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);396397    const fractionalizer = await deployFractionalizer(web3, owner);398    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);399400    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();401    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();402403    const rftTokenId = await refungibleContract.methods.nextTokenId().call();404    await refungibleContract.methods.mint(owner, rftTokenId).send();405    406    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())407      .to.be.rejectedWith(/No corresponding NFT token found$/g);408  });409410  itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {411    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);412    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);413414    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);415    const {rftTokenAddress} = await createRFTToken(api, web3, owner, fractionalizer, 100n);416    417    const {tokenId} = tokenIdFromAddress(rftTokenAddress);418    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);419    await refungibleTokenContract.methods.transfer(receiver, 50).send();420    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();421    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call())422      .to.be.rejectedWith(/Not all pieces are owned by the caller$/g);423  });424425  itWeb3('send QTZ/UNQ to contract from non owner', async ({api, web3, privateKeyWrapper}) => {426    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);427    const payer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);428429    const fractionalizer = await deployFractionalizer(web3, owner);430    const amount = 10n * UNIQUE;431    await expect(web3.eth.sendTransaction({from: payer, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS})).to.be.rejected;432  });433434  itWeb3('fractionalize NFT with NFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {435    const alice = privateKeyWrapper('//Alice');436    let collectionId;437    {438      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});439      const events = await submitTransactionAsync(alice, tx);440      const result = getCreateCollectionResult(events);441      collectionId = result.collectionId;442    }443    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);444    let nftTokenId;445    {446      const createData = {nft: {}};447      const tx = api.tx.unique.createItem(collectionId, {Ethereum: owner}, createData as any);448      const events = await executeTransaction(api, alice, tx);449      const result = getCreateItemResult(events);450      nftTokenId = result.itemId;451    }452    {453      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);454      await executeTransaction(api, alice, tx);455    }456    const nftCollectionAddress = collectionIdToAddress(collectionId);457    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);458    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();459460    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);461    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();462    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())463      .to.be.rejectedWith(/TransferNotAllowed$/g);464  });465  466  itWeb3('fractionalize NFT with RFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {467    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);468    const alice = privateKeyWrapper('//Alice');469470    let collectionId;471    {472      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'ReFungible'});473      const events = await submitTransactionAsync(alice, tx);474      const result = getCreateCollectionResult(events);475      collectionId = result.collectionId;476    }477    const rftCollectionAddress = collectionIdToAddress(collectionId);478    const fractionalizer = await deployFractionalizer(web3, owner);479    {480      const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: fractionalizer.options.address});481      await submitTransactionAsync(alice, changeAdminTx);482    }483    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();484    {485      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);486      await executeTransaction(api, alice, tx);487    }488489    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);490    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);491    const nftTokenId = await nftContract.methods.nextTokenId().call();492    await nftContract.methods.mint(owner, nftTokenId).send();493494    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();495    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();496497    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100n).call())498      .to.be.rejectedWith(/TransferNotAllowed$/g);499  });500});
after · tests/src/eth/fractionalizer/fractionalizer.test.ts
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/>.161718import {readFile} from 'fs/promises';1920import {IKeyringPair} from '@polkadot/types/types';21import {evmToAddress} from '@polkadot/util-crypto';2223import {Contract} from 'web3-eth-contract';2425import {usingEthPlaygrounds, expect, itEth, EthUniqueHelper} from '../util/playgrounds';26import {CompiledContract} from '../util/playgrounds/types';27import {requirePalletsOrSkip, Pallets} from '../../util/playgrounds';282930let compiledFractionalizer: CompiledContract;3132const compileContract = async (helper: EthUniqueHelper): Promise<CompiledContract> => {33  if(!compiledFractionalizer) {34    compiledFractionalizer = await helper.ethContract.compile('Fractionalizer', (await readFile(`${__dirname}/Fractionalizer.sol`)).toString(), [35      {solPath: 'api/CollectionHelpers.sol', fsPath: `${__dirname}/../api/CollectionHelpers.sol`},36      {solPath: 'api/ContractHelpers.sol', fsPath: `${__dirname}/../api/ContractHelpers.sol`},37      {solPath: 'api/UniqueRefungibleToken.sol', fsPath: `${__dirname}/../api/UniqueRefungibleToken.sol`},38      {solPath: 'api/UniqueRefungible.sol', fsPath: `${__dirname}/../api/UniqueRefungible.sol`},39      {solPath: 'api/UniqueNFT.sol', fsPath: `${__dirname}/../api/UniqueNFT.sol`},40    ]);41  }42  return compiledFractionalizer;43}444546const deployContract = async (helper: EthUniqueHelper, owner: string): Promise<Contract> => {47  const compiled = await compileContract(helper);48  return await helper.ethContract.deployByAbi(owner, compiled.abi, compiled.object);49}505152const initContract = async (helper: EthUniqueHelper, owner: string): Promise<{contract: Contract, rftCollectionAddress: string}> => {53  const fractionalizer = await deployContract(helper, owner);54  const amount = 10n * helper.balance.getOneTokenNominal();55  const web3 = helper.getWeb3();56  await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, gas: helper.eth.DEFAULT_GAS});57  const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({value: Number(2n * helper.balance.getOneTokenNominal())});58  const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;59  return {contract: fractionalizer, rftCollectionAddress};60}6162const mintRFTToken = async (helper: EthUniqueHelper, owner: string, fractionalizer: Contract, amount: bigint): Promise<{63  nftCollectionAddress: string, nftTokenId: number, rftTokenAddress: string64}> => {65  const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');66  const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);67  const nftTokenId = await nftContract.methods.nextTokenId().call();68  await nftContract.methods.mint(owner, nftTokenId).send({from: owner});6970  await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});71  await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send({from: owner});72  const result = await fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, amount).send({from: owner});73  const {_collection, _tokenId, _rftToken} = result.events.Fractionalized.returnValues;74  return {75    nftCollectionAddress: _collection,76    nftTokenId: _tokenId,77    rftTokenAddress: _rftToken,78  };79}808182describe('Fractionalizer contract usage', () => {83  let donor: IKeyringPair;8485  before(async function() {86    await usingEthPlaygrounds(async (helper: EthUniqueHelper, privateKey) => {87      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);88      donor = privateKey('//Alice');89    });90  });9192  itEth('Set RFT collection', async ({helper}) => {93    const owner = await helper.eth.createAccountWithBalance(donor, 10n);94    const fractionalizer = await deployContract(helper, owner);95    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');96    const rftContract = helper.ethNativeContract.collection(rftCollection.collectionAddress, 'rft', owner);9798    await rftContract.methods.addCollectionAdmin(fractionalizer.options.address).send({from: owner});99    const result = await fractionalizer.methods.setRFTCollection(rftCollection.collectionAddress).send({from: owner});100    expect(result.events).to.be.like({101      RFTCollectionSet: {102        returnValues: {103          _collection: rftCollection.collectionAddress,104        },105      },106    });107  });108109  itEth('Mint RFT collection', async ({helper}) => {110    const owner = await helper.eth.createAccountWithBalance(donor, 10n);111    const fractionalizer = await deployContract(helper, owner);112    await helper.balance.transferToSubstrate(donor, evmToAddress(fractionalizer.options.address), 10n * helper.balance.getOneTokenNominal());113114    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * helper.balance.getOneTokenNominal())});115    expect(result.events).to.be.like({116      RFTCollectionSet: {},117    });118    expect(result.events.RFTCollectionSet.returnValues._collection).to.be.ok;119  });120121  itEth('Set Allowlist', async ({helper}) => {122    const owner = await helper.eth.createAccountWithBalance(donor, 20n);123    const {contract: fractionalizer} = await initContract(helper, owner);124    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');125126    const result1 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});127    expect(result1.events).to.be.like({128      AllowListSet: {129        returnValues: {130          _collection: nftCollection.collectionAddress,131          _status: true,132        },133      },134    });135    const result2 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, false).send({from: owner});136    expect(result2.events).to.be.like({137      AllowListSet: {138        returnValues: {139          _collection: nftCollection.collectionAddress,140          _status: false,141        },142      },143    });144  });145146  itEth('NFT to RFT', async ({helper}) => {147    const owner = await helper.eth.createAccountWithBalance(donor, 20n);148149    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');150    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);151    const nftTokenId = await nftContract.methods.nextTokenId().call();152    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});153154    const {contract: fractionalizer} = await initContract(helper, owner);155156    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});157    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send({from: owner});158    const result = await fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100).send({from: owner});159    expect(result.events).to.be.like({160      Fractionalized: {161        returnValues: {162          _collection: nftCollection.collectionAddress,163          _tokenId: nftTokenId,164          _amount: '100',165        },166      },167    });168    const rftTokenAddress = result.events.Fractionalized.returnValues._rftToken;169170    const rftTokenContract = helper.ethNativeContract.rftToken(rftTokenAddress);171    expect(await rftTokenContract.methods.balanceOf(owner).call()).to.equal('100');172  });173174  itEth('RFT to NFT', async ({helper}) => {175    const owner = await helper.eth.createAccountWithBalance(donor, 20n);176177    const {contract: fractionalizer, rftCollectionAddress} = await initContract(helper, owner);178    const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await mintRFTToken(helper, owner, fractionalizer, 100n);179180    const {collectionId, tokenId} = helper.ethAddress.extractTokenId(rftTokenAddress);181    const refungibleAddress = helper.ethAddress.fromCollectionId(collectionId);182    expect(rftCollectionAddress).to.be.equal(refungibleAddress);183    const refungibleTokenContract = helper.ethNativeContract.rftToken(rftTokenAddress, owner);184    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send({from: owner});185    const result = await fractionalizer.methods.rft2nft(refungibleAddress, tokenId).send({from: owner});186    expect(result.events).to.be.like({187      Defractionalized: {188        returnValues: {189          _rftToken: rftTokenAddress,190          _nftCollection: nftCollectionAddress,191          _nftTokenId: nftTokenId,192        },193      },194    });195  });196197  itEth('Test fractionalizer NFT <-> RFT mapping ', async ({helper}) => {198    const owner = await helper.eth.createAccountWithBalance(donor, 20n);199200    const {contract: fractionalizer, rftCollectionAddress} = await initContract(helper, owner);201    const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await mintRFTToken(helper, owner, fractionalizer, 100n);202203    const {collectionId, tokenId} = helper.ethAddress.extractTokenId(rftTokenAddress);204    const refungibleAddress = helper.ethAddress.fromCollectionId(collectionId);205    expect(rftCollectionAddress).to.be.equal(refungibleAddress);206    const refungibleTokenContract = helper.ethNativeContract.rftToken(rftTokenAddress, owner);207    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send({from: owner});208209    const rft2nft = await fractionalizer.methods.rft2nftMapping(rftTokenAddress).call();210    expect(rft2nft).to.be.like({211      _collection: nftCollectionAddress,212      _tokenId: nftTokenId,213    });214215    const nft2rft = await fractionalizer.methods.nft2rftMapping(nftCollectionAddress, nftTokenId).call();216    expect(nft2rft).to.be.eq(tokenId.toString());217  });218});219220221222describe('Negative Integration Tests for fractionalizer', () => {223  let donor: IKeyringPair;224225  before(async function() {226    await usingEthPlaygrounds(async (helper: EthUniqueHelper, privateKey) => {227      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);228      donor = privateKey('//Alice');229    });230  });231232  itEth('call setRFTCollection twice', async ({helper}) => {233    const owner = await helper.eth.createAccountWithBalance(donor, 20n);234    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');235    const refungibleContract = helper.ethNativeContract.collection(rftCollection.collectionAddress, 'rft', owner);236237    const fractionalizer = await deployContract(helper, owner);238    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send({from: owner});239    await fractionalizer.methods.setRFTCollection(rftCollection.collectionAddress).send({from: owner});240241    await expect(fractionalizer.methods.setRFTCollection(rftCollection.collectionAddress).call())242      .to.be.rejectedWith(/RFT collection is already set$/g);243  });244245  itEth('call setRFTCollection with NFT collection', async ({helper}) => {246    const owner = await helper.eth.createAccountWithBalance(donor, 20n);247    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');248    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);249250    const fractionalizer = await deployContract(helper, owner);251    await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send({from: owner});252253    await expect(fractionalizer.methods.setRFTCollection(nftCollection.collectionAddress).call())254      .to.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);255  });256257  itEth('call setRFTCollection while not collection admin', async ({helper}) => {258    const owner = await helper.eth.createAccountWithBalance(donor, 20n);259    const fractionalizer = await deployContract(helper, owner);260    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');261262    await expect(fractionalizer.methods.setRFTCollection(rftCollection.collectionAddress).call())263      .to.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);264  });265266  itEth('call setRFTCollection after createAndSetRFTCollection', async ({helper}) => {267    const owner = await helper.eth.createAccountWithBalance(donor, 20n);268    const fractionalizer = await deployContract(helper, owner);269    await helper.balance.transferToSubstrate(donor, evmToAddress(fractionalizer.options.address), 10n * helper.balance.getOneTokenNominal());270271    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * helper.balance.getOneTokenNominal())});272    const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;273274    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())275      .to.be.rejectedWith(/RFT collection is already set$/g);276  });277278  itEth('call nft2rft without setting RFT collection for contract', async ({helper}) => {279    const owner = await helper.eth.createAccountWithBalance(donor, 20n);280281    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');282    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);283    const nftTokenId = await nftContract.methods.nextTokenId().call();284    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});285286    const fractionalizer = await deployContract(helper, owner);287288    await expect(fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100).call())289      .to.be.rejectedWith(/RFT collection is not set$/g);290  });291292  itEth('call nft2rft while not owner of NFT token', async ({helper}) => {293    const owner = await helper.eth.createAccountWithBalance(donor, 20n);294    const nftOwner = await helper.eth.createAccountWithBalance(donor, 10n);295296    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');297    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);298    const nftTokenId = await nftContract.methods.nextTokenId().call();299    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});300    await nftContract.methods.transfer(nftOwner, 1).send({from: owner});301302303    const {contract: fractionalizer} = await initContract(helper, owner);304    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});305306    await expect(fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100).call({from: owner}))307      .to.be.rejectedWith(/Only token owner could fractionalize it$/g);308  });309310  itEth('call nft2rft while not in list of allowed accounts', async ({helper}) => {311    const owner = await helper.eth.createAccountWithBalance(donor, 20n);312313    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');314    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);315    const nftTokenId = await nftContract.methods.nextTokenId().call();316    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});317318    const {contract: fractionalizer} = await initContract(helper, owner);319320    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send({from: owner});321    await expect(fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100).call())322      .to.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);323  });324325  itEth('call nft2rft while fractionalizer doesnt have approval for nft token', async ({helper}) => {326    const owner = await helper.eth.createAccountWithBalance(donor, 20n);327328    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');329    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);330    const nftTokenId = await nftContract.methods.nextTokenId().call();331    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});332333    const {contract: fractionalizer} = await initContract(helper, owner);334335    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});336    await expect(fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100).call())337      .to.be.rejectedWith(/ApprovedValueTooLow$/g);338  });339340  itEth('call rft2nft without setting RFT collection for contract', async ({helper}) => {341    const owner = await helper.eth.createAccountWithBalance(donor, 20n);342343    const fractionalizer = await deployContract(helper, owner);344    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');345    const refungibleContract = helper.ethNativeContract.collection(rftCollection.collectionAddress, 'rft', owner);346    const rftTokenId = await refungibleContract.methods.nextTokenId().call();347    await refungibleContract.methods.mint(owner, rftTokenId).send({from: owner});348    349    await expect(fractionalizer.methods.rft2nft(rftCollection.collectionAddress, rftTokenId).call({from: owner}))350      .to.be.rejectedWith(/RFT collection is not set$/g);351  });352353  itEth('call rft2nft for RFT token that is not from configured RFT collection', async ({helper}) => {354    const owner = await helper.eth.createAccountWithBalance(donor, 20n);355356    const {contract: fractionalizer} = await initContract(helper, owner);357    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');358    const refungibleContract = helper.ethNativeContract.collection(rftCollection.collectionAddress, 'rft', owner);359    const rftTokenId = await refungibleContract.methods.nextTokenId().call();360    await refungibleContract.methods.mint(owner, rftTokenId).send({from: owner});361    362    await expect(fractionalizer.methods.rft2nft(rftCollection.collectionAddress, rftTokenId).call())363      .to.be.rejectedWith(/Wrong RFT collection$/g);364  });365366  itEth('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({helper}) => {367    const owner = await helper.eth.createAccountWithBalance(donor, 20n);368    const rftCollection = await helper.eth.createRefungibleCollection(owner, 'rft', 'RFT collection', 'RFT');369    const refungibleContract = helper.ethNativeContract.collection(rftCollection.collectionAddress, 'rft', owner);370371    const fractionalizer = await deployContract(helper, owner);372373    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send({from: owner});374    await fractionalizer.methods.setRFTCollection(rftCollection.collectionAddress).send({from: owner});375376    const rftTokenId = await refungibleContract.methods.nextTokenId().call();377    await refungibleContract.methods.mint(owner, rftTokenId).send({from: owner});378    379    await expect(fractionalizer.methods.rft2nft(rftCollection.collectionAddress, rftTokenId).call())380      .to.be.rejectedWith(/No corresponding NFT token found$/g);381  });382383  itEth('call rft2nft without owning all RFT pieces', async ({helper}) => {384    const owner = await helper.eth.createAccountWithBalance(donor, 20n);385    const receiver = await helper.eth.createAccountWithBalance(donor, 10n);386387    const {contract: fractionalizer, rftCollectionAddress} = await initContract(helper, owner);388    const {rftTokenAddress} = await mintRFTToken(helper, owner, fractionalizer, 100n);389    390    const {tokenId} = helper.ethAddress.extractTokenId(rftTokenAddress);391    const refungibleTokenContract = helper.ethNativeContract.rftToken(rftTokenAddress, owner);392    await refungibleTokenContract.methods.transfer(receiver, 50).send({from: owner});393    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send({from: receiver});394    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call({from: receiver}))395      .to.be.rejectedWith(/Not all pieces are owned by the caller$/g);396  });397398  itEth('send QTZ/UNQ to contract from non owner', async ({helper}) => {399    const owner = await helper.eth.createAccountWithBalance(donor, 20n);400    const payer = await helper.eth.createAccountWithBalance(donor, 10n);401402    const fractionalizer = await deployContract(helper, owner);403    const amount = 10n * helper.balance.getOneTokenNominal();404    const web3 = helper.getWeb3();405    await expect(web3.eth.sendTransaction({from: payer, to: fractionalizer.options.address, value: `${amount}`, gas: helper.eth.DEFAULT_GAS})).to.be.rejected;406  });407408  itEth('fractionalize NFT with NFT transfers disallowed', async ({helper}) => {409    const nftCollection = await helper.nft.mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});410411    const owner = await helper.eth.createAccountWithBalance(donor, 20n);412    const nftToken = await nftCollection.mintToken(donor, {Ethereum: owner});413    await helper.executeExtrinsic(donor, 'api.tx.unique.setTransfersEnabledFlag', [nftCollection.collectionId, false], true);414    const nftCollectionAddress = helper.ethAddress.fromCollectionId(nftCollection.collectionId);415    const {contract: fractionalizer} = await initContract(helper, owner);416    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send({from: owner});417418    const nftContract = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);419    await nftContract.methods.approve(fractionalizer.options.address, nftToken.tokenId).send({from: owner});420    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftToken.tokenId, 100).call())421      .to.be.rejectedWith(/TransferNotAllowed$/g);422  });423  424  itEth('fractionalize NFT with RFT transfers disallowed', async ({helper}) => {425    const owner = await helper.eth.createAccountWithBalance(donor, 20n);426427    const rftCollection = await helper.rft.mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});428    const rftCollectionAddress = helper.ethAddress.fromCollectionId(rftCollection.collectionId);429    const fractionalizer = await deployContract(helper, owner);430    await rftCollection.addAdmin(donor, {Ethereum: fractionalizer.options.address});431432    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send({from: owner});433    await helper.executeExtrinsic(donor, 'api.tx.unique.setTransfersEnabledFlag', [rftCollection.collectionId, false], true);434435    const nftCollection = await helper.eth.createNonfungibleCollection(owner, 'nft', 'NFT collection', 'NFT');436    const nftContract = helper.ethNativeContract.collection(nftCollection.collectionAddress, 'nft', owner);437    const nftTokenId = await nftContract.methods.nextTokenId().call();438    await nftContract.methods.mint(owner, nftTokenId).send({from: owner});439440    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollection.collectionAddress, true).send({from: owner});441    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send({from: owner});442443    await expect(fractionalizer.methods.nft2rft(nftCollection.collectionAddress, nftTokenId, 100n).call())444      .to.be.rejectedWith(/TransferNotAllowed$/g);445  });446});
modifiedtests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -12,8 +12,10 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
+import chaiLike from 'chai-like';
 import {requirePalletsOrSkip} from '../../../util/playgrounds';
 chai.use(chaiAsPromised);
+chai.use(chaiLike);
 export const expect = chai.expect;
 
 export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {