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

Code coverage based on concrete tests only #309

Open
smol-ninja opened this issue Oct 15, 2024 · 4 comments
Open

Code coverage based on concrete tests only #309

smol-ninja opened this issue Oct 15, 2024 · 4 comments
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: ci Changes to our CI configuration files and scripts. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.

Comments

@smol-ninja
Copy link
Member

smol-ninja commented Oct 15, 2024

Currently, code coverage includes both fuzz and concrete tests. The fuzz tests require that functions are not reverting. That's why we use assume and bound in them. Thus, they only test for non reverting situations.

On the other hand, concrete tests is to test for each and every line and all possible branches, which is what coverage should be telling us. Currently, even if some of the branches are missed in concrete but called in fuzz, the coverage will not be able to detect that.

An example is missing notNull modifier in isTransferrable (cantina finding).

Thus, I propose to run coverage only using concrete tests.

RFC @sablier-labs/solidity.

Here is a comparison. As you can see the coverage for SablierFlow.sol went down when calculating it based on concrete tests, demonstrating that there are missing concrete tests for some lines / branches.

--mp "tests/{integration}/**/*.sol" --mp "tests/integration/concrete/**/*.sol"
Screenshot 2024-10-15 at 12 02 17 Screenshot 2024-10-15 at 12 03 28

PS: similar suggestion for lockup.

@smol-ninja smol-ninja added priority: 1 This is important. It should be dealt with shortly. effort: low Easy or tiny task that takes less than a day. work: clear Sense-categorize-respond. The relationship between cause and effect is clear. type: ci Changes to our CI configuration files and scripts. labels Oct 15, 2024
@PaulRBerg
Copy link
Member

IIRC, there were cases in Lockup circa 2023 when only the fuzz tests covered some branches because it was very, very difficult to get a concrete test to cover them.

But anyway, I will let you two decide and lead the way.

@smol-ninja smol-ninja added priority: 2 We will do our best to deal with this. and removed priority: 1 This is important. It should be dealt with shortly. labels Oct 15, 2024
@andreivladbrg
Copy link
Member

andreivladbrg commented Oct 15, 2024

Thus, they only test for non reverting situations

that's correct, but since we have all reverting scenarios in concrete tests, how is the coverage affected?

concrete tests is to test for each and every line and all possible branches

this is not quiet possible as we have lines like this one:

flow/src/SablierFlow.sol

Lines 668 to 673 in 04f3ed6

// Although the refundable amount should never exceed the balance, this condition is checked
// to avoid exploits in case of a bug.
if (refundableAmount > _streams[streamId].balance) {
revert Errors.SablierFlow_InvalidCalculation(streamId, _streams[streamId].balance, amount);
}


btw, one of the reasons for having a lower coverage on concrete compared to concrete + fuzz is due to missing getter tests, which would be addressed in #299 (in fuzz we use the getters often so the lines are covered) let's see how will these tests change this

@smol-ninja
Copy link
Member Author

@andreivladbrg you were right. #299 increased coverage for SablierFlowBase, with concrete tests, to 100% on all accounts from (96%, 97%, 100%, 92%) before. However, it only increased coverage for SablierFlow by 0.2%-0.4% (just a note and no call to action at this time).

@andreivladbrg
Copy link
Member

andreivladbrg commented Oct 29, 2024

increased coverage for SablierFlowBase, with concrete tests, to 100% on all

great news

it only increased coverage for SablierFlow by 0.2%-0.4% (just a note and no call to action at this time).

oh, that's less that i would've estimated, interesting, thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: ci Changes to our CI configuration files and scripts. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.
Projects
None yet
Development

No branches or pull requests

3 participants