git.delta.rocks / unique-network / refs/commits / 8c337cff2bc8

difftreelog

refactor rename function

Trubnikov Sergey2022-09-13parent: #8a59560.patch.diff
in: master

11 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -245,6 +245,7 @@
 	}
 
 	#[weight(<SelfWeightOf<T>>::create_collection())]
+	#[solidity(rename_selector = "createRFTCollection")]
 	fn create_refungible_collection(
 		&mut self,
 		caller: caller,
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -30,7 +30,7 @@
 }
 
 /// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x675f3074
+/// @dev the ERC-165 identifier for this interface is 0x88ee8ef1
 contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
 	/// Create an NFT collection
 	/// @param name Name of the collection
@@ -69,9 +69,9 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
-	/// @dev EVM selector for this function is: 0x44a68ad5,
-	///  or in textual repr: createRefungibleCollection(string,string,string)
-	function createRefungibleCollection(
+	/// @dev EVM selector for this function is: 0xab173450,
+	///  or in textual repr: createRFTCollection(string,string,string)
+	function createRFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -21,7 +21,7 @@
 }
 
 /// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x675f3074
+/// @dev the ERC-165 identifier for this interface is 0x88ee8ef1
 interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
 	/// Create an NFT collection
 	/// @param name Name of the collection
@@ -45,9 +45,9 @@
 		string memory baseUri
 	) external returns (address);
 
-	/// @dev EVM selector for this function is: 0x44a68ad5,
-	///  or in textual repr: createRefungibleCollection(string,string,string)
-	function createRefungibleCollection(
+	/// @dev EVM selector for this function is: 0xab173450,
+	///  or in textual repr: createRFTCollection(string,string,string)
+	function createRFTCollection(
 		string memory name,
 		string memory description,
 		string memory tokenPrefix
modifiedtests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -59,7 +59,7 @@
       { "internalType": "string", "name": "description", "type": "string" },
       { "internalType": "string", "name": "tokenPrefix", "type": "string" }
     ],
-    "name": "createRefungibleCollection",
+    "name": "createRFTCollection",
     "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
     "stateMutability": "nonpayable",
     "type": "function"
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -41,7 +41,7 @@
   
     const collectionCountBefore = await getCreatedCollectionCount(api);
     const result = await collectionHelper.methods
-      .createRefungibleCollection(collectionName, description, tokenPrefix)
+      .createRFTCollection(collectionName, description, tokenPrefix)
       .send();
     const collectionCountAfter = await getCreatedCollectionCount(api);
   
@@ -65,7 +65,7 @@
       .call()).to.be.false;
 
     await collectionHelpers.methods
-      .createRefungibleCollection('A', 'A', 'A')
+      .createRFTCollection('A', 'A', 'A')
       .send();
     
     expect(await collectionHelpers.methods
@@ -76,7 +76,7 @@
   itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const collectionHelpers = evmCollectionHelpers(web3, owner);
-    let result = await collectionHelpers.methods.createRefungibleCollection('Sponsor collection', '1', '1').send();
+    let result = await collectionHelpers.methods.createRFTCollection('Sponsor collection', '1', '1').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
@@ -96,7 +96,7 @@
   itWeb3('Set limits', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const collectionHelpers = evmCollectionHelpers(web3, owner);
-    const result = await collectionHelpers.methods.createRefungibleCollection('Const collection', '5', '5').send();
+    const result = await collectionHelpers.methods.createRFTCollection('Const collection', '5', '5').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const limits = {
       accountTokenOwnershipLimit: 1000,
@@ -141,7 +141,7 @@
       .isCollectionExist(collectionAddressForNonexistentCollection).call())
       .to.be.false;
     
-    const result = await collectionHelpers.methods.createRefungibleCollection('Collection address exist', '7', '7').send();
+    const result = await collectionHelpers.methods.createRFTCollection('Collection address exist', '7', '7').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     expect(await collectionHelpers.methods
       .isCollectionExist(collectionIdAddress).call())
@@ -164,7 +164,7 @@
       const tokenPrefix = 'A';
     
       await expect(helper.methods
-        .createRefungibleCollection(collectionName, description, tokenPrefix)
+        .createRFTCollection(collectionName, description, tokenPrefix)
         .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGHT);
       
     }
@@ -174,7 +174,7 @@
       const description = 'A'.repeat(MAX_DESCRIPTION_LENGHT + 1);
       const tokenPrefix = 'A';
       await expect(helper.methods
-        .createRefungibleCollection(collectionName, description, tokenPrefix)
+        .createRFTCollection(collectionName, description, tokenPrefix)
         .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGHT);
     }
     {  
@@ -183,7 +183,7 @@
       const description = 'A';
       const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGHT + 1);
       await expect(helper.methods
-        .createRefungibleCollection(collectionName, description, tokenPrefix)
+        .createRFTCollection(collectionName, description, tokenPrefix)
         .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGHT);
     }
   });
