Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forge test reports a huge gas number if vm.pauseGasMetering is in effect at the end of a test #5491

Closed
2 tasks done
emo-eth opened this issue Jul 28, 2023 · 1 comment · Fixed by #8717
Closed
2 tasks done
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug
Milestone

Comments

@emo-eth
Copy link
Contributor

emo-eth commented Jul 28, 2023

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • 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)
@zerosnacks
Copy link
Member

Related: #4370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants