From 9d75fc279dba9b72ef674b6bbcf6523e08c9192a Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 8 Nov 2024 11:40:28 +0200 Subject: [PATCH] Repro for 9115 --- test/GasReport.t.sol | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/GasReport.t.sol diff --git a/test/GasReport.t.sol b/test/GasReport.t.sol new file mode 100644 index 0000000..bd60772 --- /dev/null +++ b/test/GasReport.t.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; +import {UnsafeUpgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; +import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; + +import "forge-std/Test.sol"; + +contract CheapDeposit is Initializable, UUPSUpgradeable { + uint256 public amount; + + function initialize(uint256 _amount) public initializer { + amount = _amount; + } + + function _authorizeUpgrade(address newImplementation) internal override {} + + function deposit(uint256 amount) external { + amount = amount * 2; + } +} + +contract ExpensiveDeposit is Initializable, UUPSUpgradeable { + uint256 public amount; + + function initialize(uint256 _amount) public initializer { + amount = _amount; + } + + function _authorizeUpgrade(address newImplementation) internal override {} + + function deposit(uint256 amount) external { + amount = amount * 10; + } +} + +contract GasReportTest is Test { + function test_gas_report() public { + CheapDeposit cheap = CheapDeposit( + UnsafeUpgrades.deployUUPSProxy( + address(new CheapDeposit()), + abi.encodeCall(CheapDeposit.initialize, (600_000)) + ) + ); + ExpensiveDeposit expensive = ExpensiveDeposit( + UnsafeUpgrades.deployUUPSProxy( + address(new ExpensiveDeposit()), + abi.encodeCall(ExpensiveDeposit.initialize, (600_000)) + ) + ); + cheap.deposit(1); + expensive.deposit(1); + } +}