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 does not ensure termination #3629

Closed
2 tasks done
yehjxraymond opened this issue Nov 7, 2022 · 3 comments · Fixed by #8274
Closed
2 tasks done

forge test does not ensure termination #3629

yehjxraymond opened this issue Nov 7, 2022 · 3 comments · Fixed by #8274
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug

Comments

@yehjxraymond
Copy link

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 (44f3a4b 2022-07-18T00:09:43.728981Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

forge test does not ensure that the program terminates. There was an infinite loop in one of the smart contract that I'm testing and it gets stuck at Compiler run successful (with warnings) when forge test is ran.

To replicate the issue, create a test or contract under test that doesn't terminate, ie:

...
    function testLoop() public {
        while (true) {
            // Do nothing
        }
    }
...

Running forge test will have the terminal stuck at Compiler run successful (with warnings) until manually terminated. This may be a problem when testing in CI where the program will consume extra compute hours.

Suggestion is to allow for test to have a gas limit that can be adjusted by the user or a global timeout for the test. This ensure that the program always terminates and also testers can be more aware of the gas consumed.

@yehjxraymond yehjxraymond added the T-bug Type: bug label Nov 7, 2022
@mds1
Copy link
Collaborator

mds1 commented Nov 7, 2022

There is a gas limit, so it will exit once that's hit. It's possible that while (true) {} would run forever if it's not evaluating some expression each loop. If you're using GitHub CI you can set timeouts there with jobs.<job_id>.steps[*].timeout-minutes and jobs.<job_id>.timeout-minutes: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes

@mattsse
Copy link
Member

mattsse commented Nov 7, 2022

the default sender's balance is quite high so this would run for a while.

hence, I wouldn't consider this a bug.

@rkrasiuk rkrasiuk added Cmd-forge-test Command: forge test C-forge Command: forge labels Nov 8, 2022
@thedavidmeister
Copy link

@mattsse hmm, i've got a loop seeming to run forever, no gas limit being hit even if i prank some address, and i can't see a way to set a gas limit with a cheatcode

in my case i'm trying to test that i DO hit always gas limit under certain conditions, so having it loop forever is not helpful

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

Successfully merging a pull request may close this issue.

5 participants