-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: Investigate Test Coverage Drop #427
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for contracts-stylus ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
0xNeshi
force-pushed
the
coverage/investigate
branch
from
December 5, 2024 08:30
861094c
to
589c4ba
Compare
0xNeshi
force-pushed
the
coverage/investigate
branch
from
December 5, 2024 09:31
c59d562
to
f84dfa1
Compare
Made this PR ready for review, as merging it would immediately address points 9 ( |
This was referenced Dec 9, 2024
Closing this in favor of #438 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Towards #426
Discussion
Reason for Coverage % Nosedive
Codecov shows that the % drop happened somewhere between October 28th and November 4th. Further investigation shows that the "problematic" commit was introduced by PR #379 (the commit is not actually "problematic", read further).
Below is the link to all the files for which coverage was affected in this commit:
https://app.codecov.io/github/OpenZeppelin/rust-contracts-stylus/commit/9c2b1b4b23145acddafb7b888e9e69a09fa6134c/indirect-changes
Explaining the coverage file diff on Codecov in case it helps (link above): the image below shows the coverage change for contracts/src/token/erc20/extensions/capped.rs - it shows that previously this motsu test was included in the coverage report (the highlighted left column shows line numbers included in previous coverage, while the non-highlighted right column shows line numbers now excluded from coverage).
In short, it seems that up until this commit, all motsu tests were included in the coverage %! This wrongly increased our coverage %. After this commit, the motsu tests were excluded from coverage. That means that the sudden 12% drop in coverage was not an anomaly, but a correction.
The commit did not manually change anything to affect coverage in this way. The reason why tests were magically excluded is not yet absolutely clear, but it seems most likely that this
motsu::test
implementation change, which no longer made the fn block wrapped bywith_context
, madellvm-cov
(our coverage tool) aware that this is in fact test code, and that it shouldn't be a part of the coverage report.There were also some changes to the
llvm-cov
dependencies in this period, which could've affected the coverage step in our CI, but this is much less likely imo.Problems and Recommendations on Increasing Coverage %
Below is a list of problems affecting our test coverage and possible mitigation steps:
sol!
macros (events, errors, storage) is included in test coverage (effect: high).#[cfg_attr(coverage, coverage(off))]
(see example, and pseudo code is below).VestingWallet
is a ~6% increased coverage.coverage(off)
.Cargo.toml > default-members
and we do not include it explicitly in our coverage command. This should be addressed.#[cfg_attr(coverage, coverage(off))]
.IErc20::transfer
is tested by calling_update
, causing code coverage to registertransfer
as "unconvered") (effect: medium).IErc165
-related tests exist verifying the generatedINTERFACE_ID
value is correct, but no tests exist that call<ContractName>::supports_interface
(effect: low).supports_interface
tests.MethodError
impls uncovered (effect: low).#[cfg_attr(coverage, coverage(off))]
.#[public]
attr is included in coverage (effect: low). - this PR solves thisllvm-cov
to nightly in this PR removed this from coverage (e.g. see nonces.rs) 👀#[cfg(test)] mod tests
(unit tests) are included in coverage (effect: none). NOTE: technically not a problem atm, as the effect of this is positive or neutral. If we still wanted to exclude them, see mitigation steps below.#[cfg_attr(coverage, coverage(off))]
#[test]
-related code automatically taiki-e/cargo-llvm-cov#123 (comment)) (this ties into our previous discussion on unit test organization where this was one of the proposals https://openzeppelin.slack.com/archives/C06R5AGFE9G/p1732625889805619?thread_ts=1732618832.030739&cid=C06R5AGFE9G)#[motsu::test]
attributes included in test coverage (effect: unknown). - this PR solves thismod tests
should be included in coverage (see previous point). However, since ./lib/motsu/, and ./lib/motsu-proc/ do not have their own tests (already covered in previous points), we are inadvertently covering those in this roundabout way. I think this is a bug though, and not a feature.mod tests
.llvm-cov
to nightly in this PR removed this from coverage (e.g. see nonces.rs) 👀 But for some reason,motsu-proc
crate code is still "covered".Took the liberty to investigate why the number of ignored integration tests jumped 2->10, namely in Erc721 and Erc1155 contracts. The reason for this is that
e2e
does not support asserting that a call reverted withstylus_sdk::call::Error
, which these tests are trying to assert.This issue is already known and is being tracked here: #228