1234567891011121314151617import {expect} from 'chai';18import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode} from './util/helpers';1920describe('EVM sponsoring', () => {21 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {22 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);23 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);24 const caller = createEthAccount(web3);25 const originalCallerBalance = await web3.eth.getBalance(caller);26 expect(originalCallerBalance).to.be.equal('0');2728 const flipper = await deployFlipper(web3, owner);2930 const helpers = contractHelpers(web3, owner);31 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});32 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});33 34 await helpers.methods.setSponsor(flipper.options.address, sponsor).send({from: owner});35 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});3637 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;38 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});39 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});40 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;4142 const originalSponsorBalance = await web3.eth.getBalance(sponsor);43 expect(originalSponsorBalance).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(sponsor)).to.be.not.equals(originalSponsorBalance);51 });5253 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {54 const alice = privateKeyWrapper('//Alice');5556 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);57 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);58 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);59 const originalCallerBalance = await web3.eth.getBalance(caller);60 expect(originalCallerBalance).to.be.not.equal('0');6162 const collector = await deployCollector(web3, owner);6364 const helpers = contractHelpers(web3, owner);65 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});66 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});6768 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;69 await helpers.methods.setSponsoringMode(collector.options.address, SponsoringMode.Allowlisted).send({from: owner});70 await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});71 expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;7273 await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});74 await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});7576 const originalSponsorBalance = await web3.eth.getBalance(sponsor);77 expect(originalSponsorBalance).to.be.not.equal('0');7879 await collector.methods.giveMoney().send({from: caller, value: '10000'});8081 82 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());83 expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);84 expect(await collector.methods.getCollected().call()).to.be.equal('10000');85 });86});