Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 17, 2023
1 parent 2a513fd commit 60b3722
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 89 deletions.
6 changes: 2 additions & 4 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ use foundry_common::{
};
use foundry_config::Config;
use foundry_evm::{
executor::{
fork::{BlockchainDb, BlockchainDbMeta, SharedBackend},
inspector::DEFAULT_CREATE2_DEPLOYER,
},
cheatcodes::DEFAULT_CREATE2_DEPLOYER,
executor::fork::{BlockchainDb, BlockchainDbMeta, SharedBackend},
revm,
revm::primitives::{BlockEnv, CfgEnv, SpecId, TxEnv, U256 as rU256},
utils::apply_chain_and_block_specific_env_changes,
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_cli::{
use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
use foundry_config::{find_project_root_path, Config};
use foundry_evm::{
executor::{inspector::cheatcodes::util::configure_tx_env, opts::EvmOpts, EvmError},
executor::{backend::configure_tx_env, opts::EvmOpts, EvmError},
revm::primitives::U256 as rU256,
trace::TracingExecutor,
};
Expand Down
6 changes: 4 additions & 2 deletions crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use core::fmt::Debug;
use ethers_solc::Artifact;
use eyre::{Result, WrapErr};
use foundry_evm::{
cheatcodes::CheatsConfig,
decode::decode_console_logs,
executor::{inspector::CheatsConfig, Backend, ExecutorBuilder},
executor::{Backend, ExecutorBuilder},
};
use foundry_utils::types::ToEthers;
use solang_parser::pt::{self, CodeLocation};
Expand Down Expand Up @@ -291,7 +292,8 @@ impl SessionSource {
// Build a new executor
let executor = ExecutorBuilder::new()
.inspectors(|stack| {
let cheats = CheatsConfig::new(&self.config.foundry_config, &self.config.evm_opts);
let cheats =
CheatsConfig::new(&self.config.foundry_config, self.config.evm_opts.clone());
stack.chisel_state(final_pc).trace(true).cheatcodes(cheats.into())
})
.gas_limit(self.config.evm_opts.gas_limit())
Expand Down
2 changes: 1 addition & 1 deletion crates/chisel/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl ChiselRunner {
let RawCallResult { result, reverted, logs, traces, labels, chisel_state, .. } = res;

Ok(ChiselResult {
returned: result.0,
returned: result,
success: !reverted,
gas_used,
logs,
Expand Down
29 changes: 15 additions & 14 deletions crates/common/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Commonly used traits

use auto_impl::auto_impl;
use ethers_core::abi::Function;

/// Extension trait for matching tests
#[auto_impl::auto_impl(&)]
#[auto_impl(&)]
pub trait TestFilter: Send + Sync {
/// Returns whether the test should be included
fn matches_test(&self, test_name: impl AsRef<str>) -> bool;
Expand All @@ -14,7 +15,7 @@ pub trait TestFilter: Send + Sync {
}

/// Extension trait for `Function`
#[auto_impl::auto_impl(&)]
#[auto_impl(&)]
pub trait TestFunctionExt {
/// Whether this function should be executed as invariant test
fn is_invariant_test(&self) -> bool;
Expand Down Expand Up @@ -51,46 +52,46 @@ impl TestFunctionExt for Function {
}
}

impl<'a> TestFunctionExt for &'a str {
impl TestFunctionExt for String {
fn is_invariant_test(&self) -> bool {
self.starts_with("invariant") || self.starts_with("statefulFuzz")
self.as_str().is_invariant_test()
}

fn is_fuzz_test(&self) -> bool {
unimplemented!("no naming convention for fuzz tests.")
self.as_str().is_fuzz_test()
}

fn is_test(&self) -> bool {
self.starts_with("test")
self.as_str().is_test()
}

fn is_test_fail(&self) -> bool {
self.starts_with("testFail")
self.as_str().is_test_fail()
}

fn is_setup(&self) -> bool {
self.eq_ignore_ascii_case("setup")
self.as_str().is_setup()
}
}

impl TestFunctionExt for String {
impl TestFunctionExt for str {
fn is_invariant_test(&self) -> bool {
self.as_str().is_invariant_test()
self.starts_with("invariant") || self.starts_with("statefulFuzz")
}

fn is_fuzz_test(&self) -> bool {
self.as_str().is_fuzz_test()
unimplemented!("no naming convention for fuzz tests.")
}

fn is_test(&self) -> bool {
self.as_str().is_test()
self.starts_with("test")
}

fn is_test_fail(&self) -> bool {
self.as_str().is_test_fail()
self.starts_with("testFail")
}

fn is_setup(&self) -> bool {
self.as_str().is_setup()
self.eq_ignore_ascii_case("setup")
}
}
19 changes: 0 additions & 19 deletions crates/evm/src/executor/abi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
//! Several ABI-related utilities for executors.

use alloy_primitives::Address;
pub use foundry_abi::{
console::{self, ConsoleEvents, CONSOLE_ABI},
hardhat_console::{self, HardhatConsoleCalls, HARDHATCONSOLE_ABI as HARDHAT_CONSOLE_ABI},
hevm::{self, HEVMCalls, HEVM_ABI},
};
use once_cell::sync::Lazy;
use std::collections::HashMap;

/// The cheatcode handler address (0x7109709ECfa91a80626fF3989D68f67F5b1DD12D).
///
/// This is the same address as the one used in DappTools's HEVM.
/// `address(bytes20(uint160(uint256(keccak256('hevm cheat code')))))`
pub const CHEATCODE_ADDRESS: Address = Address::new([
0x71, 0x09, 0x70, 0x9E, 0xcf, 0xa9, 0x1a, 0x80, 0x62, 0x6f, 0xf3, 0x98, 0x9d, 0x68, 0xf6, 0x7f,
0x5b, 0x1d, 0xd1, 0x2d,
]);

/// The Hardhat console address (0x000000000000000000636F6e736F6c652e6c6f67).
///
/// See: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-core/console.sol
pub const HARDHAT_CONSOLE_ADDRESS: Address = Address::new([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65,
0x2e, 0x6c, 0x6f, 0x67,
]);

/// If the input starts with a known `hardhat/console.log` `uint` selector, then this will replace
/// it with the selector `abigen!` bindings expect.
pub fn patch_hardhat_console_selector(input: &mut Vec<u8>) {
Expand Down
7 changes: 3 additions & 4 deletions crates/evm/src/executor/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Foundry's main executor backend abstraction and implementation.

use crate::{
abi::CHEATCODE_ADDRESS,
executor::{
backend::{in_memory_db::FoundryEvmInMemoryDB, snapshot::BackendSnapshot},
fork::{CreateFork, ForkId, MultiFork, SharedBackend},
Expand All @@ -16,7 +15,7 @@ use ethers::{
utils::keccak256,
};
use eyre::Result;
use foundry_cheatcodes::{Cheatcodes, DEFAULT_CREATE2_DEPLOYER};
use foundry_cheatcodes::{Cheatcodes, CHEATCODE_ADDRESS, DEFAULT_CREATE2_DEPLOYER};
use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
use foundry_utils::types::{ToAlloy, ToEthers};
pub use in_memory_db::MemDb;
Expand Down Expand Up @@ -1603,8 +1602,8 @@ fn apply_state_changeset(
}
}

/// Configures the env for the transaction
fn configure_tx_env(env: &mut revm::primitives::Env, tx: &Transaction) {
/// Configures the revm [`Env`] for the given [`Transaction`].
pub fn configure_tx_env(env: &mut revm::primitives::Env, tx: &Transaction) {
env.tx.caller = tx.from.to_alloy();
env.tx.gas_limit = tx.gas.as_u64();
env.tx.gas_price = tx.gas_price.unwrap_or_default().to_alloy();
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/executor/fork/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ impl Future for MultiForkHandler {
}
}
Err(err) => {
let _ = sender.send(Err(err));
let _ = sender.send(Err(eyre::eyre!("{err}")));
for sender in additional_senders {
let _ = sender.send(Err(err));
let _ = sender.send(Err(eyre::eyre!("{err}")));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/evm/src/executor/inspector/logs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::executor::{
patch_hardhat_console_selector, HardhatConsoleCalls, HARDHAT_CONSOLE_ADDRESS,
};
use crate::executor::{patch_hardhat_console_selector, HardhatConsoleCalls};
use alloy_primitives::{Address, Bytes, B256};
use ethers::{
abi::{AbiDecode, Token},
types::{Bytes as ethersBytes, Log, H256},
};
use foundry_cheatcodes::HARDHAT_CONSOLE_ADDRESS;
use foundry_macros::ConsoleFmt;
use foundry_utils::types::ToEthers;
use revm::{
Expand Down
6 changes: 2 additions & 4 deletions crates/evm/src/fuzz/invariant/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use super::{
InvariantFuzzTestResult, RandomCallGenerator, TargetedContracts,
};
use crate::{
executor::{
inspector::Fuzzer, Executor, RawCallResult, StateChangeset, CHEATCODE_ADDRESS,
HARDHAT_CONSOLE_ADDRESS,
},
executor::{inspector::Fuzzer, Executor, RawCallResult, StateChangeset},
fuzz::{
strategies::{
build_initial_state, collect_created_contracts, collect_state_from_call,
Expand All @@ -21,6 +18,7 @@ use crate::{
};
use ethers::abi::{Abi, Address, Detokenize, FixedBytes, Tokenizable, TokenizableItem};
use eyre::{eyre, ContextCompat, Result};
use foundry_cheatcodes::{CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS};
use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact};
use foundry_config::{FuzzDictionaryConfig, InvariantConfig};
use foundry_utils::types::{ToAlloy, ToEthers};
Expand Down
4 changes: 3 additions & 1 deletion crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ pub mod utils;

// Re-exports
pub use ethers::types::Address;
pub use foundry_cheatcodes as cheatcodes;
pub use hashbrown;
use revm::interpreter::{CallScheme, CreateScheme};
pub use revm::{
self,
primitives::{Address as aAddress, HashMap},
};

use revm::interpreter::{CallScheme, CreateScheme};
use serde::{Deserialize, Serialize};

/// Stores the caller address to be used as _sender_ account for:
Expand Down
17 changes: 7 additions & 10 deletions crates/evm/src/trace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{
abi::CHEATCODE_ADDRESS, debug::Instruction, trace::identifier::LocalTraceIdentifier, CallKind,
};
use crate::{debug::Instruction, trace::identifier::LocalTraceIdentifier, CallKind};
pub use decoder::{CallTraceDecoder, CallTraceDecoderBuilder};
use ethers::{
abi::{ethereum_types::BigEndianHash, Address, RawLog},
core::utils::to_checksum,
types::{Bytes, DefaultFrame, GethDebugTracingOptions, StructLog, H256, U256},
};
pub use executor::TracingExecutor;
use foundry_cheatcodes::CHEATCODE_ADDRESS;
use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact};
use foundry_utils::types::ToEthers;
use hashbrown::HashMap;
Expand Down Expand Up @@ -513,9 +512,9 @@ impl fmt::Display for CallTrace {
self.gas_cost,
Paint::yellow(CALL),
Paint::yellow("new"),
self.label.as_ref().unwrap_or(&"<Unknown>".to_string()),
self.label.as_deref().unwrap_or("<Unknown>"),
address
)?;
)
} else {
let (func, inputs) = match &self.data {
RawOrDecodedCall::Raw(bytes) => {
Expand All @@ -533,7 +532,7 @@ impl fmt::Display for CallTrace {
CallKind::StaticCall => "[staticcall]",
CallKind::CallCode => "[callcode]",
CallKind::DelegateCall => "[delegatecall]",
_ => unreachable!(),
CallKind::Create | CallKind::Create2 => unreachable!(),
};

let color = trace_color(self);
Expand All @@ -546,14 +545,12 @@ impl fmt::Display for CallTrace {
if !self.value.is_zero() {
format!("{{value: {}}}", self.value)
} else {
"".to_string()
String::new()
},
inputs,
Paint::yellow(action),
)?;
)
}

Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/trace/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
decode,
executor::CHEATCODE_ADDRESS,
trace::{
utils, utils::decode_cheatcode_outputs, CallTrace, LogCallOrder, RawOrDecodedCall,
RawOrDecodedLog, RawOrDecodedReturnData,
Expand All @@ -11,6 +10,7 @@ use ethers::{
abi::{Abi, Function},
types::{Action, Address, Call, CallResult, Create, CreateResult, Res, Suicide},
};
use foundry_cheatcodes::CHEATCODE_ADDRESS;
use foundry_common::SELECTOR_LEN;
use foundry_utils::types::ToEthers;
use revm::interpreter::InstructionResult;
Expand Down
3 changes: 2 additions & 1 deletion crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use forge::{
analysis::SourceAnalyzer, anchors::find_anchors, ContractId, CoverageReport,
CoverageReporter, DebugReporter, ItemAnchor, LcovReporter, SummaryReporter,
},
executor::{inspector::CheatsConfig, opts::EvmOpts},
executor::opts::EvmOpts,
result::SuiteResult,
revm::primitives::SpecId,
utils::{build_ic_pc_map, ICPCMap},
Expand All @@ -27,6 +27,7 @@ use foundry_cli::{
};
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs};
use foundry_config::{Config, SolcReq};
use foundry_evm::cheatcodes::CheatsConfig;
use foundry_utils::types::ToEthers;
use semver::Version;
use std::{collections::HashMap, path::PathBuf, sync::mpsc::channel};
Expand Down
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/script/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use foundry_cli::{
utils::{has_batch_support, has_different_gas_calc},
};
use foundry_common::{estimate_eip1559_fees, shell, try_get_http_provider, RetryProvider};
use foundry_evm::cheatcodes::impls::BroadcastableTransactions;
use futures::StreamExt;
use std::{cmp::min, collections::HashSet, ops::Mul, sync::Arc};
use tracing::trace;
Expand Down
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/script/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use eyre::Result;
use foundry_cli::utils::LoadConfig;
use foundry_common::{contracts::flatten_contracts, try_get_http_provider};
use foundry_debugger::DebuggerArgs;
use foundry_evm::cheatcodes::impls::BroadcastableTransaction;
use foundry_utils::types::ToAlloy;
use std::sync::Arc;
use tracing::trace;
Expand Down
6 changes: 2 additions & 4 deletions crates/forge/bin/cmd/script/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ use ethers::{
};
use eyre::Result;
use forge::{
executor::{
inspector::{cheatcodes::util::BroadcastableTransactions, CheatsConfig},
Backend, ExecutorBuilder,
},
executor::{Backend, ExecutorBuilder},
revm::primitives::U256 as rU256,
trace::{CallTraceDecoder, Traces},
CallKind,
};
use foundry_cli::utils::{ensure_clean_constructor, needs_setup};
use foundry_common::{shell, RpcUrl};
use foundry_evm::cheatcodes::{impls::BroadcastableTransactions, CheatsConfig};
use foundry_utils::types::ToEthers;
use futures::future::join_all;
use parking_lot::RwLock;
Expand Down
7 changes: 4 additions & 3 deletions crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ use foundry_config::{
Config,
};
use foundry_evm::{
decode,
executor::inspector::{
cheatcodes::{util::BroadcastableTransactions, BroadcastableTransaction},
self,
cheatcodes::{
impls::{BroadcastableTransaction, BroadcastableTransactions},
DEFAULT_CREATE2_DEPLOYER,
},
decode,
};
use foundry_utils::types::{ToAlloy, ToEthers};
use futures::future;
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/script/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl ScriptRunner {
let breakpoints = res.cheatcodes.map(|cheats| cheats.breakpoints).unwrap_or_default();

Ok(ScriptResult {
returned: result.0,
returned: result,
success: !reverted,
gas_used,
logs,
Expand Down
Loading

0 comments on commit 60b3722

Please sign in to comment.