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

difftreelog

Merge pull request #835 from UniqueNetwork/tests/generalization

Yaroslav Bolyukin2023-01-18parents: #d161923 #5954afe.patch.diff
in: master

20 files changed

modifiedtests/src/apiConsts.test.tsdiffbeforeafterboth
--- a/tests/src/apiConsts.test.ts
+++ b/tests/src/apiConsts.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {ApiPromise} from '@polkadot/api';
-import {usingPlaygrounds, itSub, expect} from './util';
+import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';
 
 
 const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
@@ -40,9 +40,6 @@
   ownerCanDestroy: true,
   transfersEnabled: true,
 };
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
-const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
 
 describe('integration test: API UNIQUE consts', () => {
   let api: ApiPromise;
@@ -106,11 +103,11 @@
   });
 
   itSub('HELPERS_CONTRACT_ADDRESS', () => {
-    expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());
+    expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());
   });
 
   itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {
-    expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());
+    expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());
   });
 });
 
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -45,32 +45,6 @@
     await collection.burnTokens(alice, 1n);
     expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
   });
-
-  itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
-    const collection = await helper.rft.mintCollection(alice);
-    const token = await collection.mintToken(alice, 100n);
-
-    await token.burn(alice, 90n);
-    expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
-
-    await token.burn(alice, 10n);
-    expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
-  });
-
-  itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
-    const collection = await helper.rft.mintCollection(alice);
-    const token = await collection.mintToken(alice, 100n);
-
-    await token.transfer(alice, {Substrate: bob.address}, 1n);
-
-    expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
-    expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
-
-    await token.burn(bob, 1n);
-
-    expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
-    expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
-  });
 });
 
 describe('integration test: ext. burnItem() with admin permissions:', () => {
@@ -104,16 +78,6 @@
     await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);
     expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
   });
-
-  itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
-    const collection = await helper.rft.mintCollection(alice);
-    await collection.setLimits(alice, {ownerCanTransfer: true});
-    await collection.addAdmin(alice, {Substrate: bob.address});
-    const token = await collection.mintToken(alice, 100n);
-
-    await token.burnFrom(bob, {Substrate: alice.address}, 100n);
-    expect(await token.doesExist()).to.be.false;
-  });
 });
 
 describe('Negative integration test: ext. burnItem():', () => {
@@ -138,31 +102,6 @@
     const token = await collection.mintToken(alice);
 
     await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
-  });
-
-  itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice);
-    const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
-    const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
-    // 1. Cannot burn non-owned token:
-    await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
-    await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
-    // 2. Cannot burn non-existing token:
-    await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
-    await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
-    // 3. Can burn zero amount of owned tokens (EIP-20)
-    await aliceToken.burn(alice, 0n);
-
-    // 4. Storage is not corrupted:
-    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
-    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-
-    // 4.1 Tokens can be transfered:
-    await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
-    await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
-    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
   });
 
   itSub('Transfer a burned token', async ({helper}) => {
modifiedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionHelperAddress.test.ts
+++ b/tests/src/eth/collectionHelperAddress.test.ts
@@ -16,9 +16,7 @@
 
 import {itEth, usingEthPlaygrounds, expect} from './util';
 import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets} from '../util';
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+import {COLLECTION_HELPER, Pallets} from '../util';
 
 describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
   let donor: IKeyringPair;
@@ -36,7 +34,7 @@
     const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
 
     expect((await nftCollection.methods.collectionHelperAddress().call())
-      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
   });
 
   itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
