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

test: add an expectRevert test #6340

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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