git.delta.rocks / unique-network / refs/commits / cd9df53a9d65

difftreelog

refactor use playgrounds in eth sponsoring test

Daniel Shiposha2022-09-30parent: #09dc1ff.patch.diff
in: master

1 file changed

modifiedtests/src/eth/sponsoring.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// 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/>.
1616
17import {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';
1919
20describe('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');
23
22 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);
28
26 expect(originalCallerBalance).to.be.equal('0');29 expect(originalCallerBalance).to.be.equal(0n);
2730
31 // const flipper = await deployFlipper(web3, owner);
28 const flipper = await deployFlipper(web3, owner);32 const flipper = await helper.eth.deployFlipper(owner);
2933
30 const helpers = contractHelpers(web3, owner);34 const helpers = helper.ethNativeContract.contractHelpers(owner);
35
31 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;
4146
42 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);
4449
45 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;
4752
48 // Balance should be taken from flipper instead of caller53 // Balance should be taken from flipper instead of caller
49 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 });
5257
53 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');
60
54 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);
65
58 expect(originalCallerBalance).to.be.not.equal('0');66 expect(originalCallerBalance).to.be.not.equal(0n);
5967
60 const collector = await deployCollector(web3, owner);68 const collector = await helper.eth.deployCollectorContract(owner);
6169
62 const helpers = contractHelpers(web3, owner);70 const helpers = helper.ethNativeContract.contractHelpers(owner);
71
63 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});
7382
74 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);
7685
77 await collector.methods.giveMoney().send({from: caller, value: '10000'});86 await collector.methods.giveMoney().send({from: caller, value: '10000'});
7887
79 // 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});