Configuring fuzzer parameters per test and per contract #744
Labels
A-cheatcodes
Area: cheatcodes
A-testing
Area: testing
C-forge
Command: forge
Cmd-forge-test
Command: forge test
T-feature
Type: feature
Component
Forge
Describe the feature you would like
There are multiple ongoing improvements to the fuzzer, which will result in additional fuzzer settings that should be exposed to the user. These include:
It's common to want to vary the values of these settings by test or by contract, instead of just globally. For example, see the Uniswap V3 echidna tests where they have multiple config files.
The scope of this issue is currently to just discuss approaches to specify separate fuzzing config for different tests. Below are some potential approaches, feel free to suggest others. @gakonst pointed out the cheat code based approaches may be tricky because currently proptest config lives outside of the EVM, so implementing that approach may require some refactoring
Approach 1:
foundry.toml
onlyThe
foundry.toml
config file has profiles so you can change the config easily. We can simply leverage these profiles and the--match-test
and--match-contract
flags to craft various combinations. For example:Then run tests with a
tests.sh
like this:This is nice because it works right now and requires no changes, but it's a bit clunky
Approach 2: Extend
foundry.toml
and a single cheat codeIn this approach, the config file lets you specify fuzz profiles, and there's a cheat code you can use at the contract or test level to specify a profile name. For example:
Then in a test of contract you'd use
Aside from requiring refactoring for cheat code support, another downside of this approach is that you need a new profile for every specific fuzzer configuration (i.e. there's no way to just change one fuzz setting in one test without creating a new profile specific for that test)
Approach 3: Extend
foundry.toml
and multiple cheat codesThis extends approach 2 by adding cheat codes for each fuzzer setting to remedy the downside mentioned. For example:
Approach 4: Cheat codes only
Remove all fuzzing config from
foundry.toml
, and specify everything as cheat codes. For example:The text was updated successfully, but these errors were encountered: