Skip to content

Add assertRevert #26

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,29 @@ contract DSTest {
assertEq0(a, b);
}
}
function assertRevert(address target, bytes memory data, string memory expectedMessage) internal {
assertRevert(target, data, 0, expectedMessage);
}
function assertRevert(address target, bytes memory data, uint256 value, string memory expectedMessage) internal {
bool succeeded;
bytes memory response;
(succeeded, response) = target.call{value:value}(data);
if (succeeded) {
emit log("Error: call not reverted");
fail();
} else {
string memory message;
assembly {
let size := mload(add(response, 0x44))
message := mload(0x40)
mstore(message, size)
mstore(0x40, add(message, and(add(add(size, 0x20), 0x1f), not(0x1f))))
returndatacopy(add(message, 0x20), 0x44, size)
}
if (keccak256(abi.encodePacked(message)) != keccak256(abi.encodePacked(expectedMessage))) {
emit log("Error: revert message not satisfied");
fail();
}
}
}
}