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

feat: improve code coverage #438

Merged
merged 26 commits into from
Dec 12, 2024
Merged

Conversation

qalisander
Copy link
Member

@qalisander qalisander commented Dec 8, 2024

Disable code coverage for sol! and sol_interface! macros.
Enforce #[storage] macro instead of sol_storage!. (#[storage] struct is recognized by codecov)
Add missing tests to code coverage.

Towards #426

Copy link

netlify bot commented Dec 8, 2024

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit 733f2e7
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/67599c8f56a0010008e38ca2

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

Attention: Patch coverage is 13.33333% with 26 lines in your changes missing coverage. Please review.

Project coverage is 89.6%. Comparing base (49ff333) to head (733f2e7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
contracts/src/access/control.rs 0.0% 2 Missing ⚠️
...tracts/src/token/erc1155/extensions/uri_storage.rs 60.0% 2 Missing ⚠️
...ntracts/src/token/erc721/extensions/uri_storage.rs 0.0% 2 Missing ⚠️
contracts/src/access/ownable.rs 0.0% 1 Missing ⚠️
contracts/src/access/ownable_two_step.rs 0.0% 1 Missing ⚠️
contracts/src/finance/vesting_wallet.rs 0.0% 1 Missing ⚠️
...racts/src/token/erc1155/extensions/metadata_uri.rs 0.0% 1 Missing ⚠️
contracts/src/token/erc1155/extensions/supply.rs 0.0% 1 Missing ⚠️
contracts/src/token/erc1155/mod.rs 0.0% 1 Missing ⚠️
contracts/src/token/erc20/extensions/capped.rs 0.0% 1 Missing ⚠️
... and 13 more
Additional details and impacted files
Files with missing lines Coverage Δ
contracts/src/utils/cryptography/ecdsa.rs 47.1% <ø> (+14.1%) ⬆️
contracts/src/access/ownable.rs 94.1% <0.0%> (+35.8%) ⬆️
contracts/src/access/ownable_two_step.rs 99.2% <0.0%> (+26.8%) ⬆️
contracts/src/finance/vesting_wallet.rs 55.6% <0.0%> (+24.4%) ⬆️
...racts/src/token/erc1155/extensions/metadata_uri.rs 78.5% <0.0%> (+49.1%) ⬆️
contracts/src/token/erc1155/extensions/supply.rs 81.1% <0.0%> (+9.4%) ⬆️
contracts/src/token/erc1155/mod.rs 96.9% <0.0%> (+24.9%) ⬆️
contracts/src/token/erc20/extensions/capped.rs 83.3% <0.0%> (+64.8%) ⬆️
contracts/src/token/erc20/extensions/metadata.rs 22.2% <0.0%> (+18.0%) ⬆️
contracts/src/token/erc20/extensions/permit.rs 0.0% <0.0%> (ø)
... and 14 more

... and 10 files with indirect coverage changes

.github/workflows/test.yml Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
contracts/src/finance/vesting_wallet.rs Show resolved Hide resolved
contracts/src/utils/math/storage.rs Outdated Show resolved Hide resolved
@qalisander qalisander marked this pull request as ready for review December 10, 2024 11:13
@qalisander qalisander requested a review from bidzyyys as a code owner December 10, 2024 11:13
@qalisander qalisander requested a review from 0xNeshi December 10, 2024 12:16
Copy link
Collaborator

@0xNeshi 0xNeshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring party 😄 Nice work, added a couple of comments

contracts/src/token/erc721/mod.rs Show resolved Hide resolved
contracts/src/utils/cryptography/ecdsa.rs Show resolved Hide resolved
contracts/src/utils/nonces.rs Show resolved Hide resolved
lib/motsu-proc/src/test.rs Show resolved Hide resolved
contracts/src/access/control.rs Show resolved Hide resolved
contracts/src/access/control.rs Show resolved Hide resolved
lib/motsu-proc/src/test.rs Show resolved Hide resolved
#( #contract_declarations )*
let res = #fn_block;
let test = | #( #contract_arg_defs ),* | #fn_block;
let res = test( #( #contract_args ),* );
::motsu::prelude::Context::current().reset_storage();
res
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR description you mention that you added missing tests to code coverage, but there aren't any here.
Maybe you forgot to push?

Copy link
Member Author

@qalisander qalisander Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very good question:D
Actually these few lines of code (where you commented) did main job..
Each test case body, even marked with #[motsu::test] is included into code coverage now.
By the end we've received more covered code lines, that inflated total code coverage by 11-12%.
A bit scammy, but I feel there is more value in test cases and test functions included into coverage. Considering that, we can increase our target for a higher percentage of coverage by the end.

Copy link
Collaborator

@0xNeshi 0xNeshi Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "missing tests" I was referring to both here and in my findings are tests for non-covered paths in our contracts (points 4-7 in findings) 😅 Many of our code paths are not covered, even the ones that are not dependent on interacting with other contracts. If you don't plan on adding those now (I wouldn't blame you, we should add them as we go along), could you then update the description as per #438 (comment)?


I really don't see the benefit of including tests in code coverage. The primary concern of code coverage metrics is ensuring the reliability and correctness of the production code, or in our case the contracts.

This is why cargo-llvm-cov, our coverage tool, excludes test files by default.

Making sure that test lines are covered serves no practical purpose other than inflating the coverage percentage.

Copy link
Member Author

@qalisander qalisander Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. and I was referring to an actual test body:D
This pr has frequent conflicts with a new code added. Make sense to merge it sooner.

There are many uncovered places in the code base (mostly covered by e2e, but not motsu). So there is a work left to be done.

We can think about centralized approach of excluding all test cases. But not as it was before: some tests are included, other randomly excluded. Coverage of missing lines has bigger priority at the moment:D

Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @qalisander !

.github/workflows/test.yml Show resolved Hide resolved
contracts/src/access/control.rs Show resolved Hide resolved
contracts/src/access/control.rs Show resolved Hide resolved
contracts/src/access/ownable.rs Outdated Show resolved Hide resolved
contracts/src/access/ownable_two_step.rs Outdated Show resolved Hide resolved
contracts/src/utils/cryptography/ecdsa.rs Outdated Show resolved Hide resolved
contracts/src/utils/cryptography/ecdsa.rs Show resolved Hide resolved
contracts/src/utils/nonces.rs Show resolved Hide resolved
contracts/src/utils/pausable.rs Outdated Show resolved Hide resolved
lib/motsu-proc/src/test.rs Show resolved Hide resolved
@bidzyyys
Copy link
Collaborator

@qalisander you also need to change in antora docs sol_storage! -> #[storage]

Copy link
Collaborator

@0xNeshi 0xNeshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🔥

contracts/src/token/erc1155/extensions/uri_storage.rs Outdated Show resolved Hide resolved
@qalisander qalisander force-pushed the qalisander/make-codecov-great-again branch from 3a7bc3b to b52baa6 Compare December 11, 2024 09:47
@qalisander
Copy link
Member Author

I've updated antora docs, examples and readme's. Now all of them should use #[storage] macro

@bidzyyys bidzyyys self-requested a review December 11, 2024 12:54
Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @qalisander! Go go go 🚀

README.md Show resolved Hide resolved
contracts/src/token/erc1155/mod.rs Show resolved Hide resolved
@qalisander qalisander merged commit 603e74e into main Dec 12, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants