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

difftreelog

chore add Fractionalizer contract documentation, prevent QTZ/UNQ transfers from nonowners, tests for TransfersNotAllowed

Grigoriy Simonov2022-08-11parent: #6d585f9.patch.diff
in: master

3 files changed

modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -186,7 +186,7 @@
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 
 		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)
-			.map_err(|_| "transfer error")?;
+			.map_err(dispatch_to_evm::<T>)?;
 		Ok(true)
 	}
 
modifiedtests/src/eth/fractionalizer/Fractionalizer.soldiffbeforeafterboth
--- a/tests/src/eth/fractionalizer/Fractionalizer.sol
+++ b/tests/src/eth/fractionalizer/Fractionalizer.sol
@@ -6,6 +6,9 @@
 import {UniqueRefungible} from "../api/UniqueRefungible.sol";
 import {UniqueNFT} from "../api/UniqueNFT.sol";
 
+/// @dev Fractionalization contract. It stores mappings between NFT and RFT tokens,
+///  stores allowlist of NFT tokens available for fractionalization, has methods
+///  for fractionalization and defractionalization of NFT tokens.
 contract Fractionalizer {
     struct Token {
         address _collection;
@@ -17,9 +20,10 @@
     mapping(address => Token) rft2nftMapping;
     bytes32 refungibleCollectionType = keccak256(bytes("ReFungible"));
 
-    constructor() {
-    }
+    //TODO: add nonPayable  modifier after Solidity updates to 0.9.
+    receive() external payable onlyOwner {}
 
+    /// @dev Method modifier to only allow contract owner to call it.
     modifier onlyOwner() {
         address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;
         ContractHelpers contractHelpers = ContractHelpers(contracthelpersAddress);
@@ -28,11 +32,26 @@
         _;
     }
 
+    /// @dev This emits when RFT collection setting is changed.
     event RFTCollectionSet(address _collection);
+
+    /// @dev This emits when NFT collection is allowed or disallowed.
     event AllowListSet(address _collection, bool _status);
+
+    /// @dev This emits when NFT token is fractionalized by contract.
     event Fractionalized(address _collection, uint256 _tokenId, address _rftToken, uint128 _amount);
+
+    /// @dev This emits when NFT token is defractionalized by contract.
     event Defractionalized(address _rftToken, address _nftCollection, uint256 _nftTokenId);
 
+    /// Set RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
+    /// would be created in this collection.
+    /// @dev Throws if RFT collection is already configured for this contract.
+    ///  Throws if collection of wrong type (NFT, Fungible) is provided instead
+    ///  of RFT collection.
+    ///  Throws if `msg.sender` is not owner or admin of provided RFT collection.
+    ///  Can only be called by contract owner.
+    /// @param _collection address of RFT collection.
     function setRFTCollection(address _collection) public onlyOwner {
         require(
             rftCollection == address(0),
@@ -53,6 +72,13 @@
         emit RFTCollectionSet(rftCollection);
     }
 
+    /// Creates and sets RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
+    /// would be created in this collection.
+    /// @dev Throws if RFT collection is already configured for this contract.
+    ///  Can only be called by contract owner.
+    /// @param _name name for created RFT collection.
+    /// @param _description description for created RFT collection.
+    /// @param _tokenPrefix token prefix for created RFT collection.
     function createAndSetRFTCollection(string calldata _name, string calldata _description, string calldata _tokenPrefix) public onlyOwner {
         require(
             rftCollection == address(0),
@@ -63,11 +89,25 @@
         emit RFTCollectionSet(rftCollection);
     }
 
+    /// Allow or disallow NFT collection tokens from being fractionalized by this contract.
+    /// @dev Can only be called by contract owner.
+    /// @param collection NFT token address.
+    /// @param status `true` to allow and `false` to disallow NFT token.
     function setNftCollectionIsAllowed(address collection, bool status) public onlyOwner {
         nftCollectionAllowList[collection] = status;
         emit AllowListSet(collection, status);
     }
 
+    /// Fractionilize NFT token.
+    /// @dev Takes NFT token from `msg.sender` and transfers RFT token to `msg.sender`
+    ///  instead. Creates new RFT token if provided NFT token never was fractionalized
+    ///  by this contract or existing RFT token if it was.
+    ///  Throws if RFT collection isn't configured for this contract.
+    ///  Throws if fractionalization of provided NFT token is not allowed
+    ///  Throws if `msg.sender` is not owner of provided NFT token
+    /// @param  _collection NFT collection address
+    /// @param  _token id of NFT token to be fractionalized
+    /// @param  _pieces number of pieces new RFT token would have
     function nft2rft(address _collection, uint256 _token, uint128 _pieces) public {
         require(
             rftCollection != address(0),
@@ -109,6 +149,15 @@
         emit Fractionalized(_collection, _token, rftTokenAddress, _pieces);
     }
 
+    /// Defrationalize NFT token.
+    /// @dev Takes RFT token from `msg.sender` and transfers corresponding NFT token
+    ///  to `msg.sender` instead.
+    ///  Throws if RFT collection isn't configured for this contract.
+    ///  Throws if provided RFT token is no from configured RFT collection.
+    ///  Throws if RFT token was not created by this contract.
+    ///  Throws if `msg.sender` isn't owner of all RFT token pieces.
+    /// @param _collection RFT collection address
+    /// @param _token id of RFT token
     function rft2nft(address _collection, uint256 _token) public {
         require(
             rftCollection != address(0),
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 {submitTransactionAsync} from '../../substrate/substrate-api';23import {UNIQUE} from '../../util/helpers';24import {collectionIdToAddress, CompiledContract, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, 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 chaiAsPromised from 'chai-as-promised';30import chaiLike from 'chai-like';31import {IKeyringPair} from '@polkadot/types/types';32chai.use(chaiAsPromised);33chai.use(chaiLike);34const expect = chai.expect;35let fractionalizer: CompiledContract;3637async function compileFractionalizer() {38  if (!fractionalizer) {39    const input = {40      language: 'Solidity',41      sources: {42        ['Fractionalizer.sol']: {43          content: (await readFile(`${__dirname}/Fractionalizer.sol`)).toString(),44        },45      },46      settings: {47        outputSelection: {48          '*': {49            '*': ['*'],50          },51        },52      },53    };54    const json = JSON.parse(solc.compile(JSON.stringify(input), {import: await findImports()}));55    const out = json.contracts['Fractionalizer.sol']['Fractionalizer'];5657    fractionalizer = {58      abi: out.abi,59      object: '0x' + out.evm.bytecode.object,60    };61  }62  return fractionalizer;63}6465async function findImports() {66  const collectionHelpers = (await readFile(`${__dirname}/../api/CollectionHelpers.sol`)).toString();67  const contractHelpers = (await readFile(`${__dirname}/../api/ContractHelpers.sol`)).toString();68  const uniqueRefungibleToken = (await readFile(`${__dirname}/../api/UniqueRefungibleToken.sol`)).toString();69  const uniqueRefungible = (await readFile(`${__dirname}/../api/UniqueRefungible.sol`)).toString();70  const uniqueNFT = (await readFile(`${__dirname}/../api/UniqueNFT.sol`)).toString();7172  return function(path: string) {73    switch (path) {74      case 'api/CollectionHelpers.sol': return {contents: `${collectionHelpers}`};75      case 'api/ContractHelpers.sol': return {contents: `${contractHelpers}`};76      case 'api/UniqueRefungibleToken.sol': return {contents: `${uniqueRefungibleToken}`};77      case 'api/UniqueRefungible.sol': return {contents: `${uniqueRefungible}`};78      case 'api/UniqueNFT.sol': return {contents: `${uniqueNFT}`};79      default: return {error: 'File not found'};80    }81  };82}8384async function deployFractionalizer(web3: Web3, owner: string) {85  const compiled = await compileFractionalizer();86  const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {87    data: compiled.object,88    from: owner,89    ...GAS_ARGS,90  });91  return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});92}9394async function initFractionalizer(api: ApiPromise, web3: Web3, privateKeyWrapper: (account: string) => IKeyringPair, owner: string) {95  const fractionalizer = await deployFractionalizer(web3, owner);96  const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);97  const alice = privateKeyWrapper('//Alice');98  await submitTransactionAsync(alice, tx);99  const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send();100  const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;101  return {fractionalizer, rftCollectionAddress};102}103104async function createRFTToken(api: ApiPromise, web3: Web3, owner: string, fractionalizer: Contract, amount: bigint) {105  const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);106  const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);107  const nftTokenId = await nftContract.methods.nextTokenId().call();108  await nftContract.methods.mint(owner, nftTokenId).send();109110  await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();111  await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();112  const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, amount).send();113  const {_collection, _tokenId, _rftToken} = result.events.Fractionalized.returnValues;114  return {115    nftCollectionAddress: _collection,116    nftTokenId: _tokenId,117    rftTokenAddress: _rftToken,118  };119}120121describe('Fractionalizer contract usage', () => {122  itWeb3('Set RFT collection', async ({api, web3, privateKeyWrapper}) => {123    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124    const fractionalizer = await deployFractionalizer(web3, owner);125    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);126    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);127    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();128    const result = await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();129    expect(result.events).to.be.like({130      RFTCollectionSet: {131        returnValues: {132          _collection: collectionIdAddress,133        },134      },135    });136  });137138  itWeb3('Mint RFT collection', async ({api, web3, privateKeyWrapper}) => {139    const alice = privateKeyWrapper('//Alice');140    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);141    const fractionalizer = await deployFractionalizer(web3, owner);142    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);143    await submitTransactionAsync(alice, tx);144145    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});146    expect(result.events).to.be.like({147      RFTCollectionSet: {},148    });149    expect(result.events.RFTCollectionSet.returnValues._collection).to.be.ok;150  });151152  itWeb3('Set Allowlist', async ({api, web3, privateKeyWrapper}) => {153    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);154    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);    155156    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  });226});227228229230describe('Negative Integration Tests for fractionalizer', () => {231  itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {232    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);233    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);234    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);235236    const fractionalizer = await deployFractionalizer(web3, owner);237    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();238    await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();239240    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())241      .to.eventually.be.rejectedWith(/RFT collection is already set$/g);242  });243244  itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {245    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);246    const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);247    const nftContract = uniqueNFT(web3, collectionIdAddress, owner);248249    const fractionalizer = await deployFractionalizer(web3, owner);250    await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send();251252    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())253      .to.eventually.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);254  });255256  itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {257    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);258    const fractionalizer = await deployFractionalizer(web3, owner);259    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);260261    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())262      .to.eventually.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);263  });264265  itWeb3('call setRFTCollection after createAndSetRFTCollection', async ({api, web3, privateKeyWrapper}) => {266    const alice = privateKeyWrapper('//Alice');267    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);268    const fractionalizer = await deployFractionalizer(web3, owner);269    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);270    await submitTransactionAsync(alice, tx);271272    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});273    const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;274275    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())276      .to.eventually.be.rejectedWith(/RFT collection is already set$/g);277  });278279  itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {280    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);281282    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);283    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);284    const nftTokenId = await nftContract.methods.nextTokenId().call();285    await nftContract.methods.mint(owner, nftTokenId).send();286287    const fractionalizer = await deployFractionalizer(web3, owner);288289    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())290      .to.eventually.be.rejectedWith(/RFT collection is not set$/g);291  });292293  itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {294    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);295    const nftOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);296297    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);298    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);299    const nftTokenId = await nftContract.methods.nextTokenId().call();300    await nftContract.methods.mint(owner, nftTokenId).send();301    await nftContract.methods.transfer(nftOwner, 1).send();302303304    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);305    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();306307    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())308      .to.eventually.be.rejectedWith(/Only token owner could fractionalize it$/g);309  });310311  itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {312    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);313314    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);315    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);316    const nftTokenId = await nftContract.methods.nextTokenId().call();317    await nftContract.methods.mint(owner, nftTokenId).send();318319    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);320321    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();322    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())323      .to.eventually.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);324  });325326  itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {327    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);328329    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);330    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);331    const nftTokenId = await nftContract.methods.nextTokenId().call();332    await nftContract.methods.mint(owner, nftTokenId).send();333334    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);335336    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();337    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())338      .to.eventually.be.rejectedWith(/ApprovedValueTooLow$/g);339  });340341  itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {342    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);343344    const fractionalizer = await deployFractionalizer(web3, owner);345    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);346    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);347    const rftTokenId = await refungibleContract.methods.nextTokenId().call();348    await refungibleContract.methods.mint(owner, rftTokenId).send();349    350    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())351      .to.eventually.be.rejectedWith(/RFT collection is not set$/g);352  });353354  itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {355    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);356357    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);358    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);359    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);360    const rftTokenId = await refungibleContract.methods.nextTokenId().call();361    await refungibleContract.methods.mint(owner, rftTokenId).send();362    363    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())364      .to.eventually.be.rejectedWith(/Wrong RFT collection$/g);365  });366367  itWeb3('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({api, web3, privateKeyWrapper}) => {368    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);369    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);370371    const fractionalizer = await deployFractionalizer(web3, owner);372    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);373374    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();375    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();376377    const rftTokenId = await refungibleContract.methods.nextTokenId().call();378    await refungibleContract.methods.mint(owner, rftTokenId).send();379    380    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())381      .to.eventually.be.rejectedWith(/No corresponding NFT token found$/g);382  });383384  itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {385    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);386    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);387388    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);389    const {rftTokenAddress} = await createRFTToken(api, web3, owner, fractionalizer, 100n);390    391    const {tokenId} = tokenIdFromAddress(rftTokenAddress);392    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);393    await refungibleTokenContract.methods.transfer(receiver, 50).send();394    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();395    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call())396      .to.eventually.be.rejectedWith(/Not all pieces are owned by the caller$/g);397  });398});
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 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} from '../../util/helpers';24import {collectionIdToAddress, CompiledContract, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, 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();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  itWeb3('Set RFT collection', async ({api, web3, privateKeyWrapper}) => {120    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);121    const fractionalizer = await deployFractionalizer(web3, owner);122    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);123    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);124    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();125    const result = await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();126    expect(result.events).to.be.like({127      RFTCollectionSet: {128        returnValues: {129          _collection: collectionIdAddress,130        },131      },132    });133  });134135  itWeb3('Mint RFT collection', async ({api, web3, privateKeyWrapper}) => {136    const alice = privateKeyWrapper('//Alice');137    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);138    const fractionalizer = await deployFractionalizer(web3, owner);139    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);140    await submitTransactionAsync(alice, tx);141142    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});143    expect(result.events).to.be.like({144      RFTCollectionSet: {},145    });146    expect(result.events.RFTCollectionSet.returnValues._collection).to.be.ok;147  });148149  itWeb3('Set Allowlist', async ({api, web3, privateKeyWrapper}) => {150    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);151    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);152    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);153    const result1 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send({from: owner});154    expect(result1.events).to.be.like({155      AllowListSet: {156        returnValues: {157          _collection: nftCollectionAddress,158          _status: true,159        },160      },161    });162    const result2 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, false).send({from: owner});163    expect(result2.events).to.be.like({164      AllowListSet: {165        returnValues: {166          _collection: nftCollectionAddress,167          _status: false,168        },169      },170    });171  });172173  itWeb3('NFT to RFT', async ({api, web3, privateKeyWrapper}) => {174    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);175176    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);177    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);178    const nftTokenId = await nftContract.methods.nextTokenId().call();179    await nftContract.methods.mint(owner, nftTokenId).send();180181    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);182183    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();184    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();185    const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send();186    expect(result.events).to.be.like({187      Fractionalized: {188        returnValues: {189          _collection: nftCollectionAddress,190          _tokenId: nftTokenId,191          _amount: '100',192        },193      },194    });195    const rftTokenAddress = result.events.Fractionalized.returnValues._rftToken;196    const rftTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);197    expect(await rftTokenContract.methods.balanceOf(owner).call()).to.equal('100');198  });199200  itWeb3('RFT to NFT', async ({api, web3, privateKeyWrapper}) => {201    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);202203    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);204    const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await createRFTToken(api, web3, owner, fractionalizer, 100n);205206    const {collectionId, tokenId} = tokenIdFromAddress(rftTokenAddress);207    const refungibleAddress = collectionIdToAddress(collectionId);208    expect(rftCollectionAddress).to.be.equal(refungibleAddress);209    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);210    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send();211    const result = await fractionalizer.methods.rft2nft(refungibleAddress, tokenId).send();212    expect(result.events).to.be.like({213      Defractionalized: {214        returnValues: {215          _rftToken: rftTokenAddress,216          _nftCollection: nftCollectionAddress,217          _nftTokenId: nftTokenId,218        },219      },220    });221  });222});223224225226describe('Negative Integration Tests for fractionalizer', () => {227  itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {228    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);229    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);230    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);231232    const fractionalizer = await deployFractionalizer(web3, owner);233    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();234    await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();235236    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())237      .to.be.rejectedWith(/RFT collection is already set$/g);238  });239240  itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {241    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);242    const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);243    const nftContract = uniqueNFT(web3, collectionIdAddress, owner);244245    const fractionalizer = await deployFractionalizer(web3, owner);246    await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send();247248    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())249      .to.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);250  });251252  itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {253    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);254    const fractionalizer = await deployFractionalizer(web3, owner);255    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);256257    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())258      .to.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);259  });260261  itWeb3('call setRFTCollection after createAndSetRFTCollection', async ({api, web3, privateKeyWrapper}) => {262    const alice = privateKeyWrapper('//Alice');263    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);264    const fractionalizer = await deployFractionalizer(web3, owner);265    const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);266    await submitTransactionAsync(alice, tx);267268    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});269    const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;270271    await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())272      .to.be.rejectedWith(/RFT collection is already set$/g);273  });274275  itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {276    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);277278    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);279    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);280    const nftTokenId = await nftContract.methods.nextTokenId().call();281    await nftContract.methods.mint(owner, nftTokenId).send();282283    const fractionalizer = await deployFractionalizer(web3, owner);284285    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())286      .to.be.rejectedWith(/RFT collection is not set$/g);287  });288289  itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {290    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);291    const nftOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);292293    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);294    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);295    const nftTokenId = await nftContract.methods.nextTokenId().call();296    await nftContract.methods.mint(owner, nftTokenId).send();297    await nftContract.methods.transfer(nftOwner, 1).send();298299300    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);301    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();302303    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())304      .to.be.rejectedWith(/Only token owner could fractionalize it$/g);305  });306307  itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {308    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);309310    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);311    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);312    const nftTokenId = await nftContract.methods.nextTokenId().call();313    await nftContract.methods.mint(owner, nftTokenId).send();314315    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);316317    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();318    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())319      .to.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);320  });321322  itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {323    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);324325    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);326    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);327    const nftTokenId = await nftContract.methods.nextTokenId().call();328    await nftContract.methods.mint(owner, nftTokenId).send();329330    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);331332    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();333    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())334      .to.be.rejectedWith(/ApprovedValueTooLow$/g);335  });336337  itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {338    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);339340    const fractionalizer = await deployFractionalizer(web3, owner);341    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);342    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);343    const rftTokenId = await refungibleContract.methods.nextTokenId().call();344    await refungibleContract.methods.mint(owner, rftTokenId).send();345    346    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())347      .to.be.rejectedWith(/RFT collection is not set$/g);348  });349350  itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {351    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);352353    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);354    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);355    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);356    const rftTokenId = await refungibleContract.methods.nextTokenId().call();357    await refungibleContract.methods.mint(owner, rftTokenId).send();358    359    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())360      .to.be.rejectedWith(/Wrong RFT collection$/g);361  });362363  itWeb3('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({api, web3, privateKeyWrapper}) => {364    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);365    const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);366367    const fractionalizer = await deployFractionalizer(web3, owner);368    const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);369370    await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();371    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();372373    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(/No corresponding NFT token found$/g);378  });379380  itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {381    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);382    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);383384    const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);385    const {rftTokenAddress} = await createRFTToken(api, web3, owner, fractionalizer, 100n);386    387    const {tokenId} = tokenIdFromAddress(rftTokenAddress);388    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);389    await refungibleTokenContract.methods.transfer(receiver, 50).send();390    await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();391    await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call())392      .to.be.rejectedWith(/Not all pieces are owned by the caller$/g);393  });394395  itWeb3('send QTZ/UNQ to contract from non owner', async ({api, web3, privateKeyWrapper}) => {396    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);397    const payer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);398399    const fractionalizer = await deployFractionalizer(web3, owner);400    const amount = 10n * UNIQUE;401    await expect(web3.eth.sendTransaction({from: payer, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS})).to.be.rejected;402  });403404  itWeb3('fractionalize NFT with NFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {405    const alice = privateKeyWrapper('//Alice');406    let collectionId;407    {408      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});409      const events = await submitTransactionAsync(alice, tx);410      const result = getCreateCollectionResult(events);411      collectionId = result.collectionId;412    }413    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);414    let nftTokenId;415    {416      const createData = {nft: {}};417      const tx = api.tx.unique.createItem(collectionId, {Ethereum: owner}, createData as any);418      const events = await executeTransaction(api, alice, tx);419      const result = getCreateItemResult(events);420      nftTokenId = result.itemId;421    }422    {423      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);424      await executeTransaction(api, alice, tx);425    }426    const nftCollectionAddress = collectionIdToAddress(collectionId);427    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);428    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();429430    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);431    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();432    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())433      .to.be.rejectedWith(/TransferNotAllowed$/g);434  });435  436  itWeb3('fractionalize NFT with RFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {437    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);438    const alice = privateKeyWrapper('//Alice');439440    let collectionId;441    {442      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'ReFungible'});443      const events = await submitTransactionAsync(alice, tx);444      const result = getCreateCollectionResult(events);445      collectionId = result.collectionId;446    }447    const rftCollectionAddress = collectionIdToAddress(collectionId);448    const fractionalizer = await deployFractionalizer(web3, owner);449    {450      const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: fractionalizer.options.address});451      await submitTransactionAsync(alice, changeAdminTx);452    }453    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();454    {455      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);456      await executeTransaction(api, alice, tx);457    }458459    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);460    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);461    const nftTokenId = await nftContract.methods.nextTokenId().call();462    await nftContract.methods.mint(owner, nftTokenId).send();463464    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();465    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();466467    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100n).call())468      .to.be.rejectedWith(/TransferNotAllowed$/g);469  });470});