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
before · tests/src/eth/fractionalizer/Fractionalizer.sol
1// SPDX-License-Identifier:  Apache License2pragma solidity >=0.8.0;3import {CollectionHelpers} from "../api/CollectionHelpers.sol";4import {ContractHelpers} from "../api/ContractHelpers.sol";5import {UniqueRefungibleToken} from "../api/UniqueRefungibleToken.sol";6import {UniqueRefungible} from "../api/UniqueRefungible.sol";7import {UniqueNFT} from "../api/UniqueNFT.sol";89contract Fractionalizer {10    struct Token {11        address _collection;12        uint256 _tokenId;13    }14    address rftCollection;15    mapping(address => bool) nftCollectionAllowList;16    mapping(address => mapping(uint256 => uint256)) nft2rftMapping;17    mapping(address => Token) rft2nftMapping;18    bytes32 refungibleCollectionType = keccak256(bytes("ReFungible"));1920    constructor() {21    }2223    modifier onlyOwner() {24        address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;25        ContractHelpers contractHelpers = ContractHelpers(contracthelpersAddress);26        address contractOwner = contractHelpers.contractOwner(address(this));27        require(msg.sender == contractOwner, "Only owner can");28        _;29    }3031    event RFTCollectionSet(address _collection);32    event AllowListSet(address _collection, bool _status);33    event Fractionalized(address _collection, uint256 _tokenId, address _rftToken, uint128 _amount);34    event Defractionalized(address _rftToken, address _nftCollection, uint256 _nftTokenId);3536    function setRFTCollection(address _collection) public onlyOwner {37        require(38            rftCollection == address(0),39            "RFT collection is already set"40        );41        UniqueRefungible refungibleContract = UniqueRefungible(_collection);42        string memory collectionType = refungibleContract.uniqueCollectionType();43        44        require(45            keccak256(bytes(collectionType)) == refungibleCollectionType,46            "Wrong collection type. Collection is not refungible."47        );48        require(49            refungibleContract.verifyOwnerOrAdmin(),50            "Fractionalizer contract should be an admin of the collection"51        );52        rftCollection = _collection;53        emit RFTCollectionSet(rftCollection);54    }5556    function createAndSetRFTCollection(string calldata _name, string calldata _description, string calldata _tokenPrefix) public onlyOwner {57        require(58            rftCollection == address(0),59            "RFT collection is already set"60        );61        address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;62        rftCollection = CollectionHelpers(collectionHelpers).createRefungibleCollection(_name, _description, _tokenPrefix);63        emit RFTCollectionSet(rftCollection);64    }6566    function setNftCollectionIsAllowed(address collection, bool status) public onlyOwner {67        nftCollectionAllowList[collection] = status;68        emit AllowListSet(collection, status);69    }7071    function nft2rft(address _collection, uint256 _token, uint128 _pieces) public {72        require(73            rftCollection != address(0),74            "RFT collection is not set"75        );76        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);77        require(78            nftCollectionAllowList[_collection] == true,79            "Fractionalization of this collection is not allowed by admin"80        );81        require(82            UniqueNFT(_collection).ownerOf(_token) == msg.sender,83            "Only token owner could fractionalize it"84        );85        UniqueNFT(_collection).transferFrom(86            msg.sender,87            address(this),88            _token89        );90        uint256 rftTokenId;91        address rftTokenAddress;92        UniqueRefungibleToken rftTokenContract;93        if (nft2rftMapping[_collection][_token] == 0) {94            rftTokenId = rftCollectionContract.nextTokenId();95            rftCollectionContract.mint(address(this), rftTokenId);96            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);97            nft2rftMapping[_collection][_token] = rftTokenId;98            rft2nftMapping[rftTokenAddress] = Token(_collection, _token);99100            rftTokenContract = UniqueRefungibleToken(rftTokenAddress);101            rftTokenContract.setParentNFT(_collection, _token);102        } else {103            rftTokenId = nft2rftMapping[_collection][_token];104            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);105            rftTokenContract = UniqueRefungibleToken(rftTokenAddress);106        }107        rftTokenContract.repartition(_pieces);108        rftTokenContract.transfer(msg.sender, _pieces);109        emit Fractionalized(_collection, _token, rftTokenAddress, _pieces);110    }111112    function rft2nft(address _collection, uint256 _token) public {113        require(114            rftCollection != address(0),115            "RFT collection is not set"116        );117        require(118            rftCollection == _collection,119            "Wrong RFT collection"120        );121        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);122        address rftTokenAddress = rftCollectionContract.tokenContractAddress(_token);123        Token memory nftToken = rft2nftMapping[rftTokenAddress];124        require(125            nftToken._collection != address(0),126            "No corresponding NFT token found"127        );128        UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(rftTokenAddress);129        require(130            rftTokenContract.balanceOf(msg.sender) == rftTokenContract.totalSupply(),131            "Not all pieces are owned by the caller"132        );133        rftCollectionContract.transferFrom(msg.sender, address(this), _token);134        UniqueNFT(nftToken._collection).transferFrom(135            address(this),136            msg.sender,137            nftToken._tokenId138        );139        emit Defractionalized(rftTokenAddress, nftToken._collection, nftToken._tokenId);140    }141}
after · tests/src/eth/fractionalizer/Fractionalizer.sol
1// SPDX-License-Identifier:  Apache License2pragma solidity >=0.8.0;3import {CollectionHelpers} from "../api/CollectionHelpers.sol";4import {ContractHelpers} from "../api/ContractHelpers.sol";5import {UniqueRefungibleToken} from "../api/UniqueRefungibleToken.sol";6import {UniqueRefungible} from "../api/UniqueRefungible.sol";7import {UniqueNFT} from "../api/UniqueNFT.sol";89/// @dev Fractionalization contract. It stores mappings between NFT and RFT tokens,10///  stores allowlist of NFT tokens available for fractionalization, has methods11///  for fractionalization and defractionalization of NFT tokens.12contract Fractionalizer {13    struct Token {14        address _collection;15        uint256 _tokenId;16    }17    address rftCollection;18    mapping(address => bool) nftCollectionAllowList;19    mapping(address => mapping(uint256 => uint256)) nft2rftMapping;20    mapping(address => Token) rft2nftMapping;21    bytes32 refungibleCollectionType = keccak256(bytes("ReFungible"));2223    //TODO: add nonPayable  modifier after Solidity updates to 0.9.24    receive() external payable onlyOwner {}2526    /// @dev Method modifier to only allow contract owner to call it.27    modifier onlyOwner() {28        address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;29        ContractHelpers contractHelpers = ContractHelpers(contracthelpersAddress);30        address contractOwner = contractHelpers.contractOwner(address(this));31        require(msg.sender == contractOwner, "Only owner can");32        _;33    }3435    /// @dev This emits when RFT collection setting is changed.36    event RFTCollectionSet(address _collection);3738    /// @dev This emits when NFT collection is allowed or disallowed.39    event AllowListSet(address _collection, bool _status);4041    /// @dev This emits when NFT token is fractionalized by contract.42    event Fractionalized(address _collection, uint256 _tokenId, address _rftToken, uint128 _amount);4344    /// @dev This emits when NFT token is defractionalized by contract.45    event Defractionalized(address _rftToken, address _nftCollection, uint256 _nftTokenId);4647    /// Set RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens48    /// would be created in this collection.49    /// @dev Throws if RFT collection is already configured for this contract.50    ///  Throws if collection of wrong type (NFT, Fungible) is provided instead51    ///  of RFT collection.52    ///  Throws if `msg.sender` is not owner or admin of provided RFT collection.53    ///  Can only be called by contract owner.54    /// @param _collection address of RFT collection.55    function setRFTCollection(address _collection) public onlyOwner {56        require(57            rftCollection == address(0),58            "RFT collection is already set"59        );60        UniqueRefungible refungibleContract = UniqueRefungible(_collection);61        string memory collectionType = refungibleContract.uniqueCollectionType();62        63        require(64            keccak256(bytes(collectionType)) == refungibleCollectionType,65            "Wrong collection type. Collection is not refungible."66        );67        require(68            refungibleContract.verifyOwnerOrAdmin(),69            "Fractionalizer contract should be an admin of the collection"70        );71        rftCollection = _collection;72        emit RFTCollectionSet(rftCollection);73    }7475    /// Creates and sets RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens76    /// would be created in this collection.77    /// @dev Throws if RFT collection is already configured for this contract.78    ///  Can only be called by contract owner.79    /// @param _name name for created RFT collection.80    /// @param _description description for created RFT collection.81    /// @param _tokenPrefix token prefix for created RFT collection.82    function createAndSetRFTCollection(string calldata _name, string calldata _description, string calldata _tokenPrefix) public onlyOwner {83        require(84            rftCollection == address(0),85            "RFT collection is already set"86        );87        address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;88        rftCollection = CollectionHelpers(collectionHelpers).createRefungibleCollection(_name, _description, _tokenPrefix);89        emit RFTCollectionSet(rftCollection);90    }9192    /// Allow or disallow NFT collection tokens from being fractionalized by this contract.93    /// @dev Can only be called by contract owner.94    /// @param collection NFT token address.95    /// @param status `true` to allow and `false` to disallow NFT token.96    function setNftCollectionIsAllowed(address collection, bool status) public onlyOwner {97        nftCollectionAllowList[collection] = status;98        emit AllowListSet(collection, status);99    }100101    /// Fractionilize NFT token.102    /// @dev Takes NFT token from `msg.sender` and transfers RFT token to `msg.sender`103    ///  instead. Creates new RFT token if provided NFT token never was fractionalized104    ///  by this contract or existing RFT token if it was.105    ///  Throws if RFT collection isn't configured for this contract.106    ///  Throws if fractionalization of provided NFT token is not allowed107    ///  Throws if `msg.sender` is not owner of provided NFT token108    /// @param  _collection NFT collection address109    /// @param  _token id of NFT token to be fractionalized110    /// @param  _pieces number of pieces new RFT token would have111    function nft2rft(address _collection, uint256 _token, uint128 _pieces) public {112        require(113            rftCollection != address(0),114            "RFT collection is not set"115        );116        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);117        require(118            nftCollectionAllowList[_collection] == true,119            "Fractionalization of this collection is not allowed by admin"120        );121        require(122            UniqueNFT(_collection).ownerOf(_token) == msg.sender,123            "Only token owner could fractionalize it"124        );125        UniqueNFT(_collection).transferFrom(126            msg.sender,127            address(this),128            _token129        );130        uint256 rftTokenId;131        address rftTokenAddress;132        UniqueRefungibleToken rftTokenContract;133        if (nft2rftMapping[_collection][_token] == 0) {134            rftTokenId = rftCollectionContract.nextTokenId();135            rftCollectionContract.mint(address(this), rftTokenId);136            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);137            nft2rftMapping[_collection][_token] = rftTokenId;138            rft2nftMapping[rftTokenAddress] = Token(_collection, _token);139140            rftTokenContract = UniqueRefungibleToken(rftTokenAddress);141            rftTokenContract.setParentNFT(_collection, _token);142        } else {143            rftTokenId = nft2rftMapping[_collection][_token];144            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);145            rftTokenContract = UniqueRefungibleToken(rftTokenAddress);146        }147        rftTokenContract.repartition(_pieces);148        rftTokenContract.transfer(msg.sender, _pieces);149        emit Fractionalized(_collection, _token, rftTokenAddress, _pieces);150    }151152    /// Defrationalize NFT token.153    /// @dev Takes RFT token from `msg.sender` and transfers corresponding NFT token154    ///  to `msg.sender` instead.155    ///  Throws if RFT collection isn't configured for this contract.156    ///  Throws if provided RFT token is no from configured RFT collection.157    ///  Throws if RFT token was not created by this contract.158    ///  Throws if `msg.sender` isn't owner of all RFT token pieces.159    /// @param _collection RFT collection address160    /// @param _token id of RFT token161    function rft2nft(address _collection, uint256 _token) public {162        require(163            rftCollection != address(0),164            "RFT collection is not set"165        );166        require(167            rftCollection == _collection,168            "Wrong RFT collection"169        );170        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);171        address rftTokenAddress = rftCollectionContract.tokenContractAddress(_token);172        Token memory nftToken = rft2nftMapping[rftTokenAddress];173        require(174            nftToken._collection != address(0),175            "No corresponding NFT token found"176        );177        UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(rftTokenAddress);178        require(179            rftTokenContract.balanceOf(msg.sender) == rftTokenContract.totalSupply(),180            "Not all pieces are owned by the caller"181        );182        rftCollectionContract.transferFrom(msg.sender, address(this), _token);183        UniqueNFT(nftToken._collection).transferFrom(184            address(this),185            msg.sender,186            nftToken._tokenId187        );188        emit Defractionalized(rftTokenAddress, nftToken._collection, nftToken._tokenId);189    }190}
modifiedtests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fractionalizer/fractionalizer.test.ts
+++ b/tests/src/eth/fractionalizer/fractionalizer.test.ts
@@ -19,17 +19,15 @@
 import {ApiPromise} from '@polkadot/api';
 import {evmToAddress} from '@polkadot/util-crypto';
 import {readFile} from 'fs/promises';
