difftreelog
refactor use playgrounds in eth sponsoring test
in: master
1 file changed
tests/src/eth/sponsoring.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {expect} from 'chai';17import {SponsoringMode} from './util/helpers';18import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode} from './util/helpers';18import {itEth, expect} from '../eth/util/playgrounds';191920describe('EVM sponsoring', () => {20describe('EVM sponsoring', () => {21 itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {21 itEth('Fee is deducted from contract if sponsoring is enabled', async ({helper, privateKey}) => {22 const alice = privateKey('//Alice');2322 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);24 const owner = await helper.eth.createAccountWithBalance(alice);23 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const sponsor = await helper.eth.createAccountWithBalance(alice);24 const caller = createEthAccount(web3);26 const caller = await helper.eth.createAccount();25 const originalCallerBalance = await web3.eth.getBalance(caller);27 const originalCallerBalance = await helper.balance.getEthereum(caller);2826 expect(originalCallerBalance).to.be.equal('0');29 expect(originalCallerBalance).to.be.equal(0n);273031 // const flipper = await deployFlipper(web3, owner);28 const flipper = await deployFlipper(web3, owner);32 const flipper = await helper.eth.deployFlipper(owner);293330 const helpers = contractHelpers(web3, owner);34 const helpers = helper.ethNativeContract.contractHelpers(owner);3531 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});36 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});32 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});37 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});39 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});44 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});40 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;45 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;414642 const originalSponsorBalance = await web3.eth.getBalance(sponsor);47 const originalSponsorBalance = await helper.balance.getEthereum(sponsor);43 expect(originalSponsorBalance).to.be.not.equal('0');48 expect(originalSponsorBalance).to.be.not.equal(0n);444945 await flipper.methods.flip().send({from: caller});50 await flipper.methods.flip().send({from: caller});46 expect(await flipper.methods.getValue().call()).to.be.true;51 expect(await flipper.methods.getValue().call()).to.be.true;475248 // Balance should be taken from flipper instead of caller53 // Balance should be taken from flipper instead of caller49 expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);54 expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);50 expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);55 expect(await helper.balance.getEthereum(sponsor)).to.be.not.equal(originalSponsorBalance);51 });56 });525753 itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {58 itEth('...but this doesn\'t applies to payable value', async ({helper, privateKey}) => {59 const alice = privateKey('//Alice');6054 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);61 const owner = await helper.eth.createAccountWithBalance(alice);55 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);62 const sponsor = await helper.eth.createAccountWithBalance(alice);56 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);63 const caller = await helper.eth.createAccountWithBalance(alice);57 const originalCallerBalance = await web3.eth.getBalance(caller);64 const originalCallerBalance = await helper.balance.getEthereum(caller);6558 expect(originalCallerBalance).to.be.not.equal('0');66 expect(originalCallerBalance).to.be.not.equal(0n);596760 const collector = await deployCollector(web3, owner);68 const collector = await helper.eth.deployCollectorContract(owner);616962 const helpers = contractHelpers(web3, owner);70 const helpers = helper.ethNativeContract.contractHelpers(owner);7163 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});72 await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});64 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});73 await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});71 await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});80 await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});72 await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});81 await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});738274 const originalSponsorBalance = await web3.eth.getBalance(sponsor);83 const originalSponsorBalance = await helper.balance.getEthereum(sponsor);75 expect(originalSponsorBalance).to.be.not.equal('0');84 expect(originalSponsorBalance).to.be.not.equal(0n);768577 await collector.methods.giveMoney().send({from: caller, value: '10000'});86 await collector.methods.giveMoney().send({from: caller, value: '10000'});788779 // Balance will be taken from both caller (value) and from collector (fee)88 // Balance will be taken from both caller (value) and from collector (fee)80 expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());89 expect(await helper.balance.getEthereum(caller)).to.be.equals((originalCallerBalance - 10000n));81 expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);90 expect(await helper.balance.getEthereum(sponsor)).to.be.not.equals(originalSponsorBalance);82 expect(await collector.methods.getCollected().call()).to.be.equal('10000');91 expect(await collector.methods.getCollected().call()).to.be.equal('10000');83 });92 });84});93});