Skip to content

Commit

Permalink
chore(evm, utils): Move utility error traits to utils (#5286)
Browse files Browse the repository at this point in the history
* chore: add error to utils

* chore: remove error from evm, resolve conflicts and add foundry-utils

* chore: fmt
  • Loading branch information
Evalir authored Jul 4, 2023
1 parent 2487f00 commit bf56869
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion evm/src/decode.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions evm/src/executor/backend/error.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 3 additions & 5 deletions evm/src/executor/inspector/cheatcodes/error.rs
Original file line number Diff line number Diff line change
@@ -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`].
Expand Down Expand Up @@ -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),
}
}

Expand Down
8 changes: 2 additions & 6 deletions evm/src/executor/inspector/cheatcodes/expect.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion evm/src/executor/inspector/cheatcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use self::{
};
use crate::{
abi::HEVMCalls,
error::SolError,
executor::{
backend::DatabaseExt, inspector::cheatcodes::env::RecordedLogs, CHEATCODE_ADDRESS,
HARDHAT_CONSOLE_ADDRESS,
Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion evm/src/executor/inspector/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
debug::{DebugArena, DebugNode, DebugStep, Instruction},
error::SolError,
executor::{
backend::DatabaseExt,
inspector::utils::{gas_used, get_create_address},
Expand All @@ -11,6 +10,7 @@ use crate::{
};
use bytes::Bytes;
use ethers::types::Address;
use foundry_utils::error::SolError;
use revm::{
inspectors::GasInspector,
interpreter::{
Expand Down
2 changes: 0 additions & 2 deletions evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion evm/src/error.rs → utils/src/error.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{
use tracing::trace;

pub mod abi;
pub mod error;
pub mod glob;
pub mod rpc;

Expand Down

0 comments on commit bf56869

Please sign in to comment.