git.delta.rocks / unique-network / refs/commits / 9505eb68d4e4

difftreelog

source

tests/src/eth/reFungibleToken.test.ts30.3 KiBsourcehistory
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 {Pallets, requirePalletsOrSkip} from '../util';18import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {Contract} from 'web3-eth-contract';2122// FIXME: Need erc721 for ReFubgible.23describe('Check ERC721 token URI for ReFungible', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2930      donor = await privateKey({filename: __filename});31    });32  });3334  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {35    const owner = await helper.eth.createAccountWithBalance(donor);36    const receiver = helper.eth.createAccount();3738    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);39    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);4041    const result = await contract.methods.mint(receiver).send();4243    const event = result.events.Transfer;44    const tokenId = event.returnValues.tokenId;45    expect(tokenId).to.be.equal('1');46    expect(event.address).to.be.equal(collectionAddress);47    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');48    expect(event.returnValues.to).to.be.equal(receiver);4950    if (propertyKey && propertyValue) {51      // Set URL or suffix5253      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();54    }5556    return {contract, nextTokenId: tokenId};57  }5859  itEth('Empty tokenURI', async ({helper}) => {60    const {contract, nextTokenId} = await setup(helper, '');61    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');62  });6364  itEth('TokenURI from url', async ({helper}) => {65    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');66    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');67  });6869  itEth('TokenURI from baseURI', async ({helper}) => {70    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');71    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');72  });7374  itEth('TokenURI from baseURI + suffix', async ({helper}) => {75    const suffix = '/some/suffix';76    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);77    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);78  });79});8081describe('Refungible: Plain calls', () => {82  let donor: IKeyringPair;83  let alice: IKeyringPair;8485  before(async function() {86    await usingEthPlaygrounds(async (helper, privateKey) => {87      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);8889      donor = await privateKey({filename: __filename});90      [alice] = await helper.arrange.createAccounts([50n], donor);91    });92  });9394  itEth('Can perform approve()', async ({helper}) => {95    const owner = await helper.eth.createAccountWithBalance(donor);96    const spender = helper.eth.createAccount();97    const collection = await helper.rft.mintCollection(alice);98    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});99100    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);101    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);102103    {104      const result = await contract.methods.approve(spender, 100).send({from: owner});105      const event = result.events.Approval;106      expect(event.address).to.be.equal(tokenAddress);107      expect(event.returnValues.owner).to.be.equal(owner);108      expect(event.returnValues.spender).to.be.equal(spender);109      expect(event.returnValues.value).to.be.equal('100');110    }111112    {113      const allowance = await contract.methods.allowance(owner, spender).call();114      expect(+allowance).to.equal(100);115    }116  });117118  itEth('Can perform approveCross()', async ({helper}) => {119    const owner = await helper.eth.createAccountWithBalance(donor);120    const spender = helper.eth.createAccount();121    const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];122    const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);123    const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);124125126    const collection = await helper.rft.mintCollection(alice);127    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});128129    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);130    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);131132    {133      const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});134      const event = result.events.Approval;135      expect(event.address).to.be.equal(tokenAddress);136      expect(event.returnValues.owner).to.be.equal(owner);137      expect(event.returnValues.spender).to.be.equal(spender);138      expect(event.returnValues.value).to.be.equal('100');139    }140141    {142      const allowance = await contract.methods.allowance(owner, spender).call();143      expect(+allowance).to.equal(100);144    }145146147    {148      const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});149      const event = result.events.Approval;150      expect(event.address).to.be.equal(tokenAddress);151      expect(event.returnValues.owner).to.be.equal(owner);152      expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));153      expect(event.returnValues.value).to.be.equal('100');154    }155156    {157      const allowance = await collection.getTokenApprovedPieces(tokenId, {Ethereum: owner}, {Substrate: spenderSub.address});158      expect(allowance).to.equal(100n);159    }160161    {162      //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()163    }164  });165166  itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {167    const nonOwner = await helper.eth.createAccountWithBalance(donor);168    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);169    const owner = await helper.eth.createAccountWithBalance(donor);170    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});171    const token = await collection.mintToken(alice, 100n, {Ethereum: owner});172173    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);174    const tokenEvm = await helper.ethNativeContract.rftToken(tokenAddress, owner);175176    await expect(tokenEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');177  });178179  [180    'transferFrom',181    'transferFromCross',182  ].map(testCase =>183    itEth(`Can perform ${testCase}`, async ({helper}) => {184      const isCross = testCase === 'transferFromCross';185      const owner = await helper.eth.createAccountWithBalance(donor);186      const ownerCross = helper.ethCrossAccount.fromAddress(owner);187      const spender = await helper.eth.createAccountWithBalance(donor);188      const receiverEth = helper.eth.createAccount();189      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);190      const [receiverSub] = await helper.arrange.createAccounts([1n], donor);191      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);192193      const collection = await helper.rft.mintCollection(alice);194      const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});195196      const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);197      const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);198199      await contract.methods.approve(spender, 100).send({from: owner});200201      // 1. Can transfer from202      // 1.1 Plain ethereum or cross address:203      {204        const result = await contract.methods[testCase](205          isCross ? ownerCross : owner,206          isCross ? receiverCrossEth : receiverEth,207          49,208        ).send({from: spender});209210        // Check events:211        const transferEvent = result.events.Transfer;212        expect(transferEvent.address).to.be.equal(tokenAddress);213        expect(transferEvent.returnValues.from).to.be.equal(owner);214        expect(transferEvent.returnValues.to).to.be.equal(receiverEth);215        expect(transferEvent.returnValues.value).to.be.equal('49');216217        const approvalEvent = result.events.Approval;218        expect(approvalEvent.address).to.be.equal(tokenAddress);219        expect(approvalEvent.returnValues.owner).to.be.equal(owner);220        expect(approvalEvent.returnValues.spender).to.be.equal(spender);221        expect(approvalEvent.returnValues.value).to.be.equal('51');222223        // Check balances:224        const receiverBalance = await contract.methods.balanceOf(receiverEth).call();225        const ownerBalance = await contract.methods.balanceOf(owner).call();226227        expect(+receiverBalance).to.equal(49);228        expect(+ownerBalance).to.equal(151);229      }230231      // 1.2 Cross substrate address:232      if (testCase === 'transferFromCross') {233        const result = await contract.methods.transferFromCross(ownerCross, receiverCrossSub, 51).send({from: spender});234        // Check events:235        const transferEvent = result.events.Transfer;236        expect(transferEvent.address).to.be.equal(tokenAddress);237        expect(transferEvent.returnValues.from).to.be.equal(owner);238        expect(transferEvent.returnValues.to).to.be.equal(helper.address.substrateToEth(receiverSub.address));239        expect(transferEvent.returnValues.value).to.be.equal('51');240241        const approvalEvent = result.events.Approval;242        expect(approvalEvent.address).to.be.equal(tokenAddress);243        expect(approvalEvent.returnValues.owner).to.be.equal(owner);244        expect(approvalEvent.returnValues.spender).to.be.equal(spender);245        expect(approvalEvent.returnValues.value).to.be.equal('0');246247        // Check balances:248        const receiverBalance = await collection.getTokenBalance(tokenId, {Substrate: receiverSub.address});249        const ownerBalance = await contract.methods.balanceOf(owner).call();250        expect(receiverBalance).to.equal(51n);251        expect(+ownerBalance).to.equal(100);252      }253    }));254255  [256    'transfer',257    'transferCross',258  ].map(testCase =>259    itEth(`Can perform ${testCase}()`, async ({helper}) => {260      const isCross = testCase === 'transferCross';261      const owner = await helper.eth.createAccountWithBalance(donor);262      const receiverEth = helper.eth.createAccount();263      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);264      const [receiverSub] = await helper.arrange.createAccounts([1n], donor);265      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);266      const collection = await helper.rft.mintCollection(alice);267      const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});268269      const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);270      const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);271272      // 1. Can transfer to plain ethereum or cross-ethereum account:273      {274        const result = await contract.methods[testCase](isCross ? receiverCrossEth : receiverEth, 50).send({from: owner});275        // Check events276        const transferEvent = result.events.Transfer;277        expect(transferEvent.address).to.be.equal(tokenAddress);278        expect(transferEvent.returnValues.from).to.be.equal(owner);279        expect(transferEvent.returnValues.to).to.be.equal(receiverEth);280        expect(transferEvent.returnValues.value).to.be.equal('50');281        // Check balances:282        const ownerBalance = await contract.methods.balanceOf(owner).call();283        const receiverBalance = await contract.methods.balanceOf(receiverEth).call();284        expect(+ownerBalance).to.equal(150);285        expect(+receiverBalance).to.equal(50);286      }287288      // 2. Can transfer to cross-substrate account:289      if(isCross) {290        const result = await contract.methods.transferCross(receiverCrossSub, 50).send({from: owner});291        // Check events:292        const event = result.events.Transfer;293        expect(event.address).to.be.equal(tokenAddress);294        expect(event.returnValues.from).to.be.equal(owner);295        expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(receiverSub.address));296        expect(event.returnValues.value).to.be.equal('50');297        // Check balances:298        const ownerBalance = await contract.methods.balanceOf(owner).call();299        const receiverBalance = await collection.getTokenBalance(tokenId, {Substrate: receiverSub.address});300        expect(+ownerBalance).to.equal(100);301        expect(receiverBalance).to.equal(50n);302      }303    }));304305  [306    'transfer',307    'transferCross',308  ].map(testCase =>309    itEth(`Cannot ${testCase}() non-owned token`, async ({helper}) => {310      const isCross = testCase === 'transferCross';311      const owner = await helper.eth.createAccountWithBalance(donor);312      const ownerCross = helper.ethCrossAccount.fromAddress(owner);313      const receiverEth = await helper.eth.createAccountWithBalance(donor);314      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);315      const collection = await helper.rft.mintCollection(alice);316      const rftOwner = await collection.mintToken(alice, 10n, {Ethereum: owner});317      const rftReceiver = await collection.mintToken(alice, 10n, {Ethereum: receiverEth});318      const tokenIdNonExist = 9999999;319320      const tokenAddress1 = helper.ethAddress.fromTokenId(collection.collectionId, rftOwner.tokenId);321      const tokenAddress2 = helper.ethAddress.fromTokenId(collection.collectionId, rftReceiver.tokenId);322      const tokenAddressNonExist = helper.ethAddress.fromTokenId(collection.collectionId, tokenIdNonExist);323      const tokenEvmOwner = await helper.ethNativeContract.rftToken(tokenAddress1, owner);324      const tokenEvmReceiver = await helper.ethNativeContract.rftToken(tokenAddress2, owner);325      const tokenEvmNonExist = await helper.ethNativeContract.rftToken(tokenAddressNonExist, owner);326327      // 1. Can transfer zero amount (EIP-20):328      await tokenEvmOwner.methods[testCase](isCross ? receiverCrossEth : receiverEth, 0).send({from: owner});329      // 2. Cannot transfer non-owned token:330      await expect(tokenEvmReceiver.methods[testCase](isCross ? ownerCross : owner, 0).send({from: owner})).to.be.rejected;331      await expect(tokenEvmReceiver.methods[testCase](isCross ? ownerCross : owner, 5).send({from: owner})).to.be.rejected;332      // 3. Cannot transfer non-existing token:333      await expect(tokenEvmNonExist.methods[testCase](isCross ? ownerCross : owner, 0).send({from: owner})).to.be.rejected;334      await expect(tokenEvmNonExist.methods[testCase](isCross ? ownerCross : owner, 5).send({from: owner})).to.be.rejected;335336      // 4. Storage is not corrupted:337      expect(await rftOwner.getTop10Owners()).to.deep.eq([{Ethereum: owner.toLowerCase()}]);338      expect(await rftReceiver.getTop10Owners()).to.deep.eq([{Ethereum: receiverEth.toLowerCase()}]);339      expect(await helper.rft.getTokenTop10Owners(collection.collectionId, tokenIdNonExist)).to.deep.eq([]);340341      // 4.1 Tokens can be transferred:342      await tokenEvmOwner.methods[testCase](isCross ? receiverCrossEth : receiverEth, 10).send({from: owner});343      await tokenEvmReceiver.methods[testCase](isCross ? ownerCross : owner, 10).send({from: receiverEth});344      expect(await rftOwner.getTop10Owners()).to.deep.eq([{Ethereum: receiverEth.toLowerCase()}]);345      expect(await rftReceiver.getTop10Owners()).to.deep.eq([{Ethereum: owner.toLowerCase()}]);346    }));347348  itEth('Can perform repartition()', async ({helper}) => {349    const owner = await helper.eth.createAccountWithBalance(donor);350    const receiver = await helper.eth.createAccountWithBalance(donor);351    const collection = await helper.rft.mintCollection(alice);352    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});353354    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);355    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);356357    await contract.methods.repartition(200).send({from: owner});358    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);359    await contract.methods.transfer(receiver, 110).send({from: owner});360    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);361    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);362363    await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected; // Transaction is reverted364365    await contract.methods.transfer(receiver, 90).send({from: owner});366    expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);367    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);368369    await contract.methods.repartition(150).send({from: receiver});370    await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected; // Transaction is reverted371    expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);372  });373374  itEth('Can repartition with increased amount', async ({helper}) => {375    const owner = await helper.eth.createAccountWithBalance(donor);376    const collection = await helper.rft.mintCollection(alice);377    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});378379    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);380    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);381382    const result = await contract.methods.repartition(200).send();383384    const event = result.events.Transfer;385    expect(event.address).to.be.equal(tokenAddress);386    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');387    expect(event.returnValues.to).to.be.equal(owner);388    expect(event.returnValues.value).to.be.equal('100');389  });390391  itEth('Can repartition with decreased amount', async ({helper}) => {392    const owner = await helper.eth.createAccountWithBalance(donor);393    const collection = await helper.rft.mintCollection(alice);394    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});395396    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);397    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);398399    const result = await contract.methods.repartition(50).send();400    const event = result.events.Transfer;401    expect(event.address).to.be.equal(tokenAddress);402    expect(event.returnValues.from).to.be.equal(owner);403    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');404    expect(event.returnValues.value).to.be.equal('50');405  });406407  itEth('Receiving Transfer event on burning into full ownership', async ({helper}) => {408    const caller = await helper.eth.createAccountWithBalance(donor);409    const receiver = await helper.eth.createAccountWithBalance(donor);410    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Devastation', '6', '6');411    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);412413    const result = await contract.methods.mint(caller).send();414    const tokenId = result.events.Transfer.returnValues.tokenId;415    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);416    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, caller, true);417418    await tokenContract.methods.repartition(2).send();419    await tokenContract.methods.transfer(receiver, 1).send();420421    const events: any = [];422    contract.events.allEvents((_: any, event: any) => {423      events.push(event);424    });425    await tokenContract.methods.burnFrom(caller, 1).send();426427    if (events.length == 0) await helper.wait.newBlocks(1);428    const event = events[0];429    expect(event.address).to.be.equal(collectionAddress);430    expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');431    expect(event.returnValues.to).to.be.equal(receiver);432    expect(event.returnValues.tokenId).to.be.equal(tokenId);433  });434435  itEth('Can perform burnFromCross()', async ({helper}) => {436    const owner = await helper.eth.createAccountWithBalance(donor);437    const ownerSub = (await helper.arrange.createAccounts([10n], donor))[0];438    const ownerCross = helper.ethCrossAccount.fromAddress(owner);439    const spender = await helper.eth.createAccountWithBalance(donor);440441    const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);442    const ownerSubCross = helper.ethCrossAccount.fromKeyringPair(ownerSub);443444    const collection = await helper.rft.mintCollection(alice);445    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});446447448    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);449    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);450451    {452      await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});453454      await expect(contract.methods.burnFromCross(ownerCross, 50).send({from: spender})).to.be.fulfilled;455      await expect(contract.methods.burnFromCross(ownerCross, 100).send({from: spender})).to.be.rejected;456      expect(await contract.methods.balanceOf(owner).call({from: owner})).to.be.equal('150');457    }458    {459      const {tokenId} = await collection.mintToken(alice, 200n, {Substrate: ownerSub.address});460      await collection.approveToken(ownerSub, tokenId, {Ethereum: spender}, 100n);461      const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);462      const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);463464      await expect(contract.methods.burnFromCross(ownerSubCross, 50).send({from: spender})).to.be.fulfilled;465      await expect(contract.methods.burnFromCross(ownerSubCross, 100).send({from: spender})).to.be.rejected;466      expect(await collection.getTokenBalance(tokenId, {Substrate: ownerSub.address})).to.be.equal(150n);467    }468  });469});470471describe('Refungible: Fees', () => {472  let donor: IKeyringPair;473  let alice: IKeyringPair;474475  before(async function() {476    await usingEthPlaygrounds(async (helper, privateKey) => {477      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);478479      donor = await privateKey({filename: __filename});480      [alice] = await helper.arrange.createAccounts([50n], donor);481    });482  });483484  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {485    const owner = await helper.eth.createAccountWithBalance(donor);486    const spender = helper.eth.createAccount();487    const collection = await helper.rft.mintCollection(alice);488    const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});489490    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);491    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);492493    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));494    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));495  });496497  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {498    const owner = await helper.eth.createAccountWithBalance(donor);499    const spender = await helper.eth.createAccountWithBalance(donor);500    const collection = await helper.rft.mintCollection(alice);501    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});502503    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);504    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);505506    await contract.methods.approve(spender, 100).send({from: owner});507508    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));509    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));510  });511512  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {513    const owner = await helper.eth.createAccountWithBalance(donor);514    const receiver = helper.eth.createAccount();515    const collection = await helper.rft.mintCollection(alice);516    const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});517518    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);519    const contract = await helper.ethNativeContract.rftToken(tokenAddress, owner);520521    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));522    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));523  });524});525526describe('Refungible: Substrate calls', () => {527  let donor: IKeyringPair;528  let alice: IKeyringPair;529530  before(async function() {531    await usingEthPlaygrounds(async (helper, privateKey) => {532      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);533534      donor = await privateKey({filename: __filename});535      [alice] = await helper.arrange.createAccounts([50n], donor);536    });537  });538539  itEth('Events emitted for approve()', async ({helper}) => {540    const receiver = helper.eth.createAccount();541    const collection = await helper.rft.mintCollection(alice);542    const token = await collection.mintToken(alice, 200n);543544    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);545    const contract = await helper.ethNativeContract.rftToken(tokenAddress);546547    const events: any = [];548    contract.events.allEvents((_: any, event: any) => {549      events.push(event);550    });551552    expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;553    if (events.length == 0) await helper.wait.newBlocks(1);554    const event = events[0];555556    expect(event.event).to.be.equal('Approval');557    expect(event.address).to.be.equal(tokenAddress);558    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));559    expect(event.returnValues.spender).to.be.equal(receiver);560    expect(event.returnValues.value).to.be.equal('100');561  });562563  itEth('Events emitted for transferFrom()', async ({helper}) => {564    const [bob] = await helper.arrange.createAccounts([10n], donor);565    const receiver = helper.eth.createAccount();566    const collection = await helper.rft.mintCollection(alice);567    const token = await collection.mintToken(alice, 200n);568    await token.approve(alice, {Substrate: bob.address}, 100n);569570    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);571    const contract = await helper.ethNativeContract.rftToken(tokenAddress);572573    const events: any = [];574    contract.events.allEvents((_: any, event: any) => {575      events.push(event);576    });577578    expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver},  51n)).to.be.true;579    if (events.length == 0) await helper.wait.newBlocks(1);580581    let event = events[0];582    expect(event.event).to.be.equal('Transfer');583    expect(event.address).to.be.equal(tokenAddress);584    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));585    expect(event.returnValues.to).to.be.equal(receiver);586    expect(event.returnValues.value).to.be.equal('51');587588    event = events[1];589    expect(event.event).to.be.equal('Approval');590    expect(event.address).to.be.equal(tokenAddress);591    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));592    expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));593    expect(event.returnValues.value).to.be.equal('49');594  });595596  itEth('Events emitted for transfer()', async ({helper}) => {597    const receiver = helper.eth.createAccount();598    const collection = await helper.rft.mintCollection(alice);599    const token = await collection.mintToken(alice, 200n);600601    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);602    const contract = await helper.ethNativeContract.rftToken(tokenAddress);603604    const events: any = [];605    contract.events.allEvents((_: any, event: any) => {606      events.push(event);607    });608609    expect(await token.transfer(alice, {Ethereum: receiver},  51n)).to.be.true;610    if (events.length == 0) await helper.wait.newBlocks(1);611    const event = events[0];612613    expect(event.event).to.be.equal('Transfer');614    expect(event.address).to.be.equal(tokenAddress);615    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));616    expect(event.returnValues.to).to.be.equal(receiver);617    expect(event.returnValues.value).to.be.equal('51');618  });619});620621describe('ERC 1633 implementation', () => {622  let donor: IKeyringPair;623624  before(async function() {625    await usingEthPlaygrounds(async (helper, privateKey) => {626      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);627628      donor = await privateKey({filename: __filename});629    });630  });631632  itEth('Default parent token address and id', async ({helper}) => {633    const owner = await helper.eth.createAccountWithBalance(donor);634635    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Sands', '', 'GRAIN');636    const collectionContract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);637638    const result = await collectionContract.methods.mint(owner).send();639    const tokenId = result.events.Transfer.returnValues.tokenId;640641    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);642    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner);643644    expect(await tokenContract.methods.parentToken().call()).to.be.equal(collectionAddress);645    expect(await tokenContract.methods.parentTokenId().call()).to.be.equal(tokenId);646  });647});