git.delta.rocks / unique-network / refs/commits / 2c327ed12409

difftreelog

add test `Gas price boundaries`

Trubnikov Sergey2023-03-22parent: #f51771c.patch.diff
in: master

1 file changed

modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
403 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');403 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');
404 });404 });
405
406 itEth('Gas price boundaries', async ({helper}) => {
407 const owner = await helper.eth.createAccountWithBalance(donor);
408 const sponsor = await helper.eth.createAccountWithBalance(donor);
409 const caller = await helper.eth.createAccountWithBalance(donor);
410 const helpers = await helper.ethNativeContract.contractHelpers(owner);
411 const flipper = await helper.eth.deployFlipper(owner);
412
413 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
414 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
415
416 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});
417 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
418
419 let sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
420 let callerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
421
422 let expectValue = await flipper.methods.getValue().call();
423
424 const flip = async (gasPrice: bigint, shouldPass = true) => {
425 await flipper.methods.flip().send({from: caller, gasPrice: gasPrice});
426 expectValue = !expectValue;
427 expect(await flipper.methods.getValue().call()).to.be.eq(expectValue);
428 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
429 const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
430 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.eq(shouldPass);
431 expect(callerBalanceAfter === callerBalanceBefore).to.be.eq(shouldPass);
432 sponsorBalanceBefore = sponsorBalanceAfter;
433 callerBalanceBefore = callerBalanceAfter;
434 };
435
436 const gasPrice = BigInt(await helper.eth.getGasPrice());
437 await flip(gasPrice);
438 await flip(gasPrice * 2n);
439 await flip(gasPrice * 21n / 10n);
440 await flip(gasPrice * 22n / 10n, false);
441 });
405});442});
406443
407describe('Sponsoring Fee Limit', () => {444describe('Sponsoring Fee Limit', () => {