From daefe5e5442cf1d477e9f51408eaff3ca00ec2c8 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:44:04 +0100 Subject: [PATCH] test: add an expectRevert test (#6340) --- testdata/cheats/ExpectRevert.t.sol | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/testdata/cheats/ExpectRevert.t.sol b/testdata/cheats/ExpectRevert.t.sol index 00200477bf74..8e67c4ad2f91 100644 --- a/testdata/cheats/ExpectRevert.t.sol +++ b/testdata/cheats/ExpectRevert.t.sol @@ -8,7 +8,7 @@ contract Reverter { error CustomError(); function revertWithMessage(string memory message) public pure { - require(false, message); + revert(message); } function doNotRevert() public pure {} @@ -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 { @@ -37,7 +37,7 @@ contract Reverter { contract ConstructorReverter { constructor(string memory message) { - require(false, message); + revert(message); } } @@ -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"); } } @@ -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,