-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 coverage
does not work for if statements within for loops
#3600
Comments
I'm unfortunately seeing the same issue. It seems to be related to coverage of "if" statements. Is there any update on this bug? |
unfortunately not, maybe you can @their-developers in this issue to see if there any updates |
Just bumped into this, as well: It looks like the common denominator between my case and @KittyFu307's is the presence of an if statement in a for loop. Therefore, the title of this issue should be changed to something like " |
Hi @rkrasiuk any update for this issue? Thank you for your time |
@KittyFu307 it may be useful to rename the title of this issue to include a reference to for loops so that other users who bump into the same problem can reach us here. |
forge coverage
can not coverage all branchesforge coverage
does not work for if statements within for loops
Sure~ have already done |
Actually, as per the code shared by @KittyFu307 in the OP, and per @chrismin's comment, this issue may be about if statements more broadly, not just some cases within for loops. I've recently bumped into another nasty bug in the coverage command, which may be related (though this is based on a gut feeling): |
I can't manage to pin down what this bug is about, exactly. #3497 may also be related. |
Update: I have managed to get to the bottom of this, opened an issue here: @KittyFu307 this is definitely the same issue you encountered in your |
I think that I have figured it out - @KittyFu307, your original issue was actually reporting on two bugs in Foundry. One I documented myself in #4310; the other has been documented and discussed in #3497. If someone else could confirm my guess, then I suggest we close this issue in favor of #4310 and #3497, which are more targeted. |
Oh @PaulRBerg Thank you for taking the time to debug this error. I am pretty sure that the problem of the |
No worries, @KittyFu307. Pinging @onbjerg in case he could take a quick look? Seems like an easy fix. |
I am completely out of the loop on Foundry so I do not have the context necessary to figure out if this is an easy fix or not. My best guess is that the common denominator for all of these complexly linked issues is that we detect branches by detecting sequences of bytecode, and it is possible that detection is not strict enough for overlapping cases. For the other isssues (array access, calls) there are hidden reverts, so essentially all of the issues boil down to this one, as they can be thought of as an if-statement with a revert in the else clause |
Thank you for taking the time to respond, @onbjerg.
There are cases when there are clearly no hidden reverts, e.g. the one I documented in #4310: function isOdd(uint256 number) external view returns (bool odd) {
uint256[] memory arr = new uint256[](1);
arr[0] = block.timestamp;
if (number % 2 == 1) {
odd = true;
arr[0];
} else {
odd = false;
}
} The Regarding calls - it may be the case that a hidden revert is what generates partial coverage for certain calls. However, as I suggested here, there should definitely be a way to opt-out of the default revert-covering requirements with a comment (e.g. |
That |
Interesting point, @mds1, but unfortunately, no, this wasn't the issue. After adding the
However, if Forge did actually report partial coverage for non-payable functions, that would be a bad user experience IMO.
|
I've same issues on our project. @PaulRBerg any update on this issue? |
No, @deboguer-jng. Also, I have never been involved in the development of the |
confirmed fixed with #8414 please reopen if you hit any similar issue |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (70f4fb5 2022-11-03T00:06:25.653195Z)
What command(s) is the bug in?
forge coverage
Operating System
macOS (Apple Silicon)
Describe the bug
When I run
forge coverage
to test the coverage for my code, I found that I have written the code to match the all branches but the result seems not. If I call the external function, it will not cover this branch.The coverage result is
But I think my test function have covered all situations, and the result is not
The text was updated successfully, but these errors were encountered: