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

feat(cheatcodes): expectRevert with specific reverter address #8770

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
82 changes: 81 additions & 1 deletion crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,26 @@ interface Vm {
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(bytes calldata revertData) external;

/// Expects an error with any revert data on next call to reverter address.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(address reverter) external;

/// Expects an error from reverter address on next call, with any revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(bytes4 revertData, address reverter) external;

/// Expects an error from reverter address on next call, that exactly matches the revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectRevert(bytes calldata revertData, address reverter) external;

/// Expects an error on next call that starts with the revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectPartialRevert(bytes4 revertData) external;

/// Expects an error on next call to reverter address, that starts with the revert data.
#[cheatcode(group = Testing, safety = Unsafe)]
function expectPartialRevert(bytes4 revertData, address reverter) external;

/// Expects an error on next cheatcode call with any revert data.
#[cheatcode(group = Testing, safety = Unsafe, status = Internal)]
function _expectCheatcodeRevert() external;
Expand Down
19 changes: 13 additions & 6 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ impl Cheatcodes {
return match expect::handle_expect_revert(
false,
true,
expected_revert.reason.as_deref(),
expected_revert.partial_match,
&expected_revert,
outcome.result.result,
outcome.result.output.clone(),
&self.config.available_artifacts,
Expand Down Expand Up @@ -1234,8 +1233,17 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
}
}

// Handle expected reverts
if let Some(expected_revert) = &self.expected_revert {
// Handle expected reverts.
if let Some(expected_revert) = &mut self.expected_revert {
// Record current reverter address before processing the expect revert if call reverted,
// expect revert is set with expected reverter address and no actual reverter set yet.
if outcome.result.is_revert() &&
expected_revert.reverter.is_some() &&
expected_revert.reverted_by.is_none()
{
expected_revert.reverted_by = Some(call.target_address);
}

if ecx.journaled_state.depth() <= expected_revert.depth {
let needs_processing = match expected_revert.kind {
ExpectedRevertKind::Default => !cheatcode_call,
Expand All @@ -1251,8 +1259,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
return match expect::handle_expect_revert(
cheatcode_call,
false,
expected_revert.reason.as_deref(),
expected_revert.partial_match,
&expected_revert,
outcome.result.result,
outcome.result.output.clone(),
&self.config.available_artifacts,
Expand Down
Loading
Loading