From c232f5f3d728159a7f8fcc933177156def70a8e5 Mon Sep 17 00:00:00 2001 From: jmakwana01 Date: Mon, 1 Sep 2025 13:05:36 +0000 Subject: [PATCH] fix: replace gas-based immutability check with direct storage slot check --- Immutable/test/Immutable.t.sol | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Immutable/test/Immutable.t.sol b/Immutable/test/Immutable.t.sol index 0034a47d..6f66dd57 100644 --- a/Immutable/test/Immutable.t.sol +++ b/Immutable/test/Immutable.t.sol @@ -10,24 +10,21 @@ contract ContractImmutableTest is Test { function setUp() public {} function testContractImmutable() external { - uint256 startGas = gasleft(); contractImmutable = new ContractImmutable(10); - uint256 gasUsed = startGas - gasleft(); - - assertEq(contractImmutable.value(), 10, "expected value to be 10"); - - if (gasUsed < 90000) assertFalse(false); - else assertFalse(true); + bytes32 slot0 = vm.load(address(contractImmutable), bytes32(uint256(0))); + // since `value` is immutable, it won't be in storage + assertEq(slot0, bytes32(0)); + assertEq(contractImmutable.value(), 10); } function testContractImmutable2() external { - uint256 startGas = gasleft(); contractImmutable = new ContractImmutable(550); - uint256 gasUsed = startGas - gasleft(); - - assertEq(contractImmutable.value(), 550, "expected value to be 550"); + bytes32 slot0 = vm.load(address(contractImmutable), bytes32(uint256(0))); + // since `value` is immutable, it won't be in storage + assertEq(slot0, bytes32(0)); + assertEq(contractImmutable.value(), 550); + } - if (gasUsed < 90000) assertFalse(false); - else assertFalse(true); + } -} +