-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cheatcode): expect revert only for calls with greater depth
- Loading branch information
Showing
11 changed files
with
139 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "cheats/Vm.sol"; | ||
|
||
contract Reverter { | ||
function doNotRevert() public {} | ||
|
||
function revertWithMessage(string calldata message) public { | ||
revert(message); | ||
} | ||
} | ||
|
||
// https://github.com/foundry-rs/foundry/issues/8639 | ||
contract Issue7238Test is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
function testExpectRevertString() public { | ||
Reverter reverter = new Reverter(); | ||
vm.expectRevert("revert"); | ||
reverter.revertWithMessage("revert"); | ||
} | ||
|
||
// FAIL | ||
function testFailRevertNotOnImmediateNextCall() public { | ||
Reverter reverter = new Reverter(); | ||
// expectRevert should only work for the next call. However, | ||
// we do not inmediately revert, so, | ||
// we fail. | ||
vm.expectRevert("revert"); | ||
reverter.doNotRevert(); | ||
reverter.revertWithMessage("revert"); | ||
} | ||
|
||
// FAIL | ||
function testFailCheatcodeRevert() public { | ||
// This expectRevert is hanging, as the next cheatcode call is ignored. | ||
vm.expectRevert(); | ||
vm.fsMetadata("something/something"); // try to go to some non-existent path to cause a revert | ||
} | ||
|
||
function testFailEarlyRevert() public { | ||
vm.expectRevert(); | ||
rever(); | ||
} | ||
|
||
function rever() internal { | ||
revert(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters