-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
assertTrue fail to raise errors in fuzzing #2375
Comments
You are about 13 days outdated with your Forge version, but I also cannot reproduce this:
Most likely the fuzzer does not input 2**31 which is a separate issue - please update the issue to reflect that 😄 |
I updated the
I'll update the issue if I manage to simplify the reproducible code above. |
Here is a slightly simplified version.
Also not very sure what title best describe this issue. |
This is not necessarily always the case. I used Not sure what the best title is either since it (to me) seems highly unlikely you will ever hit a failing case with random numbers. Not super strong with math, but given you need the first 21 bits to be 1 it seems extremely unlikely you would hit a number like that in 256 fuzz runs? Noting here that numbers Edit: Doing a |
I see, so to put it more precisely, the fuzzer didn't generate something that hit the edge cases in my test due to low probability. Would you recommend to write tests specifically for those edge cases? |
Yes, I think so. Not entirely sure, maybe @mds1 has some ideas for how to improve the fuzzer in this case and/or use |
Yeah I'd love to learn more about it. |
You can create a discussion here https://github.com/foundry-rs/foundry/discussions/new Feel free to ping me and @mds1 😄 |
@stephenctw IIUC, you are expecting the fuzzer to fail by finding a value with over 20 consecutive ones as the lowest order bits? If so, like @onbjerg said that is quite specific and therefore very unlikely for the fuzzer to find it. Can you explain a bit more about your use case and what exactly you are trying to test? I'm not sure if this is a contrived example or representative of something that may be commonly tested. I ask because the best path forward on how to structure these tests and what changes we may want to make to foundry's fuzz logic might depend on the answer (the fuzzer isn't purely random, and does try to smart in various ways). I'd recommend going with @onbjerg's suggestion of creating a discussion with details around your use case and what you'd expect from the fuzzer, and we can go from there 🙂 |
Hey @mds1, basically I want to test and check if the output of my algorithm is under a certain valid value, something like the counting ones in the above code snippet. Now I understand that it is not what fuzzer is used for, instead I should specifically feed the inputs like 20 consecutive ones and test them individually. Thanks for the clarification! |
Ah, yes you may be interested in #858 for some inspiration on how to structure those style tests. I also have https://github.com/mds1/solidity-generators which is mostly done and may help you generate the input arrays |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (a81ea4c 2022-07-19T07:23:43.1341688Z)
What command(s) is the bug in?
forge test
Operating System
WSL2
Describe the bug
Fuzz test with assertTrue fails to raise error (testFuzzing). Remove the fuzz from test then assertTrue raises error properly(testNormal). The fuzz test should throw an error when the input is 2 ** 31 = 2147483648;
The text was updated successfully, but these errors were encountered: