git.delta.rocks / unique-network / refs/commits / 1e30fde0a36a

difftreelog

Review: contractSponsoring tests

Max Andreev2022-12-21parent: #a12554c.patch.diff
in: master
Combine some duplicated tests.
Add checks

1 file changed

modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
2222
23describe('Sponsoring EVM contracts', () => {23describe('Sponsoring EVM contracts', () => {
24 let donor: IKeyringPair;24 let donor: IKeyringPair;
25 let nominal: bigint;
2526
26 before(async () => {27 before(async () => {
27 await usingPlaygrounds(async (_helper, privateKey) => {28 await usingPlaygrounds(async (helper, privateKey) => {
28 donor = await privateKey({filename: __filename});29 donor = await privateKey({filename: __filename});
30 nominal = helper.balance.getOneTokenNominal();
29 });31 });
30 });32 });
31
32 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper}) => {
33 const owner = await helper.eth.createAccountWithBalance(donor);
34 const flipper = await helper.eth.deployFlipper(owner);
35 const helpers = helper.ethNativeContract.contractHelpers(owner);
36
37 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
38 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;
39 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
40 });
4133
42 itEth('Set self sponsored events', async ({helper}) => {34 itEth('Self sponsoring can be set by the address that deployed the contract', async ({helper}) => {
43 const owner = await helper.eth.createAccountWithBalance(donor);35 const owner = await helper.eth.createAccountWithBalance(donor);
44 const flipper = await helper.eth.deployFlipper(owner);36 const flipper = await helper.eth.deployFlipper(owner);
45 const helpers = helper.ethNativeContract.contractHelpers(owner);37 const helpers = helper.ethNativeContract.contractHelpers(owner);
46 38
39 // 1. owner can set selfSponsoring:
40 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
47 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();41 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send({from: owner});
42 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
43
44 // 1.1 Can get sponsor using methods.sponsor:
45 const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
46 expect(actualSponsor.eth).to.eq(flipper.options.address);
47 expect(actualSponsor.sub).to.eq('0');
48
49 // 2. Events should be:
48 const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);50 const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);
49 expect(ethEvents).to.be.deep.equal([51 expect(ethEvents).to.be.deep.equal([
50 {52 {
66 ]);68 ]);
67 });69 });
6870
69 itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper}) => {71 itEth('Self sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {
70 const owner = await helper.eth.createAccountWithBalance(donor);72 const owner = await helper.eth.createAccountWithBalance(donor);
71 const notOwner = await helper.eth.createAccountWithBalance(donor);73 const notOwner = await helper.eth.createAccountWithBalance(donor);
72 const helpers = helper.ethNativeContract.contractHelpers(owner);74 const helpers = helper.ethNativeContract.contractHelpers(owner);
83 const flipper = await helper.eth.deployFlipper(owner);85 const flipper = await helper.eth.deployFlipper(owner);
8486
85 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;87 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
86 await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;88 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
87 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;89 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
88 });90 });
8991
98 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;100 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
99 });101 });
100 102
101 itEth('Sponsor can be set by the address that deployed the contract', async ({helper}) => {
102 const owner = await helper.eth.createAccountWithBalance(donor);
103 const sponsor = await helper.eth.createAccountWithBalance(donor);
104 const helpers = helper.ethNativeContract.contractHelpers(owner);
105 const flipper = await helper.eth.deployFlipper(owner);
106
107 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
108 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
109 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
110 });
111
112 itEth('Set sponsor event', async ({helper}) => {103 itEth('Sponsor can be set by the address that deployed the contract', async ({helper}) => {
113 const owner = await helper.eth.createAccountWithBalance(donor);104 const owner = await helper.eth.createAccountWithBalance(donor);
114 const sponsor = await helper.eth.createAccountWithBalance(donor);105 const sponsor = await helper.eth.createAccountWithBalance(donor);
115 const helpers = helper.ethNativeContract.contractHelpers(owner);106 const helpers = helper.ethNativeContract.contractHelpers(owner);
116 const flipper = await helper.eth.deployFlipper(owner);107 const flipper = await helper.eth.deployFlipper(owner);
117 108
109 // 1. owner can set a sponsor:
110 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
118 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();111 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
112 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
113
114 // 2. Events should be:
119 const events = helper.eth.normalizeEvents(result.events);115 const events = helper.eth.normalizeEvents(result.events);
120 expect(events).to.be.deep.equal([116 expect(events).to.be.deep.equal([
121 {117 {
129 ]);125 ]);
130 });126 });
131 127
132 itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper}) => {128 itEth('Sponsor cannot be set by the address that did not deployed the contract', async ({helper}) => {
133 const owner = await helper.eth.createAccountWithBalance(donor);129 const owner = await helper.eth.createAccountWithBalance(donor);
134 const sponsor = await helper.eth.createAccountWithBalance(donor);130 const sponsor = await helper.eth.createAccountWithBalance(donor);
135 const notOwner = await helper.eth.createAccountWithBalance(donor);131 const notOwner = await helper.eth.createAccountWithBalance(donor);
141 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;137 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
142 });138 });
143
144 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper}) => {
145 const owner = await helper.eth.createAccountWithBalance(donor);
146 const sponsor = await helper.eth.createAccountWithBalance(donor);
147 const helpers = helper.ethNativeContract.contractHelpers(owner);
148 const flipper = await helper.eth.deployFlipper(owner);
149
150 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
151 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
152 await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;
153 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
154 });
155139
156 itEth('Confirm sponsorship event', async ({helper}) => {140 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper}) => {
157 const owner = await helper.eth.createAccountWithBalance(donor);141 const owner = await helper.eth.createAccountWithBalance(donor);
158 const sponsor = await helper.eth.createAccountWithBalance(donor);142 const sponsor = await helper.eth.createAccountWithBalance(donor);
159 const helpers = helper.ethNativeContract.contractHelpers(owner);143 const helpers = helper.ethNativeContract.contractHelpers(owner);
160 const flipper = await helper.eth.deployFlipper(owner);144 const flipper = await helper.eth.deployFlipper(owner);
161145
146 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
162 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;147 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
148
149 // 1. sponsor can confirm sponsorship:
163 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});150 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
151 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
152
153 // 1.1 Can get sponsor using methods.sponsor:
154 const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
155 expect(actualSponsor.eth).to.eq(sponsor);
156 expect(actualSponsor.sub).to.eq('0');
157
158 // 2. Events should be:
164 const events = helper.eth.normalizeEvents(result.events);159 const events = helper.eth.normalizeEvents(result.events);
165 expect(events).to.be.deep.equal([160 expect(events).to.be.deep.equal([
166 {161 {
198 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;193 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
199 });194 });
200
201 itEth('Get self sponsored sponsor', async ({helper}) => {
202 const owner = await helper.eth.createAccountWithBalance(donor);
203 const helpers = helper.ethNativeContract.contractHelpers(owner);
204 const flipper = await helper.eth.deployFlipper(owner);
205
206 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
207
208 const result = await helpers.methods.sponsor(flipper.options.address).call();
209
210 expect(result[0]).to.be.eq(flipper.options.address);
211 expect(result[1]).to.be.eq('0');
212 });
213
214 itEth('Get confirmed sponsor', async ({helper}) => {
215 const owner = await helper.eth.createAccountWithBalance(donor);
216 const sponsor = await helper.eth.createAccountWithBalance(donor);
217 const helpers = helper.ethNativeContract.contractHelpers(owner);
218 const flipper = await helper.eth.deployFlipper(owner);
219
220 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
221 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
222
223 const result = await helpers.methods.sponsor(flipper.options.address).call();
224
225 expect(result[0]).to.be.eq(sponsor);
226 expect(result[1]).to.be.eq('0');
227 });
228195
229 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {196 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {
230 const owner = await helper.eth.createAccountWithBalance(donor);197 const owner = await helper.eth.createAccountWithBalance(donor);
236 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();203 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
237 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});204 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
238 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;205 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
239 206 // 1. Can remove sponsor:
240 await helpers.methods.removeSponsor(flipper.options.address).send();207 const result = await helpers.methods.removeSponsor(flipper.options.address).send();
241 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;208 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
209
210 // 2. Events should be:
211 const events = helper.eth.normalizeEvents(result.events);
212 expect(events).to.be.deep.equal([
213 {
214 address: flipper.options.address,
215 event: 'ContractSponsorRemoved',
216 args: {
217 contractAddress: flipper.options.address,
218 },
219 },
220 ]);
221
222 // TODO: why call method reverts?
223 // const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
224 // expect(actualSponsor.eth).to.eq(sponsor);
225 // expect(actualSponsor.sub).to.eq('0');
242 });226 });
243
244 itEth('Remove sponsor event', async ({helper}) => {
245 const owner = await helper.eth.createAccountWithBalance(donor);
246 const sponsor = await helper.eth.createAccountWithBalance(donor);
247 const helpers = helper.ethNativeContract.contractHelpers(owner);
248 const flipper = await helper.eth.deployFlipper(owner);
249
250 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
251 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
252
253 const result = await helpers.methods.removeSponsor(flipper.options.address).send();
254 const events = helper.eth.normalizeEvents(result.events);
255 expect(events).to.be.deep.equal([
256 {
257 address: flipper.options.address,
258 event: 'ContractSponsorRemoved',
259 args: {
260 contractAddress: flipper.options.address,
261 },
262 },
263 ]);
264 });
265227
266 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {228 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {
267 const owner = await helper.eth.createAccountWithBalance(donor);229 const owner = await helper.eth.createAccountWithBalance(donor);
276 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;238 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
277 239
278 await expect(helpers.methods.removeSponsor(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');240 await expect(helpers.methods.removeSponsor(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');
241 await expect(helpers.methods.removeSponsor(flipper.options.address).send({from: notOwner})).to.be.rejected;
279 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;242 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
280 });243 });
281244
292 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});255 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});
293 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});256 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
294257
295 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));258 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
296 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));259 const callerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
297260
298 await flipper.methods.flip().send({from: caller});261 await flipper.methods.flip().send({from: caller});
299 expect(await flipper.methods.getValue().call()).to.be.true;262 expect(await flipper.methods.getValue().call()).to.be.true;
300263
301 // Balance should be taken from sponsor instead of caller264 // Balance should be taken from sponsor instead of caller
302 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));265 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
303 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));266 const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
304 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;267 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
305 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);268 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
306 });269 });
331 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);294 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
332 });295 });
333296
297 [
298 {balance: 0n, label: '0'},
299 {balance: 10n, label: '10'},
300 ].map(testCase => {
334 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper}) => {301 itEth(`Allow-listed address that has ${testCase.label} UNQ can call a contract. Sponsor balance should decrease`, async ({helper}) => {
335 const owner = await helper.eth.createAccountWithBalance(donor);302 const owner = await helper.eth.createAccountWithBalance(donor);
336 const sponsor = await helper.eth.createAccountWithBalance(donor);303 const sponsor = await helper.eth.createAccountWithBalance(donor);
337 const caller = helper.eth.createAccount();304 const caller = helper.eth.createAccount();
305 await helper.eth.transferBalanceFromSubstrate(donor, caller, testCase.balance);
338 const helpers = helper.ethNativeContract.contractHelpers(owner);306 const helpers = helper.ethNativeContract.contractHelpers(owner);
339 const flipper = await helper.eth.deployFlipper(owner);307 const flipper = await helper.eth.deployFlipper(owner);
340308
347 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();315 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
348 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});316 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
349317
350 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));318 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
351 expect(sponsorBalanceBefore).to.be.not.equal('0');319 expect(sponsorBalanceBefore > 0n).to.be.true;
352320
353 await flipper.methods.flip().send({from: caller});321 await flipper.methods.flip().send({from: caller});
354 expect(await flipper.methods.getValue().call()).to.be.true;322 expect(await flipper.methods.getValue().call()).to.be.true;
355323
356 // Balance should be taken from flipper instead of caller324 // Balance should be taken from flipper instead of caller
357 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));325 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
358 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;326 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
327 // Caller's balance does not change:
328 const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
329 expect(callerBalanceAfter).to.eq(testCase.balance * nominal);
359 });330 });
360331 });
361 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper}) => {
362 const owner = await helper.eth.createAccountWithBalance(donor);
363 const caller = await helper.eth.createAccount();
364 const helpers = helper.ethNativeContract.contractHelpers(owner);
365 const flipper = await helper.eth.deployFlipper(owner);
366
367 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
368 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
369
370 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
371
372 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);
373 expect(originalFlipperBalance).to.be.not.equal('0');
374
375 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/Returned error: insufficient funds for gas \* price \+ value/);
376 expect(await flipper.methods.getValue().call()).to.be.false;
377
378 // Balance should be taken from flipper instead of caller
379 // FIXME the comment is wrong! What check should be here?
380 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
381 expect(balanceAfter).to.be.equal(originalFlipperBalance);
382 });
383332
384 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {333 itEth('Non-allow-listed address can call a contract. Sponsor balance should not decrease', async ({helper}) => {
385 const owner = await helper.eth.createAccountWithBalance(donor);334 const owner = await helper.eth.createAccountWithBalance(donor);
386 const sponsor = await helper.eth.createAccountWithBalance(donor);
387 const caller = await helper.eth.createAccountWithBalance(donor);335 const caller = helper.eth.createAccount();
388 const helpers = helper.ethNativeContract.contractHelpers(owner);336 const contractHelpers = helper.ethNativeContract.contractHelpers(owner);
337
338 // Deploy flipper and send some tokens:
389 const flipper = await helper.eth.deployFlipper(owner);339 const flipper = await helper.eth.deployFlipper(owner);
390
391 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});340 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
392 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});341 expect(await flipper.methods.getValue().call()).to.be.false;
393342 // flipper address has some tokens:
394 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});343 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);
344 expect(originalFlipperBalance > 0n).to.be.true;
345
346 // Set Allowlisted sponsoring mode. caller is not in allow list:
395 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});347 await contractHelpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
396
397 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();348 await contractHelpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
398 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});349 await contractHelpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
399350
400 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));351 // 1. Caller has no UNQ and is not in allow list. So he cannot flip:
401 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
402
403 await flipper.methods.flip().send({from: caller});352 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/Returned error: insufficient funds for gas \* price \+ value/);
404 expect(await flipper.methods.getValue().call()).to.be.true;353 expect(await flipper.methods.getValue().call()).to.be.false;
405354
355 // Flipper's balance does not change:
406 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));356 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
407 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
408 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
409 expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);357 expect(balanceAfter).to.be.equal(originalFlipperBalance);
410 });358 });
411359
412 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {360 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
427 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});375 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
428376
429 const originalFlipperBalance = await helper.balance.getEthereum(sponsor);377 const originalFlipperBalance = await helper.balance.getEthereum(sponsor);
430 expect(originalFlipperBalance).to.be.not.equal('0');378 expect(originalFlipperBalance > 0n).to.be.true;
431379
432 await flipper.methods.flip().send({from: caller});380 await flipper.methods.flip().send({from: caller});
433 expect(await flipper.methods.getValue().call()).to.be.true;381 expect(await flipper.methods.getValue().call()).to.be.true;