-import {submitTransactionAsync} from '../../substrate/substrate-api';
-import {UNIQUE} from '../../util/helpers';
+import {executeTransaction, submitTransactionAsync} from '../../substrate/substrate-api';
+import {getCreateCollectionResult, getCreateItemResult, UNIQUE} from '../../util/helpers';
 import {collectionIdToAddress, CompiledContract, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, GAS_ARGS, itWeb3, tokenIdFromAddress, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from '../util/helpers';
 import {Contract} from 'web3-eth-contract';
 import * as solc from 'solc';
 
 import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
 import chaiLike from 'chai-like';
 import {IKeyringPair} from '@polkadot/types/types';
-chai.use(chaiAsPromised);
 chai.use(chaiLike);
 const expect = chai.expect;
 let fractionalizer: CompiledContract;
@@ -93,9 +91,8 @@
 
 async function initFractionalizer(api: ApiPromise, web3: Web3, privateKeyWrapper: (account: string) => IKeyringPair, owner: string) {
   const fractionalizer = await deployFractionalizer(web3, owner);
-  const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);
-  const alice = privateKeyWrapper('//Alice');
-  await submitTransactionAsync(alice, tx);
+  const amount = 10n * UNIQUE;
+  await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS});
   const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send();
   const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;
   return {fractionalizer, rftCollectionAddress};
