foundry_cheatcodes/test/
assume.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{Cheatcode, Cheatcodes, CheatsCtxt, Error, Result};
use foundry_evm_core::constants::MAGIC_ASSUME;
use spec::Vm::{assumeCall, assumeNoRevertCall};
use std::fmt::Debug;

#[derive(Clone, Debug)]
pub struct AssumeNoRevert {
    /// The call depth at which the cheatcode was added.
    pub depth: u64,
}

impl Cheatcode for assumeCall {
    fn apply(&self, _state: &mut Cheatcodes) -> Result {
        let Self { condition } = self;
        if *condition {
            Ok(Default::default())
        } else {
            Err(Error::from(MAGIC_ASSUME))
        }
    }
}

impl Cheatcode for assumeNoRevertCall {
    fn apply_stateful(&self, ccx: &mut CheatsCtxt) -> Result {
        ccx.state.assume_no_revert =
            Some(AssumeNoRevert { depth: ccx.ecx.journaled_state.depth() });
        Ok(Default::default())
    }
}