Skip to content

Commit

Permalink
refactor(evm): executor API, merge evm result types (#7422)
Browse files Browse the repository at this point in the history
* refactor(evm): executor API, merge evm result types

* chore: MSRV

* fix: persist cheatcode state

* log

* fix: setup revert
  • Loading branch information
DaniPopes authored Mar 18, 2024
1 parent dfefc0f commit 04fca21
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 543 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resolver = "2"
[workspace.package]
version = "0.2.0"
edition = "2021"
rust-version = "1.75" # Remember to update clippy.toml as well
rust-version = "1.76" # Remember to update clippy.toml as well
authors = ["Foundry Contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/foundry-rs/foundry"
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.75"
msrv = "1.76"
7 changes: 3 additions & 4 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use foundry_config::{error::ExtractConfigError, figment::Figment, Chain, Config,
use foundry_debugger::Debugger;
use foundry_evm::{
debug::DebugArena,
executors::{DeployResult, EvmError, ExecutionErr, RawCallResult},
executors::{DeployResult, EvmError, RawCallResult},
opts::EvmOpts,
traces::{
identifier::{EtherscanIdentifier, SignaturesIdentifier},
Expand Down Expand Up @@ -339,8 +339,7 @@ impl From<RawCallResult> for TraceResult {

impl From<DeployResult> for TraceResult {
fn from(result: DeployResult) -> Self {
let DeployResult { gas_used, traces, debug, .. } = result;

let RawCallResult { gas_used, traces, debug, .. } = result.raw;
Self {
success: true,
traces: vec![(TraceKind::Execution, traces.expect("traces is None"))],
Expand All @@ -356,7 +355,7 @@ impl TryFrom<EvmError> for TraceResult {
fn try_from(err: EvmError) -> Result<Self, Self::Error> {
match err {
EvmError::Execution(err) => {
let ExecutionErr { reverted, gas_used, traces, debug: run_debug, .. } = *err;
let RawCallResult { reverted, gas_used, traces, debug: run_debug, .. } = err.raw;
Ok(TraceResult {
success: !reverted,
traces: vec![(TraceKind::Execution, traces.expect("traces is None"))],
Expand Down
35 changes: 0 additions & 35 deletions crates/common/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,6 @@ pub fn abi_decode_calldata(
Ok(res)
}

/// Helper trait for converting types to Functions. Helpful for allowing the `call`
/// function on the EVM to be generic over `String`, `&str` and `Function`.
pub trait IntoFunction {
/// Consumes self and produces a function
///
/// # Panics
///
/// This function does not return a Result, so it is expected that the consumer
/// uses it correctly so that it does not panic.
fn into(self) -> Function;
}

impl IntoFunction for Function {
fn into(self) -> Function {
self
}
}

impl IntoFunction for String {
#[track_caller]
fn into(self) -> Function {
IntoFunction::into(self.as_str())
}
}

impl<'a> IntoFunction for &'a str {
#[track_caller]
fn into(self) -> Function {
match get_func(self) {
Ok(func) => func,
Err(e) => panic!("could not parse function: {e}"),
}
}
}

/// Given a function signature string, it tries to parse it as a `Function`
pub fn get_func(sig: &str) -> Result<Function> {
Function::parse(sig).wrap_err("could not parse function signature")
Expand Down
18 changes: 8 additions & 10 deletions crates/config/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ macro_rules! impl_figment_convert {
($name:ty) => {
impl<'a> From<&'a $name> for $crate::figment::Figment {
fn from(args: &'a $name) -> Self {
if let Some(root) = args.root.clone() {
$crate::Config::figment_with_root(root)
} else {
$crate::Config::figment_with_root($crate::find_project_root_path(None).unwrap())
}
.merge(args)
let root = args.root.clone()
.unwrap_or_else(|| $crate::find_project_root_path(None)
.unwrap_or_else(|e| panic!("could not find project root: {e}")));
$crate::Config::figment_with_root(root).merge(args)
}
}

Expand All @@ -79,8 +77,8 @@ macro_rules! impl_figment_convert {
impl<'a> From<&'a $name> for $crate::figment::Figment {
fn from(args: &'a $name) -> Self {
let mut figment: $crate::figment::Figment = From::from(&args.$start);
$ (
figment = figment.merge(&args.$more);
$(
figment = figment.merge(&args.$more);
)*
figment
}
Expand All @@ -97,8 +95,8 @@ macro_rules! impl_figment_convert {
impl<'a> From<&'a $name> for $crate::figment::Figment {
fn from(args: &'a $name) -> Self {
let mut figment: $crate::figment::Figment = From::from(&args.$start);
$ (
figment = figment.merge(&args.$more);
$(
figment = figment.merge(&args.$more);
)*
figment = figment.merge(args);
figment
Expand Down
Loading

0 comments on commit 04fca21

Please sign in to comment.