@@ -46,7 +44,7 @@
 
     const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
     expect((await rftCollection.methods.collectionHelperAddress().call())
-      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
   });
 
   itEth('FT', async ({helper}) => {
@@ -56,7 +54,7 @@
     const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
 
     expect((await collection.methods.collectionHelperAddress().call())
-      .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+      .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
   });
 
   itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -18,6 +18,7 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {expect, itEth, usingEthPlaygrounds} from './util';
 import {CollectionLimitField} from './util/playgrounds/types';
+import {COLLECTION_HELPER} from '../util';
 
 
 describe('Create NFT collection from EVM', () => {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -17,38 +17,6 @@
 import {expect, itEth, usingEthPlaygrounds} from './util';
 import {IKeyringPair} from '@polkadot/types/types';
 
-describe('Fungible: Information getting', () => {
-  let donor: IKeyringPair;
-  let alice: IKeyringPair;
-
-  before(async function() {
-    await usingEthPlaygrounds(async (helper, privateKey) => {
-      donor = await privateKey({filename: __filename});
-      [alice] = await helper.arrange.createAccounts([20n], donor);
-    });
-  });
-
-  itEth('totalSupply', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.ft.mintCollection(alice);
-    await collection.mint(alice, 200n);
-
-    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
-    const totalSupply = await contract.methods.totalSupply().call();
-    expect(totalSupply).to.equal('200');
-  });
-
-  itEth('balanceOf', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.ft.mintCollection(alice);
-    await collection.mint(alice, 200n, {Ethereum: caller});
-
-    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
-    const balance = await contract.methods.balanceOf(caller).call();
-    expect(balance).to.equal('200');
-  });
-});
-
 describe('Fungible: Plain calls', () => {
   let donor: IKeyringPair;
   let alice: IKeyringPair;
@@ -59,24 +27,6 @@
       donor = await privateKey({filename: __filename});
       [alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);
     });
-  });
-
-  itEth('Can perform mint()', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const receiver = helper.eth.createAccount();
-    const collection = await helper.ft.mintCollection(alice);
-    await collection.addAdmin(alice, {Ethereum: owner});
-
-    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
-
-    const result = await contract.methods.mint(receiver, 100).send();
-
-    const event = result.events.Transfer;
-    expect(event.address).to.equal(collectionAddress);
-    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
-    expect(event.returnValues.to).to.equal(receiver);
-    expect(event.returnValues.value).to.equal('100');
   });
 
   [
addedtests/src/eth/getCode.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/getCode.test.ts
@@ -0,0 +1,53 @@
+// 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/>.
+
+import {expect, itEth, usingEthPlaygrounds} from './util';
+import {IKeyringPair} from '@polkadot/types/types';
+import {COLLECTION_HELPER, CONTRACT_HELPER} from '../util';
+
+describe('RPC eth_getCode', () => {
+  let donor: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+    });
+  });
+
+  [
+    {address: COLLECTION_HELPER},
+    {address: CONTRACT_HELPER},
+  ].map(testCase => {
+    itEth(`returns value for native contract: ${testCase.address}`, async ({helper}) => {
+      const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [testCase.address])).toJSON();
+      const contractCodeEth = (await helper.getWeb3().eth.getCode(testCase.address));
+
+      expect(contractCodeSub).to.has.length.greaterThan(4);
+      expect(contractCodeEth).to.has.length.greaterThan(4);
+    });
+  });
+
+  itEth('returns value for custom contract', async ({helper}) => {
+    const signer = await helper.eth.createAccountWithBalance(donor);
+    const flipper = await helper.eth.deployFlipper(signer);
+
+    const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [flipper.options.address])).toJSON();
+    const contractCodeEth = (await helper.getWeb3().eth.getCode(flipper.options.address));
+
+    expect(contractCodeSub).to.has.length.greaterThan(4);
+    expect(contractCodeEth).to.has.length.greaterThan(4);
+  });
+});
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/nonFungible.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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';212223describe('NFT: Information getting', () => {24  let donor: IKeyringPair;25  let alice: IKeyringPair;2627  before(async function() {28    await usingEthPlaygrounds(async (helper, privateKey) => {29      donor = await privateKey({filename: __filename});30      [alice] = await helper.arrange.createAccounts([10n], donor);31    });32  });3334  itEth('totalSupply', async ({helper}) => {35    const collection = await helper.nft.mintCollection(alice, {});36    await collection.mintToken(alice);3738    const caller = await helper.eth.createAccountWithBalance(donor);3940    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);41    const totalSupply = await contract.methods.totalSupply().call();4243    expect(totalSupply).to.equal('1');44  });4546  itEth('balanceOf', async ({helper}) => {47    const collection = await helper.nft.mintCollection(alice, {});48    const caller = await helper.eth.createAccountWithBalance(donor);4950    await collection.mintToken(alice, {Ethereum: caller});51    await collection.mintToken(alice, {Ethereum: caller});52    await collection.mintToken(alice, {Ethereum: caller});5354    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);55    const balance = await contract.methods.balanceOf(caller).call();5657    expect(balance).to.equal('3');58  });5960  itEth('ownerOf', async ({helper}) => {61    const collection = await helper.nft.mintCollection(alice, {});62    const caller = await helper.eth.createAccountWithBalance(donor);6364    const token = await collection.mintToken(alice, {Ethereum: caller});6566    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6768    const owner = await contract.methods.ownerOf(token.tokenId).call();6970    expect(owner).to.equal(caller);71  });7273  itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {74    const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});75    const caller = helper.eth.createAccount();7677    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7879    expect(await contract.methods.name().call()).to.equal('test');80    expect(await contract.methods.symbol().call()).to.equal('TEST');81  });82});8384describe('Check ERC721 token URI for NFT', () => {85  let donor: IKeyringPair;8687  before(async function() {88    await usingEthPlaygrounds(async (_helper, privateKey) => {89      donor = await privateKey({filename: __filename});90    });91  });9293  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {94    const owner = await helper.eth.createAccountWithBalance(donor);95    const receiver = helper.eth.createAccount();9697    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);98    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);99100    const result = await contract.methods.mint(receiver).send();101    const tokenId = result.events.Transfer.returnValues.tokenId;102    expect(tokenId).to.be.equal('1');103104    if (propertyKey && propertyValue) {105      // Set URL or suffix106      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();107    }108109    const event = result.events.Transfer;110    expect(event.address).to.be.equal(collectionAddress);111    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');112    expect(event.returnValues.to).to.be.equal(receiver);113    expect(event.returnValues.tokenId).to.be.equal(tokenId);114115    return {contract, nextTokenId: tokenId};116  }117118  itEth('Empty tokenURI', async ({helper}) => {119    const {contract, nextTokenId} = await setup(helper, '');120    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');121  });122123  itEth('TokenURI from url', async ({helper}) => {124    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');125    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');126  });127128  itEth('TokenURI from baseURI', async ({helper}) => {129    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');130    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');131  });132133  itEth('TokenURI from baseURI + suffix', async ({helper}) => {134    const suffix = '/some/suffix';135    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);136    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);137  });138});139140describe('NFT: Plain calls', () => {141  let donor: IKeyringPair;142  let minter: IKeyringPair;143  let bob: IKeyringPair;144  let charlie: IKeyringPair;145146  before(async function() {147    await usingEthPlaygrounds(async (helper, privateKey) => {148      donor = await privateKey({filename: __filename});149      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);150    });151  });152153  itEth('Can perform mint() & get crossOwner()', async ({helper}) => {154    const owner = await helper.eth.createAccountWithBalance(donor);155    const receiver = helper.eth.createAccount();156157    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');158    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);159160    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();161    const tokenId = result.events.Transfer.returnValues.tokenId;162    expect(tokenId).to.be.equal('1');163164    const event = result.events.Transfer;165    expect(event.address).to.be.equal(collectionAddress);166    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');167    expect(event.returnValues.to).to.be.equal(receiver);168169    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');170    expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);171    // TODO: this wont work right now, need release 919000 first172    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();173    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();174    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);175  });176177  // TODO combine all minting tests in one place178  [179    'substrate' as const,180    'ethereum' as const,181  ].map(testCase => {182    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {183      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);184185      const receiverEth = helper.eth.createAccount();186      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);187      const receiverSub = bob;188      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);189190      // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);191      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });192      const permissions: ITokenPropertyPermission[] = properties193        .map(p => {194          return {195            key: p.key, permission: {196              tokenOwner: false,197              collectionAdmin: true,198              mutable: false,199            },200          };201        });202203      const collection = await helper.nft.mintCollection(minter, {204        tokenPrefix: 'ethp',205        tokenPropertyPermissions: permissions,206      });207      await collection.addAdmin(minter, {Ethereum: collectionAdmin});208209      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);210      const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);211      let expectedTokenId = await contract.methods.nextTokenId().call();212      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();213      let tokenId = result.events.Transfer.returnValues.tokenId;214      expect(tokenId).to.be.equal(expectedTokenId);215216      let event = result.events.Transfer;217      expect(event.address).to.be.equal(collectionAddress);218      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');219      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));220      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);221222      expectedTokenId = await contract.methods.nextTokenId().call();223      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();224      event = result.events.Transfer;225      expect(event.address).to.be.equal(collectionAddress);226      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');227      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));228      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);229230      tokenId = result.events.Transfer.returnValues.tokenId;231232      expect(tokenId).to.be.equal(expectedTokenId);233234      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties235        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));236237      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))238        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});239    });240  });241242  itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {243    const nonOwner = await helper.eth.createAccountWithBalance(donor);244    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);245246    const collection = await helper.nft.mintCollection(minter);247    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);248    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');249250    await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))251      .to.be.rejectedWith('PublicMintingNotAllowed');252  });253254  //TODO: CORE-302 add eth methods255  itEth.skip('Can perform mintBulk()', async ({helper}) => {256    const caller = await helper.eth.createAccountWithBalance(donor);257    const receiver = helper.eth.createAccount();258259    const collection = await helper.nft.mintCollection(minter);260    await collection.addAdmin(minter, {Ethereum: caller});261262    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);263    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);264    {265      const bulkSize = 3;266      const nextTokenId = await contract.methods.nextTokenId().call();267      expect(nextTokenId).to.be.equal('1');268      const result = await contract.methods.mintBulkWithTokenURI(269        receiver,270        Array.from({length: bulkSize}, (_, i) => (271          [+nextTokenId + i, `Test URI ${i}`]272        )),273      ).send({from: caller});274275      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);276      for (let i = 0; i < bulkSize; i++) {277        const event = events[i];278        expect(event.address).to.equal(collectionAddress);279        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');280        expect(event.returnValues.to).to.equal(receiver);281        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);282283        expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);284      }285    }286  });287288  itEth('Can perform burn()', async ({helper}) => {289    const caller = await helper.eth.createAccountWithBalance(donor);290291    const collection = await helper.nft.mintCollection(minter, {});292    const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});293294    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);295    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);296297    {298      const result = await contract.methods.burn(tokenId).send({from: caller});299300      const event = result.events.Transfer;301      expect(event.address).to.be.equal(collectionAddress);302      expect(event.returnValues.from).to.be.equal(caller);303      expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');304      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);305    }306  });307308  itEth('Can perform approve()', async ({helper}) => {309    const owner = await helper.eth.createAccountWithBalance(donor);310    const spender = helper.eth.createAccount();311312    const collection = await helper.nft.mintCollection(minter, {});313    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});314315    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);316    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);317318    {319      const result = await contract.methods.approve(spender, tokenId).send({from: owner});320321      const event = result.events.Approval;322      expect(event.address).to.be.equal(collectionAddress);323      expect(event.returnValues.owner).to.be.equal(owner);324      expect(event.returnValues.approved).to.be.equal(spender);325      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);326    }327  });328329  itEth('Can perform setApprovalForAll()', async ({helper}) => {330    const owner = await helper.eth.createAccountWithBalance(donor);331    const operator = helper.eth.createAccount();332333    const collection = await helper.nft.mintCollection(minter, {});334335    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);336    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);337338    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();339    expect(approvedBefore).to.be.equal(false);340341    {342      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});343344      expect(result.events.ApprovalForAll).to.be.like({345        address: collectionAddress,346        event: 'ApprovalForAll',347        returnValues: {348          owner,349          operator,350          approved: true,351        },352      });353354      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();355      expect(approvedAfter).to.be.equal(true);356    }357358    {359      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});360361      expect(result.events.ApprovalForAll).to.be.like({362        address: collectionAddress,363        event: 'ApprovalForAll',364        returnValues: {365          owner,366          operator,367          approved: false,368        },369      });370371      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();372      expect(approvedAfter).to.be.equal(false);373    }374  });375376  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {377    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});378379    const owner = await helper.eth.createAccountWithBalance(donor);380    const operator = await helper.eth.createAccountWithBalance(donor, 100n);381382    const token = await collection.mintToken(minter, {Ethereum: owner});383384    const address = helper.ethAddress.fromCollectionId(collection.collectionId);385    const contract = await helper.ethNativeContract.collection(address, 'nft');386387    {388      await contract.methods.setApprovalForAll(operator, true).send({from: owner});389      const ownerCross = helper.ethCrossAccount.fromAddress(owner);390      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});391      const events = result.events.Transfer;392393      expect(events).to.be.like({394        address,395        event: 'Transfer',396        returnValues: {397          from: owner,398          to: '0x0000000000000000000000000000000000000000',399          tokenId: token.tokenId.toString(),400        },401      });402    }403404    expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;405  });406407  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {408    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});409410    const owner = await helper.eth.createAccountWithBalance(donor);411    const operator = await helper.eth.createAccountWithBalance(donor);412    const receiver = charlie;413414    const token = await collection.mintToken(minter, {Ethereum: owner});415416    const address = helper.ethAddress.fromCollectionId(collection.collectionId);417    const contract = await helper.ethNativeContract.collection(address, 'nft');418419    {420      await contract.methods.setApprovalForAll(operator, true).send({from: owner});421      const ownerCross = helper.ethCrossAccount.fromAddress(owner);422      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);423      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});424      const event = result.events.Transfer;425      expect(event).to.be.like({426        address: helper.ethAddress.fromCollectionId(collection.collectionId),427        event: 'Transfer',428        returnValues: {429          from: owner,430          to: helper.address.substrateToEth(receiver.address),431          tokenId: token.tokenId.toString(),432        },433      });434    }435436    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});437  });438439  itEth('Can perform burnFromCross()', async ({helper}) => {440    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});441    const ownerSub = bob;442    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);443    const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);444    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);445446    const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);447    const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);448449    const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});450    const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});451452    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);453    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');454455    // Approve tokens from substrate and ethereum:456    await token1.approve(ownerSub, {Ethereum: burnerEth});457    await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});458459    // can burnFromCross:460    const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});461    const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});462    const events1 = result1.events.Transfer;463    const events2 = result2.events.Transfer;464465    // Check events for burnFromCross (substrate and ethereum):466    [467      [events1, token1, helper.address.substrateToEth(ownerSub.address)],468      [events2, token2, ownerEth],469    ].map(burnData => {470      expect(burnData[0]).to.be.like({471        address: collectionAddress,472        event: 'Transfer',473        returnValues: {474          from: burnData[2],475          to: '0x0000000000000000000000000000000000000000',476          tokenId: burnData[1].tokenId.toString(),477        },478      });479    });480481    expect(await token1.doesExist()).to.be.false;482    expect(await token2.doesExist()).to.be.false;483  });484485  // TODO combine all approve tests in one place486  itEth('Can perform approveCross()', async ({helper}) => {487    // arrange: create accounts488    const owner = await helper.eth.createAccountWithBalance(donor, 100n);489    const ownerCross = helper.ethCrossAccount.fromAddress(owner);490    const receiverSub = charlie;491    const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);492    const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);493    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);494495    // arrange: create collection and tokens:496    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});497    const token1 = await collection.mintToken(minter, {Ethereum: owner});498    const token2 = await collection.mintToken(minter, {Ethereum: owner});499500    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');501502    // Can approveCross substrate and ethereum address:503    const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});504    const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});505    const eventSub = resultSub.events.Approval;506    const eventEth = resultEth.events.Approval;507    expect(eventSub).to.be.like({508      address: helper.ethAddress.fromCollectionId(collection.collectionId),509      event: 'Approval',510      returnValues: {511        owner,512        approved: helper.address.substrateToEth(receiverSub.address),513        tokenId: token1.tokenId.toString(),514      },515    });516    expect(eventEth).to.be.like({517      address: helper.ethAddress.fromCollectionId(collection.collectionId),518      event: 'Approval',519      returnValues: {520        owner,521        approved: receiverEth,522        tokenId: token2.tokenId.toString(),523      },524    });525526    // Substrate address can transferFrom approved tokens:527    await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});528    expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});529    // Ethereum address can transferFromCross approved tokens:530    await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});531    expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});532  });533534  itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {535    const nonOwner = await helper.eth.createAccountWithBalance(donor);536    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);537    const owner = await helper.eth.createAccountWithBalance(donor);538    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});539    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');540    const token = await collection.mintToken(minter, {Ethereum: owner});541542    await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');543  });544545  itEth('Can reaffirm approved address', async ({helper}) => {546    const owner = await helper.eth.createAccountWithBalance(donor, 100n);547    const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);548    const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);549    const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);550    const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);551    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});552    const token1 = await collection.mintToken(minter, {Ethereum: owner});553    const token2 = await collection.mintToken(minter, {Ethereum: owner});554    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');555556    // Can approve and reaffirm approved address:557    await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});558    await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});559560    // receiver1 cannot transferFrom:561    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;562    // receiver2 can transferFrom:563    await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});564565    // can set approved address to self address to remove approval:566    await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});567    await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});568569    // receiver1 cannot transfer token anymore:570    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;571  });572573  itEth('Can perform transferFrom()', async ({helper}) => {574    const owner = await helper.eth.createAccountWithBalance(donor);575    const spender = await helper.eth.createAccountWithBalance(donor);576    const receiver = helper.eth.createAccount();577578    const collection = await helper.nft.mintCollection(minter, {});579    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});580581    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);582    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);583584    await contract.methods.approve(spender, tokenId).send({from: owner});585586    {587      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});588589      const event = result.events.Transfer;590      expect(event.address).to.be.equal(collectionAddress);591      expect(event.returnValues.from).to.be.equal(owner);592      expect(event.returnValues.to).to.be.equal(receiver);593      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);594    }595596    {597      const balance = await contract.methods.balanceOf(receiver).call();598      expect(+balance).to.equal(1);599    }600601    {602      const balance = await contract.methods.balanceOf(owner).call();603      expect(+balance).to.equal(0);604    }605  });606607  itEth('Can perform transferFromCross()', async ({helper}) => {608    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});609610    const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);611    const spender = await helper.eth.createAccountWithBalance(donor);612613    const token = await collection.mintToken(minter, {Substrate: owner.address});614615    const address = helper.ethAddress.fromCollectionId(collection.collectionId);616    const contract = await helper.ethNativeContract.collection(address, 'nft');617618    await token.approve(owner, {Ethereum: spender});619620    {621      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);622      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);623      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});624      const event = result.events.Transfer;625      expect(event).to.be.like({626        address: helper.ethAddress.fromCollectionId(collection.collectionId),627        event: 'Transfer',628        returnValues: {629          from: helper.address.substrateToEth(owner.address),630          to: helper.address.substrateToEth(receiver.address),631          tokenId: token.tokenId.toString(),632        },633      });634    }635636    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});637  });638639  itEth('Can perform transfer()', async ({helper}) => {640    const collection = await helper.nft.mintCollection(minter, {});641    const owner = await helper.eth.createAccountWithBalance(donor);642    const receiver = helper.eth.createAccount();643644    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});645646    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);647    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);648649    {650      const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});651652      const event = result.events.Transfer;653      expect(event.address).to.be.equal(collectionAddress);654      expect(event.returnValues.from).to.be.equal(owner);655      expect(event.returnValues.to).to.be.equal(receiver);656      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);657    }658659    {660      const balance = await contract.methods.balanceOf(owner).call();661      expect(+balance).to.equal(0);662    }663664    {665      const balance = await contract.methods.balanceOf(receiver).call();666      expect(+balance).to.equal(1);667    }668  });669670  itEth('Can perform transferCross()', async ({helper}) => {671    const collection = await helper.nft.mintCollection(minter, {});672    const owner = await helper.eth.createAccountWithBalance(donor);673    const receiverEth = await helper.eth.createAccountWithBalance(donor);674    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);675    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);676677    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});678679    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);680    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);681682    {683      // Can transferCross to ethereum address:684      const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});685      // Check events:686      const event = result.events.Transfer;687      expect(event.address).to.be.equal(collectionAddress);688      expect(event.returnValues.from).to.be.equal(owner);689      expect(event.returnValues.to).to.be.equal(receiverEth);690      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);691692      // owner has balance = 0:693      const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();694      expect(+ownerBalance).to.equal(0);695      // receiver owns token:696      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();697      expect(+receiverBalance).to.equal(1);698      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});699    }700701    {702      // Can transferCross to substrate address:703      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});704      // Check events:705      const event = substrateResult.events.Transfer;706      expect(event.address).to.be.equal(collectionAddress);707      expect(event.returnValues.from).to.be.equal(receiverEth);708      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));709      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);710711      // owner has balance = 0:712      const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();713      expect(+ownerBalance).to.equal(0);714      // receiver owns token:715      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});716      expect(receiverBalance).to.contain(tokenId);717    }718  });719720  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {721    const sender = await helper.eth.createAccountWithBalance(donor);722    const tokenOwner = await helper.eth.createAccountWithBalance(donor);723    const receiverSub = minter;724    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);725726    const collection = await helper.nft.mintCollection(minter, {});727    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);728    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);729730    await collection.mintToken(minter, {Ethereum: sender});731    const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});732733    // Cannot transferCross someone else's token:734    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;735    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;736    // Cannot transfer token if it does not exist:737    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;738  }));739});740741describe('NFT: Fees', () => {742  let donor: IKeyringPair;743  let alice: IKeyringPair;744  let bob: IKeyringPair;745  let charlie: IKeyringPair;746747  before(async function() {748    await usingEthPlaygrounds(async (helper, privateKey) => {749      donor = await privateKey({filename: __filename});750      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);751    });752  });753754  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {755    const owner = await helper.eth.createAccountWithBalance(donor);756    const spender = helper.eth.createAccount();757758    const collection = await helper.nft.mintCollection(alice, {});759    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});760761    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);762763    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));764    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));765  });766767  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {768    const owner = await helper.eth.createAccountWithBalance(donor);769    const spender = await helper.eth.createAccountWithBalance(donor);770771    const collection = await helper.nft.mintCollection(alice, {});772    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});773774    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);775776    await contract.methods.approve(spender, tokenId).send({from: owner});777778    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));779    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));780  });781782  itEth('Can perform transferFromCross()', async ({helper}) => {783    const collectionMinter = alice;784    const owner = bob;785    const receiver = charlie;786    const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});787788    const spender = await helper.eth.createAccountWithBalance(donor, 100n);789790    const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});791792    const address = helper.ethAddress.fromCollectionId(collection.collectionId);793    const contract = await helper.ethNativeContract.collection(address, 'nft');794795    await token.approve(owner, {Ethereum: spender});796797    {798      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);799      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);800      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});801      const event = result.events.Transfer;802      expect(event).to.be.like({803        address: helper.ethAddress.fromCollectionId(collection.collectionId),804        event: 'Transfer',805        returnValues: {806          from: helper.address.substrateToEth(owner.address),807          to: helper.address.substrateToEth(receiver.address),808          tokenId: token.tokenId.toString(),809        },810      });811    }812813    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});814  });815816  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {817    const owner = await helper.eth.createAccountWithBalance(donor);818    const receiver = helper.eth.createAccount();819820    const collection = await helper.nft.mintCollection(alice, {});821    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});822823    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);824825    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));826    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));827  });828});829830describe('NFT: Substrate calls', () => {831  let donor: IKeyringPair;832  let alice: IKeyringPair;833834  before(async function() {835    await usingEthPlaygrounds(async (helper, privateKey) => {836      donor = await privateKey({filename: __filename});837      [alice] = await helper.arrange.createAccounts([20n], donor);838    });839  });840841  itEth('Events emitted for mint()', async ({helper}) => {842    const collection = await helper.nft.mintCollection(alice, {});843    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);844    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');845846    const events: any = [];847    contract.events.allEvents((_: any, event: any) => {848      events.push(event);849    });850851    const {tokenId} = await collection.mintToken(alice);852    if (events.length == 0) await helper.wait.newBlocks(1);853    const event = events[0];854855    expect(event.event).to.be.equal('Transfer');856    expect(event.address).to.be.equal(collectionAddress);857    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');858    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));859    expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());860  });861862  itEth('Events emitted for burn()', async ({helper}) => {863    const collection = await helper.nft.mintCollection(alice, {});864    const token = await collection.mintToken(alice);865866    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);867    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');868869    const events: any = [];870    contract.events.allEvents((_: any, event: any) => {871      events.push(event);872    });873874    await token.burn(alice);875    if (events.length == 0) await helper.wait.newBlocks(1);876    const event = events[0];877878    expect(event.event).to.be.equal('Transfer');879    expect(event.address).to.be.equal(collectionAddress);880    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));881    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');882    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());883  });884885  itEth('Events emitted for approve()', async ({helper}) => {886    const receiver = helper.eth.createAccount();887888    const collection = await helper.nft.mintCollection(alice, {});889    const token = await collection.mintToken(alice);890891    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);892    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');893894    const events: any = [];895    contract.events.allEvents((_: any, event: any) => {896      events.push(event);897    });898899    await token.approve(alice, {Ethereum: receiver});900    if (events.length == 0) await helper.wait.newBlocks(1);901    const event = events[0];902903    expect(event.event).to.be.equal('Approval');904    expect(event.address).to.be.equal(collectionAddress);905    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));906    expect(event.returnValues.approved).to.be.equal(receiver);907    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());908  });909910  itEth('Events emitted for transferFrom()', async ({helper}) => {911    const [bob] = await helper.arrange.createAccounts([10n], donor);912    const receiver = helper.eth.createAccount();913914    const collection = await helper.nft.mintCollection(alice, {});915    const token = await collection.mintToken(alice);916    await token.approve(alice, {Substrate: bob.address});917918    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);919    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');920921    const events: any = [];922    contract.events.allEvents((_: any, event: any) => {923      events.push(event);924    });925926    await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});927928    if (events.length == 0) await helper.wait.newBlocks(1);929    const event = events[0];930931    expect(event.address).to.be.equal(collectionAddress);932    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));933    expect(event.returnValues.to).to.be.equal(receiver);934    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);935  });936937  itEth('Events emitted for transfer()', async ({helper}) => {938    const receiver = helper.eth.createAccount();939940    const collection = await helper.nft.mintCollection(alice, {});941    const token = await collection.mintToken(alice);942943    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);944    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');945946    const events: any = [];947    contract.events.allEvents((_: any, event: any) => {948      events.push(event);949    });950951    await token.transfer(alice, {Ethereum: receiver});952953    if (events.length == 0) await helper.wait.newBlocks(1);954    const event = events[0];955956    expect(event.address).to.be.equal(collectionAddress);957    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));958    expect(event.returnValues.to).to.be.equal(receiver);959    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);960  });961});962963describe('Common metadata', () => {964  let donor: IKeyringPair;965  let alice: IKeyringPair;966967  before(async function() {968    await usingEthPlaygrounds(async (helper, privateKey) => {969      donor = await privateKey({filename: __filename});970      [alice] = await helper.arrange.createAccounts([20n], donor);971    });972  });973974  itEth('Returns collection name', async ({helper}) => {975    const caller = await helper.eth.createAccountWithBalance(donor);976    const tokenPropertyPermissions = [{977      key: 'URI',978      permission: {979        mutable: true,980        collectionAdmin: true,981        tokenOwner: false,982      },983    }];984    const collection = await helper.nft.mintCollection(985      alice,986      {987        name: 'oh River',988        tokenPrefix: 'CHANGE',989        properties: [{key: 'ERC721Metadata', value: '1'}],990        tokenPropertyPermissions,991      },992    );993994    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);995    const name = await contract.methods.name().call();996    expect(name).to.equal('oh River');997  });998999  itEth('Returns symbol name', async ({helper}) => {1000    const caller = await helper.eth.createAccountWithBalance(donor);1001    const tokenPropertyPermissions = [{1002      key: 'URI',1003      permission: {1004        mutable: true,1005        collectionAdmin: true,1006        tokenOwner: false,1007      },1008    }];1009    const collection = await helper.nft.mintCollection(1010      alice,1011      {1012        name: 'oh River',1013        tokenPrefix: 'CHANGE',1014        properties: [{key: 'ERC721Metadata', value: '1'}],1015        tokenPropertyPermissions,1016      },1017    );10181019    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);1020    const symbol = await contract.methods.symbol().call();1021    expect(symbol).to.equal('CHANGE');1022  });1023});10241025describe('Negative tests', () => {1026  let donor: IKeyringPair;1027  let minter: IKeyringPair;1028  let alice: IKeyringPair;10291030  before(async function() {1031    await usingEthPlaygrounds(async (helper, privateKey) => {1032      donor = await privateKey({filename: __filename});1033      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);1034    });1035  });10361037  itEth('[negative] Cant perform burn without approval', async ({helper}) => {1038    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});10391040    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1041    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10421043    const token = await collection.mintToken(minter, {Ethereum: owner});10441045    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1046    const contract = await helper.ethNativeContract.collection(address, 'nft');10471048    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1049    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10501051    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1052    await contract.methods.setApprovalForAll(spender, false).send({from: owner});10531054    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1055  });10561057  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1058    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1059    const receiver = alice;10601061    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1062    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10631064    const token = await collection.mintToken(minter, {Ethereum: owner});10651066    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1067    const contract = await helper.ethNativeContract.collection(address, 'nft');10681069    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1070    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);10711072    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;10731074    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1075    await contract.methods.setApprovalForAll(spender, false).send({from: owner});10761077    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1078  });1079});
after · tests/src/eth/nonFungible.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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Check ERC721 token URI for NFT', () => {23  let donor: IKeyringPair;2425  before(async function() {26    await usingEthPlaygrounds(async (_helper, privateKey) => {27      donor = await privateKey({filename: __filename});28    });29  });3031  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {32    const owner = await helper.eth.createAccountWithBalance(donor);33    const receiver = helper.eth.createAccount();3435    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);36    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);3738    const result = await contract.methods.mint(receiver).send();39    const tokenId = result.events.Transfer.returnValues.tokenId;40    expect(tokenId).to.be.equal('1');4142    if (propertyKey && propertyValue) {43      // Set URL or suffix44      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();45    }4647    const event = result.events.Transfer;48    expect(event.address).to.be.equal(collectionAddress);49    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');50    expect(event.returnValues.to).to.be.equal(receiver);51    expect(event.returnValues.tokenId).to.be.equal(tokenId);5253    return {contract, nextTokenId: tokenId};54  }5556  itEth('Empty tokenURI', async ({helper}) => {57    const {contract, nextTokenId} = await setup(helper, '');58    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');59  });6061  itEth('TokenURI from url', async ({helper}) => {62    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');63    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');64  });6566  itEth('TokenURI from baseURI', async ({helper}) => {67    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');68    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');69  });7071  itEth('TokenURI from baseURI + suffix', async ({helper}) => {72    const suffix = '/some/suffix';73    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);74    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);75  });76});7778describe('NFT: Plain calls', () => {79  let donor: IKeyringPair;80  let minter: IKeyringPair;81  let bob: IKeyringPair;82  let charlie: IKeyringPair;8384  before(async function() {85    await usingEthPlaygrounds(async (helper, privateKey) => {86      donor = await privateKey({filename: __filename});87      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);88    });89  });9091  // TODO combine all minting tests in one place92  [93    'substrate' as const,94    'ethereum' as const,95  ].map(testCase => {96    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {97      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);9899      const receiverEth = helper.eth.createAccount();100      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);101      const receiverSub = bob;102      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);103104      // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);105      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });106      const permissions: ITokenPropertyPermission[] = properties107        .map(p => {108          return {109            key: p.key, permission: {110              tokenOwner: false,111              collectionAdmin: true,112              mutable: false,113            },114          };115        });116117      const collection = await helper.nft.mintCollection(minter, {118        tokenPrefix: 'ethp',119        tokenPropertyPermissions: permissions,120      });121      await collection.addAdmin(minter, {Ethereum: collectionAdmin});122123      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);124      const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);125      let expectedTokenId = await contract.methods.nextTokenId().call();126      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();127      let tokenId = result.events.Transfer.returnValues.tokenId;128      expect(tokenId).to.be.equal(expectedTokenId);129130      let event = result.events.Transfer;131      expect(event.address).to.be.equal(collectionAddress);132      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');133      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));134      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);135136      expectedTokenId = await contract.methods.nextTokenId().call();137      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();138      event = result.events.Transfer;139      expect(event.address).to.be.equal(collectionAddress);140      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');141      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));142      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);143144      tokenId = result.events.Transfer.returnValues.tokenId;145146      expect(tokenId).to.be.equal(expectedTokenId);147148      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties149        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));150151      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))152        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});153    });154  });155156  itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {157    const nonOwner = await helper.eth.createAccountWithBalance(donor);158    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);159160    const collection = await helper.nft.mintCollection(minter);161    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);162    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');163164    await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))165      .to.be.rejectedWith('PublicMintingNotAllowed');166  });167168  //TODO: CORE-302 add eth methods169  itEth.skip('Can perform mintBulk()', async ({helper}) => {170    const caller = await helper.eth.createAccountWithBalance(donor);171    const receiver = helper.eth.createAccount();172173    const collection = await helper.nft.mintCollection(minter);174    await collection.addAdmin(minter, {Ethereum: caller});175176    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);177    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);178    {179      const bulkSize = 3;180      const nextTokenId = await contract.methods.nextTokenId().call();181      expect(nextTokenId).to.be.equal('1');182      const result = await contract.methods.mintBulkWithTokenURI(183        receiver,184        Array.from({length: bulkSize}, (_, i) => (185          [+nextTokenId + i, `Test URI ${i}`]186        )),187      ).send({from: caller});188189      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);190      for (let i = 0; i < bulkSize; i++) {191        const event = events[i];192        expect(event.address).to.equal(collectionAddress);193        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');194        expect(event.returnValues.to).to.equal(receiver);195        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);196197        expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);198      }199    }200  });201202  itEth('Can perform burn()', async ({helper}) => {203    const caller = await helper.eth.createAccountWithBalance(donor);204205    const collection = await helper.nft.mintCollection(minter, {});206    const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});207208    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);209    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);210211    {212      const result = await contract.methods.burn(tokenId).send({from: caller});213214      const event = result.events.Transfer;215      expect(event.address).to.be.equal(collectionAddress);216      expect(event.returnValues.from).to.be.equal(caller);217      expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');218      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);219    }220  });221222  itEth('Can perform approve()', async ({helper}) => {223    const owner = await helper.eth.createAccountWithBalance(donor);224    const spender = helper.eth.createAccount();225226    const collection = await helper.nft.mintCollection(minter, {});227    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});228229    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);230    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);231232    {233      const result = await contract.methods.approve(spender, tokenId).send({from: owner});234235      const event = result.events.Approval;236      expect(event.address).to.be.equal(collectionAddress);237      expect(event.returnValues.owner).to.be.equal(owner);238      expect(event.returnValues.approved).to.be.equal(spender);239      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);240    }241  });242243  itEth('Can perform setApprovalForAll()', async ({helper}) => {244    const owner = await helper.eth.createAccountWithBalance(donor);245    const operator = helper.eth.createAccount();246247    const collection = await helper.nft.mintCollection(minter, {});248249    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);250    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);251252    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();253    expect(approvedBefore).to.be.equal(false);254255    {256      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});257258      expect(result.events.ApprovalForAll).to.be.like({259        address: collectionAddress,260        event: 'ApprovalForAll',261        returnValues: {262          owner,263          operator,264          approved: true,265        },266      });267268      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();269      expect(approvedAfter).to.be.equal(true);270    }271272    {273      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});274275      expect(result.events.ApprovalForAll).to.be.like({276        address: collectionAddress,277        event: 'ApprovalForAll',278        returnValues: {279          owner,280          operator,281          approved: false,282        },283      });284285      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();286      expect(approvedAfter).to.be.equal(false);287    }288  });289290  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {291    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});292293    const owner = await helper.eth.createAccountWithBalance(donor);294    const operator = await helper.eth.createAccountWithBalance(donor, 100n);295296    const token = await collection.mintToken(minter, {Ethereum: owner});297298    const address = helper.ethAddress.fromCollectionId(collection.collectionId);299    const contract = await helper.ethNativeContract.collection(address, 'nft');300301    {302      await contract.methods.setApprovalForAll(operator, true).send({from: owner});303      const ownerCross = helper.ethCrossAccount.fromAddress(owner);304      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});305      const events = result.events.Transfer;306307      expect(events).to.be.like({308        address,309        event: 'Transfer',310        returnValues: {311          from: owner,312          to: '0x0000000000000000000000000000000000000000',313          tokenId: token.tokenId.toString(),314        },315      });316    }317318    expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;319  });320321  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {322    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});323324    const owner = await helper.eth.createAccountWithBalance(donor);325    const operator = await helper.eth.createAccountWithBalance(donor);326    const receiver = charlie;327328    const token = await collection.mintToken(minter, {Ethereum: owner});329330    const address = helper.ethAddress.fromCollectionId(collection.collectionId);331    const contract = await helper.ethNativeContract.collection(address, 'nft');332333    {334      await contract.methods.setApprovalForAll(operator, true).send({from: owner});335      const ownerCross = helper.ethCrossAccount.fromAddress(owner);336      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);337      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});338      const event = result.events.Transfer;339      expect(event).to.be.like({340        address: helper.ethAddress.fromCollectionId(collection.collectionId),341        event: 'Transfer',342        returnValues: {343          from: owner,344          to: helper.address.substrateToEth(receiver.address),345          tokenId: token.tokenId.toString(),346        },347      });348    }349350    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});351  });352353  itEth('Can perform burnFromCross()', async ({helper}) => {354    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});355    const ownerSub = bob;356    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);357    const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);358    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);359360    const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);361    const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);362363    const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});364    const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});365366    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);367    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');368369    // Approve tokens from substrate and ethereum:370    await token1.approve(ownerSub, {Ethereum: burnerEth});371    await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});372373    // can burnFromCross:374    const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});375    const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});376    const events1 = result1.events.Transfer;377    const events2 = result2.events.Transfer;378379    // Check events for burnFromCross (substrate and ethereum):380    [381      [events1, token1, helper.address.substrateToEth(ownerSub.address)],382      [events2, token2, ownerEth],383    ].map(burnData => {384      expect(burnData[0]).to.be.like({385        address: collectionAddress,386        event: 'Transfer',387        returnValues: {388          from: burnData[2],389          to: '0x0000000000000000000000000000000000000000',390          tokenId: burnData[1].tokenId.toString(),391        },392      });393    });394395    expect(await token1.doesExist()).to.be.false;396    expect(await token2.doesExist()).to.be.false;397  });398399  // TODO combine all approve tests in one place400  itEth('Can perform approveCross()', async ({helper}) => {401    // arrange: create accounts402    const owner = await helper.eth.createAccountWithBalance(donor, 100n);403    const ownerCross = helper.ethCrossAccount.fromAddress(owner);404    const receiverSub = charlie;405    const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);406    const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);407    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);408409    // arrange: create collection and tokens:410    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});411    const token1 = await collection.mintToken(minter, {Ethereum: owner});412    const token2 = await collection.mintToken(minter, {Ethereum: owner});413414    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');415416    // Can approveCross substrate and ethereum address:417    const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});418    const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});419    const eventSub = resultSub.events.Approval;420    const eventEth = resultEth.events.Approval;421    expect(eventSub).to.be.like({422      address: helper.ethAddress.fromCollectionId(collection.collectionId),423      event: 'Approval',424      returnValues: {425        owner,426        approved: helper.address.substrateToEth(receiverSub.address),427        tokenId: token1.tokenId.toString(),428      },429    });430    expect(eventEth).to.be.like({431      address: helper.ethAddress.fromCollectionId(collection.collectionId),432      event: 'Approval',433      returnValues: {434        owner,435        approved: receiverEth,436        tokenId: token2.tokenId.toString(),437      },438    });439440    // Substrate address can transferFrom approved tokens:441    await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});442    expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});443    // Ethereum address can transferFromCross approved tokens:444    await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});445    expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});446  });447448  itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {449    const nonOwner = await helper.eth.createAccountWithBalance(donor);450    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);451    const owner = await helper.eth.createAccountWithBalance(donor);452    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});453    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');454    const token = await collection.mintToken(minter, {Ethereum: owner});455456    await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');457  });458459  itEth('Can reaffirm approved address', async ({helper}) => {460    const owner = await helper.eth.createAccountWithBalance(donor, 100n);461    const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);462    const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);463    const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);464    const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);465    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});466    const token1 = await collection.mintToken(minter, {Ethereum: owner});467    const token2 = await collection.mintToken(minter, {Ethereum: owner});468    const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');469470    // Can approve and reaffirm approved address:471    await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});472    await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});473474    // receiver1 cannot transferFrom:475    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;476    // receiver2 can transferFrom:477    await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});478479    // can set approved address to self address to remove approval:480    await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});481    await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});482483    // receiver1 cannot transfer token anymore:484    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;485  });486487  itEth('Can perform transferFrom()', async ({helper}) => {488    const owner = await helper.eth.createAccountWithBalance(donor);489    const spender = await helper.eth.createAccountWithBalance(donor);490    const receiver = helper.eth.createAccount();491492    const collection = await helper.nft.mintCollection(minter, {});493    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});494495    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);496    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);497498    await contract.methods.approve(spender, tokenId).send({from: owner});499500    {501      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});502503      const event = result.events.Transfer;504      expect(event.address).to.be.equal(collectionAddress);505      expect(event.returnValues.from).to.be.equal(owner);506      expect(event.returnValues.to).to.be.equal(receiver);507      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);508    }509510    {511      const balance = await contract.methods.balanceOf(receiver).call();512      expect(+balance).to.equal(1);513    }514515    {516      const balance = await contract.methods.balanceOf(owner).call();517      expect(+balance).to.equal(0);518    }519  });520521  itEth('Can perform transferFromCross()', async ({helper}) => {522    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});523524    const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);525    const spender = await helper.eth.createAccountWithBalance(donor);526527    const token = await collection.mintToken(minter, {Substrate: owner.address});528529    const address = helper.ethAddress.fromCollectionId(collection.collectionId);530    const contract = await helper.ethNativeContract.collection(address, 'nft');531532    await token.approve(owner, {Ethereum: spender});533534    {535      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);536      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);537      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});538      const event = result.events.Transfer;539      expect(event).to.be.like({540        address: helper.ethAddress.fromCollectionId(collection.collectionId),541        event: 'Transfer',542        returnValues: {543          from: helper.address.substrateToEth(owner.address),544          to: helper.address.substrateToEth(receiver.address),545          tokenId: token.tokenId.toString(),546        },547      });548    }549550    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});551  });552553  itEth('Can perform transfer()', async ({helper}) => {554    const collection = await helper.nft.mintCollection(minter, {});555    const owner = await helper.eth.createAccountWithBalance(donor);556    const receiver = helper.eth.createAccount();557558    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});559560    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);561    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);562563    {564      const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});565566      const event = result.events.Transfer;567      expect(event.address).to.be.equal(collectionAddress);568      expect(event.returnValues.from).to.be.equal(owner);569      expect(event.returnValues.to).to.be.equal(receiver);570      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);571    }572573    {574      const balance = await contract.methods.balanceOf(owner).call();575      expect(+balance).to.equal(0);576    }577578    {579      const balance = await contract.methods.balanceOf(receiver).call();580      expect(+balance).to.equal(1);581    }582  });583584  itEth('Can perform transferCross()', async ({helper}) => {585    const collection = await helper.nft.mintCollection(minter, {});586    const owner = await helper.eth.createAccountWithBalance(donor);587    const receiverEth = await helper.eth.createAccountWithBalance(donor);588    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);589    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);590591    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});592593    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);594    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);595596    {597      // Can transferCross to ethereum address:598      const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});599      // Check events:600      const event = result.events.Transfer;601      expect(event.address).to.be.equal(collectionAddress);602      expect(event.returnValues.from).to.be.equal(owner);603      expect(event.returnValues.to).to.be.equal(receiverEth);604      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);605606      // owner has balance = 0:607      const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();608      expect(+ownerBalance).to.equal(0);609      // receiver owns token:610      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();611      expect(+receiverBalance).to.equal(1);612      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});613    }614615    {616      // Can transferCross to substrate address:617      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});618      // Check events:619      const event = substrateResult.events.Transfer;620      expect(event.address).to.be.equal(collectionAddress);621      expect(event.returnValues.from).to.be.equal(receiverEth);622      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));623      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);624625      // owner has balance = 0:626      const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();627      expect(+ownerBalance).to.equal(0);628      // receiver owns token:629      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});630      expect(receiverBalance).to.contain(tokenId);631    }632  });633634  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {635    const sender = await helper.eth.createAccountWithBalance(donor);636    const tokenOwner = await helper.eth.createAccountWithBalance(donor);637    const receiverSub = minter;638    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);639640    const collection = await helper.nft.mintCollection(minter, {});641    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);642    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);643644    await collection.mintToken(minter, {Ethereum: sender});645    const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});646647    // Cannot transferCross someone else's token:648    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;649    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;650    // Cannot transfer token if it does not exist:651    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;652  }));653});654655describe('NFT: Fees', () => {656  let donor: IKeyringPair;657  let alice: IKeyringPair;658  let bob: IKeyringPair;659  let charlie: IKeyringPair;660661  before(async function() {662    await usingEthPlaygrounds(async (helper, privateKey) => {663      donor = await privateKey({filename: __filename});664      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);665    });666  });667668  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {669    const owner = await helper.eth.createAccountWithBalance(donor);670    const spender = helper.eth.createAccount();671672    const collection = await helper.nft.mintCollection(alice, {});673    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});674675    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);676677    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));678    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));679  });680681  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {682    const owner = await helper.eth.createAccountWithBalance(donor);683    const spender = await helper.eth.createAccountWithBalance(donor);684685    const collection = await helper.nft.mintCollection(alice, {});686    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});687688    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);689690    await contract.methods.approve(spender, tokenId).send({from: owner});691692    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));693    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));694  });695696  itEth('Can perform transferFromCross()', async ({helper}) => {697    const collectionMinter = alice;698    const owner = bob;699    const receiver = charlie;700    const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});701702    const spender = await helper.eth.createAccountWithBalance(donor, 100n);703704    const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});705706    const address = helper.ethAddress.fromCollectionId(collection.collectionId);707    const contract = await helper.ethNativeContract.collection(address, 'nft');708709    await token.approve(owner, {Ethereum: spender});710711    {712      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);713      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);714      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});715      const event = result.events.Transfer;716      expect(event).to.be.like({717        address: helper.ethAddress.fromCollectionId(collection.collectionId),718        event: 'Transfer',719        returnValues: {720          from: helper.address.substrateToEth(owner.address),721          to: helper.address.substrateToEth(receiver.address),722          tokenId: token.tokenId.toString(),723        },724      });725    }726727    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});728  });729730  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {731    const owner = await helper.eth.createAccountWithBalance(donor);732    const receiver = helper.eth.createAccount();733734    const collection = await helper.nft.mintCollection(alice, {});735    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});736737    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);738739    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));740    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));741  });742});743744describe('NFT: Substrate calls', () => {745  let donor: IKeyringPair;746  let alice: IKeyringPair;747748  before(async function() {749    await usingEthPlaygrounds(async (helper, privateKey) => {750      donor = await privateKey({filename: __filename});751      [alice] = await helper.arrange.createAccounts([20n], donor);752    });753  });754755  itEth('Events emitted for mint()', async ({helper}) => {756    const collection = await helper.nft.mintCollection(alice, {});757    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);758    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');759760    const events: any = [];761    contract.events.allEvents((_: any, event: any) => {762      events.push(event);763    });764765    const {tokenId} = await collection.mintToken(alice);766    if (events.length == 0) await helper.wait.newBlocks(1);767    const event = events[0];768769    expect(event.event).to.be.equal('Transfer');770    expect(event.address).to.be.equal(collectionAddress);771    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');772    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));773    expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());774  });775776  itEth('Events emitted for burn()', async ({helper}) => {777    const collection = await helper.nft.mintCollection(alice, {});778    const token = await collection.mintToken(alice);779780    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);781    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');782783    const events: any = [];784    contract.events.allEvents((_: any, event: any) => {785      events.push(event);786    });787788    await token.burn(alice);789    if (events.length == 0) await helper.wait.newBlocks(1);790    const event = events[0];791792    expect(event.event).to.be.equal('Transfer');793    expect(event.address).to.be.equal(collectionAddress);794    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));795    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');796    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());797  });798799  itEth('Events emitted for approve()', async ({helper}) => {800    const receiver = helper.eth.createAccount();801802    const collection = await helper.nft.mintCollection(alice, {});803    const token = await collection.mintToken(alice);804805    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);806    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');807808    const events: any = [];809    contract.events.allEvents((_: any, event: any) => {810      events.push(event);811    });812813    await token.approve(alice, {Ethereum: receiver});814    if (events.length == 0) await helper.wait.newBlocks(1);815    const event = events[0];816817    expect(event.event).to.be.equal('Approval');818    expect(event.address).to.be.equal(collectionAddress);819    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));820    expect(event.returnValues.approved).to.be.equal(receiver);821    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());822  });823824  itEth('Events emitted for transferFrom()', async ({helper}) => {825    const [bob] = await helper.arrange.createAccounts([10n], donor);826    const receiver = helper.eth.createAccount();827828    const collection = await helper.nft.mintCollection(alice, {});829    const token = await collection.mintToken(alice);830    await token.approve(alice, {Substrate: bob.address});831832    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);833    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');834835    const events: any = [];836    contract.events.allEvents((_: any, event: any) => {837      events.push(event);838    });839840    await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});841842    if (events.length == 0) await helper.wait.newBlocks(1);843    const event = events[0];844845    expect(event.address).to.be.equal(collectionAddress);846    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));847    expect(event.returnValues.to).to.be.equal(receiver);848    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);849  });850851  itEth('Events emitted for transfer()', async ({helper}) => {852    const receiver = helper.eth.createAccount();853854    const collection = await helper.nft.mintCollection(alice, {});855    const token = await collection.mintToken(alice);856857    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);858    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');859860    const events: any = [];861    contract.events.allEvents((_: any, event: any) => {862      events.push(event);863    });864865    await token.transfer(alice, {Ethereum: receiver});866867    if (events.length == 0) await helper.wait.newBlocks(1);868    const event = events[0];869870    expect(event.address).to.be.equal(collectionAddress);871    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));872    expect(event.returnValues.to).to.be.equal(receiver);873    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);874  });875});876877describe('Common metadata', () => {878  let donor: IKeyringPair;879  let alice: IKeyringPair;880881  before(async function() {882    await usingEthPlaygrounds(async (helper, privateKey) => {883      donor = await privateKey({filename: __filename});884      [alice] = await helper.arrange.createAccounts([20n], donor);885    });886  });887888  itEth('Returns collection name', async ({helper}) => {889    const caller = await helper.eth.createAccountWithBalance(donor);890    const tokenPropertyPermissions = [{891      key: 'URI',892      permission: {893        mutable: true,894        collectionAdmin: true,895        tokenOwner: false,896      },897    }];898    const collection = await helper.nft.mintCollection(899      alice,900      {901        name: 'oh River',902        tokenPrefix: 'CHANGE',903        properties: [{key: 'ERC721Metadata', value: '1'}],904        tokenPropertyPermissions,905      },906    );907908    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);909    const name = await contract.methods.name().call();910    expect(name).to.equal('oh River');911  });912913  itEth('Returns symbol name', async ({helper}) => {914    const caller = await helper.eth.createAccountWithBalance(donor);915    const tokenPropertyPermissions = [{916      key: 'URI',917      permission: {918        mutable: true,919        collectionAdmin: true,920        tokenOwner: false,921      },922    }];923    const collection = await helper.nft.mintCollection(924      alice,925      {926        name: 'oh River',927        tokenPrefix: 'CHANGE',928        properties: [{key: 'ERC721Metadata', value: '1'}],929        tokenPropertyPermissions,930      },931    );932933    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);934    const symbol = await contract.methods.symbol().call();935    expect(symbol).to.equal('CHANGE');936  });937});938939describe('Negative tests', () => {940  let donor: IKeyringPair;941  let minter: IKeyringPair;942  let alice: IKeyringPair;943944  before(async function() {945    await usingEthPlaygrounds(async (helper, privateKey) => {946      donor = await privateKey({filename: __filename});947      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);948    });949  });950951  itEth('[negative] Cant perform burn without approval', async ({helper}) => {952    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});953954    const owner = await helper.eth.createAccountWithBalance(donor, 100n);955    const spender = await helper.eth.createAccountWithBalance(donor, 100n);956957    const token = await collection.mintToken(minter, {Ethereum: owner});958959    const address = helper.ethAddress.fromCollectionId(collection.collectionId);960    const contract = await helper.ethNativeContract.collection(address, 'nft');961962    const ownerCross = helper.ethCrossAccount.fromAddress(owner);963    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;964965    await contract.methods.setApprovalForAll(spender, true).send({from: owner});966    await contract.methods.setApprovalForAll(spender, false).send({from: owner});967968    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;969  });970971  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {972    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});973    const receiver = alice;974975    const owner = await helper.eth.createAccountWithBalance(donor, 100n);976    const spender = await helper.eth.createAccountWithBalance(donor, 100n);977978    const token = await collection.mintToken(minter, {Ethereum: owner});979980    const address = helper.ethAddress.fromCollectionId(collection.collectionId);981    const contract = await helper.ethNativeContract.collection(address, 'nft');982983    const ownerCross = helper.ethCrossAccount.fromAddress(owner);984    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);985986    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;987988    await contract.methods.setApprovalForAll(spender, true).send({from: owner});989    await contract.methods.setApprovalForAll(spender, false).send({from: owner});990991    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;992  });993});
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -19,90 +19,6 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {ITokenPropertyPermission} from '../util/playgrounds/types';
 
