git.delta.rocks / unique-network / refs/commits / 15c21abe7df6

difftreelog

chore refactor RFT token tests

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

3 files changed

modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -15,8 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {createCollectionExpectSuccess, UNIQUE} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';
-import reFungibleTokenAbi from './reFungibleTokenAbi.json';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers';
 import {expect} from 'chai';
 
 describe('Refungible: Information getting', () => {
@@ -84,7 +83,7 @@
     await contract.methods.mint(caller, tokenId).send();
 
     const tokenAddress = tokenIdToAddress(collectionId, tokenId);
-    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});
+    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
 
     await tokenContract.methods.repartition(2).send();
     await tokenContract.methods.transfer(receiver, 1).send();
@@ -108,7 +107,7 @@
     await contract.methods.mint(caller, tokenId).send();
 
     const tokenAddress = tokenIdToAddress(collectionId, tokenId);
-    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});
+    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
 
     await tokenContract.methods.repartition(2).send();
     await tokenContract.methods.transfer(receiver, 1).send();
@@ -250,7 +249,7 @@
     await contract.methods.mint(caller, tokenId).send();
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+    const tokenContract = uniqueRefungibleToken(web3, address, caller);
     await tokenContract.methods.repartition(15).send();
 
     {
@@ -345,7 +344,7 @@
     await contract.methods.mint(caller, tokenId).send();
 
     const tokenAddress = tokenIdToAddress(collectionId, tokenId);
-    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});
+    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
 
     await tokenContract.methods.repartition(2).send();
     await tokenContract.methods.transfer(receiver, 1).send();
@@ -377,7 +376,7 @@
     await contract.methods.mint(caller, tokenId).send();
 
     const tokenAddress = tokenIdToAddress(collectionId, tokenId);
