Skip to content

Commit

Permalink
test: add an expectRevert test (#6340)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Nov 17, 2023
1 parent 8c044be commit daefe5e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions testdata/cheats/ExpectRevert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract Reverter {
error CustomError();

function revertWithMessage(string memory message) public pure {
require(false, message);
revert(message);
}

function doNotRevert() public pure {}
Expand All @@ -27,7 +27,7 @@ contract Reverter {

function callThenRevert(Dummy dummy, string memory message) public pure {
dummy.callMe();
require(false, message);
revert(message);
}

function revertWithoutReason() public pure {
Expand All @@ -37,7 +37,7 @@ contract Reverter {

contract ConstructorReverter {
constructor(string memory message) {
require(false, message);
revert(message);
}
}

Expand All @@ -63,7 +63,7 @@ contract Dummy {
}

function largeReturnType() public pure returns (LargeDummyStruct memory) {
require(false, "reverted with large return type");
revert("reverted with large return type");
}
}

Expand All @@ -80,6 +80,12 @@ contract ExpectRevertTest is DSTest {
reverter.revertWithMessage("revert");
}

function testFailExpectRevertWrongString() public {
Reverter reverter = new Reverter();
vm.expectRevert("my not so cool error");
reverter.revertWithMessage("my cool error");
}

function testFailRevertNotOnImmediateNextCall() public {
Reverter reverter = new Reverter();
// expectRevert should only work for the next call. However,
Expand Down

0 comments on commit daefe5e

Please sign in to comment.