From 0bf75d218f2cbbdc6b86946b2c415352e3167394 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 20 Sep 2023 13:57:33 +0300 Subject: [PATCH] Added testing contract. --- .../testing/001_gas_testing_deployment.ts | 28 +++++++++++++++++++ contracts/src/testing/GasConsumerBalance.sol | 18 ++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 contracts/deployment_scripts/testing/001_gas_testing_deployment.ts create mode 100644 contracts/src/testing/GasConsumerBalance.sol diff --git a/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts new file mode 100644 index 0000000000..d577d4b145 --- /dev/null +++ b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts @@ -0,0 +1,28 @@ +import {HardhatRuntimeEnvironment} from 'hardhat/types'; +import {DeployFunction} from 'hardhat-deploy/types'; +import { Receipt } from 'hardhat-deploy/dist/types'; + + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const l2Network = hre; + const {deployer} = await hre.getNamedAccounts(); + + const gcb = await l2Network.deployments.deploy("GasConsumerBalance", { + from: deployer, + log: true + }) + + + const gasConsumerBalance = await hre.ethers.getContractAt("GasConsumerBalance", gcb.address) + const gasEstimation = await gasConsumerBalance.estimateGas.get_balance({from: deployer}); + + await hre.deployments.execute("GasConsumerBalance", { + from: deployer, + gasLimit: gasEstimation.div(2), + log: true + }, "get_balance"); +}; + + +export default func; +func.tags = ['GasDebug']; diff --git a/contracts/src/testing/GasConsumerBalance.sol b/contracts/src/testing/GasConsumerBalance.sol new file mode 100644 index 0000000000..3b42c3334e --- /dev/null +++ b/contracts/src/testing/GasConsumerBalance.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: Apache 2 +pragma solidity ^0.8.0; + +contract GasConsumerBalance { + address public owner; + + constructor() { + owner = msg.sender; + } + + // solc-ignore-next-line func-mutability + function get_balance() public { address(this).balance; } + + function destroy() public { + require(msg.sender == owner, "You are not the owner"); + selfdestruct(payable(address(this))); + } +} \ No newline at end of file