diff --git a/evm/Cargo.toml b/evm/Cargo.toml index 0adb88c36cfc..ca9ce3f73675 100644 --- a/evm/Cargo.toml +++ b/evm/Cargo.toml @@ -9,6 +9,7 @@ keywords = ["ethereum", "web3", "evm"] [dependencies] foundry-abi = { path = "../abi" } +foundry-utils = { path = "../utils" } foundry-common = { path = "../common" } foundry-config = { path = "../config" } foundry-macros = { path = "../macros" } diff --git a/evm/src/decode.rs b/evm/src/decode.rs index 2c0ae73fd102..bf65f2bcedd8 100644 --- a/evm/src/decode.rs +++ b/evm/src/decode.rs @@ -1,7 +1,6 @@ //! Various utilities to decode test results use crate::{ abi::ConsoleEvents::{self, *}, - error::ERROR_PREFIX, executor::inspector::cheatcodes::util::MAGIC_SKIP_BYTES, }; use ethers::{ @@ -11,6 +10,7 @@ use ethers::{ types::Log, }; use foundry_common::{abi::format_token, SELECTOR_LEN}; +use foundry_utils::error::ERROR_PREFIX; use itertools::Itertools; use once_cell::sync::Lazy; use revm::interpreter::{return_ok, InstructionResult}; diff --git a/evm/src/executor/backend/error.rs b/evm/src/executor/backend/error.rs index 2f4a7f862d4a..eb3a595b10c2 100644 --- a/evm/src/executor/backend/error.rs +++ b/evm/src/executor/backend/error.rs @@ -1,6 +1,5 @@ -use crate::error::SolError; - use ethers::types::{Address, BlockId, H256, U256}; +use foundry_utils::error::SolError; use futures::channel::mpsc::{SendError, TrySendError}; use std::{ convert::Infallible, diff --git a/evm/src/executor/inspector/cheatcodes/error.rs b/evm/src/executor/inspector/cheatcodes/error.rs index b763690d2570..5461a9fa6a0b 100644 --- a/evm/src/executor/inspector/cheatcodes/error.rs +++ b/evm/src/executor/inspector/cheatcodes/error.rs @@ -1,12 +1,10 @@ -use crate::{ - error::SolError, - executor::backend::{error::NoCheatcodeAccessError, DatabaseError}, -}; +use crate::executor::backend::{error::NoCheatcodeAccessError, DatabaseError}; use ethers::{ abi::AbiEncode, prelude::k256::ecdsa::signature::Error as SignatureError, types::Bytes, }; use foundry_common::errors::FsPathError; use foundry_config::UnresolvedEnvVarError; +use foundry_utils::error::{encode_error, SolError}; use std::{borrow::Cow, fmt::Arguments}; /// Type alias with a default Ok type of [`Bytes`], and default Err type of [`Error`]. @@ -174,7 +172,7 @@ impl SolError for Error { fn encode_error(&self) -> Bytes { match self { Self::CustomBytes(cow) => cow_to_bytes(cow), - e => crate::error::encode_error(e), + e => encode_error(e), } } diff --git a/evm/src/executor/inspector/cheatcodes/expect.rs b/evm/src/executor/inspector/cheatcodes/expect.rs index f4562c65a9f3..fff7b8bbf476 100644 --- a/evm/src/executor/inspector/cheatcodes/expect.rs +++ b/evm/src/executor/inspector/cheatcodes/expect.rs @@ -1,14 +1,10 @@ use super::{bail, ensure, fmt_err, Cheatcodes, Result}; -use crate::{ - abi::HEVMCalls, - error::{ERROR_PREFIX, REVERT_PREFIX}, - executor::backend::DatabaseExt, - utils::h160_to_b160, -}; +use crate::{abi::HEVMCalls, executor::backend::DatabaseExt, utils::h160_to_b160}; use ethers::{ abi::{AbiDecode, RawLog}, types::{Address, Bytes, H160, U256}, }; +use foundry_utils::error::{ERROR_PREFIX, REVERT_PREFIX}; use revm::{ interpreter::{return_ok, InstructionResult}, primitives::Bytecode, diff --git a/evm/src/executor/inspector/cheatcodes/mod.rs b/evm/src/executor/inspector/cheatcodes/mod.rs index 5f7e9d8af5e3..a89e6bd138c2 100644 --- a/evm/src/executor/inspector/cheatcodes/mod.rs +++ b/evm/src/executor/inspector/cheatcodes/mod.rs @@ -5,7 +5,6 @@ use self::{ }; use crate::{ abi::HEVMCalls, - error::SolError, executor::{ backend::DatabaseExt, inspector::cheatcodes::env::RecordedLogs, CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS, @@ -21,6 +20,7 @@ use ethers::{ }, }; use foundry_common::evm::Breakpoints; +use foundry_utils::error::SolError; use itertools::Itertools; use revm::{ interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter}, diff --git a/evm/src/executor/inspector/debugger.rs b/evm/src/executor/inspector/debugger.rs index e44530b59aed..3f6a344aabae 100644 --- a/evm/src/executor/inspector/debugger.rs +++ b/evm/src/executor/inspector/debugger.rs @@ -1,6 +1,5 @@ use crate::{ debug::{DebugArena, DebugNode, DebugStep, Instruction}, - error::SolError, executor::{ backend::DatabaseExt, inspector::utils::{gas_used, get_create_address}, @@ -11,6 +10,7 @@ use crate::{ }; use bytes::Bytes; use ethers::types::Address; +use foundry_utils::error::SolError; use revm::{ inspectors::GasInspector, interpreter::{ diff --git a/evm/src/lib.rs b/evm/src/lib.rs index 282e7341e99a..e0326fa6e714 100644 --- a/evm/src/lib.rs +++ b/evm/src/lib.rs @@ -26,8 +26,6 @@ pub mod fuzz; /// utils for working with revm pub mod utils; -pub mod error; - // Re-exports pub use ethers::types::Address; pub use hashbrown::{self, HashMap}; diff --git a/evm/src/error.rs b/utils/src/error.rs similarity index 95% rename from evm/src/error.rs rename to utils/src/error.rs index dbec73f7e078..e92dee054d15 100644 --- a/evm/src/error.rs +++ b/utils/src/error.rs @@ -1,6 +1,6 @@ //! error handling and support -use ethers::{abi::AbiEncode, types::Bytes}; +use ethers_core::{abi::AbiEncode, types::Bytes}; use std::fmt::Display; /// Solidity revert prefix. diff --git a/utils/src/lib.rs b/utils/src/lib.rs index bbad373539d8..ff8db14b69f0 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -21,6 +21,7 @@ use std::{ use tracing::trace; pub mod abi; +pub mod error; pub mod glob; pub mod rpc;