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
before · tests/src/eth/reFungible.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 {createCollectionExpectSuccess, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';19import reFungibleTokenAbi from './reFungibleTokenAbi.json';20import {expect} from 'chai';2122describe('Refungible: Information getting', () => {23  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {24    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25    const helper = evmCollectionHelpers(web3, caller);26    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();27    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);28    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});29    const nextTokenId = await contract.methods.nextTokenId().call();30    await contract.methods.mint(caller, nextTokenId).send();31    const totalSupply = await contract.methods.totalSupply().call();32    expect(totalSupply).to.equal('1');33  });3435  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {36    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);37    const helper = evmCollectionHelpers(web3, caller);38    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();39    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);40    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});4142    {43      const nextTokenId = await contract.methods.nextTokenId().call();44      await contract.methods.mint(caller, nextTokenId).send();45    }46    {47      const nextTokenId = await contract.methods.nextTokenId().call();48      await contract.methods.mint(caller, nextTokenId).send();49    }50    {51      const nextTokenId = await contract.methods.nextTokenId().call();52      await contract.methods.mint(caller, nextTokenId).send();53    }5455    const balance = await contract.methods.balanceOf(caller).call();5657    expect(balance).to.equal('3');58  });5960  itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {61    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);62    const helper = evmCollectionHelpers(web3, caller);63    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();64    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);65    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});6667    const tokenId = await contract.methods.nextTokenId().call();68    await contract.methods.mint(caller, tokenId).send();6970    const owner = await contract.methods.ownerOf(tokenId).call();7172    expect(owner).to.equal(caller);73  });7475  itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {76    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);77    const receiver = createEthAccount(web3);78    const helper = evmCollectionHelpers(web3, caller);79    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();80    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);81    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});8283    const tokenId = await contract.methods.nextTokenId().call();84    await contract.methods.mint(caller, tokenId).send();8586    const tokenAddress = tokenIdToAddress(collectionId, tokenId);87    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});8889    await tokenContract.methods.repartition(2).send();90    await tokenContract.methods.transfer(receiver, 1).send();9192    await tokenContract.methods.burnFrom(caller, 1).send();9394    const owner = await contract.methods.ownerOf(tokenId).call();9596    expect(owner).to.equal(receiver);97  });9899  itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {100    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);101    const receiver = createEthAccount(web3);102    const helper = evmCollectionHelpers(web3, caller);103    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();104    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);105    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});106107    const tokenId = await contract.methods.nextTokenId().call();108    await contract.methods.mint(caller, tokenId).send();109110    const tokenAddress = tokenIdToAddress(collectionId, tokenId);111    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});112113    await tokenContract.methods.repartition(2).send();114    await tokenContract.methods.transfer(receiver, 1).send();115116    const owner = await contract.methods.ownerOf(tokenId).call();117118    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');119  });120});121122describe('Refungible: Plain calls', () => {123  itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {124    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125    const helper = evmCollectionHelpers(web3, owner);126    let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();127    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);128    const receiver = createEthAccount(web3);129    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});130    const nextTokenId = await contract.methods.nextTokenId().call();131132    expect(nextTokenId).to.be.equal('1');133    result = await contract.methods.mintWithTokenURI(134      receiver,135      nextTokenId,136      'Test URI',137    ).send();138139    const events = normalizeEvents(result.events);140141    expect(events).to.include.deep.members([142      {143        address: collectionIdAddress,144        event: 'Transfer',145        args: {146          from: '0x0000000000000000000000000000000000000000',147          to: receiver,148          tokenId: nextTokenId,149        },150      },151    ]);152153    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');154  });155156  itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {157    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);158    const helper = evmCollectionHelpers(web3, caller);159    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();160    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);161    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});162163    const receiver = createEthAccount(web3);164165    {166      const nextTokenId = await contract.methods.nextTokenId().call();167      expect(nextTokenId).to.be.equal('1');168      const result = await contract.methods.mintBulkWithTokenURI(169        receiver,170        [171          [nextTokenId, 'Test URI 0'],172          [+nextTokenId + 1, 'Test URI 1'],173          [+nextTokenId + 2, 'Test URI 2'],174        ],175      ).send();176      const events = normalizeEvents(result.events);177178      expect(events).to.include.deep.members([179        {180          address: collectionIdAddress,181          event: 'Transfer',182          args: {183            from: '0x0000000000000000000000000000000000000000',184            to: receiver,185            tokenId: nextTokenId,186          },187        },188        {189          address: collectionIdAddress,190          event: 'Transfer',191          args: {192            from: '0x0000000000000000000000000000000000000000',193            to: receiver,194            tokenId: String(+nextTokenId + 1),195          },196        },197        {198          address: collectionIdAddress,199          event: 'Transfer',200          args: {201            from: '0x0000000000000000000000000000000000000000',202            to: receiver,203            tokenId: String(+nextTokenId + 2),204          },205        },206      ]);207208      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');209      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');210      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');211    }212  });213214  itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {215    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);216    const helper = evmCollectionHelpers(web3, caller);217    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();218    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);219    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});220221    const tokenId = await contract.methods.nextTokenId().call();222    await contract.methods.mint(caller, tokenId).send();223    {224      const result = await contract.methods.burn(tokenId).send();225      const events = normalizeEvents(result.events);226      expect(events).to.include.deep.members([227        {228          address: collectionIdAddress,229          event: 'Transfer',230          args: {231            from: caller,232            to: '0x0000000000000000000000000000000000000000',233            tokenId: tokenId.toString(),234          },235        },236      ]);237    }238  });239240  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {241    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);242    const helper = evmCollectionHelpers(web3, caller);243    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();244    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);245    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});246247    const receiver = createEthAccount(web3);248249    const tokenId = await contract.methods.nextTokenId().call();250    await contract.methods.mint(caller, tokenId).send();251252    const address = tokenIdToAddress(collectionId, tokenId);253    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});254    await tokenContract.methods.repartition(15).send();255256    {257      const erc20Events = await recordEvents(tokenContract, async () => {258        const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();259        const events = normalizeEvents(result.events);260        expect(events).to.include.deep.members([261          {262            address: collectionIdAddress,263            event: 'Transfer',264            args: {265              from: caller,266              to: receiver,267              tokenId: tokenId.toString(),268            },269          },270        ]);271      });272      273      expect(erc20Events).to.include.deep.members([274        {275          address,276          event: 'Transfer',277          args: {278            from: caller,279            to: receiver,280            value: '15',281          },282        },283      ]);284    }285286    {287      const balance = await contract.methods.balanceOf(receiver).call();288      expect(+balance).to.equal(1);289    }290291    {292      const balance = await contract.methods.balanceOf(caller).call();293      expect(+balance).to.equal(0);294    }295  });296297  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {298    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);299    const helper = evmCollectionHelpers(web3, caller);300    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();301    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);302    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});303304    const receiver = createEthAccount(web3);305306    const tokenId = await contract.methods.nextTokenId().call();307    await contract.methods.mint(caller, tokenId).send();308309    {310      const result = await contract.methods.transfer(receiver, tokenId).send();311      const events = normalizeEvents(result.events);312      expect(events).to.include.deep.members([313        {314          address: collectionIdAddress,315          event: 'Transfer',316          args: {317            from: caller,318            to: receiver,319            tokenId: tokenId.toString(),320          },321        },322      ]);323    }324325    {326      const balance = await contract.methods.balanceOf(caller).call();327      expect(+balance).to.equal(0);328    }329330    {331      const balance = await contract.methods.balanceOf(receiver).call();332      expect(+balance).to.equal(1);333    }334  });335336  itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {337    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);338    const receiver = createEthAccount(web3);339    const helper = evmCollectionHelpers(web3, caller);340    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();341    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);342    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});343344    const tokenId = await contract.methods.nextTokenId().call();345    await contract.methods.mint(caller, tokenId).send();346347    const tokenAddress = tokenIdToAddress(collectionId, tokenId);348    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});349350    await tokenContract.methods.repartition(2).send();351    await tokenContract.methods.transfer(receiver, 1).send();352353    const events =  await recordEvents(contract, async () => 354      await tokenContract.methods.transfer(receiver, 1).send());355    expect(events).to.deep.equal([356      {357        address: collectionIdAddress,358        event: 'Transfer',359        args: {360          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',361          to: receiver,362          tokenId: tokenId.toString(),363        },364      },365    ]);366  });367368  itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {369    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);370    const receiver = createEthAccount(web3);371    const helper = evmCollectionHelpers(web3, caller);372    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();373    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);374    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});375376    const tokenId = await contract.methods.nextTokenId().call();377    await contract.methods.mint(caller, tokenId).send();378379    const tokenAddress = tokenIdToAddress(collectionId, tokenId);380    const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, tokenAddress, {from: caller, ...GAS_ARGS});381382    await tokenContract.methods.repartition(2).send();383    384    const events =  await recordEvents(contract, async () => 385      await tokenContract.methods.transfer(receiver, 1).send());386      387    expect(events).to.deep.equal([388      {389        address: collectionIdAddress,390        event: 'Transfer',391        args: {392          from: caller,393          to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',394          tokenId: tokenId.toString(),395        },396      },397    ]);398  });399});400401describe('RFT: Fees', () => {402  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {403    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);404    const helper = evmCollectionHelpers(web3, caller);405    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();406    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);407    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});408409    const receiver = createEthAccount(web3);410411    const tokenId = await contract.methods.nextTokenId().call();412    await contract.methods.mint(caller, tokenId).send();413414    const cost = await recordEthFee(api, caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());415    expect(cost < BigInt(0.2 * Number(UNIQUE)));416    expect(cost > 0n);417  });418419  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {420    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);421    const helper = evmCollectionHelpers(web3, caller);422    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();423    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);424    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});425426    const receiver = createEthAccount(web3);427428    const tokenId = await contract.methods.nextTokenId().call();429    await contract.methods.mint(caller, tokenId).send();430431    const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());432    expect(cost < BigInt(0.2 * Number(UNIQUE)));433    expect(cost > 0n);434  });435});436437describe('Common metadata', () => {438  itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {439    const collection = await createCollectionExpectSuccess({440      name: 'token name',441      mode: {type: 'ReFungible'},442    });443    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);444445    const address = collectionIdToAddress(collection);446    const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});447    const name = await contract.methods.name().call();448449    expect(name).to.equal('token name');450  });451452  itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {453    const collection = await createCollectionExpectSuccess({454      tokenPrefix: 'TOK',455      mode: {type: 'ReFungible'},456    });457    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);458459    const address = collectionIdToAddress(collection);460    const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});461    const symbol = await contract.methods.symbol().call();462463    expect(symbol).to.equal('TOK');464  });465});
after · tests/src/eth/reFungible.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 {createCollectionExpectSuccess, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers';19import {expect} from 'chai';2021describe('Refungible: Information getting', () => {22  itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {23    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);24    const helper = evmCollectionHelpers(web3, caller);25    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();26    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);27    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});28    const nextTokenId = await contract.methods.nextTokenId().call();29    await contract.methods.mint(caller, nextTokenId).send();30    const totalSupply = await contract.methods.totalSupply().call();31    expect(totalSupply).to.equal('1');32  });3334  itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {35    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);36    const helper = evmCollectionHelpers(web3, caller);37    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();38    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);39    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});4041    {42      const nextTokenId = await contract.methods.nextTokenId().call();43      await contract.methods.mint(caller, nextTokenId).send();44    }45    {46      const nextTokenId = await contract.methods.nextTokenId().call();47      await contract.methods.mint(caller, nextTokenId).send();48    }49    {50      const nextTokenId = await contract.methods.nextTokenId().call();51      await contract.methods.mint(caller, nextTokenId).send();52    }5354    const balance = await contract.methods.balanceOf(caller).call();5556    expect(balance).to.equal('3');57  });5859  itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {60    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);61    const helper = evmCollectionHelpers(web3, caller);62    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();63    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);64    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});6566    const tokenId = await contract.methods.nextTokenId().call();67    await contract.methods.mint(caller, tokenId).send();6869    const owner = await contract.methods.ownerOf(tokenId).call();7071    expect(owner).to.equal(caller);72  });7374  itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {75    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);76    const receiver = createEthAccount(web3);77    const helper = evmCollectionHelpers(web3, caller);78    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();79    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);80    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});8182    const tokenId = await contract.methods.nextTokenId().call();83    await contract.methods.mint(caller, tokenId).send();8485    const tokenAddress = tokenIdToAddress(collectionId, tokenId);86    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);8788    await tokenContract.methods.repartition(2).send();89    await tokenContract.methods.transfer(receiver, 1).send();9091    await tokenContract.methods.burnFrom(caller, 1).send();9293    const owner = await contract.methods.ownerOf(tokenId).call();9495    expect(owner).to.equal(receiver);96  });9798  itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {99    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);100    const receiver = createEthAccount(web3);101    const helper = evmCollectionHelpers(web3, caller);102    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();103    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);104    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});105106    const tokenId = await contract.methods.nextTokenId().call();107    await contract.methods.mint(caller, tokenId).send();108109    const tokenAddress = tokenIdToAddress(collectionId, tokenId);110    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);111112    await tokenContract.methods.repartition(2).send();113    await tokenContract.methods.transfer(receiver, 1).send();114115    const owner = await contract.methods.ownerOf(tokenId).call();116117    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');118  });119});120121describe('Refungible: Plain calls', () => {122  itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {123    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124    const helper = evmCollectionHelpers(web3, owner);125    let result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();126    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);127    const receiver = createEthAccount(web3);128    const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});129    const nextTokenId = await contract.methods.nextTokenId().call();130131    expect(nextTokenId).to.be.equal('1');132    result = await contract.methods.mintWithTokenURI(133      receiver,134      nextTokenId,135      'Test URI',136    ).send();137138    const events = normalizeEvents(result.events);139140    expect(events).to.include.deep.members([141      {142        address: collectionIdAddress,143        event: 'Transfer',144        args: {145          from: '0x0000000000000000000000000000000000000000',146          to: receiver,147          tokenId: nextTokenId,148        },149      },150    ]);151152    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');153  });154155  itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {156    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);157    const helper = evmCollectionHelpers(web3, caller);158    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();159    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);160    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});161162    const receiver = createEthAccount(web3);163164    {165      const nextTokenId = await contract.methods.nextTokenId().call();166      expect(nextTokenId).to.be.equal('1');167      const result = await contract.methods.mintBulkWithTokenURI(168        receiver,169        [170          [nextTokenId, 'Test URI 0'],171          [+nextTokenId + 1, 'Test URI 1'],172          [+nextTokenId + 2, 'Test URI 2'],173        ],174      ).send();175      const events = normalizeEvents(result.events);176177      expect(events).to.include.deep.members([178        {179          address: collectionIdAddress,180          event: 'Transfer',181          args: {182            from: '0x0000000000000000000000000000000000000000',183            to: receiver,184            tokenId: nextTokenId,185          },186        },187        {188          address: collectionIdAddress,189          event: 'Transfer',190          args: {191            from: '0x0000000000000000000000000000000000000000',192            to: receiver,193            tokenId: String(+nextTokenId + 1),194          },195        },196        {197          address: collectionIdAddress,198          event: 'Transfer',199          args: {200            from: '0x0000000000000000000000000000000000000000',201            to: receiver,202            tokenId: String(+nextTokenId + 2),203          },204        },205      ]);206207      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');208      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');209      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');210    }211  });212213  itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {214    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);215    const helper = evmCollectionHelpers(web3, caller);216    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();217    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);218    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});219220    const tokenId = await contract.methods.nextTokenId().call();221    await contract.methods.mint(caller, tokenId).send();222    {223      const result = await contract.methods.burn(tokenId).send();224      const events = normalizeEvents(result.events);225      expect(events).to.include.deep.members([226        {227          address: collectionIdAddress,228          event: 'Transfer',229          args: {230            from: caller,231            to: '0x0000000000000000000000000000000000000000',232            tokenId: tokenId.toString(),233          },234        },235      ]);236    }237  });238239  itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {240    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);241    const helper = evmCollectionHelpers(web3, caller);242    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();243    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);244    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});245246    const receiver = createEthAccount(web3);247248    const tokenId = await contract.methods.nextTokenId().call();249    await contract.methods.mint(caller, tokenId).send();250251    const address = tokenIdToAddress(collectionId, tokenId);252    const tokenContract = uniqueRefungibleToken(web3, address, caller);253    await tokenContract.methods.repartition(15).send();254255    {256      const erc20Events = await recordEvents(tokenContract, async () => {257        const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();258        const events = normalizeEvents(result.events);259        expect(events).to.include.deep.members([260          {261            address: collectionIdAddress,262            event: 'Transfer',263            args: {264              from: caller,265              to: receiver,266              tokenId: tokenId.toString(),267            },268          },269        ]);270      });271      272      expect(erc20Events).to.include.deep.members([273        {274          address,275          event: 'Transfer',276          args: {277            from: caller,278            to: receiver,279            value: '15',280          },281        },282      ]);283    }284285    {286      const balance = await contract.methods.balanceOf(receiver).call();287      expect(+balance).to.equal(1);288    }289290    {291      const balance = await contract.methods.balanceOf(caller).call();292      expect(+balance).to.equal(0);293    }294  });295296  itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {297    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);298    const helper = evmCollectionHelpers(web3, caller);299    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();300    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);301    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});302303    const receiver = createEthAccount(web3);304305    const tokenId = await contract.methods.nextTokenId().call();306    await contract.methods.mint(caller, tokenId).send();307308    {309      const result = await contract.methods.transfer(receiver, tokenId).send();310      const events = normalizeEvents(result.events);311      expect(events).to.include.deep.members([312        {313          address: collectionIdAddress,314          event: 'Transfer',315          args: {316            from: caller,317            to: receiver,318            tokenId: tokenId.toString(),319          },320        },321      ]);322    }323324    {325      const balance = await contract.methods.balanceOf(caller).call();326      expect(+balance).to.equal(0);327    }328329    {330      const balance = await contract.methods.balanceOf(receiver).call();331      expect(+balance).to.equal(1);332    }333  });334335  itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {336    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);337    const receiver = createEthAccount(web3);338    const helper = evmCollectionHelpers(web3, caller);339    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();340    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);341    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});342343    const tokenId = await contract.methods.nextTokenId().call();344    await contract.methods.mint(caller, tokenId).send();345346    const tokenAddress = tokenIdToAddress(collectionId, tokenId);347    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);348349    await tokenContract.methods.repartition(2).send();350    await tokenContract.methods.transfer(receiver, 1).send();351352    const events =  await recordEvents(contract, async () => 353      await tokenContract.methods.transfer(receiver, 1).send());354    expect(events).to.deep.equal([355      {356        address: collectionIdAddress,357        event: 'Transfer',358        args: {359          from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',360          to: receiver,361          tokenId: tokenId.toString(),362        },363      },364    ]);365  });366367  itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {368    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);369    const receiver = createEthAccount(web3);370    const helper = evmCollectionHelpers(web3, caller);371    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();372    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);373    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});374375    const tokenId = await contract.methods.nextTokenId().call();376    await contract.methods.mint(caller, tokenId).send();377378    const tokenAddress = tokenIdToAddress(collectionId, tokenId);379    const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);380381    await tokenContract.methods.repartition(2).send();382    383    const events =  await recordEvents(contract, async () => 384      await tokenContract.methods.transfer(receiver, 1).send());385      386    expect(events).to.deep.equal([387      {388        address: collectionIdAddress,389        event: 'Transfer',390        args: {391          from: caller,392          to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',393          tokenId: tokenId.toString(),394        },395      },396    ]);397  });398});399400describe('RFT: Fees', () => {401  itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {402    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);403    const helper = evmCollectionHelpers(web3, caller);404    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();405    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);406    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});407408    const receiver = createEthAccount(web3);409410    const tokenId = await contract.methods.nextTokenId().call();411    await contract.methods.mint(caller, tokenId).send();412413    const cost = await recordEthFee(api, caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());414    expect(cost < BigInt(0.2 * Number(UNIQUE)));415    expect(cost > 0n);416  });417418  itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {419    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);420    const helper = evmCollectionHelpers(web3, caller);421    const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();422    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);423    const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});424425    const receiver = createEthAccount(web3);426427    const tokenId = await contract.methods.nextTokenId().call();428    await contract.methods.mint(caller, tokenId).send();429430    const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());431    expect(cost < BigInt(0.2 * Number(UNIQUE)));432    expect(cost > 0n);433  });434});435436describe('Common metadata', () => {437  itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {438    const collection = await createCollectionExpectSuccess({439      name: 'token name',440      mode: {type: 'ReFungible'},441    });442    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);443444    const address = collectionIdToAddress(collection);445    const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});446    const name = await contract.methods.name().call();447448    expect(name).to.equal('token name');449  });450451  itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {452    const collection = await createCollectionExpectSuccess({453      tokenPrefix: 'TOK',454      mode: {type: 'ReFungible'},455    });456    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);457458    const address = collectionIdToAddress(collection);459    const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});460    const symbol = await contract.methods.symbol().call();461462    expect(symbol).to.equal('TOK');463  });464});
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,8 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';
-import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
-import reFungibleTokenAbi from './reFungibleTokenAbi.json';
+import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
@@ -34,7 +33,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, caller);
     const totalSupply = await contract.methods.totalSupply().call();
 
     expect(totalSupply).to.equal('200');
