Skip to content
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

feat(cheatcodes): count assertion for expectRevert #9484

Merged
merged 21 commits into from
Dec 6, 2024

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Dec 4, 2024

Motivation

Closes #509

Solution

Implement expectRevert overloads with the count arg. Negative assertions can be made by setting count to 0

    /// Expects a `count` number of reverts from the upcoming calls with any revert data or reverter.
    function expectRevert(uint64 count) external;

    /// Expects a `count` number of reverts from the upcoming calls that match the revert data.
    function expectRevert(bytes4 revertData, uint64 count) external;

    /// Expects a `count` number of reverts from the upcoming calls that exactly match the revert data.
    function expectRevert(bytes calldata revertData, uint64 count) external;

    /// Expects a `count` number of reverts from the upcoming calls from the reverter address.
    function expectRevert(address reverter, uint64 count) external;

    /// Expects a `count` number of reverts from the upcoming calls from the reverter address that match the revert data.
    function expectRevert(bytes4 revertData, address reverter, uint64 count) external;

    /// Expects a `count` number of reverts from the upcoming calls from the reverter address that exactly match the revert data.
    function expectRevert(bytes calldata revertData, address reverter, uint64 count) external;

@yash-atreya yash-atreya changed the title Yash/expect revert count feat(cheatcodes): count assertion for expectRevert Dec 4, 2024
@yash-atreya yash-atreya marked this pull request as ready for review December 5, 2024 07:37
@yash-atreya yash-atreya self-assigned this Dec 5, 2024
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Looks good to me, pending other reviews

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

lgtm

) {
if let Ok(decoded) = Vec::<u8>::abi_decode(&actual_revert[4..], false) {
actual_revert = decoded;
// Reverter check
Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes sense, cannot think of a cleaner way to structure code as we need to check both reverter and revert reason

@yash-atreya yash-atreya merged commit 63484d0 into master Dec 6, 2024
21 checks passed
@yash-atreya yash-atreya deleted the yash/expect-revert-count branch December 6, 2024 06:34
yash-atreya added a commit to foundry-rs/forge-std that referenced this pull request Dec 6, 2024
Ref: foundry-rs/foundry#9484

```solidity

    /// Expects `count` number of reverts from the upcoming calls with any revert data or reverter.
    function expectRevert(uint64 count) external;

    /// Expects `count` number of reverts from the upcoming calls that match the revert data.
    function expectRevert(bytes4 revertData, uint64 count) external;

    /// Expects `count` number of reverts from the upcoming calls that exactly match the revert data.
    function expectRevert(bytes calldata revertData, uint64 count) external;

    /// Expects `count` number of reverts from the upcoming calls from the reverter address.
    function expectRevert(address reverter, uint64 count) external;

    /// Expects `count` number of reverts from the upcoming calls from the reverter address that match the revert data.
    function expectRevert(bytes4 revertData, address reverter, uint64 count) external;

    /// Expects `count` number of reverts from the upcoming calls from the reverter address that exactly match the revert data.
    function expectRevert(bytes calldata revertData, address reverter, uint64 count) external;
```
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add negative assertions for expectEmit and expectRevert using count syntax
3 participants