Skip to content

Conversation

@nathanhleung
Copy link
Contributor

Motivation

One of my tests which called vm.expectRevert() was failing with FAIL. Reason: call did not revert as expected, even though it was still reverting (with the expected reason) when I removed the call to vm.expectRevert(); for a while, I couldn't figure out why.

It took me a bit of time before realizing that the docs specify that vm.expectRevert() must be placed immediately before the call that is expected to revert. Part of my confusion was that I had another test that had a call to vm.expectRevert() followed by vm.prank(), and calls to other cheatcodes are ignored (so because that test was working, I thought I could just put vm.expectRevert() at the top of the test).

Screenshot 2024-07-17 at 10 43 14

https://book.getfoundry.sh/cheatcodes/expect-revert

Solution

I updated the error message in the vm.expectRevert() cheatcode implementation to specify that failures are because the next call did not revert as expected. This wording also more closely matches the emphasis in the Foundry book docs.

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this seems more useful, wdyt @klkvr

@nathanhleung
Copy link
Contributor Author

bump @klkvr

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

makes sense, this would make errors less confusing

@DaniPopes DaniPopes merged commit 741db53 into foundry-rs:master Jul 28, 2024
@nathanhleung nathanhleung deleted the nathanhleung/expect-revert-error-message branch July 29, 2024 17:38
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.

4 participants