@@ -151,8 +148,7 @@
 
   itWeb3('Set Allowlist', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);    
-
+    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);
     const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);
     const result1 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send({from: owner});
     expect(result1.events).to.be.like({
@@ -238,7 +234,7 @@
     await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();
 
     await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
-      .to.eventually.be.rejectedWith(/RFT collection is already set$/g);
+      .to.be.rejectedWith(/RFT collection is already set$/g);
   });
 
   itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {
@@ -250,7 +246,7 @@
     await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send();
 
     await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
-      .to.eventually.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);
+      .to.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);
   });
 
   itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {
@@ -259,7 +255,7 @@
     const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);
 
     await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
-      .to.eventually.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);
+      .to.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);
   });
 
   itWeb3('call setRFTCollection after createAndSetRFTCollection', async ({api, web3, privateKeyWrapper}) => {
@@ -273,7 +269,7 @@
     const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;
 
     await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
-      .to.eventually.be.rejectedWith(/RFT collection is already set$/g);
+      .to.be.rejectedWith(/RFT collection is already set$/g);
   });
 
   itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {
@@ -287,7 +283,7 @@
     const fractionalizer = await deployFractionalizer(web3, owner);
 
     await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())
-      .to.eventually.be.rejectedWith(/RFT collection is not set$/g);
+      .to.be.rejectedWith(/RFT collection is not set$/g);
   });
 
   itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {
@@ -305,7 +301,7 @@
     await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();
 
     await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())