-describe('Refungible: Information getting', () => {
-  let donor: IKeyringPair;
-
-  before(async function() {
-    await usingEthPlaygrounds(async (helper, privateKey) => {
-      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
-      donor = await privateKey({filename: __filename});
-    });
-  });
-
-  itEth('totalSupply', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
-    await contract.methods.mint(caller).send();
-
-    const totalSupply = await contract.methods.totalSupply().call();
-    expect(totalSupply).to.equal('1');
-  });
-
-  itEth('balanceOf', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
-    await contract.methods.mint(caller).send();
-    await contract.methods.mint(caller).send();
-    await contract.methods.mint(caller).send();
-
-    const balance = await contract.methods.balanceOf(caller).call();
-    expect(balance).to.equal('3');
-  });
-
-  itEth('ownerOf', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
-    const result = await contract.methods.mint(caller).send();
-    const tokenId = result.events.Transfer.returnValues.tokenId;
-
-    const owner = await contract.methods.ownerOf(tokenId).call();
-    expect(owner).to.equal(caller);
-  });
-
-  itEth('ownerOf after burn', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const receiver = helper.eth.createAccount();
-    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
-    const result = await contract.methods.mint(caller).send();
-    const tokenId = result.events.Transfer.returnValues.tokenId;
-    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
-
-    await tokenContract.methods.repartition(2).send();
-    await tokenContract.methods.transfer(receiver, 1).send();
-
-    await tokenContract.methods.burnFrom(caller, 1).send();
-
-    const owner = await contract.methods.ownerOf(tokenId).call();
-    expect(owner).to.equal(receiver);
-  });
-
-  itEth('ownerOf for partial ownership', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const receiver = helper.eth.createAccount();
-    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
-    const result = await contract.methods.mint(caller).send();
-    const tokenId = result.events.Transfer.returnValues.tokenId;
-    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
-
-    await tokenContract.methods.repartition(2).send();
-    await tokenContract.methods.transfer(receiver, 1).send();
-
-    const owner = await contract.methods.ownerOf(tokenId).call();
-    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
-  });
-});
-
 describe('Refungible: Plain calls', () => {
   let donor: IKeyringPair;
   let minter: IKeyringPair;
@@ -116,25 +32,6 @@
       donor = await privateKey({filename: __filename});
       [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
     });
-  });
-
-  itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-    const receiver = helper.eth.createAccount();
-    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
-    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-
-    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
-
-    const event = result.events.Transfer;
-    expect(event.address).to.equal(collectionAddress);
-    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
-    expect(event.returnValues.to).to.equal(receiver);
-    const tokenId = event.returnValues.tokenId;
-    expect(tokenId).to.be.equal('1');
-
-    expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
-    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
   });
 
   [
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -19,51 +19,6 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {Contract} from 'web3-eth-contract';
 
-
-describe('Refungible token: Information getting', () => {
-  let donor: IKeyringPair;
-  let alice: IKeyringPair;
-
-  before(async function() {
-    await usingEthPlaygrounds(async (helper, privateKey) => {
-      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
-      donor = await privateKey({filename: __filename});
-      [alice] = await helper.arrange.createAccounts([20n], donor);
-    });
-  });
-
-  itEth('totalSupply', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
-    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
-    const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
-    const totalSupply = await contract.methods.totalSupply().call();
-    expect(totalSupply).to.equal('200');
-  });
-
-  itEth('balanceOf', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
-    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
-    const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
-    const balance = await contract.methods.balanceOf(caller).call();
-    expect(balance).to.equal('200');
-  });
-
-  itEth('decimals', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
-    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
-    const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
-    const decimals = await contract.methods.decimals().call();
-    expect(decimals).to.equal('0');
-  });
-});
-
 // FIXME: Need erc721 for ReFubgible.
 describe('Check ERC721 token URI for ReFungible', () => {
   let donor: IKeyringPair;
addedtests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC20.test.ts
@@ -0,0 +1,91 @@
+// 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/>.
+
+import {Pallets, requirePalletsOrSkip} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+[
+  {mode: 'ft' as const, requiredPallets: []},
+  {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+].map(testCase => {
+  describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {
+    let donor: IKeyringPair;
+
+    before(async function() {
+      await usingEthPlaygrounds(async (helper, privateKey) => {
+        requirePalletsOrSkip(this, helper, testCase.requiredPallets);
+        donor = await privateKey({filename: __filename});
+      });
+    });
+
+    itEth('totalSupply', async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+      const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+      if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+      // Use collection contract for FT or token contract for RFT:
+      const contract = testCase.mode === 'ft'
+        ? collection
+        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+      // Mint tokens:
+      testCase.mode === 'ft'
+        ? await contract.methods.mint(...mintingParams).send({from: caller})
+        : await contract.methods.repartition(200).send({from: caller});
+
+      const totalSupply = await contract.methods.totalSupply().call();
+      expect(totalSupply).to.equal('200');
+    });
+
+    itEth('balanceOf', async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+      const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+      if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+      // Use collection contract for FT or token contract for RFT:
+      const contract = testCase.mode === 'ft'
+        ? collection
+        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+      // Mint tokens:
+      testCase.mode === 'ft'
+        ? await contract.methods.mint(...mintingParams).send({from: caller})
+        : await contract.methods.repartition(200).send({from: caller});
+
+      const balance = await contract.methods.balanceOf(caller).call();
+      expect(balance).to.equal('200');
+    });
+
+    itEth('decimals', async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+      if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+      // Use collection contract for FT or token contract for RFT:
+      const contract = testCase.mode === 'ft'
+        ? collection
+        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+      const decimals = await contract.methods.decimals().call();
+      expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');
+    });
+  });
+});
\ No newline at end of file
addedtests/src/eth/tokens/callMethodsERC721.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC721.test.ts
@@ -0,0 +1,143 @@
+// 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/>.
+
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+
+describe('ERC-721 call methods', () => {
+  let donor: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+    });
+  });
+
+  [
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'nft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, async ({helper}) => {
+      const callerEth = await helper.eth.createAccountWithBalance(donor);
+      const [callerSub] = await helper.arrange.createAccounts([100n], donor);
+      const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];
+
+      const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);
+      await collectionEth.methods.mint(callerEth).send({from: callerEth});
+      const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});
+      const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);
+
+      // Can get name/symbol/description for Eth collection
+      expect(await collectionEth.methods.name().call()).to.eq(name);
+      expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);
+      expect(await collectionEth.methods.description().call()).to.eq(description);
+      // Can get name/symbol/description for Sub collection
+      expect(await collectionSub.methods.name().call()).to.eq(name);
+      expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);
+      expect(await collectionSub.methods.description().call()).to.eq(description);
+    });
+  });
+
+  [
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'nft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+
+      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+      await collection.methods.mint(caller).send({from: caller});
+
+      const totalSupply = await collection.methods.totalSupply().call();
+      expect(totalSupply).to.equal('1');
+    });
+  });
+
+  [
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'nft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+
+      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+      await collection.methods.mint(caller).send({from: caller});
+      await collection.methods.mint(caller).send({from: caller});
+      await collection.methods.mint(caller).send({from: caller});
+
+      const balance = await collection.methods.balanceOf(caller).call();
+      expect(balance).to.equal('3');
+    });
+  });
+
+  [
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'nft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');
+
+      const result = await collection.methods.mint(caller).send();
+      const tokenId = result.events.Transfer.returnValues.tokenId;
+
+      const owner = await collection.methods.ownerOf(tokenId).call();
+      expect(owner).to.equal(caller);
+    });
+  });
+
+  [
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    // TODO {mode: 'nft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf after burn`, testCase.requiredPallets, async ({helper}) => {
+      const caller = await helper.eth.createAccountWithBalance(donor);
+      const receiver = helper.eth.createAccount();
+      const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf-AfterBurn', '6', '6');
+
+      const result = await collection.methods.mint(caller).send();
+      const tokenId = result.events.Transfer.returnValues.tokenId;
+      const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
+
+      await tokenContract.methods.repartition(2).send();
+      await tokenContract.methods.transfer(receiver, 1).send();
+
+      await tokenContract.methods.burnFrom(caller, 1).send();
+
+      const owner = await collection.methods.ownerOf(tokenId).call();
+      expect(owner).to.equal(receiver);
+    });
+  });
+
+  itEth.ifWithPallets('RFT: ownerOf for partial ownership', [Pallets.ReFungible], async ({helper}) => {
+    const caller = await helper.eth.createAccountWithBalance(donor);
+    const receiver = helper.eth.createAccount();
+    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
+    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+
+    const result = await contract.methods.mint(caller).send();
+    const tokenId = result.events.Transfer.returnValues.tokenId;
+    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
+
+    await tokenContract.methods.repartition(2).send();
+    await tokenContract.methods.transfer(receiver, 1).send();
+
+    const owner = await contract.methods.ownerOf(tokenId).call();
+    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+  });
+});
addedtests/src/eth/tokens/minting.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -0,0 +1,167 @@
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+
+
+describe('Minting tokens', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (helper, privateKey) => {
+      donor = await privateKey({filename: __filename});
+      [alice] = await helper.arrange.createAccounts([30n, 20n], donor);
+    });
+  });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'ft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const receiver = helper.eth.createAccount();
+      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+      const collection = await helper[testCase.mode].mintCollection(alice);
+      await collection.addAdmin(alice, {Ethereum: owner});
+
+      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+      const result = await contract.methods.mint(...mintingParams).send({from: owner});
+
+      // Check events:
+      const event = result.events.Transfer;
+      expect(event.address).to.equal(collectionAddress);
+      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.equal(receiver);
+      if (testCase.mode === 'ft')
+        expect(event.returnValues.value).to.equal('100');
+
+      // Check token exist:
+      if(testCase.mode === 'ft') {
+        expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);
+      } else {
+        const tokenId = event.returnValues.tokenId;
+        expect(tokenId).to.be.equal('1');
+        expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);
+        expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+      }
+    });
+  });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'ft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const receiver = helper.eth.createAccount();
+      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+      const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+      // Check events:
+      const event = result.events.Transfer;
+      expect(event.address).to.equal(collectionAddress);
+      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.equal(receiver);
+      if (testCase.mode === 'ft')
+        expect(event.returnValues.value).to.equal('100');
+
+      // Check token exist:
+      if(testCase.mode === 'ft') {
+        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+      } else {
+        const tokenId = event.returnValues.tokenId;
+        expect(tokenId).to.be.equal('1');
+        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+        expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+      }
+    });
+  });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+    {mode: 'ft' as const, requiredPallets: []},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const receiver = helper.eth.createAccount();
+      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+      const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+      // Check events:
+      const event = result.events.Transfer;
+      expect(event.address).to.equal(collectionAddress);
+      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.equal(receiver);
+      if (testCase.mode === 'ft')
+        expect(event.returnValues.value).to.equal('100');
+
+      // Check token exist:
+      if(testCase.mode === 'ft') {
+        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+      } else {
+        const tokenId = event.returnValues.tokenId;
+        expect(tokenId).to.be.equal('1');
+        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+        expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+      }
+    });
+  });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+  ].map(testCase => {
+    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const receiver = helper.eth.createAccount();
+
+      const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
+      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+      const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
+      const tokenId = result.events.Transfer.returnValues.tokenId;
+      expect(tokenId).to.be.equal('1');
+
+      const event = result.events.Transfer;
+      expect(event.address).to.be.equal(collectionAddress);
+      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.be.equal(receiver);
+
+      expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+      expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+      // TODO: this wont work right now, need release 919000 first
+      // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
+      // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
+      // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
+    });
+  });
+});
\ No newline at end of file
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -257,7 +257,7 @@
     }
   }
 
-  async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+  async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18, mergeDeprecated = false): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[], collection: Contract }> {
     const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
     const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);
     const functionName: string = this.createCollectionMethodName(mode);
@@ -268,8 +268,9 @@
     const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
     const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
     const events = this.helper.eth.normalizeEvents(result.events);
+    const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);
 
-    return {collectionId, collectionAddress, events};
+    return {collectionId, collectionAddress, events, collection};
   }
 
   createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, Pallets, usingPlaygrounds} from '../util';
+import {expect, itSub, usingPlaygrounds} from '../util';
 
 describe('Integration Test: Composite nesting tests', () => {
   let alice: IKeyringPair;
@@ -287,54 +287,7 @@
     await collectionFT.mint(charlie, 5n);
     await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);
     expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
-  });
-
-  // ---------- Re-Fungible ----------
-
-  itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
-    await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
-    await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
-    await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
-    await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    // Create an immediately nested token
-    const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
-    expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
-    // Create a token to be nested and nest
-    const newToken = await collectionRFT.mintToken(charlie, 5n);
-    await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
-    expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
   });
-
-  itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice);
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
-    await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});
-    await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
-    await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
-    await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
-    await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    // Create an immediately nested token
-    const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
-    expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
-    // Create a token to be nested and nest
-    const newToken = await collectionRFT.mintToken(charlie, 5n);
-    await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
-    expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
-  });
 });
 
 describe('Negative Test: Nesting', () => {
@@ -579,89 +532,5 @@
 
     expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
     expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
-  });
-
-  // ---------- Re-Fungible ----------
-
-  itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice);
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice);
-
-    // Try to create an immediately nested token
-    await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
-      .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
-
-    // Try to create a token to be nested and nest
-    const token = await collectionRFT.mintToken(alice, 5n);
-    await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
-      .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
-  });
-
-  itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice);
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice);
-
-    await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
-    await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
-    await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    // Try to create a token to be nested and nest
-    const newToken = await collectionRFT.mintToken(alice);
-    await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
-    expect(await targetToken.getChildren()).to.be.length(0);
-    expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
-    // Nest some tokens as Alice into Bob's token
-    await newToken.transfer(alice, targetToken.nestingAccount());
-
-    // Try to pull it out
-    await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
-      .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
-    expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
-  });
-
-  itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice);
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice);
-
-    await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});
-    await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
-    await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
-    // Try to create a token to be nested and nest
-    const newToken = await collectionRFT.mintToken(alice);
-    await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
-    expect(await targetToken.getChildren()).to.be.length(0);
-    expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
-    // Nest some tokens as Alice into Bob's token
-    await newToken.transfer(alice, targetToken.nestingAccount());
-
-    // Try to pull it out
-    await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
-      .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
-    expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
-  });
-
-  itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {
-    const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
-    const collectionRFT = await helper.rft.mintCollection(alice);
-    const targetToken = await collectionNFT.mintToken(alice);
-
-    // Try to create an immediately nested token
-    await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
-      .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
-
-    // Try to create a token to be nested and nest
-    const token = await collectionRFT.mintToken(alice, 5n);
-    await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
-      .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
   });
 });
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -88,20 +88,6 @@
     expect((await token.getTop10Owners()).length).to.be.equal(10);
   });
 
-  itSub('Transfer token pieces', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-    expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
-    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
-    await expect(token.transfer(alice, {Substrate: bob.address}, 41n))
-      .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
-  });
-
   itSub('Create multiple tokens', async ({helper}) => {
     const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     // TODO: fix mintMultipleTokens
@@ -118,56 +104,8 @@
     const lastTokenId = await collection.getLastTokenId();
     expect(lastTokenId).to.be.equal(3);
     expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
-  });
-
-  itSub('Burn some pieces', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-    expect(await token.burn(alice, 99n)).to.be.true;
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
   });
 
-  itSub('Burn all pieces', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-
-    expect(await token.burn(alice, 100n)).to.be.true;
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
-  });
-
-  itSub('Burn some pieces for multiple users', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-    expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
-    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
-    expect(await token.burn(alice, 40n)).to.be.true;
-
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
-
-    expect(await token.burn(bob, 59n)).to.be.true;
-
-    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
-    expect(await token.burn(bob, 1n)).to.be.true;
-
-    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
-  });
-
   itSub('Set allowance for token', async ({helper}) => {
     const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     const token = await collection.mintToken(alice, 100n);
@@ -183,68 +121,6 @@
     expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
   });
 
-  itSub('Repartition', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-
-    expect(await token.repartition(alice, 200n)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
-    expect(await token.getTotalPieces()).to.be.equal(200n);
-
-    expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
-    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
-
-    await expect(token.repartition(alice, 80n))
-      .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
-
-    expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
-    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
-    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
-
-    expect(await token.repartition(bob, 150n)).to.be.true;
-    await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
-      .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
-  });
-
-  itSub('Repartition with increased amount', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-    await token.repartition(alice, 200n);
-    const chainEvents = helper.chainLog.slice(-1)[0].events;
-    const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
-    expect(event).to.deep.include({
-      section: 'common',
-      method: 'ItemCreated',
-      index: [66, 2],
-      data: [
-        collection.collectionId,
-        token.tokenId,
-        {substrate: alice.address},
-        100n,
-      ],
-    });
-  });
-
-  itSub('Repartition with decreased amount', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const token = await collection.mintToken(alice, 100n);
-    await token.repartition(alice, 50n);
-    const chainEvents = helper.chainLog.slice(-1)[0].events;
-    const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
-    expect(event).to.deep.include({
-      section: 'common',
-      method: 'ItemDestroyed',
-      index: [66, 3],
-      data: [
-        collection.collectionId,
-        token.tokenId,
-        {substrate: alice.address},
-        50n,
-      ],
-    });
-  });
-
   itSub('Create new collection with properties', async ({helper}) => {
     const properties = [{key: 'key1', value: 'val1'}];
     const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
@@ -252,46 +128,5 @@
     const info = await collection.getData();
     expect(info?.raw.properties).to.be.deep.equal(properties);
     expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);
-  });
-});
-
-describe('Refungible negative tests', () => {
-  let donor: IKeyringPair;
-  let alice: IKeyringPair;
-  let bob: IKeyringPair;
-  let charlie: IKeyringPair;
-
-  before(async function() {
-    await usingPlaygrounds(async (helper, privateKey) => {
-      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
-      donor = await privateKey({filename: __filename});
-      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
-    });
-  });
-
-  itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
-    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-    const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
-    const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
-    // 1. Alice cannot transfer Bob's token:
-    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
-    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
-    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
-    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
-
-    // 2. Alice cannot transfer non-existing token:
-    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
-    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
-
-    // 3. Zero transfer allowed (EIP-20):
-    await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
-
-    expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
-    expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-    expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
-    expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
-    expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
   });
 });
