git.delta.rocks / unique-network / refs/commits / 587c55e5ec2a

difftreelog

Merge branch 'develop' into CI-43-try-runtime

Alexander Aksenov2022-08-16parents: #258c7f4 #d75b746.patch.diff
in: master

11 files changed

modified.docker/Dockerfile-parachaindiffbeforeafterboth
--- a/.docker/Dockerfile-parachain
+++ b/.docker/Dockerfile-parachain
@@ -7,7 +7,8 @@
 ENV RUST_TOOLCHAIN $RUST_TOOLCHAIN
 ENV CARGO_HOME="/cargo-home"
 ENV PATH="/cargo-home/bin:$PATH"
-
+ENV TZ=UTC
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
 
 RUN apt-get update && \
     apt-get install -y curl cmake pkg-config libssl-dev git clang && \
@@ -35,10 +36,10 @@
 ARG REPO_URL=
 ARG BRANCH=
 
-RUN mkdir /unique_parachain
+
 WORKDIR /unique_parachain
 
-RUN git clone $REPO_URL -b $BRANCH && \
+RUN git clone $REPO_URL -b $BRANCH . && \
     cargo build --features=$FEATURE --$PROFILE
 
 # ===== BUILD POLKADOT =====
@@ -47,7 +48,7 @@
 ARG POLKADOT_BUILD_BRANCH=
 ENV POLKADOT_BUILD_BRANCH $POLKADOT_BUILD_BRANCH
 
-RUN mkdir /unique_parachain
+
 WORKDIR /unique_parachain
 
 RUN git clone -b $POLKADOT_BUILD_BRANCH --depth 1 https://github.com/paritytech/polkadot.git && \
