foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.27k stars 1.74k forks source link

feat(`cheatcodes`): add ability to exclude certain custom errors and revert reason strings from failing tests #4271

Open PaulRBerg opened 1 year ago

PaulRBerg commented 1 year ago

Component

Forge

Describe the feature you would like

The use case is fork + fuzz tests - certain tokens like USDC have blacklists that prevent the transfer of assets between certain accounts (see lines 837 and 838 here). When Foundry fuzzes a blacklisted account, the Forge test will fail because of the following error:

Blacklistable: account is blacklisted

However, this is a false negative. The user's test should not have failed.

It would be great if there were two config options for filtering revert reason strings and custom errors.

0xPhaze commented 1 year ago

Related:

zerosnacks commented 4 months ago

For the time being, PSA: forge-std has a number of modifiers to help filter out these specific cases (I think added by OP): https://github.com/foundry-rs/forge-std/blob/75b3fcf052cc7886327e4c2eac3d1a1f36942b41/src/StdCheats.sol#L208-L278

The general request is still relevant so leaving the ticket open

emo-eth commented 1 week ago

Interested in take a stab at this!

jenpaff commented 1 week ago

Interested in take a stab at this!

assigned!

emo-eth commented 1 week ago

@PaulRBerg have you run into the scenario where you might want to toss-out multiple kinds of reverts for the same external call (while surfacing others)? Considering adding that functionality.

PaulRBerg commented 1 week ago

@emo-eth I have. I think this is what I was trying to get at with the OP — reverts due to USDC blacklisted addresses should be ignored.

emo-eth commented 1 week ago

@PaulRBerg Sorry, to be more specific, I mean multiple kinds of errors with different data, to cover a set of anticipated & acceptable revert reasons that might arise from one specific call. Think I have that working either way, but curious if you've run into that scenario.

PaulRBerg commented 1 week ago

I don't think I have.