-    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});
+    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
 
     await tokenContract.methods.repartition(2).send();
     
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
before · tests/src/eth/reFungibleToken.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';19import reFungibleTokenAbi from './reFungibleTokenAbi.json';2021import chai from 'chai';22import chaiAsPromised from 'chai-as-promised';23chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Refungible token: Information getting', () => {27  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {28    const alice = privateKeyWrapper('//Alice');2930    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;3132    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);3334    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;3536    const address = tokenIdToAddress(collectionId, tokenId);37    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});38    const totalSupply = await contract.methods.totalSupply().call();3940    expect(totalSupply).to.equal('200');41  });4243  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {44    const alice = privateKeyWrapper('//Alice');4546    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;4748    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);4950    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;5152    const address = tokenIdToAddress(collectionId, tokenId);53    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});54    const balance = await contract.methods.balanceOf(caller).call();5556    expect(balance).to.equal('200');57  });5859  itWeb3('decimals', async ({api, web3, privateKeyWrapper}) => {60    const alice = privateKeyWrapper('//Alice');6162    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;6364    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);6566    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;6768    const address = tokenIdToAddress(collectionId, tokenId);69    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});70    const decimals = await contract.methods.decimals().call();7172    expect(decimals).to.equal('0');73  });74});7576// FIXME: Need erc721 for ReFubgible.77describe('Check ERC721 token URI for ReFungible', () => {78  itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {79    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);80    const helper = evmCollectionHelpers(web3, owner);81    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();82    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);83    const receiver = createEthAccount(web3);84    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});85    86    const nextTokenId = await contract.methods.nextTokenId().call();87    expect(nextTokenId).to.be.equal('1');88    result = await contract.methods.mint(89      receiver,90      nextTokenId,91    ).send();9293    const events = normalizeEvents(result.events);94    const address = collectionIdToAddress(collectionId);9596    expect(events).to.be.deep.equal([97      {98        address,99        event: 'Transfer',100        args: {101          from: '0x0000000000000000000000000000000000000000',102          to: receiver,103          tokenId: nextTokenId,104        },105      },106    ]);107108    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');109  });110111  itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {112    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);113    const helper = evmCollectionHelpers(web3, owner);114    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();115    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);116    const receiver = createEthAccount(web3);117    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});118    119    const nextTokenId = await contract.methods.nextTokenId().call();120    expect(nextTokenId).to.be.equal('1');121    result = await contract.methods.mint(122      receiver,123      nextTokenId,124    ).send();125    126    // Set URL127    await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();128      129    const events = normalizeEvents(result.events);130    const address = collectionIdToAddress(collectionId);131132    expect(events).to.be.deep.equal([133      {134        address,135        event: 'Transfer',136        args: {137          from: '0x0000000000000000000000000000000000000000',138          to: receiver,139          tokenId: nextTokenId,140        },141      },142    ]);143144    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');145  });146147  itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {148    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);149    const helper = evmCollectionHelpers(web3, owner);150    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();151    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);152    const receiver = createEthAccount(web3);153    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});154    155    const nextTokenId = await contract.methods.nextTokenId().call();156    expect(nextTokenId).to.be.equal('1');157    result = await contract.methods.mint(158      receiver,159      nextTokenId,160    ).send();161          162    const events = normalizeEvents(result.events);163    const address = collectionIdToAddress(collectionId);164165    expect(events).to.be.deep.equal([166      {167        address,168        event: 'Transfer',169        args: {170          from: '0x0000000000000000000000000000000000000000',171          to: receiver,172          tokenId: nextTokenId,173        },174      },175    ]);176177    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);178  });179180  itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {181    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);182    const helper = evmCollectionHelpers(web3, owner);183    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();184    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);185    const receiver = createEthAccount(web3);186    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});187    188    const nextTokenId = await contract.methods.nextTokenId().call();189    expect(nextTokenId).to.be.equal('1');190    result = await contract.methods.mint(191      receiver,192      nextTokenId,193    ).send();194          195    // Set suffix196    const suffix = '/some/suffix';197    await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();198199    const events = normalizeEvents(result.events);200    const address = collectionIdToAddress(collectionId);201202    expect(events).to.be.deep.equal([203      {204        address,205        event: 'Transfer',206        args: {207          from: '0x0000000000000000000000000000000000000000',208          to: receiver,209          tokenId: nextTokenId,210        },211      },212    ]);213214    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);215  });216});217218describe('Refungible: Plain calls', () => {219  itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {220    const alice = privateKeyWrapper('//Alice');221222    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;223224    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);225226    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;227228    const address = tokenIdToAddress(collectionId, tokenId);229230    const spender = createEthAccount(web3);231232    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});233234    {235      const result = await contract.methods.approve(spender, 100).send({from: owner});236      const events = normalizeEvents(result.events);237238      expect(events).to.be.deep.equal([239        {240          address,241          event: 'Approval',242          args: {243            owner,244            spender,245            value: '100',246          },247        },248      ]);249    }250251    {252      const allowance = await contract.methods.allowance(owner, spender).call();253      expect(+allowance).to.equal(100);254    }255  });256257  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {258    const alice = privateKeyWrapper('//Alice');259260    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;261262    const owner = createEthAccount(web3);263    await transferBalanceToEth(api, alice, owner);264265    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;266267    const spender = createEthAccount(web3);268    await transferBalanceToEth(api, alice, spender);269270    const receiver = createEthAccount(web3);271272    const address = tokenIdToAddress(collectionId, tokenId);273    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});274275    await contract.methods.approve(spender, 100).send();276277    {278      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});279      const events = normalizeEvents(result.events);280      expect(events).to.include.deep.members([281        {282          address,283          event: 'Transfer',284          args: {285            from: owner,286            to: receiver,287            value: '49',288          },289        },290        {291          address,292          event: 'Approval',293          args: {294            owner,295            spender,296            value: '51',297          },298        },299      ]);300    }301302    {303      const balance = await contract.methods.balanceOf(receiver).call();304      expect(+balance).to.equal(49);305    }306307    {308      const balance = await contract.methods.balanceOf(owner).call();309      expect(+balance).to.equal(151);310    }311  });312313  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {314    const alice = privateKeyWrapper('//Alice');315316    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;317318    const owner = createEthAccount(web3);319    await transferBalanceToEth(api, alice, owner);320321    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;322323    const receiver = createEthAccount(web3);324    await transferBalanceToEth(api, alice, receiver);325326    const address = tokenIdToAddress(collectionId, tokenId);327    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});328329    {330      const result = await contract.methods.transfer(receiver, 50).send({from: owner});331      const events = normalizeEvents(result.events);332      expect(events).to.include.deep.members([333        {334          address,335          event: 'Transfer',336          args: {337            from: owner,338            to: receiver,339            value: '50',340          },341        },342      ]);343    }344345    {346      const balance = await contract.methods.balanceOf(owner).call();347      expect(+balance).to.equal(150);348    }349350    {351      const balance = await contract.methods.balanceOf(receiver).call();352      expect(+balance).to.equal(50);353    }354  });355356  itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {357    const alice = privateKeyWrapper('//Alice');358359    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;360361    const owner = createEthAccount(web3);362    await transferBalanceToEth(api, alice, owner);363364    const receiver = createEthAccount(web3);365    await transferBalanceToEth(api, alice, receiver);366367    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;368369    const address = tokenIdToAddress(collectionId, tokenId);370    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});371372    await contract.methods.repartition(200).send({from: owner});373    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);374    await contract.methods.transfer(receiver, 110).send({from: owner});375    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);376    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);377    378    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;379380    await contract.methods.transfer(receiver, 90).send({from: owner});381    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);382    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);383384    await contract.methods.repartition(150).send({from: receiver});385    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;386    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);387  });388389  itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {390    const alice = privateKeyWrapper('//Alice');391392    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;393394    const owner = createEthAccount(web3);395    await transferBalanceToEth(api, alice, owner);396397    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;398399    const address = tokenIdToAddress(collectionId, tokenId);400    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});401402    const result = await contract.methods.repartition(200).send();403    const events = normalizeEvents(result.events);404405    expect(events).to.deep.equal([406      {407        address,408        event: 'Transfer',409        args: {410          from: '0x0000000000000000000000000000000000000000',411          to: owner,412          value: '100',413        },414      },415    ]);416  });417418  itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {419    const alice = privateKeyWrapper('//Alice');420421    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;422423    const owner = createEthAccount(web3);424    await transferBalanceToEth(api, alice, owner);425426    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;427428    const address = tokenIdToAddress(collectionId, tokenId);429    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});430431    const result = await contract.methods.repartition(50).send();432    const events = normalizeEvents(result.events);433    expect(events).to.deep.equal([434      {435        address,436        event: 'Transfer',437        args: {438          from: owner,439          to: '0x0000000000000000000000000000000000000000',440          value: '50',441        },442      },443    ]);444  });445446  itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {447    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);448    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);449    const helper = evmCollectionHelpers(web3, caller);450    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();451    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);452    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});453454    const tokenId = await contract.methods.nextTokenId().call();455    await contract.methods.mint(caller, tokenId).send();456457    const address = tokenIdToAddress(collectionId, tokenId);458459    const tokenContract =  new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});460    await tokenContract.methods.repartition(2).send();461    await tokenContract.methods.transfer(receiver, 1).send();462463    const events =  await recordEvents(contract, async () => 464      await tokenContract.methods.burnFrom(caller, 1).send());465    expect(events).to.deep.equal([466      {467        address: collectionIdAddress,468        event: 'Transfer',469        args: {470          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',471          to: receiver,472          tokenId,473        },474      },475    ]);476  });477});478479describe('Refungible: Fees', () => {480  itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {481    const alice = privateKeyWrapper('//Alice');482483    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;484485    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);486    const spender = createEthAccount(web3);487488    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;489490    const address = tokenIdToAddress(collectionId, tokenId);491    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});492493    const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));494    expect(cost < BigInt(0.2 * Number(UNIQUE)));495  });496497  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {498    const alice = privateKeyWrapper('//Alice');499500    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;501502    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);503    const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);504505    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;506507    const address = tokenIdToAddress(collectionId, tokenId);508    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});509510    await contract.methods.approve(spender, 100).send({from: owner});511512    const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));513    expect(cost < BigInt(0.2 * Number(UNIQUE)));514  });515516  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {517    const alice = privateKeyWrapper('//Alice');518519    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;520521    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);522    const receiver = createEthAccount(web3);523524    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;525526    const address = tokenIdToAddress(collectionId, tokenId);527    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});528529    const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));530    expect(cost < BigInt(0.2 * Number(UNIQUE)));531  });532});533534describe('Refungible: Substrate calls', () => {535  itWeb3('Events emitted for approve()', async ({web3, api, privateKeyWrapper}) => {536    const alice = privateKeyWrapper('//Alice');537538    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;539540    const receiver = createEthAccount(web3);541542    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;543544    const address = tokenIdToAddress(collectionId, tokenId);545    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);546547    const events = await recordEvents(contract, async () => {548      expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;549    });550551    expect(events).to.be.deep.equal([552      {553        address,554        event: 'Approval',555        args: {556          owner: subToEth(alice.address),557          spender: receiver,558          value: '100',559        },560      },561    ]);562  });563564  itWeb3('Events emitted for transferFrom()', async ({web3, api, privateKeyWrapper}) => {565    const alice = privateKeyWrapper('//Alice');566567    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;568    const bob = privateKeyWrapper('//Bob');569570    const receiver = createEthAccount(web3);571572    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;573    expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;574575    const address = tokenIdToAddress(collectionId, tokenId);576    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);577578    const events = await recordEvents(contract, async () => {579      expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver},  51n)).to.be.true;580    });581582    expect(events).to.be.deep.equal([583      {584        address,585        event: 'Transfer',586        args: {587          from: subToEth(alice.address),588          to: receiver,589          value: '51',590        },591      },592      {593        address,594        event: 'Approval',595        args: {596          owner: subToEth(alice.address),597          spender: subToEth(bob.address),598          value: '49',599        },600      },601    ]);602  });603604  itWeb3('Events emitted for transfer()', async ({web3, api, privateKeyWrapper}) => {605    const alice = privateKeyWrapper('//Alice');606607    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;608609    const receiver = createEthAccount(web3);610611    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;612613    const address = tokenIdToAddress(collectionId, tokenId);614    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);615616    const events = await recordEvents(contract, async () => {617      expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver},  51n)).to.be.true;618    });619620    expect(events).to.be.deep.equal([621      {622        address,623        event: 'Transfer',624        args: {625          from: subToEth(alice.address),626          to: receiver,627          value: '51',628        },629      },630    ]);631  });632});633634describe('ERC 1633 implementation', () => {635  itWeb3('Parent NFT token address and id', async ({api, web3, privateKeyWrapper}) => {636    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);637638    const {collectionIdAddress:  nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);639    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);640    const nftTokenId = await nftContract.methods.nextTokenId().call();641    await nftContract.methods.mint(owner, nftTokenId).send();642    const nftCollectionId = collectionIdFromAddress(nftCollectionAddress);643644    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);645    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);646    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();647    await refungibleContract.methods.mint(owner, refungibleTokenId).send();648649    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);650    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);651    await refungibleTokenContract.methods.setParentNFT(nftCollectionAddress, nftTokenId).send();652653    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();654    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();655    const nftTokenAddress = tokenIdToAddress(nftCollectionId, nftTokenId);656    expect(tokenAddress).to.be.equal(nftTokenAddress);657    expect(tokenId).to.be.equal(nftTokenId);658  });659});660
after · tests/src/eth/reFungibleToken.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';18import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';1920import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Refungible token: Information getting', () => {26  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {27    const alice = privateKeyWrapper('//Alice');2829    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;3031    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);3233    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;3435    const address = tokenIdToAddress(collectionId, tokenId);36    const contract = uniqueRefungibleToken(web3, address, caller);37    const totalSupply = await contract.methods.totalSupply().call();3839    expect(totalSupply).to.equal('200');40  });4142  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {43    const alice = privateKeyWrapper('//Alice');4445    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;4647    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);4849    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;5051    const address = tokenIdToAddress(collectionId, tokenId);52    const contract = uniqueRefungibleToken(web3, address, caller);53    const balance = await contract.methods.balanceOf(caller).call();5455    expect(balance).to.equal('200');56  });5758  itWeb3('decimals', async ({api, web3, privateKeyWrapper}) => {59    const alice = privateKeyWrapper('//Alice');6061    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;6263    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);6465    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;6667    const address = tokenIdToAddress(collectionId, tokenId);68    const contract = uniqueRefungibleToken(web3, address, caller);69    const decimals = await contract.methods.decimals().call();7071    expect(decimals).to.equal('0');72  });73});7475// FIXME: Need erc721 for ReFubgible.76describe('Check ERC721 token URI for ReFungible', () => {77  itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {78    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);79    const helper = evmCollectionHelpers(web3, owner);80    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();81    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);82    const receiver = createEthAccount(web3);83    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});84    85    const nextTokenId = await contract.methods.nextTokenId().call();86    expect(nextTokenId).to.be.equal('1');87    result = await contract.methods.mint(88      receiver,89      nextTokenId,90    ).send();9192    const events = normalizeEvents(result.events);93    const address = collectionIdToAddress(collectionId);9495    expect(events).to.be.deep.equal([96      {97        address,98        event: 'Transfer',99        args: {100          from: '0x0000000000000000000000000000000000000000',101          to: receiver,102          tokenId: nextTokenId,103        },104      },105    ]);106107    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');108  });109110  itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {111    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);112    const helper = evmCollectionHelpers(web3, owner);113    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();114    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);115    const receiver = createEthAccount(web3);116    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});117    118    const nextTokenId = await contract.methods.nextTokenId().call();119    expect(nextTokenId).to.be.equal('1');120    result = await contract.methods.mint(121      receiver,122      nextTokenId,123    ).send();124    125    // Set URL126    await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();127      128    const events = normalizeEvents(result.events);129    const address = collectionIdToAddress(collectionId);130131    expect(events).to.be.deep.equal([132      {133        address,134        event: 'Transfer',135        args: {136          from: '0x0000000000000000000000000000000000000000',137          to: receiver,138          tokenId: nextTokenId,139        },140      },141    ]);142143    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');144  });145146  itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {147    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);148    const helper = evmCollectionHelpers(web3, owner);149    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();150    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);151    const receiver = createEthAccount(web3);152    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});153    154    const nextTokenId = await contract.methods.nextTokenId().call();155    expect(nextTokenId).to.be.equal('1');156    result = await contract.methods.mint(157      receiver,158      nextTokenId,159    ).send();160          161    const events = normalizeEvents(result.events);162    const address = collectionIdToAddress(collectionId);163164    expect(events).to.be.deep.equal([165      {166        address,167        event: 'Transfer',168        args: {169          from: '0x0000000000000000000000000000000000000000',170          to: receiver,171          tokenId: nextTokenId,172        },173      },174    ]);175176    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);177  });178179  itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {180    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);181    const helper = evmCollectionHelpers(web3, owner);182    let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();183    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);184    const receiver = createEthAccount(web3);185    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});186    187    const nextTokenId = await contract.methods.nextTokenId().call();188    expect(nextTokenId).to.be.equal('1');189    result = await contract.methods.mint(190      receiver,191      nextTokenId,192    ).send();193          194    // Set suffix195    const suffix = '/some/suffix';196    await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();197198    const events = normalizeEvents(result.events);199    const address = collectionIdToAddress(collectionId);200201    expect(events).to.be.deep.equal([202      {203        address,204        event: 'Transfer',205        args: {206          from: '0x0000000000000000000000000000000000000000',207          to: receiver,208          tokenId: nextTokenId,209        },210      },211    ]);212213    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);214  });215});216217describe('Refungible: Plain calls', () => {218  itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {219    const alice = privateKeyWrapper('//Alice');220221    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;222223    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);224225    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;226227    const address = tokenIdToAddress(collectionId, tokenId);228229    const spender = createEthAccount(web3);230231    const contract = uniqueRefungibleToken(web3, address, owner);232233    {234      const result = await contract.methods.approve(spender, 100).send({from: owner});235      const events = normalizeEvents(result.events);236237      expect(events).to.be.deep.equal([238        {239          address,240          event: 'Approval',241          args: {242            owner,243            spender,244            value: '100',245          },246        },247      ]);248    }249250    {251      const allowance = await contract.methods.allowance(owner, spender).call();252      expect(+allowance).to.equal(100);253    }254  });255256  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {257    const alice = privateKeyWrapper('//Alice');258259    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;260261    const owner = createEthAccount(web3);262    await transferBalanceToEth(api, alice, owner);263264    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;265266    const spender = createEthAccount(web3);267    await transferBalanceToEth(api, alice, spender);268269    const receiver = createEthAccount(web3);270271    const address = tokenIdToAddress(collectionId, tokenId);272    const contract = uniqueRefungibleToken(web3, address, owner);273274    await contract.methods.approve(spender, 100).send();275276    {277      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});278      const events = normalizeEvents(result.events);279      expect(events).to.include.deep.members([280        {281          address,282          event: 'Transfer',283          args: {284            from: owner,285            to: receiver,286            value: '49',287          },288        },289        {290          address,291          event: 'Approval',292          args: {293            owner,294            spender,295            value: '51',296          },297        },298      ]);299    }300301    {302      const balance = await contract.methods.balanceOf(receiver).call();303      expect(+balance).to.equal(49);304    }305306    {307      const balance = await contract.methods.balanceOf(owner).call();308      expect(+balance).to.equal(151);309    }310  });311312  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {313    const alice = privateKeyWrapper('//Alice');314315    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;316317    const owner = createEthAccount(web3);318    await transferBalanceToEth(api, alice, owner);319320    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;321322    const receiver = createEthAccount(web3);323    await transferBalanceToEth(api, alice, receiver);324325    const address = tokenIdToAddress(collectionId, tokenId);326    const contract = uniqueRefungibleToken(web3, address, owner);327328    {329      const result = await contract.methods.transfer(receiver, 50).send({from: owner});330      const events = normalizeEvents(result.events);331      expect(events).to.include.deep.members([332        {333          address,334          event: 'Transfer',335          args: {336            from: owner,337            to: receiver,338            value: '50',339          },340        },341      ]);342    }343344    {345      const balance = await contract.methods.balanceOf(owner).call();346      expect(+balance).to.equal(150);347    }348349    {350      const balance = await contract.methods.balanceOf(receiver).call();351      expect(+balance).to.equal(50);352    }353  });354355  itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {356    const alice = privateKeyWrapper('//Alice');357358    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;359360    const owner = createEthAccount(web3);361    await transferBalanceToEth(api, alice, owner);362363    const receiver = createEthAccount(web3);364    await transferBalanceToEth(api, alice, receiver);365366    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;367368    const address = tokenIdToAddress(collectionId, tokenId);369    const contract = uniqueRefungibleToken(web3, address, owner);370371    await contract.methods.repartition(200).send({from: owner});372    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);373    await contract.methods.transfer(receiver, 110).send({from: owner});374    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);375    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);376    377    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;378379    await contract.methods.transfer(receiver, 90).send({from: owner});380    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);381    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);382383    await contract.methods.repartition(150).send({from: receiver});384    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;385    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);386  });387388  itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {389    const alice = privateKeyWrapper('//Alice');390391    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;392393    const owner = createEthAccount(web3);394    await transferBalanceToEth(api, alice, owner);395396    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;397398    const address = tokenIdToAddress(collectionId, tokenId);399    const contract = uniqueRefungibleToken(web3, address, owner);400401    const result = await contract.methods.repartition(200).send();402    const events = normalizeEvents(result.events);403404    expect(events).to.deep.equal([405      {406        address,407        event: 'Transfer',408        args: {409          from: '0x0000000000000000000000000000000000000000',410          to: owner,411          value: '100',412        },413      },414    ]);415  });416417  itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {418    const alice = privateKeyWrapper('//Alice');419420    const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;421422    const owner = createEthAccount(web3);423    await transferBalanceToEth(api, alice, owner);424425    const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;426427    const address = tokenIdToAddress(collectionId, tokenId);428    const contract = uniqueRefungibleToken(web3, address, owner);429430    const result = await contract.methods.repartition(50).send();431    const events = normalizeEvents(result.events);432    expect(events).to.deep.equal([433      {434        address,435        event: 'Transfer',436        args: {437          from: owner,438          to: '0x0000000000000000000000000000000000000000',439          value: '50',440        },441      },442    ]);443  });444445  itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {446    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);447    const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);448    const helper = evmCollectionHelpers(web3, caller);449    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();450    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);451    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});452453    const tokenId = await contract.methods.nextTokenId().call();454    await contract.methods.mint(caller, tokenId).send();455456    const address = tokenIdToAddress(collectionId, tokenId);457458    const tokenContract =  uniqueRefungibleToken(web3, address, caller);459    await tokenContract.methods.repartition(2).send();460    await tokenContract.methods.transfer(receiver, 1).send();461462    const events =  await recordEvents(contract, async () => 463      await tokenContract.methods.burnFrom(caller, 1).send());464    expect(events).to.deep.equal([465      {466        address: collectionIdAddress,467        event: 'Transfer',468        args: {469          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',470          to: receiver,471          tokenId,472        },473      },474    ]);475  });476});477478describe('Refungible: Fees', () => {479  itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {480    const alice = privateKeyWrapper('//Alice');481482    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;483484    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);485    const spender = createEthAccount(web3);486487    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;488489    const address = tokenIdToAddress(collectionId, tokenId);490    const contract = uniqueRefungibleToken(web3, address, owner);491492    const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));493    expect(cost < BigInt(0.2 * Number(UNIQUE)));494  });495496  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {497    const alice = privateKeyWrapper('//Alice');498499    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;500501    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);502    const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);503504    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;505506    const address = tokenIdToAddress(collectionId, tokenId);507    const contract = uniqueRefungibleToken(web3, address, owner);508509    await contract.methods.approve(spender, 100).send({from: owner});510511    const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));512    expect(cost < BigInt(0.2 * Number(UNIQUE)));513  });514515  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {516    const alice = privateKeyWrapper('//Alice');517518    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;519520    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);521    const receiver = createEthAccount(web3);522523    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;524525    const address = tokenIdToAddress(collectionId, tokenId);526    const contract = uniqueRefungibleToken(web3, address, owner);527528    const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));529    expect(cost < BigInt(0.2 * Number(UNIQUE)));530  });531});532533describe('Refungible: Substrate calls', () => {534  itWeb3('Events emitted for approve()', async ({web3, api, privateKeyWrapper}) => {535    const alice = privateKeyWrapper('//Alice');536537    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;538539    const receiver = createEthAccount(web3);540541    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;542543    const address = tokenIdToAddress(collectionId, tokenId);544    const contract = uniqueRefungibleToken(web3, address);545546    const events = await recordEvents(contract, async () => {547      expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;548    });549550    expect(events).to.be.deep.equal([551      {552        address,553        event: 'Approval',554        args: {555          owner: subToEth(alice.address),556          spender: receiver,557          value: '100',558        },559      },560    ]);561  });562563  itWeb3('Events emitted for transferFrom()', async ({web3, api, privateKeyWrapper}) => {564    const alice = privateKeyWrapper('//Alice');565566    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;567    const bob = privateKeyWrapper('//Bob');568569    const receiver = createEthAccount(web3);570571    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;572    expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;573574    const address = tokenIdToAddress(collectionId, tokenId);575    const contract = uniqueRefungibleToken(web3, address);576577    const events = await recordEvents(contract, async () => {578      expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver},  51n)).to.be.true;579    });580581    expect(events).to.be.deep.equal([582      {583        address,584        event: 'Transfer',585        args: {586          from: subToEth(alice.address),587          to: receiver,588          value: '51',589        },590      },591      {592        address,593        event: 'Approval',594        args: {595          owner: subToEth(alice.address),596          spender: subToEth(bob.address),597          value: '49',598        },599      },600    ]);601  });602603  itWeb3('Events emitted for transfer()', async ({web3, api, privateKeyWrapper}) => {604    const alice = privateKeyWrapper('//Alice');605606    const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;607608    const receiver = createEthAccount(web3);609610    const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;611612    const address = tokenIdToAddress(collectionId, tokenId);613    const contract = uniqueRefungibleToken(web3, address);614615    const events = await recordEvents(contract, async () => {616      expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver},  51n)).to.be.true;617    });618619    expect(events).to.be.deep.equal([620      {621        address,622        event: 'Transfer',623        args: {624          from: subToEth(alice.address),625          to: receiver,626          value: '51',627        },628      },629    ]);630  });631});632633describe('ERC 1633 implementation', () => {634  itWeb3('Parent NFT token address and id', async ({api, web3, privateKeyWrapper}) => {635    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);636637    const {collectionIdAddress:  nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);638    const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);639    const nftTokenId = await nftContract.methods.nextTokenId().call();640    await nftContract.methods.mint(owner, nftTokenId).send();641    const nftCollectionId = collectionIdFromAddress(nftCollectionAddress);642643    const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);644    const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);645    const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();646    await refungibleContract.methods.mint(owner, refungibleTokenId).send();647648    const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);649    const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);650    await refungibleTokenContract.methods.setParentNFT(nftCollectionAddress, nftTokenId).send();651652    const tokenAddress = await refungibleTokenContract.methods.parentToken().call();653    const tokenId = await refungibleTokenContract.methods.parentTokenId().call();654    const nftTokenAddress = tokenIdToAddress(nftCollectionId, nftTokenId);655    expect(tokenAddress).to.be.equal(nftTokenAddress);656    expect(tokenId).to.be.equal(nftTokenId);657  });658});659
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -172,7 +172,7 @@
   });
 }
 
-export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string) {
+export function uniqueRefungibleToken(web3: Web3, tokenAddress: string, owner: string | undefined = undefined) {
   return new web3.eth.Contract(refungibleTokenAbi as any, tokenAddress, {
     from: owner,
     ...GAS_ARGS,