modified.docker/forking/launch-config-fork.j2diffbeforeafterboth
--- a/.docker/forking/launch-config-fork.j2
+++ b/.docker/forking/launch-config-fork.j2
@@ -84,7 +84,7 @@
     },
       "parachains": [
         {
-            "bin": "/unique-chain/current/release/unique-collator",
+            "bin": "/unique-chain/target/release/unique-collator",
             "id": "1000",
             "balance": "1000000000000000000000000",
             "chainRawInitializer": [
modified.github/workflows/build-test-master.ymldiffbeforeafterboth
--- a/.github/workflows/build-test-master.yml
+++ b/.github/workflows/build-test-master.yml
@@ -27,7 +27,7 @@
     runs-on: self-hosted-ci
 
 
-    name: Build Container, Spin it Up an test
+    name: ${{ matrix.network }} - Build and Test
 
     continue-on-error: true         #Do not stop testing of matrix runs failed.
 
modified.github/workflows/fork-update-withdata.ymldiffbeforeafterboth
--- a/.github/workflows/fork-update-withdata.yml
+++ b/.github/workflows/fork-update-withdata.yml
@@ -26,7 +26,7 @@
     # The type of runner that the job will run on
     runs-on: self-hosted-ci
 
-    name: Build Container, Spin it Up an test
+    name: ${{ matrix.network }} Fork Parachain with data
 
     continue-on-error: true         #Do not stop testing of matrix runs failed.  As it decided during PR review - it required 50/50& Let's check it with false.
 
modified.github/workflows/forkless-update-nodata.ymldiffbeforeafterboth
--- a/.github/workflows/forkless-update-nodata.yml
+++ b/.github/workflows/forkless-update-nodata.yml
@@ -58,7 +58,7 @@
     # The type of runner that the job will run on
     runs-on: self-hosted-ci
 
-    name: Build Container, Spin it Up an test
+    name: ${{ matrix.network }} - Forkless Parachain Upgrade NO data
 
     continue-on-error: true         #Do not stop testing of matrix runs failed.  As it decided during PR review - it required 50/50& Let's check it with false.
 
@@ -175,7 +175,7 @@
                 fi
                 done
            echo "Halting script"
-           exit 1
+           exit 0
         shell: bash
 
       - name: Collect Docker Logs
modified.github/workflows/node_build_test.ymldiffbeforeafterboth
--- a/.github/workflows/node_build_test.yml
+++ b/.github/workflows/node_build_test.yml
@@ -33,11 +33,11 @@
       matrix:
         include:
           - network: "Opal"
-            features: " "
+            features: "opal-runtime"
           - network: "Quartz"
-            features: "--features=quartz-runtime"
+            features: "quartz-runtime"
           - network: "Unique"
-            features: "--features=unique-runtime"
+            features: "unique-runtime"
 
     steps:
       - name: Skip if pull request is in Draft
addedcrates/struct-versioning/README.mddiffbeforeafterboth
--- /dev/null
+++ b/crates/struct-versioning/README.md
@@ -0,0 +1,62 @@
+# struct-versioning
+
+The crate contains procedural macros for versioning data structures.
+Macros [`versioned`] generate versioned variants of a struct.
+
+Example:
+```
+# use struct_versioning::versioned;
+#[versioned(version = 5, first_version = 2)]
+struct Example {}
+
+// versioned macro will generate suffixed versions of example struct,
+// starting from `Version{first_version or 1}` to `Version{version}` inclusive
+let _ver2 = ExampleVersion2 {};
+let _ver3 = ExampleVersion3 {};
+let _ver4 = ExampleVersion4 {};
+let _ver5 = ExampleVersion5 {};
+
+// last version will also be aliased with original struct name
+let _orig: Example = ExampleVersion5 {};
+
+#[versioned(version = 2, upper)]
+#[derive(PartialEq, Debug)]
+struct Upper {
+    #[version(..2)]
+    removed: u32,
+    #[version(2.., upper(10))]
+    added: u32,
+
+    #[version(..2)]
+    retyped: u32,
+    #[version(2.., upper(retyped as u64))]
+    retyped: u64,
+}
+
+// #[version] attribute on field allows to specify, in which versions of structs this field should present
+// versions here works as standard rust ranges, start is inclusive, end is exclusive
+let _up1 = UpperVersion1 {removed: 1, retyped: 0};
+let _up2 = UpperVersion2 {added: 1, retyped: 0};
+
+// and upper() allows to specify, which value should be assigned to this field in `From<OldVersion>` impl
+assert_eq!(
+    UpperVersion2::from(UpperVersion1 {removed: 0, retyped: 6}),
+    UpperVersion2 {added: 10, retyped: 6},
+);
+```
+
+In this case, the upgrade is described in `on_runtime_upgrade` using the `translate_values` substrate feature
+
+```ignore
+#[pallet::hooks]
+impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
+    fn on_runtime_upgrade() -> Weight {
+        if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
+            <TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {
+                Some(<ItemDataVersion2>::from(v))
+            })
+        }
+        0
+    }
+}
+```
modifiedcrates/struct-versioning/src/lib.rsdiffbeforeafterboth
--- a/crates/struct-versioning/src/lib.rs
+++ b/crates/struct-versioning/src/lib.rs
@@ -1,3 +1,21 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+#![doc = include_str!("../README.md")]
+
 use proc_macro::TokenStream;
 use quote::format_ident;
 use syn::{
modifiedtests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fractionalizer/fractionalizer.test.ts
+++ b/tests/src/eth/fractionalizer/fractionalizer.test.ts
@@ -20,7 +20,7 @@
 import {evmToAddress} from '@polkadot/util-crypto';
 import {readFile} from 'fs/promises';
 import {executeTransaction, submitTransactionAsync} from '../../substrate/substrate-api';
-import {getCreateCollectionResult, getCreateItemResult, UNIQUE} from '../../util/helpers';
+import {getCreateCollectionResult, getCreateItemResult, UNIQUE, requirePallets, Pallets} 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';
@@ -116,6 +116,10 @@
 }
 
 describe('Fractionalizer contract usage', () => {
+  before(async function() {
+    await requirePallets(this, [Pallets.ReFungible]);
+  });
+
   itWeb3('Set RFT collection', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const fractionalizer = await deployFractionalizer(web3, owner);
@@ -224,6 +228,10 @@
 
 
 describe('Negative Integration Tests for fractionalizer', () => {
+  before(async function() {
+    await requirePallets(this, [Pallets.ReFungible]);
+  });
+
   itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);
@@ -467,4 +475,4 @@
     await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100n).call())
       .to.be.rejectedWith(/TransferNotAllowed$/g);
   });
-});
\ No newline at end of file
+});
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
before · tests/src/eth/reFungibleToken.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/>.1617import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';1920import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Refungible token: Information getting', () => {26  before(async function() {27    await requirePallets(this, [Pallets.ReFungible]);28  });2930  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {31    const alice = privateKeyWrapper('//Alice');3233    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;3435    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);3637    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;3839    const address = tokenIdToAddress(collectionId, tokenId);40    const contract = uniqueRefungibleToken(web3, address, caller);41    const totalSupply = await contract.methods.totalSupply().call();4243    expect(totalSupply).to.equal('200');44  });4546  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {47    const alice = privateKeyWrapper('//Alice');4849    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;5051    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);5253    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;5455    const address = tokenIdToAddress(collectionId, tokenId);56    const contract = uniqueRefungibleToken(web3, address, caller);57    const balance = await contract.methods.balanceOf(caller).call();5859    expect(balance).to.equal('200');60  });6162  itWeb3('decimals', async ({api, web3, privateKeyWrapper}) => {63    const alice = privateKeyWrapper('//Alice');6465    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;6667    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);6869    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;7071    const address = tokenIdToAddress(collectionId, tokenId);72    const contract = uniqueRefungibleToken(web3, address, caller);73    const decimals = await contract.methods.decimals().call();7475    expect(decimals).to.equal('0');76  });77});7879// FIXME: Need erc721 for ReFubgible.80describe('Check ERC721 token URI for ReFungible', () => {81  before(async function() {82    await requirePallets(this, [Pallets.ReFungible]);83  });8485  itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {86    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);87    const helper = evmCollectionHelpers(web3, owner);88    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();89    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);90    const receiver = createEthAccount(web3);91    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});9293    const nextTokenId = await contract.methods.nextTokenId().call();94    expect(nextTokenId).to.be.equal('1');95    result = await contract.methods.mint(96      receiver,97      nextTokenId,98    ).send();99100    const events = normalizeEvents(result.events);101    const address = collectionIdToAddress(collectionId);102103    expect(events).to.be.deep.equal([104      {105        address,106        event: 'Transfer',107        args: {108          from: '0x0000000000000000000000000000000000000000',109          to: receiver,110          tokenId: nextTokenId,111        },112      },113    ]);114115    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');116  });117118  itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {119    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);120    const helper = evmCollectionHelpers(web3, owner);121    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();122    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);123    const receiver = createEthAccount(web3);124    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});125126    const nextTokenId = await contract.methods.nextTokenId().call();127    expect(nextTokenId).to.be.equal('1');128    result = await contract.methods.mint(129      receiver,130      nextTokenId,131    ).send();132133    // Set URL134    await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();135136    const events = normalizeEvents(result.events);137    const address = collectionIdToAddress(collectionId);138139    expect(events).to.be.deep.equal([140      {141        address,142        event: 'Transfer',143        args: {144          from: '0x0000000000000000000000000000000000000000',145          to: receiver,146          tokenId: nextTokenId,147        },148      },149    ]);150151    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');152  });153154  itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {155    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);156    const helper = evmCollectionHelpers(web3, owner);157    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();158    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);159    const receiver = createEthAccount(web3);160    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});161162    const nextTokenId = await contract.methods.nextTokenId().call();163    expect(nextTokenId).to.be.equal('1');164    result = await contract.methods.mint(165      receiver,166      nextTokenId,167    ).send();168169    const events = normalizeEvents(result.events);170    const address = collectionIdToAddress(collectionId);171172    expect(events).to.be.deep.equal([173      {174        address,175        event: 'Transfer',176        args: {177          from: '0x0000000000000000000000000000000000000000',178          to: receiver,179          tokenId: nextTokenId,180        },181      },182    ]);183184    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);185  });186187  itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {188    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);189    const helper = evmCollectionHelpers(web3, owner);190    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();191    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);192    const receiver = createEthAccount(web3);193    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});194195    const nextTokenId = await contract.methods.nextTokenId().call();196    expect(nextTokenId).to.be.equal('1');197    result = await contract.methods.mint(198      receiver,199      nextTokenId,200    ).send();201202    // Set suffix203    const suffix = '/some/suffix';204    await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();205206    const events = normalizeEvents(result.events);207    const address = collectionIdToAddress(collectionId);208209    expect(events).to.be.deep.equal([210      {211        address,212        event: 'Transfer',213        args: {214          from: '0x0000000000000000000000000000000000000000',215          to: receiver,216          tokenId: nextTokenId,217        },218      },219    ]);220221    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);222  });223});224225describe('Refungible: Plain calls', () => {226  before(async function() {227    await requirePallets(this, [Pallets.ReFungible]);228  });229230  itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {231    const alice = privateKeyWrapper('//Alice');232233    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;234235    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);236237    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;238239    const address = tokenIdToAddress(collectionId, tokenId);240241    const spender = createEthAccount(web3);242243    const contract = uniqueRefungibleToken(web3, address, owner);244245    {246      const result = await contract.methods.approve(spender, 100).send({from: owner});247      const events = normalizeEvents(result.events);248249      expect(events).to.be.deep.equal([250        {251          address,252          event: 'Approval',253          args: {254            owner,255            spender,256            value: '100',257          },258        },259      ]);260    }261262    {263      const allowance = await contract.methods.allowance(owner, spender).call();264      expect(+allowance).to.equal(100);265    }266  });267268  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {269    const alice = privateKeyWrapper('//Alice');270271    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;272273    const owner = createEthAccount(web3);274    await transferBalanceToEth(api, alice, owner);275276    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;277278    const spender = createEthAccount(web3);279    await transferBalanceToEth(api, alice, spender);280281    const receiver = createEthAccount(web3);282283    const address = tokenIdToAddress(collectionId, tokenId);284    const contract = uniqueRefungibleToken(web3, address, owner);285286    await contract.methods.approve(spender, 100).send();287288    {289      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});290      const events = normalizeEvents(result.events);291      expect(events).to.include.deep.members([292        {293          address,294          event: 'Transfer',295          args: {296            from: owner,297            to: receiver,298            value: '49',299          },300        },301        {302          address,303          event: 'Approval',304          args: {305            owner,306            spender,307            value: '51',308          },309        },310      ]);311    }312313    {314      const balance = await contract.methods.balanceOf(receiver).call();315      expect(+balance).to.equal(49);316    }317318    {319      const balance = await contract.methods.balanceOf(owner).call();320      expect(+balance).to.equal(151);321    }322  });323324  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {325    const alice = privateKeyWrapper('//Alice');326327    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;328329    const owner = createEthAccount(web3);330    await transferBalanceToEth(api, alice, owner);331332    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;333334    const receiver = createEthAccount(web3);335    await transferBalanceToEth(api, alice, receiver);336337    const address = tokenIdToAddress(collectionId, tokenId);338    const contract = uniqueRefungibleToken(web3, address, owner);339340    {341      const result = await contract.methods.transfer(receiver, 50).send({from: owner});342      const events = normalizeEvents(result.events);343      expect(events).to.include.deep.members([344        {345          address,346          event: 'Transfer',347          args: {348            from: owner,349            to: receiver,350            value: '50',351          },352        },353      ]);354    }355356    {357      const balance = await contract.methods.balanceOf(owner).call();358      expect(+balance).to.equal(150);359    }360361    {362      const balance = await contract.methods.balanceOf(receiver).call();363      expect(+balance).to.equal(50);364    }365  });366367  itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {368    const alice = privateKeyWrapper('//Alice');369370    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;371372    const owner = createEthAccount(web3);373    await transferBalanceToEth(api, alice, owner);374375    const receiver = createEthAccount(web3);376    await transferBalanceToEth(api, alice, receiver);377378    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;379380    const address = tokenIdToAddress(collectionId, tokenId);381    const contract = uniqueRefungibleToken(web3, address, owner);382383    await contract.methods.repartition(200).send({from: owner});384    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);385    await contract.methods.transfer(receiver, 110).send({from: owner});386    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);387    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);388389    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;390391    await contract.methods.transfer(receiver, 90).send({from: owner});392    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);393    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);394395    await contract.methods.repartition(150).send({from: receiver});396    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;397    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);398  });399400  itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {401    const alice = privateKeyWrapper('//Alice');402403    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;404405    const owner = createEthAccount(web3);406    await transferBalanceToEth(api, alice, owner);407408    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;409410    const address = tokenIdToAddress(collectionId, tokenId);411    const contract = uniqueRefungibleToken(web3, address, owner);412413    const result = await contract.methods.repartition(200).send();414    const events = normalizeEvents(result.events);415416    expect(events).to.deep.equal([417      {418        address,419        event: 'Transfer',420        args: {421          from: '0x0000000000000000000000000000000000000000',422          to: owner,423          value: '100',424        },425      },426    ]);427  });428429  itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {430    const alice = privateKeyWrapper('//Alice');431432    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;433434    const owner = createEthAccount(web3);435    await transferBalanceToEth(api, alice, owner);436437    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;438439    const address = tokenIdToAddress(collectionId, tokenId);440    const contract = uniqueRefungibleToken(web3, address, owner);441442    const result = await contract.methods.repartition(50).send();443    const events = normalizeEvents(result.events);444    expect(events).to.deep.equal([445      {446        address,447        event: 'Transfer',448        args: {449          from: owner,450          to: '0x0000000000000000000000000000000000000000',451          value: '50',452        },453      },454    ]);455  });456457  itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {458    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);459    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);460    const helper = evmCollectionHelpers(web3, caller);461    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();462    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);463    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});464465    const tokenId = await contract.methods.nextTokenId().call();466    await contract.methods.mint(caller, tokenId).send();467468    const address = tokenIdToAddress(collectionId, tokenId);469470    const tokenContract =  uniqueRefungibleToken(web3, address, caller);471    await tokenContract.methods.repartition(2).send();472    await tokenContract.methods.transfer(receiver, 1).send();473474    const events =  await recordEvents(contract, async () =>475      await tokenContract.methods.burnFrom(caller, 1).send());476    expect(events).to.deep.equal([477      {478        address: collectionIdAddress,479        event: 'Transfer',480        args: {481          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',482          to: receiver,483          tokenId,484        },485      },486    ]);487  });488});489490describe('Refungible: Fees', () => {491  before(async function() {492    await requirePallets(this, [Pallets.ReFungible]);493  });494495  itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {496    const alice = privateKeyWrapper('//Alice');497498    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;499500    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);501    const spender = createEthAccount(web3);502503    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;504505    const address = tokenIdToAddress(collectionId, tokenId);506    const contract = uniqueRefungibleToken(web3, address, owner);507508    const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));509    expect(cost < BigInt(0.2 * Number(UNIQUE)));510  });511512  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {513    const alice = privateKeyWrapper('//Alice');514515    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;516517    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);518    const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);519520    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;521522    const address = tokenIdToAddress(collectionId, tokenId);523    const contract = uniqueRefungibleToken(web3, address, owner);524525    await contract.methods.approve(spender, 100).send({from: owner});526527    const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));528    expect(cost < BigInt(0.2 * Number(UNIQUE)));529  });530531  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {532    const alice = privateKeyWrapper('//Alice');533534    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;535536    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);537    const receiver = createEthAccount(web3);538539    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;540541    const address = tokenIdToAddress(collectionId, tokenId);542    const contract = uniqueRefungibleToken(web3, address, owner);543544    const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));545    expect(cost < BigInt(0.2 * Number(UNIQUE)));546  });547});548549describe('Refungible: Substrate calls', () => {550  before(async function() {551    await requirePallets(this, [Pallets.ReFungible]);552  });553554  itWeb3('Events emitted for approve()', async ({web3, api, privateKeyWrapper}) => {555    const alice = privateKeyWrapper('//Alice');556557    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;558559    const receiver = createEthAccount(web3);560561    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;562563    const address = tokenIdToAddress(collectionId, tokenId);564    const contract = uniqueRefungibleToken(web3, address);565566    const events = await recordEvents(contract, async () => {567      expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;568    });569570    expect(events).to.be.deep.equal([571      {572        address,573        event: 'Approval',574        args: {575          owner: subToEth(alice.address),576          spender: receiver,577          value: '100',578        },579      },580    ]);581  });582583  itWeb3('Events emitted for transferFrom()', async ({web3, api, privateKeyWrapper}) => {584    const alice = privateKeyWrapper('//Alice');585586    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;587    const bob = privateKeyWrapper('//Bob');588589    const receiver = createEthAccount(web3);590591    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;592    expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;593594    const address = tokenIdToAddress(collectionId, tokenId);595    const contract = uniqueRefungibleToken(web3, address);596597    const events = await recordEvents(contract, async () => {598      expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver},  51n)).to.be.true;599    });600601    expect(events).to.be.deep.equal([602      {603        address,604        event: 'Transfer',605        args: {606          from: subToEth(alice.address),607          to: receiver,608          value: '51',609        },610      },611      {612        address,613        event: 'Approval',614        args: {615          owner: subToEth(alice.address),616          spender: subToEth(bob.address),617          value: '49',618        },619      },620    ]);621  });622623  itWeb3('Events emitted for transfer()', async ({web3, api, privateKeyWrapper}) => {624    const alice = privateKeyWrapper('//Alice');625626    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;627628    const receiver = createEthAccount(web3);629630    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;631632    const address = tokenIdToAddress(collectionId, tokenId);633    const contract = uniqueRefungibleToken(web3, address);634635    const events = await recordEvents(contract, async () => {636      expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver},  51n)).to.be.true;637    });638639    expect(events).to.be.deep.equal([640      {641        address,642        event: 'Transfer',643        args: {644          from: subToEth(alice.address),645          to: receiver,646          value: '51',647        },648      },649    ]);650  });651});652653describe('ERC 1633 implementation', () => {654  itWeb3('Parent NFT token address and id', async ({api, web3, privateKeyWrapper}) => {655    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);656657    const {collectionIdAddress:  nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);658    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);659    const nftTokenId = await nftContract.methods.nextTokenId().call();660    await nftContract.methods.mint(owner, nftTokenId).send();661    const nftCollectionId = collectionIdFromAddress(nftCollectionAddress);662663    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);664    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);665    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();666    await refungibleContract.methods.mint(owner, refungibleTokenId).send();667668    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);669    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);670    await refungibleTokenContract.methods.setParentNFT(nftCollectionAddress, nftTokenId).send();671672    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();673    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();674    const nftTokenAddress = tokenIdToAddress(nftCollectionId, nftTokenId);675    expect(tokenAddress).to.be.equal(nftTokenAddress);676    expect(tokenId).to.be.equal(nftTokenId);677  });678679  itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {680    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);681682    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);683    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);684    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();685    await refungibleContract.methods.mint(owner, refungibleTokenId).send();686687    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);688    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);689690    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();691    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();692    expect(tokenAddress).to.be.equal(rftTokenAddress);693    expect(tokenId).to.be.equal(refungibleTokenId);694  });695});
after · tests/src/eth/reFungibleToken.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/>.1617import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';1920import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Refungible token: Information getting', () => {26  before(async function() {27    await requirePallets(this, [Pallets.ReFungible]);28  });2930  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {31    const alice = privateKeyWrapper('//Alice');3233    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;3435    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);3637    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;3839    const address = tokenIdToAddress(collectionId, tokenId);40    const contract = uniqueRefungibleToken(web3, address, caller);41    const totalSupply = await contract.methods.totalSupply().call();4243    expect(totalSupply).to.equal('200');44  });4546  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {47    const alice = privateKeyWrapper('//Alice');4849    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;5051    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);5253    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;5455    const address = tokenIdToAddress(collectionId, tokenId);56    const contract = uniqueRefungibleToken(web3, address, caller);57    const balance = await contract.methods.balanceOf(caller).call();5859    expect(balance).to.equal('200');60  });6162  itWeb3('decimals', async ({api, web3, privateKeyWrapper}) => {63    const alice = privateKeyWrapper('//Alice');6465    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;6667    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);6869    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;7071    const address = tokenIdToAddress(collectionId, tokenId);72    const contract = uniqueRefungibleToken(web3, address, caller);73    const decimals = await contract.methods.decimals().call();7475    expect(decimals).to.equal('0');76  });77});7879// FIXME: Need erc721 for ReFubgible.80describe('Check ERC721 token URI for ReFungible', () => {81  before(async function() {82    await requirePallets(this, [Pallets.ReFungible]);83  });8485  itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {86    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);87    const helper = evmCollectionHelpers(web3, owner);88    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();89    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);90    const receiver = createEthAccount(web3);91    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});9293    const nextTokenId = await contract.methods.nextTokenId().call();94    expect(nextTokenId).to.be.equal('1');95    result = await contract.methods.mint(96      receiver,97      nextTokenId,98    ).send();99100    const events = normalizeEvents(result.events);101    const address = collectionIdToAddress(collectionId);102103    expect(events).to.be.deep.equal([104      {105        address,106        event: 'Transfer',107        args: {108          from: '0x0000000000000000000000000000000000000000',109          to: receiver,110          tokenId: nextTokenId,111        },112      },113    ]);114115    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');116  });117118  itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {119    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);120    const helper = evmCollectionHelpers(web3, owner);121    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();122    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);123    const receiver = createEthAccount(web3);124    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});125126    const nextTokenId = await contract.methods.nextTokenId().call();127    expect(nextTokenId).to.be.equal('1');128    result = await contract.methods.mint(129      receiver,130      nextTokenId,131    ).send();132133    // Set URL134    await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();135136    const events = normalizeEvents(result.events);137    const address = collectionIdToAddress(collectionId);138139    expect(events).to.be.deep.equal([140      {141        address,142        event: 'Transfer',143        args: {144          from: '0x0000000000000000000000000000000000000000',145          to: receiver,146          tokenId: nextTokenId,147        },148      },149    ]);150151    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');152  });153154  itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {155    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);156    const helper = evmCollectionHelpers(web3, owner);157    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();158    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);159    const receiver = createEthAccount(web3);160    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});161162    const nextTokenId = await contract.methods.nextTokenId().call();163    expect(nextTokenId).to.be.equal('1');164    result = await contract.methods.mint(165      receiver,166      nextTokenId,167    ).send();168169    const events = normalizeEvents(result.events);170    const address = collectionIdToAddress(collectionId);171172    expect(events).to.be.deep.equal([173      {174        address,175        event: 'Transfer',176        args: {177          from: '0x0000000000000000000000000000000000000000',178          to: receiver,179          tokenId: nextTokenId,180        },181      },182    ]);183184    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);185  });186187  itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {188    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);189    const helper = evmCollectionHelpers(web3, owner);190    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();191    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);192    const receiver = createEthAccount(web3);193    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});194195    const nextTokenId = await contract.methods.nextTokenId().call();196    expect(nextTokenId).to.be.equal('1');197    result = await contract.methods.mint(198      receiver,199      nextTokenId,200    ).send();201202    // Set suffix203    const suffix = '/some/suffix';204    await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();205206    const events = normalizeEvents(result.events);207    const address = collectionIdToAddress(collectionId);208209    expect(events).to.be.deep.equal([210      {211        address,212        event: 'Transfer',213        args: {214          from: '0x0000000000000000000000000000000000000000',215          to: receiver,216          tokenId: nextTokenId,217        },218      },219    ]);220221    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);222  });223});224225describe('Refungible: Plain calls', () => {226  before(async function() {227    await requirePallets(this, [Pallets.ReFungible]);228  });229230  itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {231    const alice = privateKeyWrapper('//Alice');232233    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;234235    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);236237    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;238239    const address = tokenIdToAddress(collectionId, tokenId);240241    const spender = createEthAccount(web3);242243    const contract = uniqueRefungibleToken(web3, address, owner);244245    {246      const result = await contract.methods.approve(spender, 100).send({from: owner});247      const events = normalizeEvents(result.events);248249      expect(events).to.be.deep.equal([250        {251          address,252          event: 'Approval',253          args: {254            owner,255            spender,256            value: '100',257          },258        },259      ]);260    }261262    {263      const allowance = await contract.methods.allowance(owner, spender).call();264      expect(+allowance).to.equal(100);265    }266  });267268  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {269    const alice = privateKeyWrapper('//Alice');270271    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;272273    const owner = createEthAccount(web3);274    await transferBalanceToEth(api, alice, owner);275276    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;277278    const spender = createEthAccount(web3);279    await transferBalanceToEth(api, alice, spender);280281    const receiver = createEthAccount(web3);282283    const address = tokenIdToAddress(collectionId, tokenId);284    const contract = uniqueRefungibleToken(web3, address, owner);285286    await contract.methods.approve(spender, 100).send();287288    {289      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});290      const events = normalizeEvents(result.events);291      expect(events).to.include.deep.members([292        {293          address,294          event: 'Transfer',295          args: {296            from: owner,297            to: receiver,298            value: '49',299          },300        },301        {302          address,303          event: 'Approval',304          args: {305            owner,306            spender,307            value: '51',308          },309        },310      ]);311    }312313    {314      const balance = await contract.methods.balanceOf(receiver).call();315      expect(+balance).to.equal(49);316    }317318    {319      const balance = await contract.methods.balanceOf(owner).call();320      expect(+balance).to.equal(151);321    }322  });323324  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {325    const alice = privateKeyWrapper('//Alice');326327    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;328329    const owner = createEthAccount(web3);330    await transferBalanceToEth(api, alice, owner);331332    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;333334    const receiver = createEthAccount(web3);335    await transferBalanceToEth(api, alice, receiver);336337    const address = tokenIdToAddress(collectionId, tokenId);338    const contract = uniqueRefungibleToken(web3, address, owner);339340    {341      const result = await contract.methods.transfer(receiver, 50).send({from: owner});342      const events = normalizeEvents(result.events);343      expect(events).to.include.deep.members([344        {345          address,346          event: 'Transfer',347          args: {348            from: owner,349            to: receiver,350            value: '50',351          },352        },353      ]);354    }355356    {357      const balance = await contract.methods.balanceOf(owner).call();358      expect(+balance).to.equal(150);359    }360361    {362      const balance = await contract.methods.balanceOf(receiver).call();363      expect(+balance).to.equal(50);364    }365  });366367  itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {368    const alice = privateKeyWrapper('//Alice');369370    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;371372    const owner = createEthAccount(web3);373    await transferBalanceToEth(api, alice, owner);374375    const receiver = createEthAccount(web3);376    await transferBalanceToEth(api, alice, receiver);377378    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;379380    const address = tokenIdToAddress(collectionId, tokenId);381    const contract = uniqueRefungibleToken(web3, address, owner);382383    await contract.methods.repartition(200).send({from: owner});384    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);385    await contract.methods.transfer(receiver, 110).send({from: owner});386    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);387    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);388389    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;390391    await contract.methods.transfer(receiver, 90).send({from: owner});392    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);393    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);394395    await contract.methods.repartition(150).send({from: receiver});396    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;397    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);398  });399400  itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {401    const alice = privateKeyWrapper('//Alice');402403    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;404405    const owner = createEthAccount(web3);406    await transferBalanceToEth(api, alice, owner);407408    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;409410    const address = tokenIdToAddress(collectionId, tokenId);411    const contract = uniqueRefungibleToken(web3, address, owner);412413    const result = await contract.methods.repartition(200).send();414    const events = normalizeEvents(result.events);415416    expect(events).to.deep.equal([417      {418        address,419        event: 'Transfer',420        args: {421          from: '0x0000000000000000000000000000000000000000',422          to: owner,423          value: '100',424        },425      },426    ]);427  });428429  itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {430    const alice = privateKeyWrapper('//Alice');431432    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;433434    const owner = createEthAccount(web3);435    await transferBalanceToEth(api, alice, owner);436437    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;438439    const address = tokenIdToAddress(collectionId, tokenId);440    const contract = uniqueRefungibleToken(web3, address, owner);441442    const result = await contract.methods.repartition(50).send();443    const events = normalizeEvents(result.events);444    expect(events).to.deep.equal([445      {446        address,447        event: 'Transfer',448        args: {449          from: owner,450          to: '0x0000000000000000000000000000000000000000',451          value: '50',452        },453      },454    ]);455  });456457  itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {458    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);459    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);460    const helper = evmCollectionHelpers(web3, caller);461    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();462    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);463    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});464465    const tokenId = await contract.methods.nextTokenId().call();466    await contract.methods.mint(caller, tokenId).send();467468    const address = tokenIdToAddress(collectionId, tokenId);469470    const tokenContract =  uniqueRefungibleToken(web3, address, caller);471    await tokenContract.methods.repartition(2).send();472    await tokenContract.methods.transfer(receiver, 1).send();473474    const events =  await recordEvents(contract, async () =>475      await tokenContract.methods.burnFrom(caller, 1).send());476    expect(events).to.deep.equal([477      {478        address: collectionIdAddress,479        event: 'Transfer',480        args: {481          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',482          to: receiver,483          tokenId,484        },485      },486    ]);487  });488});489490describe('Refungible: Fees', () => {491  before(async function() {492    await requirePallets(this, [Pallets.ReFungible]);493  });494495  itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {496    const alice = privateKeyWrapper('//Alice');497498    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;499500    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);501    const spender = createEthAccount(web3);502503    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;504505    const address = tokenIdToAddress(collectionId, tokenId);506    const contract = uniqueRefungibleToken(web3, address, owner);507508    const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));509    expect(cost < BigInt(0.2 * Number(UNIQUE)));510  });511512  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {513    const alice = privateKeyWrapper('//Alice');514515    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;516517    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);518    const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);519520    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;521522    const address = tokenIdToAddress(collectionId, tokenId);523    const contract = uniqueRefungibleToken(web3, address, owner);524525    await contract.methods.approve(spender, 100).send({from: owner});526527    const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));528    expect(cost < BigInt(0.2 * Number(UNIQUE)));529  });530531  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {532    const alice = privateKeyWrapper('//Alice');533534    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;535536    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);537    const receiver = createEthAccount(web3);538539    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;540541    const address = tokenIdToAddress(collectionId, tokenId);542    const contract = uniqueRefungibleToken(web3, address, owner);543544    const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));545    expect(cost < BigInt(0.2 * Number(UNIQUE)));546  });547});548549describe('Refungible: Substrate calls', () => {550  before(async function() {551    await requirePallets(this, [Pallets.ReFungible]);552  });553554  itWeb3('Events emitted for approve()', async ({web3, api, privateKeyWrapper}) => {555    const alice = privateKeyWrapper('//Alice');556557    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;558559    const receiver = createEthAccount(web3);560561    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;562563    const address = tokenIdToAddress(collectionId, tokenId);564    const contract = uniqueRefungibleToken(web3, address);565566    const events = await recordEvents(contract, async () => {567      expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;568    });569570    expect(events).to.be.deep.equal([571      {572        address,573        event: 'Approval',574        args: {575          owner: subToEth(alice.address),576          spender: receiver,577          value: '100',578        },579      },580    ]);581  });582583  itWeb3('Events emitted for transferFrom()', async ({web3, api, privateKeyWrapper}) => {584    const alice = privateKeyWrapper('//Alice');585586    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;587    const bob = privateKeyWrapper('//Bob');588589    const receiver = createEthAccount(web3);590591    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;592    expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;593594    const address = tokenIdToAddress(collectionId, tokenId);595    const contract = uniqueRefungibleToken(web3, address);596597    const events = await recordEvents(contract, async () => {598      expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver},  51n)).to.be.true;599    });600601    expect(events).to.be.deep.equal([602      {603        address,604        event: 'Transfer',605        args: {606          from: subToEth(alice.address),607          to: receiver,608          value: '51',609        },610      },611      {612        address,613        event: 'Approval',614        args: {615          owner: subToEth(alice.address),616          spender: subToEth(bob.address),617          value: '49',618        },619      },620    ]);621  });622623  itWeb3('Events emitted for transfer()', async ({web3, api, privateKeyWrapper}) => {624    const alice = privateKeyWrapper('//Alice');625626    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;627628    const receiver = createEthAccount(web3);629630    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;631632    const address = tokenIdToAddress(collectionId, tokenId);633    const contract = uniqueRefungibleToken(web3, address);634635    const events = await recordEvents(contract, async () => {636      expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver},  51n)).to.be.true;637    });638639    expect(events).to.be.deep.equal([640      {641        address,642        event: 'Transfer',643        args: {644          from: subToEth(alice.address),645          to: receiver,646          value: '51',647        },648      },649    ]);650  });651});652653describe('ERC 1633 implementation', () => {654  before(async function() {655    await requirePallets(this, [Pallets.ReFungible]);656  });657658  itWeb3('Parent NFT token address and id', async ({api, web3, privateKeyWrapper}) => {659    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);660661    const {collectionIdAddress:  nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);662    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);663    const nftTokenId = await nftContract.methods.nextTokenId().call();664    await nftContract.methods.mint(owner, nftTokenId).send();665    const nftCollectionId = collectionIdFromAddress(nftCollectionAddress);666667    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);668    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);669    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();670    await refungibleContract.methods.mint(owner, refungibleTokenId).send();671672    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);673    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);674    await refungibleTokenContract.methods.setParentNFT(nftCollectionAddress, nftTokenId).send();675676    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();677    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();678    const nftTokenAddress = tokenIdToAddress(nftCollectionId, nftTokenId);679    expect(tokenAddress).to.be.equal(nftTokenAddress);680    expect(tokenId).to.be.equal(nftTokenId);681  });682683  itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {684    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);685686    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);687    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);688    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();689    await refungibleContract.methods.mint(owner, refungibleTokenId).send();690691    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);692    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);693694    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();695    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();696    expect(tokenAddress).to.be.equal(rftTokenAddress);697    expect(tokenId).to.be.equal(refungibleTokenId);698  });699});
modifiedtests/src/evmCoder.test.tsdiffbeforeafterboth
--- a/tests/src/evmCoder.test.ts
+++ b/tests/src/evmCoder.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import Web3 from 'web3';
-import {createEthAccountWithBalance, createRefungibleCollection, GAS_ARGS, itWeb3} from './eth/util/helpers';
+import {createEthAccountWithBalance, createNonfungibleCollection, GAS_ARGS, itWeb3} from './eth/util/helpers';
 import * as solc from 'solc';
 
 import chai from 'chai';
@@ -92,7 +92,7 @@
 describe('Evm Coder tests', () => {
   itWeb3('Call non-existing function', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);
+    const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);
     const contract = await deployTestContract(web3, owner, collectionIdAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c');
     const testContract = await deployTestContract(web3, owner, collectionIdAddress, contract.options.address);
     {
@@ -114,4 +114,4 @@
         .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);
     }
   });
-});
\ No newline at end of file
+});