diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index 59c5ab2fc681a..4f203f5882542 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -113,8 +113,6 @@ pub struct EthApi { /// Holds all blockchain related data /// In-Memory only for now pub backend: Arc, - /// Whether this node is mining - is_mining: bool, /// available signers signers: Arc>>, /// data required for `eth_feeHistory` @@ -155,7 +153,6 @@ impl EthApi { Self { pool, backend, - is_mining: true, signers, fee_history_cache, fee_history_limit, @@ -567,38 +564,6 @@ impl EthApi { Ok(alloy_primitives::hex::encode_prefixed(&hash[..])) } - /// Returns protocol version encoded as a string (quotes are necessary). - /// - /// Handler for ETH RPC call: `eth_protocolVersion` - pub fn protocol_version(&self) -> Result { - node_info!("eth_protocolVersion"); - Ok(1) - } - - /// Returns the number of hashes per second that the node is mining with. - /// - /// Handler for ETH RPC call: `eth_hashrate` - pub fn hashrate(&self) -> Result { - node_info!("eth_hashrate"); - Ok(U256::ZERO) - } - - /// Returns the client coinbase address. - /// - /// Handler for ETH RPC call: `eth_coinbase` - pub fn author(&self) -> Result
{ - node_info!("eth_coinbase"); - Ok(self.backend.coinbase()) - } - - /// Returns true if client is actively mining new blocks. - /// - /// Handler for ETH RPC call: `eth_mining` - pub fn is_mining(&self) -> Result { - node_info!("eth_mining"); - Ok(self.is_mining) - } - /// Returns the chain ID used for transaction signing at the /// current best block. None is returned if not /// available. @@ -2419,15 +2384,6 @@ impl EthApi { Ok(blocks) } - /// Sets the reported block number - /// - /// Handler for ETH RPC call: `anvil_setBlock` - pub fn anvil_set_block(&self, block_number: u64) -> Result<()> { - node_info!("anvil_setBlock"); - self.backend.set_block_number(block_number); - Ok(()) - } - /// Sets the backend rpc url /// /// Handler for ETH RPC call: `anvil_setRpcUrl` diff --git a/crates/anvil/src/eth/backend/db.rs b/crates/anvil/src/eth/backend/db.rs index e39baee9193df..63c36021deadf 100644 --- a/crates/anvil/src/eth/backend/db.rs +++ b/crates/anvil/src/eth/backend/db.rs @@ -194,13 +194,6 @@ pub trait Db: fn current_state(&self) -> StateDb; } -impl dyn Db { - // TODO: Required until trait upcasting is stabilized: - pub fn as_dbref(&self) -> &dyn DatabaseRef { - self.as_dyn() - } -} - /// Convenience impl only used to use any `Db` on the fly as the db layer for revm's CacheDB /// This is useful to create blocks without actually writing to the `Db`, but rather in the cache of /// the `CacheDB` see also diff --git a/crates/anvil/src/eth/backend/info.rs b/crates/anvil/src/eth/backend/info.rs index 0f539f9373dcb..8adc23bafb2a4 100644 --- a/crates/anvil/src/eth/backend/info.rs +++ b/crates/anvil/src/eth/backend/info.rs @@ -21,16 +21,6 @@ impl StorageInfo { Self { backend } } - /// Returns the receipts of the current block - pub fn current_receipts(&self) -> Option> { - self.backend.mined_receipts(self.backend.best_hash()) - } - - /// Returns the current block - pub fn current_block(&self) -> Option { - self.backend.get_block(self.backend.best_number()) - } - /// Returns the receipts of the block with the given hash pub fn receipts(&self, hash: B256) -> Option> { self.backend.mined_receipts(hash) diff --git a/crates/anvil/src/eth/backend/mem/storage.rs b/crates/anvil/src/eth/backend/mem/storage.rs index 252435291cc68..937cb5fdf7918 100644 --- a/crates/anvil/src/eth/backend/mem/storage.rs +++ b/crates/anvil/src/eth/backend/mem/storage.rs @@ -486,11 +486,6 @@ impl Blockchain { pub fn get_transaction_by_hash(&self, hash: &B256) -> Option { self.storage.read().transactions.get(hash).cloned() } - - /// Returns the total number of blocks - pub fn blocks_count(&self) -> usize { - self.storage.read().blocks.len() - } } /// Represents the outcome of mining a new block diff --git a/crates/cheatcodes/src/config.rs b/crates/cheatcodes/src/config.rs index 1ad98cd93e92b..18fa37a6878ec 100644 --- a/crates/cheatcodes/src/config.rs +++ b/crates/cheatcodes/src/config.rs @@ -221,77 +221,6 @@ impl CheatsConfig { } Ok(urls) } - - /// Initialize default chain data (similar to initializeStdChains in Solidity) - pub fn initialize_chain_data(&mut self) { - if !self.chains.is_empty() { - return; // Already initialized - } - - // Use the same function to create chains - let chains = create_default_chains(); - - // Add all chains to the config - for (alias, data) in chains { - self.set_chain_with_default_rpc_url(&alias, data); - } - } - - /// Set chain with default RPC URL (similar to setChainWithDefaultRpcUrl in Solidity) - pub fn set_chain_with_default_rpc_url(&mut self, alias: &str, data: ChainData) { - // Store the default RPC URL is already stored in the data - // No need to clone it separately - - // Add chain data - self.set_chain_data(alias, data); - } - - /// Set chain data for a specific alias - pub fn set_chain_data(&mut self, alias: &str, data: ChainData) { - // Remove old chain ID mapping if it exists - if let Some(old_data) = self.chains.get(alias) { - self.chain_id_to_alias.remove(&old_data.chain_id); - } - - // Add new mappings - self.chain_id_to_alias.insert(data.chain_id, alias.to_string()); - self.chains.insert(alias.to_string(), data); - } - - /// Get chain data by alias - pub fn get_chain_data_by_alias_non_mut(&self, alias: &str) -> Result { - // Initialize chains if not already done - if self.chains.is_empty() { - // Create a temporary copy with initialized chains - // This is inefficient but handles the edge case - let temp_chains = create_default_chains(); - - if let Some(data) = temp_chains.get(alias) { - return Ok(data.clone()); - } - } else { - // Normal path - chains are initialized - if let Some(data) = self.chains.get(alias) { - return Ok(data.clone()); - } - } - - // Chain not found in either case - Err(fmt_err!("vm.getChain: Chain with alias \"{}\" not found", alias)) - } - - /// Get RPC URL for an alias - pub fn get_rpc_url_non_mut(&self, alias: &str) -> Result { - // Try to get from config first - match self.rpc_endpoint(alias) { - Ok(endpoint) => Ok(endpoint.url()?), - Err(_) => { - // If not in config, try to get default URL - let chain_data = self.get_chain_data_by_alias_non_mut(alias)?; - Ok(chain_data.default_rpc_url) - } - } - } } impl Default for CheatsConfig { @@ -322,393 +251,6 @@ impl Default for CheatsConfig { } } -// Helper function to set default chains -fn create_default_chains() -> HashMap { - let mut chains = HashMap::new(); - - // Define all chains in one place - chains.insert( - "anvil".to_string(), - ChainData { - name: "Anvil".to_string(), - chain_id: 31337, - default_rpc_url: "http://127.0.0.1:8545".to_string(), - }, - ); - - chains.insert( - "mainnet".to_string(), - ChainData { - name: "Mainnet".to_string(), - chain_id: 1, - default_rpc_url: "https://eth.llamarpc.com".to_string(), - }, - ); - - chains.insert( - "sepolia".to_string(), - ChainData { - name: "Sepolia".to_string(), - chain_id: 11155111, - default_rpc_url: "https://sepolia.infura.io/v3/b9794ad1ddf84dfb8c34d6bb5dca2001" - .to_string(), - }, - ); - - chains.insert( - "holesky".to_string(), - ChainData { - name: "Holesky".to_string(), - chain_id: 17000, - default_rpc_url: "https://rpc.holesky.ethpandaops.io".to_string(), - }, - ); - - chains.insert( - "optimism".to_string(), - ChainData { - name: "Optimism".to_string(), - chain_id: 10, - default_rpc_url: "https://mainnet.optimism.io".to_string(), - }, - ); - - chains.insert( - "optimism_sepolia".to_string(), - ChainData { - name: "Optimism Sepolia".to_string(), - chain_id: 11155420, - default_rpc_url: "https://sepolia.optimism.io".to_string(), - }, - ); - - chains.insert( - "arbitrum_one".to_string(), - ChainData { - name: "Arbitrum One".to_string(), - chain_id: 42161, - default_rpc_url: "https://arb1.arbitrum.io/rpc".to_string(), - }, - ); - - chains.insert( - "arbitrum_one_sepolia".to_string(), - ChainData { - name: "Arbitrum One Sepolia".to_string(), - chain_id: 421614, - default_rpc_url: "https://sepolia-rollup.arbitrum.io/rpc".to_string(), - }, - ); - - chains.insert( - "arbitrum_nova".to_string(), - ChainData { - name: "Arbitrum Nova".to_string(), - chain_id: 42170, - default_rpc_url: "https://nova.arbitrum.io/rpc".to_string(), - }, - ); - - chains.insert( - "polygon".to_string(), - ChainData { - name: "Polygon".to_string(), - chain_id: 137, - default_rpc_url: "https://polygon-rpc.com".to_string(), - }, - ); - - chains.insert( - "polygon_amoy".to_string(), - ChainData { - name: "Polygon Amoy".to_string(), - chain_id: 80002, - default_rpc_url: "https://rpc-amoy.polygon.technology".to_string(), - }, - ); - - chains.insert( - "avalanche".to_string(), - ChainData { - name: "Avalanche".to_string(), - chain_id: 43114, - default_rpc_url: "https://api.avax.network/ext/bc/C/rpc".to_string(), - }, - ); - - chains.insert( - "avalanche_fuji".to_string(), - ChainData { - name: "Avalanche Fuji".to_string(), - chain_id: 43113, - default_rpc_url: "https://api.avax-test.network/ext/bc/C/rpc".to_string(), - }, - ); - - chains.insert( - "bnb_smart_chain".to_string(), - ChainData { - name: "BNB Smart Chain".to_string(), - chain_id: 56, - default_rpc_url: "https://bsc-dataseed1.binance.org".to_string(), - }, - ); - - chains.insert( - "bnb_smart_chain_testnet".to_string(), - ChainData { - name: "BNB Smart Chain Testnet".to_string(), - chain_id: 97, - default_rpc_url: "https://rpc.ankr.com/bsc_testnet_chapel".to_string(), - }, - ); - - chains.insert( - "gnosis_chain".to_string(), - ChainData { - name: "Gnosis Chain".to_string(), - chain_id: 100, - default_rpc_url: "https://rpc.gnosischain.com".to_string(), - }, - ); - - chains.insert( - "moonbeam".to_string(), - ChainData { - name: "Moonbeam".to_string(), - chain_id: 1284, - default_rpc_url: "https://rpc.api.moonbeam.network".to_string(), - }, - ); - - chains.insert( - "moonriver".to_string(), - ChainData { - name: "Moonriver".to_string(), - chain_id: 1285, - default_rpc_url: "https://rpc.api.moonriver.moonbeam.network".to_string(), - }, - ); - - chains.insert( - "moonbase".to_string(), - ChainData { - name: "Moonbase".to_string(), - chain_id: 1287, - default_rpc_url: "https://rpc.testnet.moonbeam.network".to_string(), - }, - ); - - chains.insert( - "base_sepolia".to_string(), - ChainData { - name: "Base Sepolia".to_string(), - chain_id: 84532, - default_rpc_url: "https://sepolia.base.org".to_string(), - }, - ); - - chains.insert( - "base".to_string(), - ChainData { - name: "Base".to_string(), - chain_id: 8453, - default_rpc_url: "https://mainnet.base.org".to_string(), - }, - ); - - chains.insert( - "blast_sepolia".to_string(), - ChainData { - name: "Blast Sepolia".to_string(), - chain_id: 168587773, - default_rpc_url: "https://sepolia.blast.io".to_string(), - }, - ); - - chains.insert( - "blast".to_string(), - ChainData { - name: "Blast".to_string(), - chain_id: 81457, - default_rpc_url: "https://rpc.blast.io".to_string(), - }, - ); - - chains.insert( - "fantom_opera".to_string(), - ChainData { - name: "Fantom Opera".to_string(), - chain_id: 250, - default_rpc_url: "https://rpc.ankr.com/fantom/".to_string(), - }, - ); - - chains.insert( - "fantom_opera_testnet".to_string(), - ChainData { - name: "Fantom Opera Testnet".to_string(), - chain_id: 4002, - default_rpc_url: "https://rpc.ankr.com/fantom_testnet/".to_string(), - }, - ); - - chains.insert( - "fraxtal".to_string(), - ChainData { - name: "Fraxtal".to_string(), - chain_id: 252, - default_rpc_url: "https://rpc.frax.com".to_string(), - }, - ); - - chains.insert( - "fraxtal_testnet".to_string(), - ChainData { - name: "Fraxtal Testnet".to_string(), - chain_id: 2522, - default_rpc_url: "https://rpc.testnet.frax.com".to_string(), - }, - ); - - chains.insert( - "berachain_bartio_testnet".to_string(), - ChainData { - name: "Berachain bArtio Testnet".to_string(), - chain_id: 80084, - default_rpc_url: "https://bartio.rpc.berachain.com".to_string(), - }, - ); - - chains.insert( - "flare".to_string(), - ChainData { - name: "Flare".to_string(), - chain_id: 14, - default_rpc_url: "https://flare-api.flare.network/ext/C/rpc".to_string(), - }, - ); - - chains.insert( - "flare_coston2".to_string(), - ChainData { - name: "Flare Coston2".to_string(), - chain_id: 114, - default_rpc_url: "https://coston2-api.flare.network/ext/C/rpc".to_string(), - }, - ); - - chains.insert( - "mode".to_string(), - ChainData { - name: "Mode".to_string(), - chain_id: 34443, - default_rpc_url: "https://mode.drpc.org".to_string(), - }, - ); - - chains.insert( - "mode_sepolia".to_string(), - ChainData { - name: "Mode Sepolia".to_string(), - chain_id: 919, - default_rpc_url: "https://sepolia.mode.network".to_string(), - }, - ); - - chains.insert( - "zora".to_string(), - ChainData { - name: "Zora".to_string(), - chain_id: 7777777, - default_rpc_url: "https://zora.drpc.org".to_string(), - }, - ); - - chains.insert( - "zora_sepolia".to_string(), - ChainData { - name: "Zora Sepolia".to_string(), - chain_id: 999999999, - default_rpc_url: "https://sepolia.rpc.zora.energy".to_string(), - }, - ); - - chains.insert( - "race".to_string(), - ChainData { - name: "Race".to_string(), - chain_id: 6805, - default_rpc_url: "https://racemainnet.io".to_string(), - }, - ); - - chains.insert( - "race_sepolia".to_string(), - ChainData { - name: "Race Sepolia".to_string(), - chain_id: 6806, - default_rpc_url: "https://racemainnet.io".to_string(), - }, - ); - - chains.insert( - "metal".to_string(), - ChainData { - name: "Metal".to_string(), - chain_id: 1750, - default_rpc_url: "https://metall2.drpc.org".to_string(), - }, - ); - - chains.insert( - "metal_sepolia".to_string(), - ChainData { - name: "Metal Sepolia".to_string(), - chain_id: 1740, - default_rpc_url: "https://testnet.rpc.metall2.com".to_string(), - }, - ); - - chains.insert( - "binary".to_string(), - ChainData { - name: "Binary".to_string(), - chain_id: 624, - default_rpc_url: "https://rpc.zero.thebinaryholdings.com".to_string(), - }, - ); - - chains.insert( - "binary_sepolia".to_string(), - ChainData { - name: "Binary Sepolia".to_string(), - chain_id: 625, - default_rpc_url: "https://rpc.zero.thebinaryholdings.com".to_string(), - }, - ); - - chains.insert( - "orderly".to_string(), - ChainData { - name: "Orderly".to_string(), - chain_id: 291, - default_rpc_url: "https://rpc.orderly.network".to_string(), - }, - ); - - chains.insert( - "orderly_sepolia".to_string(), - ChainData { - name: "Orderly Sepolia".to_string(), - chain_id: 4460, - default_rpc_url: "https://testnet-rpc.orderly.org".to_string(), - }, - ); - - chains -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/chisel/src/session.rs b/crates/chisel/src/session.rs index 2f293c1cd9172..be8152dc242b7 100644 --- a/crates/chisel/src/session.rs +++ b/crates/chisel/src/session.rs @@ -35,20 +35,6 @@ impl ChiselSession { Ok(Self { session_source: SessionSource::new(solc, config), id: None }) } - /// Render the full source code for the current session. - /// - /// ### Returns - /// - /// Returns the full, flattened source code for the current session. - /// - /// ### Notes - /// - /// This function will not panic, but will return a blank string if the - /// session's [SessionSource] is None. - pub fn contract_source(&self) -> String { - self.session_source.to_repl_source() - } - /// Clears the cache directory /// /// ### WARNING diff --git a/crates/chisel/src/session_source.rs b/crates/chisel/src/session_source.rs index f6e36395c507e..0575a1ce14fed 100644 --- a/crates/chisel/src/session_source.rs +++ b/crates/chisel/src/session_source.rs @@ -428,37 +428,6 @@ impl SessionSource { Ok(generated_output) } - /// Convert the [SessionSource] to a valid Script contract - /// - /// ### Returns - /// - /// The [SessionSource] represented as a Forge Script contract. - pub fn to_script_source(&self) -> String { - let Version { major, minor, patch, .. } = self.solc.version; - let Self { contract_name, global_code, top_level_code, run_code, config, .. } = self; - - let script_import = - if !config.no_vm { "import {Script} from \"forge-std/Script.sol\";\n" } else { "" }; - - format!( - r#" -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^{major}.{minor}.{patch}; - -{script_import} -{global_code} - -contract {contract_name} is Script {{ - {top_level_code} - - /// @notice Script entry point - function run() public {{ - {run_code} - }} -}}"#, - ) - } - /// Convert the [SessionSource] to a valid REPL contract /// /// ### Returns @@ -585,7 +554,7 @@ contract {contract_name} {{ /// ### Returns /// /// A vector containing tuples of the inner expressions' names, types, and storage locations. - pub fn get_statement_definitions(statement: &pt::Statement) -> Vec<(String, pt::Expression)> { + fn get_statement_definitions(statement: &pt::Statement) -> Vec<(String, pt::Expression)> { match statement { pt::Statement::VariableDefinition(_, def, _) => { vec![(def.name.safe_unwrap().name.clone(), def.ty.clone())] diff --git a/crates/cli/src/utils/cmd.rs b/crates/cli/src/utils/cmd.rs index 1396d964db8aa..37c3f3e3f6dcc 100644 --- a/crates/cli/src/utils/cmd.rs +++ b/crates/cli/src/utils/cmd.rs @@ -6,10 +6,7 @@ use foundry_common::{ TestFunctionExt, }; use foundry_compilers::{ - artifacts::{CompactBytecode, Settings}, - cache::{CacheEntry, CompilerCache}, - utils::read_json_file, - Artifact, ArtifactId, ProjectCompileOutput, + artifacts::CompactBytecode, utils::read_json_file, Artifact, ArtifactId, ProjectCompileOutput, }; use foundry_config::{error::ExtractConfigError, figment::Figment, Chain, Config, NamedChain}; use foundry_debugger::Debugger; @@ -73,47 +70,6 @@ pub fn remove_contract( Ok((abi, bin, id)) } -/// Helper function for finding a contract by ContractName -// TODO: Is there a better / more ergonomic way to get the artifacts given a project and a -// contract name? -pub fn get_cached_entry_by_name( - cache: &CompilerCache, - name: &str, -) -> Result<(PathBuf, CacheEntry)> { - let mut cached_entry = None; - let mut alternatives = Vec::new(); - - for (abs_path, entry) in &cache.files { - for artifact_name in entry.artifacts.keys() { - if artifact_name == name { - if cached_entry.is_some() { - eyre::bail!( - "contract with duplicate name `{}`. please pass the path instead", - name - ) - } - cached_entry = Some((abs_path.to_owned(), entry.to_owned())); - } else { - alternatives.push(artifact_name); - } - } - } - - if let Some(entry) = cached_entry { - return Ok(entry); - } - - let mut err = format!("could not find artifact: `{name}`"); - if let Some(suggestion) = super::did_you_mean(name, &alternatives).pop() { - err = format!( - r#"{err} - - Did you mean `{suggestion}`?"# - ); - } - eyre::bail!(err) -} - /// Returns error if constructor has arguments. pub fn ensure_clean_constructor(abi: &JsonAbi) -> Result<()> { if let Some(constructor) = &abi.constructor { @@ -139,10 +95,6 @@ pub fn needs_setup(abi: &JsonAbi) -> bool { setup_fns.len() == 1 && setup_fns[0].name == "setUp" } -pub fn eta_key(state: &indicatif::ProgressState, f: &mut dyn Write) { - write!(f, "{:.1}s", state.eta().as_secs_f64()).unwrap() -} - pub fn init_progress(len: u64, label: &str) -> indicatif::ProgressBar { let pb = indicatif::ProgressBar::new(len); let mut template = @@ -153,12 +105,16 @@ pub fn init_progress(len: u64, label: &str) -> indicatif::ProgressBar { pb.set_style( indicatif::ProgressStyle::with_template(&template) .unwrap() - .with_key("eta", crate::utils::eta_key) + .with_key("eta", eta_key) .progress_chars("#>-"), ); pb } +fn eta_key(state: &indicatif::ProgressState, f: &mut dyn Write) { + write!(f, "{:.1}s", state.eta().as_secs_f64()).unwrap() +} + /// True if the network calculates gas costs differently. pub fn has_different_gas_calc(chain_id: u64) -> bool { if let Some(chain) = Chain::from(chain_id).named() { diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index 391d519d05621..40a9cb4514b8b 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -315,25 +315,6 @@ impl<'a> Git<'a> { Ok(PathBuf::from(output)) } - pub fn clone_with_branch( - shallow: bool, - from: impl AsRef, - branch: impl AsRef, - to: Option>, - ) -> Result<()> { - Self::cmd_no_root() - .stderr(Stdio::inherit()) - .args(["clone", "--recurse-submodules"]) - .args(shallow.then_some("--depth=1")) - .args(shallow.then_some("--shallow-submodules")) - .arg("-b") - .arg(branch) - .arg(from) - .args(to) - .exec() - .map(drop) - } - pub fn clone( shallow: bool, from: impl AsRef, diff --git a/crates/common/src/evm.rs b/crates/common/src/evm.rs index 4a7e459e8fa16..8903fb196cd83 100644 --- a/crates/common/src/evm.rs +++ b/crates/common/src/evm.rs @@ -2,7 +2,6 @@ use alloy_primitives::{map::HashMap, Address, B256, U256}; use clap::Parser; -use eyre::ContextCompat; use foundry_config::{ figment::{ self, @@ -271,13 +270,6 @@ pub struct EnvArgs { pub disable_block_gas_limit: bool, } -impl EvmArgs { - /// Ensures that fork url exists and returns its reference. - pub fn ensure_fork_url(&self) -> eyre::Result<&String> { - self.fork_url.as_ref().wrap_err("Missing `--fork-url` field.") - } -} - /// We have to serialize chain IDs and not names because when extracting an EVM `Env`, it expects /// `chain_id` to be `u64`. fn id(chain: &Option, s: S) -> Result { diff --git a/crates/common/src/provider/mod.rs b/crates/common/src/provider/mod.rs index 0603b91f97d2d..497f5d5543047 100644 --- a/crates/common/src/provider/mod.rs +++ b/crates/common/src/provider/mod.rs @@ -216,13 +216,6 @@ impl ProviderBuilder { self } - /// Sets aggressive `max_retry` and `initial_backoff` values - /// - /// This is only recommend for local dev nodes - pub fn aggressive(self) -> Self { - self.max_retry(100).initial_backoff(100).local(true) - } - /// Sets the JWT secret pub fn jwt(mut self, jwt: impl Into) -> Self { self.jwt = Some(jwt.into()); diff --git a/crates/common/src/serde_helpers.rs b/crates/common/src/serde_helpers.rs index 90634de397424..602d37468d2a4 100644 --- a/crates/common/src/serde_helpers.rs +++ b/crates/common/src/serde_helpers.rs @@ -1,7 +1,7 @@ //! Misc Serde helpers for foundry crates. use alloy_primitives::U256; -use serde::{de, Deserialize, Deserializer}; +use serde::{Deserialize, Deserializer}; use std::str::FromStr; /// Helper type to parse both `u64` and `U256` @@ -37,47 +37,6 @@ impl FromStr for Numeric { } } -/// Deserializes the input into an `Option`, using [`from_int_or_hex`] to deserialize the -/// inner value. -pub fn from_int_or_hex_opt<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - match Option::::deserialize(deserializer)? { - Some(val) => val.try_into_u256().map(Some), - None => Ok(None), - } -} - -/// An enum that represents either a [serde_json::Number] integer, or a hex [U256]. -#[derive(Debug, Deserialize)] -#[serde(untagged)] -pub enum NumberOrHexU256 { - /// An integer - Int(serde_json::Number), - /// A hex U256 - Hex(U256), -} - -impl NumberOrHexU256 { - /// Tries to convert this into a [U256]]. - pub fn try_into_u256(self) -> Result { - match self { - Self::Int(num) => U256::from_str(num.to_string().as_str()).map_err(E::custom), - Self::Hex(val) => Ok(val), - } - } -} - -/// Deserializes the input into a U256, accepting both 0x-prefixed hex and decimal strings with -/// arbitrary precision, defined by serde_json's [`Number`](serde_json::Number). -pub fn from_int_or_hex<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - NumberOrHexU256::deserialize(deserializer)?.try_into_u256() -} - /// Helper type to deserialize sequence of numbers #[derive(Deserialize)] #[serde(untagged)] diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index 931c29948ff01..cf102cc5c30b7 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -1,7 +1,7 @@ //! terminal utils use foundry_compilers::{ artifacts::remappings::Remapping, - report::{self, BasicStdoutReporter, Reporter}, + report::{self, Reporter}, }; use foundry_config::find_project_root; use itertools::Itertools; @@ -210,19 +210,6 @@ impl Reporter for SpinnerReporter { } } -/// If the output medium is terminal, this calls `f` within the [`SpinnerReporter`] that displays a -/// spinning cursor to display solc progress. -/// -/// If no terminal is available this falls back to common `println!` in [`BasicStdoutReporter`]. -pub fn with_spinner_reporter(f: impl FnOnce() -> T) -> T { - let reporter = if TERM_SETTINGS.indicate_progress { - report::Report::new(SpinnerReporter::spawn()) - } else { - report::Report::new(BasicStdoutReporter::default()) - }; - report::with_scoped(&reporter, f) -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/config/src/etherscan.rs b/crates/config/src/etherscan.rs index 76d50b09bc934..370a3406607d1 100644 --- a/crates/config/src/etherscan.rs +++ b/crates/config/src/etherscan.rs @@ -290,14 +290,6 @@ impl ResolvedEtherscanConfig { }) } - /// Sets the chain value and consumes the type - /// - /// This is only used to set derive the appropriate Cache path for the etherscan client - pub fn with_chain(mut self, chain: impl Into) -> Self { - self.set_chain(chain); - self - } - /// Sets the chain value pub fn set_chain(&mut self, chain: impl Into) -> &mut Self { let chain = chain.into(); @@ -361,22 +353,6 @@ pub enum EtherscanApiKey { } impl EtherscanApiKey { - /// Returns the key variant - pub fn as_key(&self) -> Option<&str> { - match self { - Self::Key(url) => Some(url), - Self::Env(_) => None, - } - } - - /// Returns the env variant - pub fn as_env(&self) -> Option<&str> { - match self { - Self::Env(val) => Some(val), - Self::Key(_) => None, - } - } - /// Returns the key this type holds /// /// # Error diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index fd495e2fba837..d1a343e12678a 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1107,17 +1107,6 @@ impl Config { evm_spec_id(self.evm_version, self.odyssey) } - /// Returns whether the compiler version should be auto-detected - /// - /// Returns `false` if `solc_version` is explicitly set, otherwise returns the value of - /// `auto_detect_solc` - pub fn is_auto_detect(&self) -> bool { - if self.solc.is_some() { - return false; - } - self.auto_detect_solc - } - /// Whether caching should be enabled for the given chain id pub fn enable_caching(&self, endpoint: &str, chain_id: impl Into) -> bool { !self.no_storage_caching && @@ -1421,34 +1410,6 @@ impl Config { .unwrap_or_default() } - /// Returns the remapping for the project's _src_ directory - /// - /// **Note:** this will add an additional `/=` remapping here so imports that - /// look like `import {Foo} from "src/Foo.sol";` are properly resolved. - /// - /// This is due the fact that `solc`'s VFS resolves [direct imports](https://docs.soliditylang.org/en/develop/path-resolution.html#direct-imports) that start with the source directory's name. - pub fn get_source_dir_remapping(&self) -> Option { - get_dir_remapping(&self.src) - } - - /// Returns the remapping for the project's _test_ directory, but only if it exists - pub fn get_test_dir_remapping(&self) -> Option { - if self.root.join(&self.test).exists() { - get_dir_remapping(&self.test) - } else { - None - } - } - - /// Returns the remapping for the project's _script_ directory, but only if it exists - pub fn get_script_dir_remapping(&self) -> Option { - if self.root.join(&self.script).exists() { - get_dir_remapping(&self.script) - } else { - None - } - } - /// Returns the `Optimizer` based on the configured settings /// /// Note: optimizer details can be set independently of `enabled` @@ -1654,16 +1615,6 @@ impl Config { } } - /// Returns the default config that uses dapptools style paths - pub fn dapptools() -> Self { - Self { - chain: Some(Chain::from_id(99)), - block_timestamp: 0, - block_number: 0, - ..Self::default() - } - } - /// Extracts a basic subset of the config, used for initialisations. /// /// # Example @@ -1867,34 +1818,6 @@ impl Config { Ok(path) } - /// Returns the path to the `foundry.toml` file, the file is searched for in - /// the current working directory and all parent directories until the root, - /// and the first hit is used. - /// - /// If this search comes up empty, then it checks if a global `foundry.toml` exists at - /// `~/.foundry/foundry.toml`, see [`Self::foundry_dir_toml`]. - pub fn find_config_file() -> Option { - fn find(path: &Path) -> Option { - if path.is_absolute() { - return match path.is_file() { - true => Some(path.to_path_buf()), - false => None, - }; - } - let cwd = std::env::current_dir().ok()?; - let mut cwd = cwd.as_path(); - loop { - let file_path = cwd.join(path); - if file_path.is_file() { - return Some(file_path); - } - cwd = cwd.parent()?; - } - } - find(Env::var_or("FOUNDRY_CONFIG", Self::FILE_NAME).as_ref()) - .or_else(|| Self::foundry_dir_toml().filter(|p| p.exists())) - } - /// Clears the foundry cache. pub fn clean_foundry_cache() -> eyre::Result<()> { if let Some(cache_dir) = Self::foundry_cache_dir() { diff --git a/crates/config/src/utils.rs b/crates/config/src/utils.rs index bcb20ab698afb..9ce407a055e86 100644 --- a/crates/config/src/utils.rs +++ b/crates/config/src/utils.rs @@ -154,24 +154,6 @@ pub fn foundry_toml_dirs(root: impl AsRef) -> Vec { .collect() } -/// Returns a remapping for the given dir -pub(crate) fn get_dir_remapping(dir: impl AsRef) -> Option { - let dir = dir.as_ref(); - if let Some(dir_name) = dir.file_name().and_then(|s| s.to_str()).filter(|s| !s.is_empty()) { - let mut r = Remapping { - context: None, - name: format!("{dir_name}/"), - path: format!("{}", dir.display()), - }; - if !r.path.ends_with('/') { - r.path.push('/') - } - Some(r) - } else { - None - } -} - /// Deserialize stringified percent. The value must be between 0 and 100 inclusive. pub(crate) fn deserialize_stringified_percent<'de, D>(deserializer: D) -> Result where diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rs index 907232cad7e98..1372590a99892 100644 --- a/crates/debugger/src/debugger.rs +++ b/crates/debugger/src/debugger.rs @@ -43,18 +43,6 @@ impl Debugger { } } - /// Starts the debugger TUI. Terminates the current process on failure or user exit. - pub fn run_tui_exit(mut self) -> ! { - let code = match self.try_run_tui() { - Ok(ExitReason::CharExit) => 0, - Err(e) => { - let _ = sh_eprintln!("{e}"); - 1 - } - }; - std::process::exit(code) - } - /// Starts the debugger TUI. pub fn try_run_tui(&mut self) -> Result { eyre::ensure!(!self.context.debug_arena.is_empty(), "debug arena is empty"); diff --git a/crates/debugger/src/lib.rs b/crates/debugger/src/lib.rs index 1c1bf9614ee2e..2bf11635d4a18 100644 --- a/crates/debugger/src/lib.rs +++ b/crates/debugger/src/lib.rs @@ -5,9 +5,6 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#[macro_use] -extern crate foundry_common; - #[macro_use] extern crate tracing; diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index 63b81e020083f..fd4bb807825b5 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -2,7 +2,6 @@ use crate::{DocBuilder, ParseItem, PreprocessorId, PreprocessorOutput}; use alloy_primitives::map::HashMap; use std::{ path::{Path, PathBuf}, - slice::IterMut, sync::Mutex, }; @@ -123,19 +122,6 @@ impl DocumentContent { } } } - - pub fn iter_items_mut(&mut self) -> ParseItemIterMut<'_> { - match self { - Self::Empty => ParseItemIterMut { next: None, other: None }, - Self::Single(item) => ParseItemIterMut { next: Some(item), other: None }, - Self::Constants(items) => { - ParseItemIterMut { next: None, other: Some(items.iter_mut()) } - } - Self::OverloadedFunctions(items) => { - ParseItemIterMut { next: None, other: Some(items.iter_mut()) } - } - } - } } #[derive(Debug)] @@ -159,27 +145,6 @@ impl<'a> Iterator for ParseItemIter<'a> { } } -#[derive(Debug)] -pub struct ParseItemIterMut<'a> { - next: Option<&'a mut ParseItem>, - other: Option>, -} - -impl<'a> Iterator for ParseItemIterMut<'a> { - type Item = &'a mut ParseItem; - - fn next(&mut self) -> Option { - if let Some(next) = self.next.take() { - return Some(next) - } - if let Some(other) = self.other.as_mut() { - return other.next() - } - - None - } -} - /// Read the preprocessor output variant from document context. /// Returns [None] if there is no output. macro_rules! read_context { diff --git a/crates/evm/core/src/backend/mod.rs b/crates/evm/core/src/backend/mod.rs index 892bf40c075bf..862615b0ede98 100644 --- a/crates/evm/core/src/backend/mod.rs +++ b/crates/evm/core/src/backend/mod.rs @@ -24,7 +24,7 @@ use revm::{ database::{CacheDB, DatabaseRef}, inspector::NoOpInspector, precompile::{PrecompileSpecId, Precompiles}, - primitives::{hardfork::SpecId, HashMap as Map, Log, KECCAK_EMPTY}, + primitives::{hardfork::SpecId, HashMap as Map, KECCAK_EMPTY}, state::{Account, AccountInfo, EvmState, EvmStorageSlot}, Database, DatabaseCommit, JournalEntry, }; @@ -664,11 +664,6 @@ impl Backend { self.active_fork_ids.map(|(i, _)| i == id).unwrap_or_default() } - /// Returns `true` if the `Backend` is currently in forking mode - pub fn is_in_forking_mode(&self) -> bool { - self.active_fork().is_some() - } - /// Returns the currently active `Fork`, if any pub fn active_fork(&self) -> Option<&Fork> { self.active_fork_ids.map(|(_, idx)| self.inner.get_fork(idx)) @@ -718,29 +713,6 @@ impl Backend { } } - /// Since each `Fork` tracks logs separately, we need to merge them to get _all_ of them - pub fn merged_logs(&self, mut logs: Vec) -> Vec { - if let Some((_, active)) = self.active_fork_ids { - let mut all_logs = Vec::with_capacity(logs.len()); - - self.inner - .forks - .iter() - .enumerate() - .filter_map(|(idx, f)| f.as_ref().map(|f| (idx, f))) - .for_each(|(idx, f)| { - if idx == active { - all_logs.append(&mut logs); - } else { - all_logs.extend(f.journaled_state.logs.clone()) - } - }); - return all_logs; - } - - logs - } - /// Initializes settings we need to keep track of. /// /// We need to track these mainly to prevent issues when switching between different evms @@ -1737,23 +1709,6 @@ impl BackendInner { self.set_fork(idx, fork) } - /// Updates the fork and the local mapping and returns the new index for the `fork_db` - pub fn update_fork_mapping( - &mut self, - id: LocalForkId, - fork_id: ForkId, - db: ForkDB, - journaled_state: JournaledState, - ) -> ForkLookupIndex { - let idx = self.forks.len(); - self.issued_local_fork_ids.insert(id, fork_id.clone()); - self.created_forks.insert(fork_id, idx); - - let fork = Fork { db, journaled_state }; - self.forks.push(Some(fork)); - idx - } - pub fn roll_fork( &mut self, id: LocalForkId, diff --git a/crates/evm/core/src/decode.rs b/crates/evm/core/src/decode.rs index c3dab88f49cd5..708dabf40904c 100644 --- a/crates/evm/core/src/decode.rs +++ b/crates/evm/core/src/decode.rs @@ -47,15 +47,11 @@ impl fmt::Display for SkipReason { /// Decode a set of logs, only returning logs from DSTest logging events and Hardhat's `console.log` pub fn decode_console_logs(logs: &[Log]) -> Vec { - logs.iter().filter_map(decode_console_log).collect() -} - -/// Decode a single log. -/// -/// This function returns [None] if it is not a DSTest log or the result of a Hardhat -/// `console.log`. -pub fn decode_console_log(log: &Log) -> Option { - console::ds::ConsoleEvents::decode_log(log).ok().map(|decoded| decoded.to_string()) + logs.iter() + .filter_map(|log| { + console::ds::ConsoleEvents::decode_log(log).ok().map(|decoded| decoded.to_string()) + }) + .collect() } /// Decodes revert data. @@ -94,16 +90,6 @@ impl RevertDecoder { self } - /// Sets the ABI to use for error decoding, if it is present. - /// - /// Note that this is decently expensive as it will hash all errors for faster indexing. - pub fn with_abi_opt(mut self, abi: Option<&JsonAbi>) -> Self { - if let Some(abi) = abi { - self.extend_from_abi(abi); - } - self - } - /// Extends the decoder with the given ABI's custom errors. pub fn extend_from_abis<'a>(&mut self, abi: impl IntoIterator) { for abi in abi { diff --git a/crates/evm/evm/src/executors/mod.rs b/crates/evm/evm/src/executors/mod.rs index bfd57a4a0ccee..21b965e4b0793 100644 --- a/crates/evm/evm/src/executors/mod.rs +++ b/crates/evm/evm/src/executors/mod.rs @@ -852,14 +852,6 @@ impl RawCallResult { } } - /// Unpacks an execution result. - pub fn from_execution_result(r: Result) -> (Self, Option) { - match r { - Ok(r) => (r, None), - Err(e) => (e.raw, Some(e.reason)), - } - } - /// Converts the result of the call into an `EvmError`. pub fn into_evm_error(self, rd: Option<&RevertDecoder>) -> EvmError { if let Some(reason) = SkipReason::decode(&self.result) { diff --git a/crates/evm/fuzz/src/lib.rs b/crates/evm/fuzz/src/lib.rs index bce67dfe320fa..b11ba81456172 100644 --- a/crates/evm/fuzz/src/lib.rs +++ b/crates/evm/fuzz/src/lib.rs @@ -284,11 +284,6 @@ impl FuzzedCases { &self.cases } - #[inline] - pub fn into_cases(self) -> Vec { - self.cases - } - /// Get the last [FuzzCase] #[inline] pub fn last(&self) -> Option<&FuzzCase> { @@ -318,32 +313,6 @@ impl FuzzedCases { .map(|c| if with_stipend { c.gas } else { c.gas.saturating_sub(c.stipend) }) .collect() } - - /// Returns the case with the highest gas usage - #[inline] - pub fn highest(&self) -> Option<&FuzzCase> { - self.cases.last() - } - - /// Returns the case with the lowest gas usage - #[inline] - pub fn lowest(&self) -> Option<&FuzzCase> { - self.cases.first() - } - - /// Returns the highest amount of gas spent on a fuzz case - #[inline] - pub fn highest_gas(&self, with_stipend: bool) -> u64 { - self.highest() - .map(|c| if with_stipend { c.gas } else { c.gas - c.stipend }) - .unwrap_or_default() - } - - /// Returns the lowest amount of gas spent on a fuzz case - #[inline] - pub fn lowest_gas(&self) -> u64 { - self.lowest().map(|c| c.gas).unwrap_or_default() - } } /// Fixtures to be used for fuzz tests. diff --git a/crates/evm/traces/src/debug/sources.rs b/crates/evm/traces/src/debug/sources.rs index cfd7056e5a8b6..40064f62409dd 100644 --- a/crates/evm/traces/src/debug/sources.rs +++ b/crates/evm/traces/src/debug/sources.rs @@ -248,17 +248,6 @@ impl ContractSources { }) } - /// Returns all (name, bytecode, source) sets. - pub fn entries(&self) -> impl Iterator { - self.artifacts_by_name.iter().flat_map(|(name, artifacts)| { - artifacts.iter().filter_map(|artifact| { - let source = - self.sources_by_id.get(artifact.build_id.as_str())?.get(&artifact.file_id)?; - Some((name.as_str(), artifact, source.as_ref())) - }) - }) - } - pub fn find_source_mapping( &self, contract_name: &str, diff --git a/crates/evm/traces/src/decoder/mod.rs b/crates/evm/traces/src/decoder/mod.rs index 44b9c9cd729b6..07dc86d2374ad 100644 --- a/crates/evm/traces/src/decoder/mod.rs +++ b/crates/evm/traces/src/decoder/mod.rs @@ -1,6 +1,6 @@ use crate::{ debug::DebugTraceIdentifier, - identifier::{IdentifiedAddress, LocalTraceIdentifier, SignaturesIdentifier, TraceIdentifier}, + identifier::{IdentifiedAddress, SignaturesIdentifier, TraceIdentifier}, CallTrace, CallTraceArena, CallTraceNode, DecodedCallData, }; use alloy_dyn_abi::{DecodedEvent, DynSolValue, EventExt, FunctionExt, JsonAbiExt}; @@ -69,12 +69,6 @@ impl CallTraceDecoderBuilder { self } - /// Add known contracts to the decoder from a `LocalTraceIdentifier`. - #[inline] - pub fn with_local_identifier_abis(self, identifier: &LocalTraceIdentifier<'_>) -> Self { - self.with_known_contracts(identifier.contracts()) - } - /// Sets the verbosity level of the decoder. #[inline] pub fn with_verbosity(mut self, level: u8) -> Self { diff --git a/crates/fmt/src/helpers.rs b/crates/fmt/src/helpers.rs index 1d036ba6b66d0..0514072448d67 100644 --- a/crates/fmt/src/helpers.rs +++ b/crates/fmt/src/helpers.rs @@ -65,24 +65,6 @@ pub fn format(src: &str) -> Result { Ok(output) } -/// Converts the start offset of a `Loc` to `(line, col)` -pub fn offset_to_line_column(content: &str, start: usize) -> (usize, usize) { - debug_assert!(content.len() > start); - - // first line is `1` - let mut line_counter = 1; - for (offset, c) in content.chars().enumerate() { - if c == '\n' { - line_counter += 1; - } - if offset > start { - return (line_counter, offset - start) - } - } - - unreachable!("content.len() > start") -} - /// Formats parser diagnostics pub fn format_diagnostics_report( content: &str, diff --git a/crates/fmt/src/lib.rs b/crates/fmt/src/lib.rs index 006b4db02abe8..0005daee1e286 100644 --- a/crates/fmt/src/lib.rs +++ b/crates/fmt/src/lib.rs @@ -20,8 +20,6 @@ pub use foundry_config::fmt::*; pub use comments::Comments; pub use formatter::{Formatter, FormatterError}; -pub use helpers::{ - format, format_diagnostics_report, format_to, offset_to_line_column, parse, parse2, Parsed, -}; +pub use helpers::{format, format_diagnostics_report, format_to, parse, parse2, Parsed}; pub use inline_config::InlineConfig; pub use visit::{Visitable, Visitor}; diff --git a/crates/forge/src/cmd/fmt.rs b/crates/forge/src/cmd/fmt.rs index 104c3224829c5..ccf64889702cb 100644 --- a/crates/forge/src/cmd/fmt.rs +++ b/crates/forge/src/cmd/fmt.rs @@ -54,7 +54,7 @@ impl FmtArgs { // Expand ignore globs and canonicalize from the get go let ignored = expand_globs(&config.root, config.fmt.ignore.iter())? .iter() - .flat_map(foundry_common::fs::canonicalize_path) + .flat_map(fs::canonicalize_path) .collect::>(); let cwd = std::env::current_dir()?; diff --git a/crates/forge/src/cmd/lint.rs b/crates/forge/src/cmd/lint.rs index 9de86faf276ec..73f277585a058 100644 --- a/crates/forge/src/cmd/lint.rs +++ b/crates/forge/src/cmd/lint.rs @@ -5,6 +5,7 @@ use forge_lint::{ sol::{SolLint, SolLintError, SolidityLinter}, }; use foundry_cli::utils::{FoundryPathExt, LoadConfig}; +use foundry_common::fs; use foundry_compilers::{solc::SolcLanguage, utils::SOLC_EXTENSIONS}; use foundry_config::{filter::expand_globs, impl_figment_convert_basic, lint::Severity}; use std::path::PathBuf; @@ -50,7 +51,7 @@ impl LintArgs { // Expand ignore globs and canonicalize from the get go let ignored = expand_globs(&config.root, config.lint.ignore.iter())? .iter() - .flat_map(foundry_common::fs::canonicalize_path) + .flat_map(fs::canonicalize_path) .collect::>(); let cwd = std::env::current_dir()?; diff --git a/crates/forge/src/cmd/test/filter.rs b/crates/forge/src/cmd/test/filter.rs index ec2e9b01b50e8..c75a71f250feb 100644 --- a/crates/forge/src/cmd/test/filter.rs +++ b/crates/forge/src/cmd/test/filter.rs @@ -185,11 +185,6 @@ impl ProjectPathsAwareFilter { &self.args_filter } - /// Returns the CLI arguments mutably. - pub fn args_mut(&mut self) -> &mut FilterArgs { - &mut self.args_filter - } - /// Returns the project paths. pub fn paths(&self) -> &ProjectPathsConfig { &self.paths diff --git a/crates/forge/src/multi_runner.rs b/crates/forge/src/multi_runner.rs index 7b10328d5908e..7346d3c80c33d 100644 --- a/crates/forge/src/multi_runner.rs +++ b/crates/forge/src/multi_runner.rs @@ -99,18 +99,6 @@ impl MultiContractRunner { .filter(|func| is_matching_test(func, filter)) } - /// Returns an iterator over all test functions in contracts that match the filter. - pub fn all_test_functions<'a: 'b, 'b>( - &'a self, - filter: &'b dyn TestFilter, - ) -> impl Iterator + 'b { - self.contracts - .iter() - .filter(|(id, _)| filter.matches_path(&id.source) && filter.matches_contract(&id.name)) - .flat_map(|(_, c)| c.abi.functions()) - .filter(|func| func.is_any_test()) - } - /// Returns all matching tests grouped by contract grouped by file (file -> (contract -> tests)) pub fn list(&self, filter: &dyn TestFilter) -> BTreeMap>> { self.matching_contracts(filter) diff --git a/crates/forge/src/result.rs b/crates/forge/src/result.rs index 90447fc26bfa0..e85d749c4890e 100644 --- a/crates/forge/src/result.rs +++ b/crates/forge/src/result.rs @@ -75,24 +75,6 @@ impl TestOutcome { self.results.values().flat_map(|suite| suite.tests()) } - /// Flattens the test outcome into a list of individual tests. - // TODO: Replace this with `tests` and make it return `TestRef<'_>` - pub fn into_tests_cloned(&self) -> impl Iterator + '_ { - self.results - .iter() - .flat_map(|(file, suite)| { - suite - .test_results - .iter() - .map(move |(sig, result)| (file.clone(), sig.clone(), result.clone())) - }) - .map(|(artifact_id, signature, result)| SuiteTestResult { - artifact_id, - signature, - result, - }) - } - /// Flattens the test outcome into a list of individual tests. pub fn into_tests(self) -> impl Iterator { self.results diff --git a/crates/forge/tests/cli/utils.rs b/crates/forge/tests/cli/utils.rs index 35b1bf73a7bfd..e812a858fcf97 100644 --- a/crates/forge/tests/cli/utils.rs +++ b/crates/forge/tests/cli/utils.rs @@ -79,16 +79,6 @@ impl EnvExternalities { }) } - pub fn arbitrum_goerli() -> Option { - Some(Self { - chain: NamedChain::ArbitrumGoerli, - rpc: network_rpc_key("arbitrum-goerli")?, - pk: network_private_key("arbitrum-goerli")?, - etherscan: etherscan_key(NamedChain::ArbitrumGoerli)?, - verifier: "blockscout".to_string(), - }) - } - pub fn mumbai() -> Option { Some(Self { chain: NamedChain::PolygonMumbai, diff --git a/crates/forge/tests/it/config.rs b/crates/forge/tests/it/config.rs index b0f9d8da20a80..e14471b3fc93d 100644 --- a/crates/forge/tests/it/config.rs +++ b/crates/forge/tests/it/config.rs @@ -36,10 +36,6 @@ impl TestConfig { self } - pub fn should_fail(self) -> Self { - self.set_should_fail(true) - } - pub fn set_should_fail(mut self, should_fail: bool) -> Self { self.should_fail = should_fail; self diff --git a/crates/forge/tests/it/test_helpers.rs b/crates/forge/tests/it/test_helpers.rs index 2043af8c01580..05e52ca983e92 100644 --- a/crates/forge/tests/it/test_helpers.rs +++ b/crates/forge/tests/it/test_helpers.rs @@ -5,10 +5,8 @@ use alloy_primitives::U256; use forge::{MultiContractRunner, MultiContractRunnerBuilder}; use foundry_cli::utils::install_crypto_provider; use foundry_compilers::{ - artifacts::{EvmVersion, Libraries, Settings}, - compilers::multi::MultiCompiler, - utils::RuntimeOrHandle, - Project, ProjectCompileOutput, SolcConfig, Vyper, + artifacts::EvmVersion, compilers::multi::MultiCompiler, utils::RuntimeOrHandle, Project, + ProjectCompileOutput, Vyper, }; use foundry_config::{ fs_permissions::PathPermission, Config, FsPermissions, FuzzConfig, FuzzDictionaryConfig, @@ -58,22 +56,6 @@ impl ForgeTestProfile { PathBuf::from(TESTDATA) } - /// Configures the solc settings for the test profile. - pub fn solc_config(&self) -> SolcConfig { - let libs = - ["fork/Fork.t.sol:DssExecLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4".to_string()]; - - let mut settings = - Settings { libraries: Libraries::parse(&libs).unwrap(), ..Default::default() }; - - if matches!(self, Self::Paris) { - settings.evm_version = Some(EvmVersion::Paris); - } - - let settings = SolcConfig::builder().settings(settings).build(); - SolcConfig { settings } - } - /// Build [Config] for test profile. /// /// Project source files are read from testdata/{profile_name} diff --git a/crates/linking/src/lib.rs b/crates/linking/src/lib.rs index 18cb47e764bf2..9e15b7877086c 100644 --- a/crates/linking/src/lib.rs +++ b/crates/linking/src/lib.rs @@ -271,13 +271,6 @@ impl<'a> Linker<'a> { ) -> Result { self.contracts.keys().map(|id| Ok((id.clone(), self.link(id, libraries)?))).collect() } - - pub fn get_linked_artifacts_cow( - &self, - libraries: &Libraries, - ) -> Result>, LinkerError> { - self.contracts.keys().map(|id| Ok((id.clone(), self.link(id, libraries)?))).collect() - } } #[cfg(test)] diff --git a/crates/sol-macro-gen/src/sol_macro_gen.rs b/crates/sol-macro-gen/src/sol_macro_gen.rs index 1e40d51169695..609fc0f02c15a 100644 --- a/crates/sol-macro-gen/src/sol_macro_gen.rs +++ b/crates/sol-macro-gen/src/sol_macro_gen.rs @@ -18,7 +18,6 @@ use std::{ env::temp_dir, fmt::Write, path::{Path, PathBuf}, - str::FromStr, }; use heck::ToSnakeCase; @@ -58,18 +57,6 @@ impl MultiSolMacroGen { Self { artifacts_path: artifacts_path.to_path_buf(), instances } } - pub fn populate_expansion(&mut self, bindings_path: &Path) -> Result<()> { - for instance in &mut self.instances { - let path = bindings_path.join(format!("{}.rs", instance.name.to_lowercase())); - let expansion = fs::read_to_string(path).wrap_err("Failed to read file")?; - - let tokens = TokenStream::from_str(&expansion) - .map_err(|e| eyre::eyre!("Failed to parse TokenStream: {e}"))?; - instance.expansion = Some(tokens); - } - Ok(()) - } - pub fn generate_bindings(&mut self, all_derives: bool) -> Result<()> { for instance in &mut self.instances { Self::generate_binding(instance, all_derives).wrap_err_with(|| { @@ -233,7 +220,7 @@ edition = "2021" } /// Attempts to detect the appropriate license. - pub fn parse_license_alias(license: &str) -> String { + fn parse_license_alias(license: &str) -> String { match license.trim().to_lowercase().as_str() { "mit" => "MIT".to_string(), "apache" | "apache2" | "apache20" | "apache2.0" => "Apache-2.0".to_string(), diff --git a/crates/test-utils/src/util.rs b/crates/test-utils/src/util.rs index 9b59f50d1e848..2a8110a31df17 100644 --- a/crates/test-utils/src/util.rs +++ b/crates/test-utils/src/util.rs @@ -592,14 +592,6 @@ impl TestProject { config_paths_exist(&paths, self.inner.project().cached); } - /// Copies the project's root directory to the given target - #[track_caller] - pub fn copy_to(&self, target: impl AsRef) { - let target = target.as_ref(); - pretty_err(target, fs::create_dir_all(target)); - pretty_err(target, copy_dir(self.root(), target)); - } - /// Creates a file with contents `contents` in the test project's directory. The /// file will be deleted when the project is dropped. pub fn create_file(&self, path: impl AsRef, contents: &str) -> PathBuf { @@ -853,11 +845,6 @@ impl TestCommand { self.cmd.envs(envs); } - /// Unsets the environment variable `k` for the command. - pub fn unset_env(&mut self, k: impl AsRef) { - self.cmd.env_remove(k); - } - /// Set the working directory for this command. /// /// Note that this does not need to be called normally, since the creation