foundry
foundry copied to clipboard
Forge test reports a huge gas number if vm.pauseGasMetering is in effect at the end of a test
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (0e33b3e 2023-07-28T00:23:39.362605000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
If a test completes after calling vm.pauseGasMetering(), and without calling vm.resumeGasMetering(), it will report gas usage is exactly 9223372036854754743 (2**63 - 21065?).
Minimal reproduction:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Test} from "forge-std/Test.sol";
contract PauseTest is Test {
function testWeirdGas1() public {
vm.pauseGasMetering();
}
function testWeirdGas2() public {
uint256 a = 1;
uint256 b = a + 1;
require(b == 2, "b is not 2");
vm.pauseGasMetering();
}
function testNormalGas() public {
vm.pauseGasMetering();
vm.resumeGasMetering();
}
}
Output:
[⠰] Compiling...
[⠢] Compiling 1 files with 0.8.20
[⠰] Solc 0.8.20 finished in 729.32ms
Compiler run successful!
Running 3 tests for test/PauseTest.t.sol:PauseTest
[PASS] testNormalGas() (gas: 3179)
[PASS] testWeirdGas1() (gas: 9223372036854754743)
[PASS] testWeirdGas2() (gas: 9223372036854754743)
Test result: ok. 3 passed; 0 failed; 0 skipped; finished in 306.25µs
Ran 1 test suites: 3 tests passed, 0 failed, 0 skipped (3 total tests)
Related: https://github.com/foundry-rs/foundry/issues/4370