-
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 specific contract #6875
Comments
unfortunately I don't have time to review this, but I've some feedback for future posts (and this post, if you would like to edit it): put your code underneath collapsible sections so that the core message does not get lost among code. |
could anyone please help me with this issue? i am not able to solve this issue. |
@ismailcanvardar One thing that I always do is disable optimizations for coverage runs. The optimizations inline a lot of code, so there's no way to attribute the runs back to the source code. Example # Default "production" profile.
[profile.default]
solc-version = "0.8.19"
optimizer = true
optimizer-runs = 20000
# Use FOUNDRY_PROFILE=lite for quicker compilation, coverage
[profile.lite]
optimizer = false Then run like:
|
Thanks for your response @KholdStare. My foundry.toml file[profile.default]
fs_permissions = [{ access = "read-write", path = "./"}]
auto_detect_solc = false
block_timestamp = 1_680_220_800 # March 31, 2023 at 00:00 GMT
bytecode_hash = "none"
evm_version = "paris"
fuzz = { runs = 1_000 }
gas_reports = ["*"]
libs = ["lib"]
optimizer = true
optimizer_runs = 10_000
out = "out"
script = "script"
solc = "0.8.21"
src = "src"
test = "test"
[profile.lite]
optimizer = false
[profile.ci]
fuzz = { runs = 10_000 }
verbosity = 4
# [etherscan]
# arbitrum_one = { key = "${API_KEY_ARBISCAN}" }
# avalanche = { key = "${API_KEY_SNOWTRACE}" }
# bnb_smart_chain = { key = "${API_KEY_BSCSCAN}" }
# gnosis_chain = { key = "${API_KEY_GNOSISSCAN}" }
# goerli = { key = "${API_KEY_ETHERSCAN}" }
# mainnet = { key = "${API_KEY_ETHERSCAN}" }
# optimism = { key = "${API_KEY_OPTIMISTIC_ETHERSCAN}" }
# polygon = { key = "${API_KEY_POLYGONSCAN}" }
# sepolia = { key = "${API_KEY_ETHERSCAN}" }
[fmt]
bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "all"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = true
[rpc_endpoints]
arbitrum_one = "https://arbitrum-mainnet.infura.io/v3/${API_KEY_INFURA}"
avalanche = "https://avalanche-mainnet.infura.io/v3/${API_KEY_INFURA}"
bnb_smart_chain = "https://bsc-dataseed.binance.org"
gnosis_chain = "https://rpc.gnosischain.com"
goerli = "https://goerli.infura.io/v3/${API_KEY_INFURA}"
localhost = "http://localhost:8545"
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${API_KEY_ALCHEMY}"
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}" So, I've added lite profile section after your comment. After that I'd ran Do you want me to add more details to solve this problem? |
Experiencing a similar problem with oracles... Something odd that I was able to do in the contract to make it work and capture the 100% coverage was adding a emit event in the function then it just magically picked it up -- otherwise it completly passes over the file and marks it as 0%. It has to be in that function as well, if I put the event emit inside the constructor nothing will happen... so something about making the emit inside the function makes it pickup all the test results. I've been able to get a 100% coverage by just deleting a ton of our code and stripping this down to bare bones to avoid conflicts with other parts of the repo.. but its hard to really give reproduction steps on this without inviting someone from the forge team to our repo... its 100% reproducible but we have about 890 tests so it takes a min. I am no rustacean by any means, but if we don't get any updates on this issue ill probably try an poke around the coverage code my self to see if I could get more details on where its going wrong. Me and OP have overrides in common so maybe it has something to do with that. |
After some reading I think #2567 might explain our problem |
@whisskey , look into lcov reports they are interactive and provide line by line results of what was covered and what was not covered... Here is a script I keep in our repo to run lcov reports: #!/bin/bash
rm -rf coverage_report
rm lcov.info
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info 'tests/*' 'script/*' '**/libraries/external/*' '**/testnet/*' '**/mocks/*' '**/indexing/*'
genhtml lcov.info -o coverage_report
google-chrome --headless --window-size=1200,800 --screenshot="coverage_report/coverage.png" "coverage_report/index.html"
printf "<img src=\"coverage.png\"/>" > coverage_report/README.md
open coverage_report/index.html Also, this is probably not the right place to ask questions like that, if you want to continue the convo I'd probably suggest opening a new issue or you can DM me on twitter @DiversityETH unless im misuderstanding you and this is related but it seemed to be posed as a question on how to improve test coverage. |
Bump on this. Getting the same issue. Running
|
was doing some more tests and there's Looking in code the difference is that in 2nd case foundry/crates/forge/bin/cmd/coverage.rs Line 264 in 034393c
foundry/crates/common/src/contracts.rs Lines 119 to 128 in 034393c
so probably something to change in @DaniPopes @klkvr could you please share some thoughts on this? thank you! I made a simple repo with issue reproduction: https://github.com/grandizzy/forge-coverage-bug (LE this could also explain Uniswap issue mentioned above as there are similar |
going to close this one for now as the latest problem signaled was solved with #8214 and don't have original repro to test, feel free to reopen if hit again. thank you |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (9e3ab9b 2024-01-04T00:18:01.892563000Z)
What command(s) is the bug in?
forge coverage
Operating System
macOS (Apple Silicon)
Describe the bug
Hi there, I've upgraded Uniswap V2 contracts to solidity v0.8.21 & I added unit tests for each contract such as Router, Pair, Factory etc. So, my issue is even my test suites totally covers the contracts that i mentioned, Router contract's coverage does not increment. I tried to remove override tags, IRouter interface inheritance, and converted internal functions to public functions. Consequently, I did not get any solution by doing these methods.
Here's the Router.t.sol;
Here's the coverage result:
I used
forge coverage
command.cc: @PaulRBerg @gakonst
The text was updated successfully, but these errors were encountered: