git.delta.rocks / unique-network / refs/commits / 4dff934f02cf

difftreelog

source

tests/src/eth/fungible.test.ts27.7 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 {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Information getting', () => {21  let donor: IKeyringPair;22  let alice: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({filename: __filename});27      [alice] = await helper.arrange.createAccounts([20n], donor);28    });29  });3031  itEth('totalSupply', async ({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.ft.mintCollection(alice);34    await collection.mint(alice, 200n);3536    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);37    const totalSupply = await contract.methods.totalSupply().call();38    expect(totalSupply).to.equal('200');39  });4041  itEth('balanceOf', async ({helper}) => {42    const caller = await helper.eth.createAccountWithBalance(donor);43    const collection = await helper.ft.mintCollection(alice);44    await collection.mint(alice, 200n, {Ethereum: caller});4546    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);47    const balance = await contract.methods.balanceOf(caller).call();48    expect(balance).to.equal('200');49  });50});5152describe('Fungible: Plain calls', () => {53  let donor: IKeyringPair;54  let alice: IKeyringPair;55  let owner: IKeyringPair;5657  before(async function() {58    await usingEthPlaygrounds(async (helper, privateKey) => {59      donor = await privateKey({filename: __filename});60      [alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);61    });62  });6364  itEth('Can perform mint()', async ({helper}) => {65    const owner = await helper.eth.createAccountWithBalance(donor);66    const receiver = helper.eth.createAccount();67    const collection = await helper.ft.mintCollection(alice);68    await collection.addAdmin(alice, {Ethereum: owner});6970    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);71    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7273    const result = await contract.methods.mint(receiver, 100).send();7475    const event = result.events.Transfer;76    expect(event.address).to.equal(collectionAddress);77    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');78    expect(event.returnValues.to).to.equal(receiver);79    expect(event.returnValues.value).to.equal('100');80  });8182  [83    'substrate' as const,84    'ethereum' as const,85  ].map(testCase => {86    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {87      // 1. Create receiver depending on the test case:88      const receiverEth = helper.eth.createAccount();89      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);90      const receiverSub = owner;91      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);9293      const ethOwner = await helper.eth.createAccountWithBalance(donor);94      const collection = await helper.ft.mintCollection(alice);95      await collection.addAdmin(alice, {Ethereum: ethOwner});9697      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);98      const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);99100      // 2. Mint tokens:101      const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();102103      const event = result.events.Transfer;104      expect(event.address).to.equal(collectionAddress);105      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');106      expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));107      expect(event.returnValues.value).to.equal('100');108109      // 3. Get balance depending on the test case:110      let balance;111      if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});112      else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});113      // 3.1 Check balance:114      expect(balance).to.eq(100n);115    });116  });117118  itEth('Can perform mintBulk()', async ({helper}) => {119    const owner = await helper.eth.createAccountWithBalance(donor);120    const bulkSize = 3;121    const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());122    const collection = await helper.ft.mintCollection(alice);123    await collection.addAdmin(alice, {Ethereum: owner});124125    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);126    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);127128    const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (129      [receivers[i], (i + 1) * 10]130    ))).send();131    const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);132    for (let i = 0; i < bulkSize; i++) {133      const event = events[i];134      expect(event.address).to.equal(collectionAddress);135      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');136      expect(event.returnValues.to).to.equal(receivers[i]);137      expect(event.returnValues.value).to.equal(String(10 * (i + 1)));138    }139  });140141  // Soft-deprecated142  itEth('Can perform burn()', async ({helper}) => {143    const owner = await helper.eth.createAccountWithBalance(donor);144    const receiver = await helper.eth.createAccountWithBalance(donor);145    const collection = await helper.ft.mintCollection(alice);146    await collection.addAdmin(alice, {Ethereum: owner});147148    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);149    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);150    await contract.methods.mint(receiver, 100).send();151152    const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});153154    const event = result.events.Transfer;155    expect(event.address).to.equal(collectionAddress);156    expect(event.returnValues.from).to.equal(receiver);157    expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');158    expect(event.returnValues.value).to.equal('49');159160    const balance = await contract.methods.balanceOf(receiver).call();161    expect(balance).to.equal('51');162  });163164  itEth('Can perform approve()', async ({helper}) => {165    const owner = await helper.eth.createAccountWithBalance(donor);166    const spender = helper.eth.createAccount();167    const collection = await helper.ft.mintCollection(alice);168    await collection.mint(alice, 200n, {Ethereum: owner});169170    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);171    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);172173    {174      const result = await contract.methods.approve(spender, 100).send({from: owner});175176      const event = result.events.Approval;177      expect(event.address).to.be.equal(collectionAddress);178      expect(event.returnValues.owner).to.be.equal(owner);179      expect(event.returnValues.spender).to.be.equal(spender);180      expect(event.returnValues.value).to.be.equal('100');181    }182183    {184      const allowance = await contract.methods.allowance(owner, spender).call();185      expect(+allowance).to.equal(100);186    }187  });188189  itEth('Can perform approveCross()', async ({helper}) => {190    const owner = await helper.eth.createAccountWithBalance(donor);191    const spender = helper.eth.createAccount();192    const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];193    const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);194    const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);195196197    const collection = await helper.ft.mintCollection(alice);198    await collection.mint(alice, 200n, {Ethereum: owner});199200    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);201    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);202203    {204      const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});205      const event = result.events.Approval;206      expect(event.address).to.be.equal(collectionAddress);207      expect(event.returnValues.owner).to.be.equal(owner);208      expect(event.returnValues.spender).to.be.equal(spender);209      expect(event.returnValues.value).to.be.equal('100');210    }211212    {213      const allowance = await contract.methods.allowance(owner, spender).call();214      expect(+allowance).to.equal(100);215    }216217218    {219      const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});220      const event = result.events.Approval;221      expect(event.address).to.be.equal(collectionAddress);222      expect(event.returnValues.owner).to.be.equal(owner);223      expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));224      expect(event.returnValues.value).to.be.equal('100');225    }226227    {228      const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});229      expect(allowance).to.equal(100n);230    }231232    {233      //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()234    }235  });236237  itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {238    const nonOwner = await helper.eth.createAccountWithBalance(donor);239    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);240    const owner = await helper.eth.createAccountWithBalance(donor);241    const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});242    await collection.mint(alice, 100n, {Ethereum: owner});243244    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);245    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);246247    await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');248  });249250251  itEth('Can perform burnFromCross()', async ({helper}) => {252    const sender = await helper.eth.createAccountWithBalance(donor, 100n);253254    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);255256    await collection.mint(owner, 200n, {Substrate: owner.address});257    await collection.approveTokens(owner, {Ethereum: sender}, 100n);258259    const address = helper.ethAddress.fromCollectionId(collection.collectionId);260    const contract = await helper.ethNativeContract.collection(address, 'ft');261262    const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});263264    const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);265    const result = await contract.methods.burnFromCross(ownerCross, 49).send({from: sender});266    const events = result.events;267268    expect(events).to.be.like({269      Transfer: {270        address: helper.ethAddress.fromCollectionId(collection.collectionId),271        event: 'Transfer',272        returnValues: {273          from: helper.address.substrateToEth(owner.address),274          to: '0x0000000000000000000000000000000000000000',275          value: '49',276        },277      },278      Approval: {279        address: helper.ethAddress.fromCollectionId(collection.collectionId),280        returnValues: {281          owner: helper.address.substrateToEth(owner.address),282          spender: sender,283          value: '51',284        },285        event: 'Approval',286      },287    });288289    const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});290    expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(49n);291  });292293  itEth('Can perform transferFrom()', async ({helper}) => {294    const owner = await helper.eth.createAccountWithBalance(donor);295    const spender = await helper.eth.createAccountWithBalance(donor);296    const receiver = helper.eth.createAccount();297    const collection = await helper.ft.mintCollection(alice);298    await collection.mint(alice, 200n, {Ethereum: owner});299300    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);301    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);302303    await contract.methods.approve(spender, 100).send();304305    {306      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});307308      let event = result.events.Transfer;309      expect(event.address).to.be.equal(collectionAddress);310      expect(event.returnValues.from).to.be.equal(owner);311      expect(event.returnValues.to).to.be.equal(receiver);312      expect(event.returnValues.value).to.be.equal('49');313314      event = result.events.Approval;315      expect(event.address).to.be.equal(collectionAddress);316      expect(event.returnValues.owner).to.be.equal(owner);317      expect(event.returnValues.spender).to.be.equal(spender);318      expect(event.returnValues.value).to.be.equal('51');319    }320321    {322      const balance = await contract.methods.balanceOf(receiver).call();323      expect(+balance).to.equal(49);324    }325326    {327      const balance = await contract.methods.balanceOf(owner).call();328      expect(+balance).to.equal(151);329    }330  });331332  itEth('Can perform transferCross()', async ({helper}) => {333    const sender = await helper.eth.createAccountWithBalance(donor);334    const receiverEth = await helper.eth.createAccountWithBalance(donor);335    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);336    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);337    const collection = await helper.ft.mintCollection(alice);338    await collection.mint(alice, 200n, {Ethereum: sender});339340    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);341    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', sender);342343    {344      // Can transferCross to ethereum address:345      const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});346      // Check events:347      const event = result.events.Transfer;348      expect(event.address).to.be.equal(collectionAddress);349      expect(event.returnValues.from).to.be.equal(sender);350      expect(event.returnValues.to).to.be.equal(receiverEth);351      expect(event.returnValues.value).to.be.equal('50');352      // Sender's balance decreased:353      const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();354      expect(+ownerBalance).to.equal(150);355      // Receiver's balance increased:356      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();357      expect(+receiverBalance).to.equal(50);358    }359360    {361      // Can transferCross to substrate address:362      const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});363      // Check events:364      const event = result.events.Transfer;365      expect(event.address).to.be.equal(collectionAddress);366      expect(event.returnValues.from).to.be.equal(sender);367      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));368      expect(event.returnValues.value).to.be.equal('50');369      // Sender's balance decreased:370      const senderBalance = await collection.getBalance({Ethereum: sender});371      expect(senderBalance).to.equal(100n);372      // Receiver's balance increased:373      const balance = await collection.getBalance({Substrate: donor.address});374      expect(balance).to.equal(50n);375    }376  });377378  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} incorrect amount`, async ({helper}) => {379    const sender = await helper.eth.createAccountWithBalance(donor);380    const receiverEth = await helper.eth.createAccountWithBalance(donor);381    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);382    const BALANCE = 200n;383    const BALANCE_TO_TRANSFER = BALANCE + 100n;384385    const collection = await helper.ft.mintCollection(alice);386    await collection.mint(alice, BALANCE, {Ethereum: sender});387    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);388    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', sender);389390    // 1. Cannot transfer more than have391    const receiver = testCase === 'transfer' ? receiverEth : receiverCrossEth;392    await expect(collectionEvm.methods[testCase](receiver, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;393    // 2. Zero transfer allowed (EIP-20):394    await collectionEvm.methods[testCase](receiver, 0n).send({from: sender});395  }));396397398  itEth('Can perform transfer()', async ({helper}) => {399    const owner = await helper.eth.createAccountWithBalance(donor);400    const receiver = await helper.eth.createAccountWithBalance(donor);401    const collection = await helper.ft.mintCollection(alice);402    await collection.mint(alice, 200n, {Ethereum: owner});403404    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);405    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);406407    {408      const result = await contract.methods.transfer(receiver, 50).send({from: owner});409410      const event = result.events.Transfer;411      expect(event.address).to.be.equal(collectionAddress);412      expect(event.returnValues.from).to.be.equal(owner);413      expect(event.returnValues.to).to.be.equal(receiver);414      expect(event.returnValues.value).to.be.equal('50');415    }416417    {418      const balance = await contract.methods.balanceOf(owner).call();419      expect(+balance).to.equal(150);420    }421422    {423      const balance = await contract.methods.balanceOf(receiver).call();424      expect(+balance).to.equal(50);425    }426  });427428  itEth('Can perform transferFromCross()', async ({helper}) => {429    const sender = await helper.eth.createAccountWithBalance(donor, 100n);430431    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);432433    const receiver = helper.eth.createAccount();434435    await collection.mint(owner, 200n, {Substrate: owner.address});436    await collection.approveTokens(owner, {Ethereum: sender}, 100n);437438    const address = helper.ethAddress.fromCollectionId(collection.collectionId);439    const contract = await helper.ethNativeContract.collection(address, 'ft');440441    const from = helper.ethCrossAccount.fromKeyringPair(owner);442    const to = helper.ethCrossAccount.fromAddress(receiver);443444    const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});445    const toBalanceBefore = await collection.getBalance({Ethereum: receiver});446447    const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});448449    expect(result.events).to.be.like({450      Transfer: {451        address,452        event: 'Transfer',453        returnValues: {454          from: helper.address.substrateToEth(owner.address),455          to: receiver,456          value: '51',457        },458      },459      Approval: {460        address,461        event: 'Approval',462        returnValues: {463          owner: helper.address.substrateToEth(owner.address),464          spender: sender,465          value: '49',466        },467      }});468469    const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});470    expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(51n);471    const toBalanceAfter = await collection.getBalance({Ethereum: receiver});472    expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);473  });474});475476describe('Fungible: Fees', () => {477  let donor: IKeyringPair;478  let alice: IKeyringPair;479480  before(async function() {481    await usingEthPlaygrounds(async (helper, privateKey) => {482      donor = await privateKey({filename: __filename});483      [alice] = await helper.arrange.createAccounts([20n], donor);484    });485  });486487  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {488    const owner = await helper.eth.createAccountWithBalance(donor);489    const spender = helper.eth.createAccount();490    const collection = await helper.ft.mintCollection(alice);491    await collection.mint(alice, 200n, {Ethereum: owner});492493    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);494    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);495496    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));497    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));498  });499500  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {501    const owner = await helper.eth.createAccountWithBalance(donor);502    const spender = await helper.eth.createAccountWithBalance(donor);503    const collection = await helper.ft.mintCollection(alice);504    await collection.mint(alice, 200n, {Ethereum: owner});505506    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);507    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);508509    await contract.methods.approve(spender, 100).send({from: owner});510511    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));512    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));513  });514515  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {516    const owner = await helper.eth.createAccountWithBalance(donor);517    const receiver = helper.eth.createAccount();518    const collection = await helper.ft.mintCollection(alice);519    await collection.mint(alice, 200n, {Ethereum: owner});520521    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);522    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);523524    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));525    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));526  });527});528529describe('Fungible: Substrate calls', () => {530  let donor: IKeyringPair;531  let alice: IKeyringPair;532  let owner: IKeyringPair;533534  before(async function() {535    await usingEthPlaygrounds(async (helper, privateKey) => {536      donor = await privateKey({filename: __filename});537      [alice, owner] = await helper.arrange.createAccounts([20n, 20n], donor);538    });539  });540541  itEth('Events emitted for approve()', async ({helper}) => {542    const receiver = helper.eth.createAccount();543    const collection = await helper.ft.mintCollection(alice);544    await collection.mint(alice, 200n);545546    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);547    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');548549    const events: any = [];550    contract.events.allEvents((_: any, event: any) => {551      events.push(event);552    });553554    await collection.approveTokens(alice, {Ethereum: receiver}, 100n);555    if (events.length == 0) await helper.wait.newBlocks(1);556    const event = events[0];557558    expect(event.event).to.be.equal('Approval');559    expect(event.address).to.be.equal(collectionAddress);560    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));561    expect(event.returnValues.spender).to.be.equal(receiver);562    expect(event.returnValues.value).to.be.equal('100');563  });564565  itEth('Events emitted for transferFrom()', async ({helper}) => {566    const [bob] = await helper.arrange.createAccounts([10n], donor);567    const receiver = helper.eth.createAccount();568    const collection = await helper.ft.mintCollection(alice);569    await collection.mint(alice, 200n);570    await collection.approveTokens(alice, {Substrate: bob.address}, 100n);571572    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);573    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');574575    const events: any = [];576    contract.events.allEvents((_: any, event: any) => {577      events.push(event);578    });579580    await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);581    if (events.length == 0) await helper.wait.newBlocks(1);582    let event = events[0];583584    expect(event.event).to.be.equal('Transfer');585    expect(event.address).to.be.equal(collectionAddress);586    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));587    expect(event.returnValues.to).to.be.equal(receiver);588    expect(event.returnValues.value).to.be.equal('51');589590    event = events[1];591    expect(event.event).to.be.equal('Approval');592    expect(event.address).to.be.equal(collectionAddress);593    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));594    expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));595    expect(event.returnValues.value).to.be.equal('49');596  });597598  itEth('Events emitted for transfer()', async ({helper}) => {599    const receiver = helper.eth.createAccount();600    const collection = await helper.ft.mintCollection(alice);601    await collection.mint(alice, 200n);602603    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);604    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');605606    const events: any = [];607    contract.events.allEvents((_: any, event: any) => {608      events.push(event);609    });610611    await collection.transfer(alice, {Ethereum:receiver}, 51n);612    if (events.length == 0) await helper.wait.newBlocks(1);613    const event = events[0];614615    expect(event.event).to.be.equal('Transfer');616    expect(event.address).to.be.equal(collectionAddress);617    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));618    expect(event.returnValues.to).to.be.equal(receiver);619    expect(event.returnValues.value).to.be.equal('51');620  });621622  itEth('Events emitted for transferFromCross()', async ({helper}) => {623    const sender = await helper.eth.createAccountWithBalance(donor, 100n);624625    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);626627    const receiver = helper.eth.createAccount();628629    await collection.mint(owner, 200n, {Substrate: owner.address});630    await collection.approveTokens(owner, {Ethereum: sender}, 100n);631632    const address = helper.ethAddress.fromCollectionId(collection.collectionId);633    const contract = await helper.ethNativeContract.collection(address, 'ft');634635    const from = helper.ethCrossAccount.fromKeyringPair(owner);636    const to = helper.ethCrossAccount.fromAddress(receiver);637638    const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});639640    expect(result.events).to.be.like({641      Transfer: {642        address,643        event: 'Transfer',644        returnValues: {645          from: helper.address.substrateToEth(owner.address),646          to: receiver,647          value: '51',648        },649      },650      Approval: {651        address,652        event: 'Approval',653        returnValues: {654          owner: helper.address.substrateToEth(owner.address),655          spender: sender,656          value: '49',657        },658      }});659  });660});