@@ -50,7 +49,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, caller);
     const balance = await contract.methods.balanceOf(caller).call();
 
     expect(balance).to.equal('200');
@@ -66,7 +65,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, caller);
     const decimals = await contract.methods.decimals().call();
 
     expect(decimals).to.equal('0');
@@ -229,7 +228,7 @@
 
     const spender = createEthAccount(web3);
 
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     {
       const result = await contract.methods.approve(spender, 100).send({from: owner});
@@ -270,7 +269,7 @@
     const receiver = createEthAccount(web3);
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     await contract.methods.approve(spender, 100).send();
 
@@ -324,7 +323,7 @@
     await transferBalanceToEth(api, alice, receiver);
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     {
       const result = await contract.methods.transfer(receiver, 50).send({from: owner});
@@ -367,7 +366,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     await contract.methods.repartition(200).send({from: owner});
     expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);
@@ -397,7 +396,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     const result = await contract.methods.repartition(200).send();
     const events = normalizeEvents(result.events);
@@ -426,7 +425,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     const result = await contract.methods.repartition(50).send();
     const events = normalizeEvents(result.events);
@@ -456,7 +455,7 @@
 
     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(2).send();
     await tokenContract.methods.transfer(receiver, 1).send();
 
@@ -488,7 +487,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
     expect(cost < BigInt(0.2 * Number(UNIQUE)));
@@ -505,7 +504,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     await contract.methods.approve(spender, 100).send({from: owner});
 
@@ -524,7 +523,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
+    const contract = uniqueRefungibleToken(web3, address, owner);
 
     const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
     expect(cost < BigInt(0.2 * Number(UNIQUE)));
@@ -542,7 +541,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+    const contract = uniqueRefungibleToken(web3, address);
 
     const events = await recordEvents(contract, async () => {
       expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;
@@ -573,7 +572,7 @@
     expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+    const contract = uniqueRefungibleToken(web3, address);
 
     const events = await recordEvents(contract, async () => {
       expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver},  51n)).to.be.true;
@@ -611,7 +610,7 @@
     const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
 
     const address = tokenIdToAddress(collectionId, tokenId);
-    const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address);
+    const contract = uniqueRefungibleToken(web3, address);
 
     const events = await recordEvents(contract, async () => {
       expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver},  51n)).to.be.true;
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,