Skip to content

Commit

Permalink
Foundry tests support interface calls (#411)
Browse files Browse the repository at this point in the history
* foundry tests support interface calls

* add unit tests

* add unit tests

* add unit tests

* onchain tests

* onchain test

* onchain test

* onchain test
  • Loading branch information
iamjacobjia authored Dec 25, 2023
1 parent 0a22aae commit d031a79
Show file tree
Hide file tree
Showing 7 changed files with 573 additions and 33 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ handlebars = "4.4"
# for cheatcode middleware
foundry-cheatcodes = { git = "https://github.com/foundry-rs/foundry.git", rev = "dee41819c6e6bd1ea5419c613d226498ed7a2c59" }
foundry-abi = { git = "https://github.com/foundry-rs/foundry.git", rev = "dee41819c6e6bd1ea5419c613d226498ed7a2c59" }
alloy-sol-types = "0.4.1"
alloy-dyn-abi = "0.4.1"
alloy-primitives = "0.4.1"

alloy-sol-types = "0.4"
alloy-dyn-abi = { version = "0.4", features = ["arbitrary", "eip712"] }
alloy-primitives = "0.4"
alloy-json-abi = "0.4"
# error handling
anyhow = "1.0"
# logging
tracing = "0.1"
tracing-subscriber = "0.3"
Expand Down
11 changes: 8 additions & 3 deletions src/evm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,15 @@ impl BoxedABI {
}

pub fn to_colored_string(&self) -> String {
if self.function == [0; 4] {
self.to_string()
if let Some(fn_sig) = self.get_func_signature() {
let fn_name = fn_sig.split('(').next().unwrap();
let mut args: String = self.b.to_colored_string();
if args.is_empty() {
args = "()".to_string();
}
format!("{}{}", fn_name, args)
} else {
format!("{}{}", self.get_func_name(), self.b.to_colored_string())
self.to_string()
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/evm/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,19 @@ impl ConciseEVMInput {
#[allow(dead_code)]
#[inline]
fn as_abi_call(&self, call_str: String) -> Option<String> {
let parts: Vec<&str> = call_str.splitn(2, '(').collect();
if parts.len() < 2 && call_str.len() == 8 {
let selector = self.fn_selector().trim_start_matches("0x").to_string();
if self.fn_signature().is_empty() || call_str.starts_with(&selector) {
return self.as_fn_selector_call();
}

let parts: Vec<&str> = call_str.splitn(2, '(').collect();
let mut fn_call = self.colored_fn_name(parts[0]).to_string();
let value = self.txn_value.unwrap_or_default();
if value != EVMU256::ZERO {
fn_call.push_str(&self.colored_value());
}

if parts.len() < 2 {
fn_call.push_str("()");
} else {
fn_call.push_str(format!("({}", parts[1]).as_str());
}

fn_call.push_str(format!("({}", parts[1]).as_str());
Some(format!("{}.{}", colored_address(&self.contract()), fn_call))
}

Expand Down Expand Up @@ -568,7 +564,7 @@ impl SolutionTx for ConciseEVMInput {
}

fn value(&self) -> String {
self.txn_value.unwrap_or_default().to_string()
prettify_value(self.txn_value.unwrap_or_default())
}

fn is_borrow(&self) -> bool {
Expand All @@ -582,6 +578,14 @@ impl SolutionTx for ConciseEVMInput {
fn swap_data(&self) -> HashMap<String, SwapInfo> {
self.swap_data.clone()
}

#[cfg(not(feature = "debug"))]
fn calldata(&self) -> String {
match self.data {
Some(ref d) => hex::encode(d.get_bytes()),
None => "".to_string(),
}
}
}

impl HasLen for EVMInput {
Expand Down
Loading

0 comments on commit d031a79

Please sign in to comment.