foundry_cheatcodes/inspector/
utils.rs
1use super::Ecx;
2use crate::inspector::Cheatcodes;
3use alloy_primitives::{Address, Bytes, U256};
4use revm::interpreter::{CreateInputs, CreateScheme};
5
6pub(crate) trait CommonCreateInput {
8 fn caller(&self) -> Address;
9 fn gas_limit(&self) -> u64;
10 fn value(&self) -> U256;
11 fn init_code(&self) -> Bytes;
12 fn scheme(&self) -> Option<CreateScheme>;
13 fn set_caller(&mut self, caller: Address);
14 fn log_debug(&self, cheatcode: &mut Cheatcodes, scheme: &CreateScheme);
15 fn allow_cheatcodes(&self, cheatcodes: &mut Cheatcodes, ecx: Ecx) -> Address;
16}
17
18impl CommonCreateInput for &mut CreateInputs {
19 fn caller(&self) -> Address {
20 self.caller
21 }
22 fn gas_limit(&self) -> u64 {
23 self.gas_limit
24 }
25 fn value(&self) -> U256 {
26 self.value
27 }
28 fn init_code(&self) -> Bytes {
29 self.init_code.clone()
30 }
31 fn scheme(&self) -> Option<CreateScheme> {
32 Some(self.scheme)
33 }
34 fn set_caller(&mut self, caller: Address) {
35 self.caller = caller;
36 }
37 fn log_debug(&self, cheatcode: &mut Cheatcodes, scheme: &CreateScheme) {
38 let kind = match scheme {
39 CreateScheme::Create => "create",
40 CreateScheme::Create2 { .. } => "create2",
41 CreateScheme::Custom { .. } => "custom",
42 };
43 debug!(target: "cheatcodes", tx=?cheatcode.broadcastable_transactions.back().unwrap(), "broadcastable {kind}");
44 }
45 fn allow_cheatcodes(&self, cheatcodes: &mut Cheatcodes, ecx: Ecx) -> Address {
46 let old_nonce = ecx
47 .journaled_state
48 .state
49 .get(&self.caller)
50 .map(|acc| acc.info.nonce)
51 .unwrap_or_default();
52 let created_address = self.created_address(old_nonce);
53 cheatcodes.allow_cheatcodes_on_create(ecx, self.caller, created_address);
54 created_address
55 }
56}