git.delta.rocks / unique-network / refs/commits / 98cf2b17a00f

difftreelog

chore refactor tests

Grigoriy Simonov2022-09-13parent: #0707cc7.patch.diff
in: master

1 file changed

modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
497 sources: {497 sources: {
498 ['TestContract.sol']: {498 ['TestContract.sol']: {
499 content:499 content:
500 `500 `
501 // SPDX-License-Identifier: MIT501 // SPDX-License-Identifier: MIT
502 pragma solidity ^0.8.0;502 pragma solidity ^0.8.0;
503 503
504 contract TestContract {504 contract TestContract {
505 event Result(bool);505 event Result(bool);
506
506 function test1() public {507 function test(uint32 cycles) public {
507 uint256 counter = 0;
508 while(true) {
509 counter ++;
510 }
511 emit Result(true);
512 }
513
514 function test2() public {508 uint256 counter = 0;
515 uint256 counter = 0;509 while(true) {
516 while(true) {510 counter ++;
517 counter ++;511 if (counter > cycles){
518 if (counter > 1){512 break;
519 break;513 }
520 }514 }
521 }515 emit Result(true);
522 emit Result(true);516 }
523 }517 }
524 }518 `,
525 `,
526 },519 },
527 },520 },
528 settings: {521 settings: {
593586
594 const gasPrice = BigInt(await web3.eth.getGasPrice());587 const gasPrice = BigInt(await web3.eth.getGasPrice());
595588
596 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 30000n * gasPrice).send();589 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();
597590
598 const originalUserBalance = await web3.eth.getBalance(user);591 const originalUserBalance = await web3.eth.getBalance(user);
599 await testContract.methods.test2().send({from: user, gas: 30000});592 await testContract.methods.test(100).send({from: user, gas: 2_000_000});
600 expect(await web3.eth.getBalance(user)).to.be.equal(originalUserBalance);593 expect(await web3.eth.getBalance(user)).to.be.equal(originalUserBalance);
601594
602 await testContract.methods.test2().send({from: user, gas: 40000});595 await testContract.methods.test(100).send({from: user, gas: 2_100_000});
603 expect(await web3.eth.getBalance(user)).to.not.be.equal(originalUserBalance);596 expect(await web3.eth.getBalance(user)).to.not.be.equal(originalUserBalance);
604 });597 });
605598
618611
619 const gasPrice = BigInt(await web3.eth.getGasPrice());612 const gasPrice = BigInt(await web3.eth.getGasPrice());
620613
621 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 30000n * gasPrice).send();614 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();
622615
623 const alice = privateKeyWrapper('//Alice');616 const alice = privateKeyWrapper('//Alice');
624 const originalAliceBalance = (await api.query.system.account(alice.address)).data.free.toBigInt();617 const originalAliceBalance = (await api.query.system.account(alice.address)).data.free.toBigInt();
628 api.tx.evm.call(621 api.tx.evm.call(
629 subToEth(alice.address),622 subToEth(alice.address),
630 testContract.options.address,623 testContract.options.address,
631 testContract.methods.test2().encodeABI(),624 testContract.methods.test(100).encodeABI(),
632 Uint8Array.from([]),625 Uint8Array.from([]),
633 30000n,626 2_000_000n,
634 gasPrice,627 gasPrice,
635 null,628 null,
636 null,629 null,
644 api.tx.evm.call(637 api.tx.evm.call(
645 subToEth(alice.address),638 subToEth(alice.address),
646 testContract.options.address,639 testContract.options.address,
647 testContract.methods.test2().encodeABI(),640 testContract.methods.test(100).encodeABI(),
648 Uint8Array.from([]),641 Uint8Array.from([]),
649 40000n,642 2_100_000n,
650 gasPrice,643 gasPrice,
651 null,644 null,
652 null,645 null,