@@ -196,7 +196,7 @@
     const tokenPrefix = 'A';
     
     await expect(helper.methods
-      .createRefungibleCollection(collectionName, description, tokenPrefix)
+      .createRFTCollection(collectionName, description, tokenPrefix)
       .call()).to.be.rejectedWith('NotSufficientFounds');
   });
 
@@ -204,7 +204,7 @@
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const notOwner = createEthAccount(web3);
     const collectionHelpers = evmCollectionHelpers(web3, owner);
-    const result = await collectionHelpers.methods.createRefungibleCollection('A', 'A', 'A').send();
+    const result = await collectionHelpers.methods.createRFTCollection('A', 'A', 'A').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contractEvmFromNotOwner = evmCollection(web3, notOwner, collectionIdAddress, {type: 'ReFungible'});
     const EXPECTED_ERROR = 'NoPermission';
@@ -229,7 +229,7 @@
   itWeb3('(!negative test!) Set limits', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const collectionHelpers = evmCollectionHelpers(web3, owner);
-    const result = await collectionHelpers.methods.createRefungibleCollection('Schema collection', 'A', 'A').send();
+    const result = await collectionHelpers.methods.createRFTCollection('Schema collection', 'A', 'A').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
     await expect(collectionEvm.methods
modifiedtests/src/eth/fractionalizer/Fractionalizer.soldiffbeforeafterboth
--- a/tests/src/eth/fractionalizer/Fractionalizer.sol
+++ b/tests/src/eth/fractionalizer/Fractionalizer.sol
@@ -25,7 +25,9 @@
     /// @dev Method modifier to only allow contract owner to call it.
     modifier onlyOwner() {
         address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;
-        ContractHelpers contractHelpers = ContractHelpers(contracthelpersAddress);
+        ContractHelpers contractHelpers = ContractHelpers(
+            contracthelpersAddress
+        );
         address contractOwner = contractHelpers.contractOwner(address(this));
         require(msg.sender == contractOwner, "Only owner can");
         _;
@@ -38,10 +40,19 @@
     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);
+    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);
+    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.
@@ -52,13 +63,11 @@
     ///  Can only be called by contract owner.
     /// @param _collection address of RFT collection.
     function setRFTCollection(address _collection) public onlyOwner {
-        require(
-            rftCollection == address(0),
-            "RFT collection is already set"
-        );
+        require(rftCollection == address(0), "RFT collection is already set");
         UniqueRefungible refungibleContract = UniqueRefungible(_collection);
-        string memory collectionType = refungibleContract.uniqueCollectionType();
-        
+        string memory collectionType = refungibleContract
+            .uniqueCollectionType();
+
         require(
             keccak256(bytes(collectionType)) == refungibleCollectionType,
             "Wrong collection type. Collection is not refungible."
@@ -78,13 +87,15 @@
     /// @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),
-            "RFT collection is already set"
-        );
+    function createAndSetRFTCollection(
+        string calldata _name,
+        string calldata _description,
+        string calldata _tokenPrefix
+    ) public onlyOwner {
+        require(rftCollection == address(0), "RFT collection is already set");
         address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;
-        rftCollection = CollectionHelpers(collectionHelpers).createRefungibleCollection(_name, _description, _tokenPrefix);
+        rftCollection = CollectionHelpers(collectionHelpers)
+            .createRFTCollection(_name, _description, _tokenPrefix);
         emit RFTCollectionSet(rftCollection);
     }
 
@@ -92,7 +103,10 @@
     /// @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 {
+    function setNftCollectionIsAllowed(address collection, bool status)
+        public
+        onlyOwner
+    {
         nftCollectionAllowList[collection] = status;
         emit AllowListSet(collection, status);
     }
@@ -107,12 +121,15 @@
     /// @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),
-            "RFT collection is not set"
+    function nft2rft(
+        address _collection,
+        uint256 _token,
+        uint128 _pieces
+    ) public {
+        require(rftCollection != address(0), "RFT collection is not set");
+        UniqueRefungible rftCollectionContract = UniqueRefungible(
+            rftCollection
         );
-        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);
         require(
             nftCollectionAllowList[_collection] == true,
             "Fractionalization of this collection is not allowed by admin"
@@ -121,25 +138,25 @@
             UniqueNFT(_collection).ownerOf(_token) == msg.sender,
             "Only token owner could fractionalize it"
         );
-        UniqueNFT(_collection).transferFrom(
-            msg.sender,
-            address(this),
-            _token
-        );
+        UniqueNFT(_collection).transferFrom(msg.sender, address(this), _token);
         uint256 rftTokenId;
         address rftTokenAddress;
         UniqueRefungibleToken rftTokenContract;
         if (nft2rftMapping[_collection][_token] == 0) {
             rftTokenId = rftCollectionContract.nextTokenId();
             rftCollectionContract.mint(address(this), rftTokenId);
-            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);
+            rftTokenAddress = rftCollectionContract.tokenContractAddress(
+                rftTokenId
+            );
             nft2rftMapping[_collection][_token] = rftTokenId;
             rft2nftMapping[rftTokenAddress] = Token(_collection, _token);
 
             rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
         } else {
             rftTokenId = nft2rftMapping[_collection][_token];
-            rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);
+            rftTokenAddress = rftCollectionContract.tokenContractAddress(
+                rftTokenId
+            );
             rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
         }
         rftTokenContract.repartition(_pieces);
