Skip to content

Commit

Permalink
Document expectRevert()
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Mar 22, 2022
1 parent a8ba72b commit 01e28fa
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/reference/cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface CheatCodes {
function etch(address who, bytes calldata code) external;
// Sets an address' code
function expectRevert() external;
function expectRevert(bytes calldata) external;
function expectRevert(bytes4) external;
// Expects an error on next call
Expand Down Expand Up @@ -376,6 +377,24 @@ An alternative version of [`expectRevert`](#expectrevert) that only takes an err
cheats.expectRevert(MyContract.CustomError.selector)
```

##### Alternative Signature without error message

```solidity
function expectRevert() external;
```

If you need to test that a function reverts _without_ a message, you can do so with `expectRevert()`.

###### Example

```solidity
function testExpectRevertNoReason() public {
Reverter reverter = new Reverter();
cheats.expectRevert();
reverter.revertWithoutReason();
}
```

<br>

---
Expand Down Expand Up @@ -425,7 +444,7 @@ This cheat code is used to assert that certain logs are emitted on the next call
2. Emit the event we are supposed to see after the next call.
3. Perform the call.

If the event is not available in the current scope (e.g because we are using an interface, or an external smart contract), we can define the event ourselves with an identical event signature.
If the event is not available in the current scope (e.g because we are using an interface, or an external smart contract), we can define the event ourselves with an identical event signature.

The cheatcode does not check the origin of the event, but simply that it was emitted during that call.

Expand Down

0 comments on commit 01e28fa

Please sign in to comment.