From a4fc74116913fa561e8d531025c9dfb738218b09 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 03 Oct 2022 09:55:31 +0000 Subject: [PATCH] fix: draft fix of contractSponsoring --- --- a/tests/src/eth/contractSponsoring.test.ts +++ b/tests/src/eth/contractSponsoring.test.ts @@ -15,43 +15,47 @@ // along with Unique Network. If not, see . import * as solc from 'solc'; -import {expect} from 'chai'; import {expectSubstrateEventsAtBlock} from '../util/helpers'; import Web3 from 'web3'; import { - contractHelpers, - createEthAccountWithBalance, - transferBalanceToEth, - deployFlipper, - itWeb3, SponsoringMode, - createEthAccount, - ethBalanceViaSub, normalizeEvents, CompiledContract, GAS_ARGS, - subToEth, + contractHelpers, + createEthAccountWithBalance, } from './util/helpers'; -import {submitTransactionAsync} from '../substrate/substrate-api'; +import {itEth, expect} from '../eth/util/playgrounds'; + -describe('Sponsoring EVM contracts', () => { - itWeb3('Self sponsored can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); +describe.only('Sponsoring EVM contracts', () => { + itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const flipper = await helper.eth.deployFlipper(owner); + const helpers = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected; expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true; }); - itWeb3('Set self sponsored events', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Set self sponsored events', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const flipper = await helper.eth.deployFlipper(owner); + const helpers = helper.ethNativeContract.contractHelpers(owner); const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send(); - // console.log(result); const ethEvents = normalizeEvents(result.events); expect(ethEvents).to.be.deep.equal([ { @@ -72,58 +76,92 @@ }, ]); + // TODO use helper.getApi() from the sceduler PR await expectSubstrateEventsAtBlock( - api, + helper.api!, result.blockNumber, 'evmContractHelpers', ['ContractSponsorSet','ContractSponsorshipConfirmed'], ); }); - itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const helpers = contractHelpers(web3, owner); + // const flipper = await deployFlipper(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const notOwner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission'); expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; }); - itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth.only('Sponsoring can be set by the address that has deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = await helper.eth.deployFlipper(owner); + expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected; expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true; }); - itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const notOwner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission'); expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false; }); - itWeb3('Sponsor can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsor can be set by the address that deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected; expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true; }); - itWeb3('Set sponsor event', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Set sponsor event', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); const events = normalizeEvents(result.events); @@ -138,41 +176,64 @@ }, ]); + // TODO use helper.getApi() from the sceduler PR await expectSubstrateEventsAtBlock( - api, + helper.api!, result.blockNumber, 'evmContractHelpers', ['ContractSponsorSet'], ); }); - itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const notOwner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission'); expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false; }); - itWeb3('Sponsorship can be confirmed by the address that pending as sponsor', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected; await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected; expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true; }); - itWeb3('Confirm sponsorship event', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Confirm sponsorship event', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected; const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); const events = normalizeEvents(result.events); @@ -187,40 +248,62 @@ }, ]); + // TODO use helper.getApi() from the sceduler PR await expectSubstrateEventsAtBlock( - api, + helper.api!, result.blockNumber, 'evmContractHelpers', ['ContractSponsorshipConfirmed'], ); }); - itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const notSponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected; await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission'); expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; }); - itWeb3('Sponsorship can not be confirmed by the address that not set as sponsor', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const notSponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor'); expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; }); - itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Get self sponsored sponsor', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const flipper = helper.ethNativeContract.contractHelpers(owner); + const helpers = helper.ethNativeContract.contractHelpers(owner); + await helpers.methods.selfSponsoredEnable(flipper.options.address).send(); const result = await helpers.methods.sponsor(flipper.options.address).call(); @@ -229,11 +312,18 @@ expect(result[1]).to.be.eq('0'); }); - itWeb3('Get confirmed sponsor', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Get confirmed sponsor', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); @@ -243,12 +333,18 @@ expect(result[1]).to.be.eq('0'); }); - itWeb3('Sponsor can be removed by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsor can be removed by the address that deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); @@ -258,12 +354,18 @@ expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; }); - itWeb3('Remove sponsor event', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Remove sponsor event', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); @@ -279,20 +381,28 @@ }, ]); + // TODO use helper.getApi() from the sceduler PR await expectSubstrateEventsAtBlock( - api, + helper.api!, result.blockNumber, 'evmContractHelpers', ['ContractSponsorRemoved'], ); }); - itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const notOwner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false; await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); @@ -303,14 +413,19 @@ expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true; }); - itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const flipper = await deployFlipper(web3, owner); - - const helpers = contractHelpers(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); @@ -318,57 +433,66 @@ await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner}); await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner}); - const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor); - const callerBalanceBefore = await ethBalanceViaSub(api, caller); + const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); + const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; // Balance should be taken from sponsor instead of caller - const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor); - const callerBalanceAfter = await ethBalanceViaSub(api, caller); + const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); + const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true; expect(callerBalanceAfter).to.be.eq(callerBalanceBefore); }); - itWeb3('In generous mode, non-allowlisted user transaction will be self sponsored', async ({api, web3, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); - - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - - const flipper = await deployFlipper(web3, owner); + itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const helpers = contractHelpers(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); await helpers.methods.selfSponsoredEnable(flipper.options.address).send(); await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner}); await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner}); - await transferBalanceToEth(api, alice, flipper.options.address); + // await transferBalanceToEth(api, alice, flipper.options.address); + await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address); - const contractBalanceBefore = await ethBalanceViaSub(api, flipper.options.address); - const callerBalanceBefore = await ethBalanceViaSub(api, caller); + const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address)); + const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; // Balance should be taken from sponsor instead of caller - const contractBalanceAfter = await ethBalanceViaSub(api, flipper.options.address); - const callerBalanceAfter = await ethBalanceViaSub(api, caller); + const contractBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address)); + const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); expect(contractBalanceAfter < contractBalanceBefore).to.be.true; expect(callerBalanceAfter).to.be.eq(callerBalanceBefore); }); - itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = createEthAccount(web3); + itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const flipper = await deployFlipper(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = createEthAccount(web3); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); - const helpers = contractHelpers(web3, owner); await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner}); await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner}); @@ -378,51 +502,61 @@ await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); - const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor); + const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); expect(sponsorBalanceBefore).to.be.not.equal('0'); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; // Balance should be taken from flipper instead of caller - const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor); + const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true; }); - itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); + itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = createEthAccount(web3); - - const flipper = await deployFlipper(web3, owner); - - const helpers = contractHelpers(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = createEthAccount(web3); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner}); await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner}); - await transferBalanceToEth(api, alice, flipper.options.address); + // await transferBalanceToEth(api, alice, flipper.options.address); + await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address); - const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address); + const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address); // await web3.eth.getBalance(flipper.options.address); expect(originalFlipperBalance).to.be.not.equal('0'); await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/); expect(await flipper.methods.getValue().call()).to.be.false; // Balance should be taken from flipper instead of caller - const balanceAfter = await web3.eth.getBalance(flipper.options.address); - expect(+balanceAfter).to.be.equals(+originalFlipperBalance); + // FIXME the comment is wrong! What check should be here? + const balanceAfter = await helper.balance.getEthereum(flipper.options.address); // await web3.eth.getBalance(flipper.options.address); + expect(balanceAfter).to.be.equals(originalFlipperBalance); }); - itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const flipper = await deployFlipper(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); - const helpers = contractHelpers(web3, owner); await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner}); await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner}); @@ -432,27 +566,33 @@ await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); - const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor); - const callerBalanceBefore = await ethBalanceViaSub(api, caller); + const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); + const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; - const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor); - const callerBalanceAfter = await ethBalanceViaSub(api, caller); + const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor)); + const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller)); expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true; expect(callerBalanceAfter).to.be.equals(callerBalanceBefore); }); - itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const originalCallerBalance = await web3.eth.getBalance(caller); + itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const flipper = await deployFlipper(web3, owner); - - const helpers = contractHelpers(web3, owner); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const caller = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + + const originalCallerBalance = await helper.balance.getEthereum(caller); // await web3.eth.getBalance(caller); await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner}); await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner}); @@ -462,26 +602,32 @@ await helpers.methods.setSponsor(flipper.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor}); - const originalFlipperBalance = await web3.eth.getBalance(sponsor); + const originalFlipperBalance = await helper.balance.getEthereum(sponsor); // await web3.eth.getBalance(sponsor); expect(originalFlipperBalance).to.be.not.equal('0'); await flipper.methods.flip().send({from: caller}); expect(await flipper.methods.getValue().call()).to.be.true; - expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance); + expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance); - const newFlipperBalance = await web3.eth.getBalance(sponsor); + const newFlipperBalance = await helper.balance.getEthereum(sponsor); expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance); await flipper.methods.flip().send({from: caller}); - expect(await web3.eth.getBalance(sponsor)).to.be.equal(newFlipperBalance); - expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance); + expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance); + expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance); }); // TODO: Find a way to calculate default rate limit - itWeb3('Default rate limit equals 7200', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Default rate limit equals 7200', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200'); }); }); @@ -547,36 +693,61 @@ return await testContract.deploy({data: compiled.object}).send({from: owner}); } - itWeb3('Default fee limit', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Default fee limit', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935'); }); - itWeb3('Set fee limit', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Set fee limit', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send(); expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100'); }); - itWeb3('Negative test - set fee limit by non-owner', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const flipper = await deployFlipper(web3, owner); - const helpers = contractHelpers(web3, owner); + itEth('Negative test - set fee limit by non-owner', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const flipper = await deployFlipper(web3, owner); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const stranger = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + const flipper = helper.ethNativeContract.contractHelpers(owner); + await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected; }); - itWeb3('Negative test - check that eth transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => { - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); + + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const user = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); - const testContract = await deployTestContract(web3, owner); - const helpers = contractHelpers(web3, owner); + const testContract = await deployTestContract(helper.getWeb3(), owner); await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner}); await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner}); @@ -584,24 +755,29 @@ await helpers.methods.setSponsor(testContract.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor}); - const gasPrice = BigInt(await web3.eth.getGasPrice()); + const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice()); await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send(); - const originalUserBalance = await web3.eth.getBalance(user); + const originalUserBalance = await helper.balance.getEthereum(user); // await web3.eth.getBalance(user); await testContract.methods.test(100).send({from: user, gas: 2_000_000}); - expect(await web3.eth.getBalance(user)).to.be.equal(originalUserBalance); + expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance); await testContract.methods.test(100).send({from: user, gas: 2_100_000}); - expect(await web3.eth.getBalance(user)).to.not.be.equal(originalUserBalance); + expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance); }); - itWeb3('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => { - const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => { + const alice = privateKey('//Alice'); - const testContract = await deployTestContract(web3, owner); - const helpers = contractHelpers(web3, owner); + // const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + // const helpers = contractHelpers(web3, owner); + const owner = await helper.eth.createAccountWithBalance(alice); + const sponsor = await helper.eth.createAccountWithBalance(alice); + const helpers = helper.ethNativeContract.contractHelpers(owner); + + const testContract = await deployTestContract(helper.getWeb3(), owner); await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner}); await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner}); @@ -609,43 +785,56 @@ await helpers.methods.setSponsor(testContract.options.address, sponsor).send(); await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor}); - const gasPrice = BigInt(await web3.eth.getGasPrice()); + const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice()); await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send(); - const alice = privateKeyWrapper('//Alice'); - const originalAliceBalance = (await api.query.system.account(alice.address)).data.free.toBigInt(); - - await submitTransactionAsync( + const originalAliceBalance = await helper.balance.getSubstrate(alice.address); // (await api.query.system.account(alice.address)).data.free.toBigInt(); + + // await submitTransactionAsync( + // alice, + // api.tx.evm.call( + // subToEth(alice.address), + // testContract.options.address, + // testContract.methods.test(100).encodeABI(), + // Uint8Array.from([]), + // 2_000_000n, + // gasPrice, + // null, + // null, + // [], + // ), + // ); + await helper.eth.sendEVM( alice, - api.tx.evm.call( - subToEth(alice.address), - testContract.options.address, - testContract.methods.test(100).encodeABI(), - Uint8Array.from([]), - 2_000_000n, - gasPrice, - null, - null, - [], - ), + testContract.options.address, + testContract.methods.test().encodeABI(), + '100', ); - expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance); + // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance); + expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance); - await submitTransactionAsync( + // await submitTransactionAsync( + // alice, + // api.tx.evm.call( + // subToEth(alice.address), + // testContract.options.address, + // testContract.methods.test(100).encodeABI(), + // Uint8Array.from([]), + // 2_100_000n, + // gasPrice, + // null, + // null, + // [], + // ), + // ); + await helper.eth.sendEVM( alice, - api.tx.evm.call( - subToEth(alice.address), - testContract.options.address, - testContract.methods.test(100).encodeABI(), - Uint8Array.from([]), - 2_100_000n, - gasPrice, - null, - null, - [], - ), + testContract.options.address, + testContract.methods.test().encodeABI(), + '100', ); - expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance); + // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance); + expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance); }); }); -- gitstuff