1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, transferBalanceToEth} from './util/helpers';45describe('EVM sponsoring', () => {6 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {7 const alice = privateKey('//Alice');89 const owner = await createEthAccountWithBalance(api, web3);10 const caller = createEthAccount(web3);11 const originalCallerBalance = await web3.eth.getBalance(caller);12 expect(originalCallerBalance).to.be.equal('0');1314 const flipper = await deployFlipper(web3, owner);1516 const helpers = contractHelpers(web3, owner);17 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});18 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});1920 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;21 await helpers.methods.toggleSponsoring(flipper.options.address, true).send({from: owner});22 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});23 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;2425 await transferBalanceToEth(api, alice, flipper.options.address);2627 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);28 expect(originalFlipperBalance).to.be.not.equal('0');2930 await flipper.methods.flip().send({from: caller});31 expect(await flipper.methods.getValue().call()).to.be.true;3233 34 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);35 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);36 });37 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {38 const alice = privateKey('//Alice');3940 const owner = await createEthAccountWithBalance(api, web3);41 const caller = await createEthAccountWithBalance(api, web3);42 const originalCallerBalance = await web3.eth.getBalance(caller);43 expect(originalCallerBalance).to.be.not.equal('0');4445 const collector = await deployCollector(web3, owner);4647 const helpers = contractHelpers(web3, owner);48 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});49 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});5051 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;52 await helpers.methods.toggleSponsoring(collector.options.address, true).send({from: owner});53 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});54 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;5556 await transferBalanceToEth(api, alice, collector.options.address);5758 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);59 expect(originalCollectorBalance).to.be.not.equal('0');6061 await collector.methods.giveMoney().send({from: caller, value: '10000'});6263 64 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());65 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);66 expect(await collector.methods.getCollected().call()).to.be.equal('10000');67 });68});