Skip to content

Commit

Permalink
implement assume_no_revert change
Browse files Browse the repository at this point in the history
  • Loading branch information
emo-eth committed Nov 7, 2024
1 parent 0a61a69 commit c215515
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions crates/cheatcodes/src/test/assume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,23 @@ fn assume_no_revert(
) -> Result {
ensure!(state.expected_revert.is_none(), ASSUME_EXPECT_REJECT_MAGIC);

// if reason is not none, check if it is 4 bytes; if so, allow partial matches
let partial_match = reason.is_some() && reason.as_ref().unwrap().len() == 4;
// if assume_no_revert is not set, set it
if state.assume_no_revert.is_none() {
state.assume_no_revert = Some(AssumeNoRevert { depth, reasons: vec![], reverted_by: None });
// if reason is not none, create a new AssumeNoRevertParams vec
if let Some(reason) = reason {
state.assume_no_revert.as_mut().unwrap().reasons =
vec![AcceptableRevertParameters { reason, partial_match, reverter }];
let params = reason.map(|reason| {
let partial_match = reason.len() == 4;
AcceptableRevertParameters { reason, partial_match, reverter }
});

match state.assume_no_revert {
Some(ref mut assume) => {
ensure!(!assume.reasons.is_empty() && params.is_some(), ASSUME_REJECT_MAGIC);
assume.reasons.push(params.unwrap());
}
None => {
state.assume_no_revert = Some(AssumeNoRevert {
depth,
reasons: if let Some(params) = params { vec![params] } else { vec![] },
reverted_by: None,
});
}
} else {
// otherwise, ensure that reasons vec is not none and new reason is also not none
let valid_assume =
!state.assume_no_revert.as_ref().unwrap().reasons.is_empty() && reason.is_some();
ensure!(valid_assume, ASSUME_REJECT_MAGIC);
// and append the new reason
state.assume_no_revert.as_mut().unwrap().reasons.push(AcceptableRevertParameters {
reason: reason.unwrap(),
partial_match,
reverter,
});
}

Ok(Default::default())
Expand Down

0 comments on commit c215515

Please sign in to comment.