@@ -157,24 +174,25 @@
     /// @param _collection RFT collection address
     /// @param _token id of RFT token
     function rft2nft(address _collection, uint256 _token) public {
-        require(
-            rftCollection != address(0),
-            "RFT collection is not set"
+        require(rftCollection != address(0), "RFT collection is not set");
+        require(rftCollection == _collection, "Wrong RFT collection");
+        UniqueRefungible rftCollectionContract = UniqueRefungible(
+            rftCollection
         );
-        require(
-            rftCollection == _collection,
-            "Wrong RFT collection"
+        address rftTokenAddress = rftCollectionContract.tokenContractAddress(
+            _token
         );
-        UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);
-        address rftTokenAddress = rftCollectionContract.tokenContractAddress(_token);
         Token memory nftToken = rft2nftMapping[rftTokenAddress];
         require(
             nftToken._collection != address(0),
             "No corresponding NFT token found"
         );
-        UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
+        UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(
+            rftTokenAddress
+        );
         require(
-            rftTokenContract.balanceOf(msg.sender) == rftTokenContract.totalSupply(),
+            rftTokenContract.balanceOf(msg.sender) ==
+                rftTokenContract.totalSupply(),
             "Not all pieces are owned by the caller"
         );
         rftCollectionContract.transferFrom(msg.sender, address(this), _token);
@@ -183,6 +201,10 @@
             msg.sender,
             nftToken._tokenId
         );
-        emit Defractionalized(rftTokenAddress, nftToken._collection, nftToken._tokenId);
+        emit Defractionalized(
+            rftTokenAddress,
+            nftToken._collection,
+            nftToken._tokenId
+        );
     }
-}
\ No newline at end of file
+}
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, 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  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 createRefungibleCollection(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 submitTransactionAsync(alice, tx);145146    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});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 createRefungibleCollection(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 createRefungibleCollection(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});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 createRefungibleCollection(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 createRefungibleCollection(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 createRefungibleCollection(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 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();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 submitTransactionAsync(alice, tx);145146    const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});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});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});
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -26,7 +26,7 @@
   itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
     const nextTokenId = await contract.methods.nextTokenId().call();
@@ -38,7 +38,7 @@
   itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -63,7 +63,7 @@
   itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -79,7 +79,7 @@
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const receiver = createEthAccount(web3);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -103,7 +103,7 @@
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const receiver = createEthAccount(web3);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -130,7 +130,7 @@
   itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, owner);
-    let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    let result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const receiver = createEthAccount(web3);
     const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
@@ -163,7 +163,7 @@
   itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -221,7 +221,7 @@
   itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -247,7 +247,7 @@
   itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -304,7 +304,7 @@
   itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -344,7 +344,7 @@
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const receiver = createEthAccount(web3);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -376,7 +376,7 @@
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const receiver = createEthAccount(web3);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -413,7 +413,7 @@
   itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -430,7 +430,7 @@
   itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRFTCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
@@ -458,7 +458,7 @@
     const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const helper = evmCollectionHelpers(web3, caller);
-    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();
+    const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
 
@@ -658,7 +658,7 @@
   itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
 
-    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);
+    const {collectionIdAddress, collectionId} = await createRFTCollection(api, web3, owner);
     const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);
     const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();
     await refungibleContract.methods.mint(owner, refungibleTokenId).send();
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -141,10 +141,10 @@
   expect(result.success).to.be.true;
 }
 
-export async function createRefungibleCollection(api: ApiPromise, web3: Web3, owner: string) {
+export async function createRFTCollection(api: ApiPromise, web3: Web3, owner: string) {
   const collectionHelper = evmCollectionHelpers(web3, owner);
   const result = await collectionHelper.methods
-    .createRefungibleCollection('A', 'B', 'C')
+    .createRFTCollection('A', 'B', 'C')
     .send();
   return await getCollectionAddressFromResult(api, result);
 }