addedtests/src/sub/refungible/burn.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/sub/refungible/burn.test.ts
@@ -0,0 +1,127 @@
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible: burn', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+      donor = await privateKey({filename: __filename});
+      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+    });
+  });
+
+  itSub('can burn some pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+    await token.burn(alice, 99n);
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
+  });
+
+  itSub('can burn all pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+
+    await token.burn(alice, 100n);
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+  });
+
+  itSub('burn pieces for multiple users', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+
+    await token.transfer(alice, {Substrate: bob.address}, 60n);
+
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+
+    await token.burn(alice, 40n);
+
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+
+    await token.burn(bob, 59n);
+
+    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+
+    await token.burn(bob, 1n);
+
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+  });
+
+  itSub('burn pieces by admin', async function({helper}) {
+    const collection = await helper.rft.mintCollection(alice);
+    await collection.setLimits(alice, {ownerCanTransfer: true});
+    await collection.addAdmin(alice, {Substrate: bob.address});
+    const token = await collection.mintToken(alice, 100n);
+
+    await token.burnFrom(bob, {Substrate: alice.address}, 100n);
+    expect(await token.doesExist()).to.be.false;
+  });
+});
+
+describe('Refungible: burn negative tests', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+      donor = await privateKey({filename: __filename});
+      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
+    });
+  });
+
+  itSub('cannot burn non-owned token pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice);
+    const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+    const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+    // 1. Cannot burn non-owned token:
+    await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 2. Cannot burn non-existing token:
+    await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+    await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 3. Can burn zero amount of owned tokens (EIP-20)
+    await aliceToken.burn(alice, 0n);
+
+    // 4. Storage is not corrupted:
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+    // 4.1 Tokens can be transfered:
+    await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+    await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+  });
+});
addedtests/src/sub/refungible/nesting.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/sub/refungible/nesting.test.ts
@@ -0,0 +1,180 @@
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';
+
+describe('Refungible nesting', () => {
+  let alice: IKeyringPair;
+  let charlie: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+      const donor = await privateKey({filename: __filename});
+      [alice, charlie] = await helper.arrange.createAccounts([50n, 10n], donor);
+    });
+  });
+
+  [
+    {restrictedMode: true},
+    {restrictedMode: false},
+  ].map(testCase => {
+    itSub(`Owner can nest their token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+      const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
+      const collectionRFT = await helper.rft.mintCollection(alice);
+      const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
+
+      await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+      await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
+      await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+      await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
+      await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
+      await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
+
+      // Create an immediately nested token
+      const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
+      expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
+
+      // Create a token to be nested and nest
+      const newToken = await collectionRFT.mintToken(charlie, 5n);
+      await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+      expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
+      expect(await newToken.getBalance({Substrate: charlie.address})).to.be.equal(3n);
+    });
+  });
+
+  itSub('Owner can unnest nested token', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+    const targetToken = await collection.mintToken(alice);
+
+    // Owner mints nested RFT token:
+    const collectionRFT = await helper.rft.mintCollection(alice);
+    const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+
+    // 1.1 Owner can partially unnest token pieces with transferFrom:
+    await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n);
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
+    expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+
+    // 1.2 Owner can unnest all pieces:
+    await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 1n);
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(10n);
+    expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+  });
+
+  itSub('Owner can burn nested token pieces', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+    const targetToken = await collection.mintToken(alice);
+
+    // Owner mints nested RFT token:
+    const collectionRFT = await helper.rft.mintCollection(alice);
+    const token = await collectionRFT.mintToken(alice, 100n, {Substrate: alice.address});
+    await token.transfer(alice, targetToken.nestingAccount(), 30n);
+
+    // 1.1 Owner can partially burnFrom nested pieces:
+    await token.burnFrom(alice, targetToken.nestingAccount(), 10n);
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(70n);
+    expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(20n);
+    expect(await targetToken.getChildren()).to.has.length(1);
+
+    // 1.1 Owner can burnFrom all nested pieces:
+    await token.burnFrom(alice, targetToken.nestingAccount(), 20n);
+    expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+    expect(await targetToken.getChildren()).to.has.length(0);
+    expect(await token.doesExist()).to.be.true;
+
+    // 2. Target token does not contain any pieces and can be burnt:
+    await targetToken.burn(alice);
+    expect(await targetToken.doesExist()).to.be.false;
+  });
+});
+
+describe('Refungible nesting negative tests', () => {
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+      const donor = await privateKey({filename: __filename});
+      [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);
+    });
+  });
+
+  itSub('cannot nest token if nesting is disabled', async ({helper}) => {
+    const collectionNFT = await helper.nft.mintCollection(alice);
+    const collectionRFT = await helper.rft.mintCollection(alice);
+    const targetToken = await collectionNFT.mintToken(alice);
+
+    // Try to create an immediately nested token
+    await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+      .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+
+    // Try to create a token to be nested and nest
+    const token = await collectionRFT.mintToken(alice, 5n);
+    await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+      .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+  });
+
+  [
+    {restrictedMode: true},
+    {restrictedMode: false},
+  ].map(testCase => {
+    itSub(`non-Owner cannot nest someone else's token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+      const collectionNFT = await helper.nft.mintCollection(alice);
+      const collectionRFT = await helper.rft.mintCollection(alice);
+      const targetToken = await collectionNFT.mintToken(alice);
+
+      await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+      await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
+      await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+      // Try to create a token to be nested and nest
+      const newToken = await collectionRFT.mintToken(alice);
+      await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+
+      expect(await targetToken.getChildren()).to.be.length(0);
+      expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
+
+      // Nest some tokens as Alice into Bob's token
+      await newToken.transfer(alice, targetToken.nestingAccount());
+
+      // Try to pull it out
+      await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
+        .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
+      expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+    });
+  });
+
+  itSub('ReFungible: disallows to nest token to an unlisted collection', async ({helper}) => {
+    const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
+    const collectionRFT = await helper.rft.mintCollection(alice);
+    const targetToken = await collectionNFT.mintToken(alice);
+
+    // Try to create an immediately nested token
+    await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+      .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+
+    // Try to create a token to be nested and nest
+    const token = await collectionRFT.mintToken(alice, 5n);
+    await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+      .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+  });
+});
addedtests/src/sub/refungible/repartition.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/sub/refungible/repartition.test.ts
@@ -0,0 +1,96 @@
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('integration test: Refungible functionality:', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+      donor = await privateKey({filename: __filename});
+      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+    });
+  });
+
+  itSub('Repartition', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+
+    expect(await token.repartition(alice, 200n)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
+    expect(await token.getTotalPieces()).to.be.equal(200n);
+
+    expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
+    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
+
+    await expect(token.repartition(alice, 80n))
+      .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
+
+    expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
+
+    expect(await token.repartition(bob, 150n)).to.be.true;
+    await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
+      .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+  });
+
+  itSub('Repartition with increased amount', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+    await token.repartition(alice, 200n);
+    const chainEvents = helper.chainLog.slice(-1)[0].events;
+    const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
+    expect(event).to.deep.include({
+      section: 'common',
+      method: 'ItemCreated',
+      index: [66, 2],
+      data: [
+        collection.collectionId,
+        token.tokenId,
+        {substrate: alice.address},
+        100n,
+      ],
+    });
+  });
+
+  itSub('Repartition with decreased amount', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+    await token.repartition(alice, 50n);
+    const chainEvents = helper.chainLog.slice(-1)[0].events;
+    const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
+    expect(event).to.deep.include({
+      section: 'common',
+      method: 'ItemDestroyed',
+      index: [66, 3],
+      data: [
+        collection.collectionId,
+        token.tokenId,
+        {substrate: alice.address},
+        50n,
+      ],
+    });
+  });
+});
+
addedtests/src/sub/refungible/transfer.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/sub/refungible/transfer.test.ts
@@ -0,0 +1,73 @@
+// 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/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible transfer tests', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+  let charlie: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+      donor = await privateKey({filename: __filename});
+      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+    });
+  });
+
+  itSub('Can transfer token pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const token = await collection.mintToken(alice, 100n);
+
+    expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+    // 1. Can transfer less or equal than have:
+    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+  });
+
+  itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+    const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+    // 1. Alice cannot transfer Bob's token:
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+    // 2. Alice cannot transfer non-existing token:
+    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+    // 3. Cannot transfer more than have:
+    await expect(tokenAlice.transfer(alice, {Substrate: bob.address}, 11n))
+      .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+
+    // 4. Zero transfer allowed (EIP-20):
+    await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
+
+    expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+    expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+    expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
+    expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
+    expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
+  });
+});
\ No newline at end of file
modifiedtests/src/util/index.tsdiffbeforeafterboth
--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -100,6 +100,9 @@
 export const LOCKING_PERIOD = 12n; // 12 blocks of relay
 export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
 
+// Native contracts
+export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
 
 export enum Pallets {
   Inflation = 'inflation',