1234567891011121314151617import {expect} from 'chai';18import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode, transferBalanceToEth} from './util/helpers';1920describe('EVM sponsoring', () => {21 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {22 const alice = privateKeyWrapper('//Alice');2324 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const caller = createEthAccount(web3);26 const originalCallerBalance = await web3.eth.getBalance(caller);27 expect(originalCallerBalance).to.be.equal('0');2829 const flipper = await deployFlipper(web3, owner);3031 const helpers = contractHelpers(web3, owner);32 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});33 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});3435 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;36 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});37 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});38 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;3940 await transferBalanceToEth(api, alice, flipper.options.address);4142 const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);43 expect(originalFlipperBalance).to.be.not.equal('0');4445 await flipper.methods.flip().send({from: caller});46 expect(await flipper.methods.getValue().call()).to.be.true;4748 49 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);50 expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);51 });52 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {53 const alice = privateKeyWrapper('//Alice');5455 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);56 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);57 const originalCallerBalance = await web3.eth.getBalance(caller);58 expect(originalCallerBalance).to.be.not.equal('0');5960 const collector = await deployCollector(web3, owner);6162 const helpers = contractHelpers(web3, owner);63 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});64 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});6566 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;67 await helpers.methods.setSponsoringMode(collector.options.address, SponsoringMode.Allowlisted).send({from: owner});68 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});69 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;7071 await transferBalanceToEth(api, alice, collector.options.address);7273 const originalCollectorBalance = await web3.eth.getBalance(collector.options.address);74 expect(originalCollectorBalance).to.be.not.equal('0');7576 await collector.methods.giveMoney().send({from: caller, value: '10000'});7778 79 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());80 expect(await web3.eth.getBalance(collector.options.address)).to.be.not.equals(originalCollectorBalance);81 expect(await collector.methods.getCollected().call()).to.be.equal('10000');82 });83});