-      .to.eventually.be.rejectedWith(/Only token owner could fractionalize it$/g);
+      .to.be.rejectedWith(/Only token owner could fractionalize it$/g);
   });
 
   itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {
@@ -320,7 +316,7 @@
 
     await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();
     await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())
-      .to.eventually.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);
+      .to.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);
   });
 
   itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {
@@ -335,7 +331,7 @@
 
     await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();
     await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())
-      .to.eventually.be.rejectedWith(/ApprovedValueTooLow$/g);
+      .to.be.rejectedWith(/ApprovedValueTooLow$/g);
   });
 
   itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {
@@ -348,7 +344,7 @@
     await refungibleContract.methods.mint(owner, rftTokenId).send();
     
     await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())
-      .to.eventually.be.rejectedWith(/RFT collection is not set$/g);
+      .to.be.rejectedWith(/RFT collection is not set$/g);
   });
 
   itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {
@@ -361,7 +357,7 @@
     await refungibleContract.methods.mint(owner, rftTokenId).send();
     
     await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())
-      .to.eventually.be.rejectedWith(/Wrong RFT collection$/g);
+      .to.be.rejectedWith(/Wrong RFT collection$/g);
   });
 
   itWeb3('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({api, web3, privateKeyWrapper}) => {
@@ -378,7 +374,7 @@
     await refungibleContract.methods.mint(owner, rftTokenId).send();
     
     await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())
