You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cheatcodes/expect-revert.md
+34-2Lines changed: 34 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,10 @@ function expectRevert(bytes4 message) external;
14
14
function expectRevert(bytes calldata message) external;
15
15
```
16
16
17
+
```solidity
18
+
function expectPartialRevert(bytes4 message) external;
19
+
```
20
+
17
21
### Description
18
22
19
23
If the **next call** does not revert with the expected data `message`, then `expectRevert` will.
@@ -22,12 +26,34 @@ After calling `expectRevert`, calls to other cheatcodes before the reverting cal
22
26
23
27
This means, for example, we can call [`prank`](./prank.md) immediately before the reverting call.
24
28
25
-
There are 3 signatures:
29
+
There are 3 signatures for `expectRevert`:
26
30
27
31
-**Without parameters**: Asserts that the next call reverts, regardless of the message.
28
-
-**With `bytes4`**: Asserts that the next call reverts with the specified 4 bytes.
32
+
-**With `bytes4`**: Asserts that the next call reverts with the specified 4 bytes and exact match of revert data.
29
33
-**With `bytes`**: Asserts that the next call reverts with the specified bytes.
30
34
35
+
and one signature for `expectPartialRevert`:
36
+
-**`bytes4`**: Asserts that the next call reverts and the specified 4 bytes match the first 4 bytes of revert data.
37
+
38
+
> ℹ️ **Note:**
39
+
>
40
+
> Custom errors can have arguments that sometimes are difficult to calculate in a testing environment or they may be unrelated to the test at hand (e.g. a value computed in the internal function of a third-party contract). In such cases, `expectPartialRevert` can be used to ignore arguments and match only on the selector of custom error. For example, testing a function that reverts with `WrongNumber(uint256 number)` custom error:
0 commit comments