git.delta.rocks / unique-network / refs/commits / 48cdcf7aa35b

difftreelog

source

tests/src/eth/sponsoring.test.ts4.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {SponsoringMode} from './util/helpers';18import {itEth, expect} from '../eth/util/playgrounds';1920describe('EVM sponsoring', () => {21  itEth('Fee is deducted from contract if sponsoring is enabled', async ({helper, privateKey}) => {22    const alice = privateKey('//Alice');2324    const owner = await helper.eth.createAccountWithBalance(alice);25    const sponsor = await helper.eth.createAccountWithBalance(alice);26    const caller = await helper.eth.createAccount();27    const originalCallerBalance = await helper.balance.getEthereum(caller);2829    expect(originalCallerBalance).to.be.equal(0n);3031    // const flipper = await deployFlipper(web3, owner);32    const flipper = await helper.eth.deployFlipper(owner);3334    const helpers = helper.ethNativeContract.contractHelpers(owner);3536    await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});37    await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});38    39    await helpers.methods.setSponsor(flipper.options.address, sponsor).send({from: owner});40    await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});4142    expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;43    await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});44    await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});45    expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;4647    const originalSponsorBalance = await helper.balance.getEthereum(sponsor);48    expect(originalSponsorBalance).to.be.not.equal(0n);4950    await flipper.methods.flip().send({from: caller});51    expect(await flipper.methods.getValue().call()).to.be.true;5253    // Balance should be taken from flipper instead of caller54    expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);55    expect(await helper.balance.getEthereum(sponsor)).to.be.not.equal(originalSponsorBalance);56  });5758  itEth('...but this doesn\'t applies to payable value', async ({helper, privateKey}) => {59    const alice = privateKey('//Alice');6061    const owner = await helper.eth.createAccountWithBalance(alice);62    const sponsor = await helper.eth.createAccountWithBalance(alice);63    const caller = await helper.eth.createAccountWithBalance(alice);64    const originalCallerBalance = await helper.balance.getEthereum(caller);6566    expect(originalCallerBalance).to.be.not.equal(0n);6768    const collector = await helper.eth.deployCollectorContract(owner);6970    const helpers = helper.ethNativeContract.contractHelpers(owner);7172    await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});73    await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});7475    expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.false;76    await helpers.methods.setSponsoringMode(collector.options.address, SponsoringMode.Allowlisted).send({from: owner});77    await helpers.methods.setSponsoringRateLimit(collector.options.address, 0).send({from: owner});78    expect(await helpers.methods.sponsoringEnabled(collector.options.address).call()).to.be.true;7980    await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});81    await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});8283    const originalSponsorBalance = await helper.balance.getEthereum(sponsor);84    expect(originalSponsorBalance).to.be.not.equal(0n);8586    await collector.methods.giveMoney().send({from: caller, value: '10000'});8788    // Balance will be taken from both caller (value) and from collector (fee)89    expect(await helper.balance.getEthereum(caller)).to.be.equals((originalCallerBalance - 10000n));90    expect(await helper.balance.getEthereum(sponsor)).to.be.not.equals(originalSponsorBalance);91    expect(await collector.methods.getCollected().call()).to.be.equal('10000');92  });93});