-      .to.eventually.be.rejectedWith(/No corresponding NFT token found$/g);
+      .to.be.rejectedWith(/No corresponding NFT token found$/g);
   });
 
   itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {
@@ -393,6 +389,82 @@
     await refungibleTokenContract.methods.transfer(receiver, 50).send();
     await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();
     await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call())
-      .to.eventually.be.rejectedWith(/Not all pieces are owned by the caller$/g);
+      .to.be.rejectedWith(/Not all pieces are owned by the caller$/g);
+  });
+
+  itWeb3('send QTZ/UNQ to contract from non owner', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const payer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+
+    const fractionalizer = await deployFractionalizer(web3, owner);
+    const amount = 10n * UNIQUE;
+    await expect(web3.eth.sendTransaction({from: payer, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS})).to.be.rejected;
+  });
+
+  itWeb3('fractionalize NFT with NFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {
+    const alice = privateKeyWrapper('//Alice');
+    let collectionId;
+    {
+      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getCreateCollectionResult(events);
+      collectionId = result.collectionId;
+    }
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    let nftTokenId;
+    {
+      const createData = {nft: {}};
+      const tx = api.tx.unique.createItem(collectionId, {Ethereum: owner}, createData as any);
+      const events = await executeTransaction(api, alice, tx);
+      const result = getCreateItemResult(events);
+      nftTokenId = result.itemId;
+    }
+    {
+      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);
+      await executeTransaction(api, alice, tx);
+    }
+    const nftCollectionAddress = collectionIdToAddress(collectionId);
+    const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);
+    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();
+
+    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);
+    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();
+    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())
+      .to.be.rejectedWith(/TransferNotAllowed$/g);
+  });
+  
+  itWeb3('fractionalize NFT with RFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const alice = privateKeyWrapper('//Alice');
+
+    let collectionId;
+    {
+      const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'ReFungible'});
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getCreateCollectionResult(events);
+      collectionId = result.collectionId;
+    }
+    const rftCollectionAddress = collectionIdToAddress(collectionId);
+    const fractionalizer = await deployFractionalizer(web3, owner);
+    {
+      const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: fractionalizer.options.address});
+      await submitTransactionAsync(alice, changeAdminTx);
+    }
+    await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();
+    {
+      const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);
+      await executeTransaction(api, alice, tx);
+    }
+
+    const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);
+    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);
+    const nftTokenId = await nftContract.methods.nextTokenId().call();
+    await nftContract.methods.mint(owner, nftTokenId).send();
+
+    await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();
+    await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();
+
+    await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100n).call())
+      .to.be.rejectedWith(/TransferNotAllowed$/g);
   });
 });
\ No newline at end of file