diff --git a/crates/cli/src/cast/cmd/access_list.rs b/crates/cli/src/cast/cmd/access_list.rs index ebfd63d27a692..261975a14f7cd 100644 --- a/crates/cli/src/cast/cmd/access_list.rs +++ b/crates/cli/src/cast/cmd/access_list.rs @@ -4,7 +4,7 @@ use ethers::{ providers::Middleware, types::{BlockId, NameOrAddress}, }; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use foundry_cli::{ opts::{EthereumOpts, TransactionOpts}, utils, @@ -57,7 +57,7 @@ pub struct AccessListArgs { } impl AccessListArgs { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let AccessListArgs { to, sig, args, data, tx, eth, block, json: to_json } = self; let config = Config::from(ð); @@ -82,7 +82,7 @@ async fn access_list, T: Into, to_json: bool, -) -> eyre::Result<()> +) -> Result<()> where M::Error: 'static, { diff --git a/crates/cli/src/cast/cmd/call.rs b/crates/cli/src/cast/cmd/call.rs index aeef292e7b351..741e03a862817 100644 --- a/crates/cli/src/cast/cmd/call.rs +++ b/crates/cli/src/cast/cmd/call.rs @@ -4,7 +4,7 @@ use ethers::{ solc::EvmVersion, types::{BlockId, NameOrAddress, U256}, }; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use forge::executor::opts::EvmOpts; use foundry_cli::{ opts::{EthereumOpts, TransactionOpts}, @@ -108,7 +108,7 @@ pub enum CallSubcommands { } impl CallArgs { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let CallArgs { to, sig, @@ -224,7 +224,7 @@ async fn fill_create( code: String, sig: Option, args: Vec, -) -> eyre::Result<()> { +) -> Result<()> { builder.value(value); let mut data = hex::decode(code.strip_prefix("0x").unwrap_or(&code))?; @@ -246,7 +246,7 @@ async fn fill_tx( sig: Option, args: Vec, data: Option, -) -> eyre::Result<()> { +) -> Result<()> { builder.value(value); if let Some(sig) = sig { diff --git a/crates/cli/src/cast/cmd/create2.rs b/crates/cli/src/cast/cmd/create2.rs index 9582eadd31928..c15a24b43e102 100644 --- a/crates/cli/src/cast/cmd/create2.rs +++ b/crates/cli/src/cast/cmd/create2.rs @@ -6,7 +6,6 @@ use ethers::{ utils::{get_create2_address_from_hash, keccak256}, }; use eyre::{Result, WrapErr}; -use foundry_cli::utils::Cmd; use rayon::prelude::*; use regex::RegexSetBuilder; use std::{str::FromStr, time::Instant}; @@ -59,16 +58,8 @@ pub struct Create2Output { pub salt: U256, } -impl Cmd for Create2Args { - type Output = Create2Output; - - fn run(self) -> eyre::Result { - Create2Args::generate_address(self) - } -} - impl Create2Args { - fn generate_address(self) -> Result { + pub fn run(self) -> Result { let Create2Args { starts_with, ends_with, diff --git a/crates/cli/src/cast/cmd/interface.rs b/crates/cli/src/cast/cmd/interface.rs index 3f1f5cfa956a1..3bd52e07b3591 100644 --- a/crates/cli/src/cast/cmd/interface.rs +++ b/crates/cli/src/cast/cmd/interface.rs @@ -1,5 +1,6 @@ use cast::{AbiPath, SimpleCast}; use clap::Parser; +use eyre::Result; use foundry_cli::opts::EtherscanOpts; use foundry_common::fs; use foundry_config::Config; @@ -37,7 +38,7 @@ pub struct InterfaceArgs { } impl InterfaceArgs { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let InterfaceArgs { path_or_address, name, pragma, output: output_location, etherscan } = self; let config = Config::from(ðerscan); diff --git a/crates/cli/src/cast/cmd/logs.rs b/crates/cli/src/cast/cmd/logs.rs index 14d923e2b93b5..433f90969469e 100644 --- a/crates/cli/src/cast/cmd/logs.rs +++ b/crates/cli/src/cast/cmd/logs.rs @@ -5,13 +5,11 @@ use ethers::{ providers::Middleware, types::{BlockId, BlockNumber, Filter, FilterBlockOption, NameOrAddress, ValueOrArray, H256}, }; +use eyre::Result; use foundry_cli::{opts::EthereumOpts, utils}; - use foundry_common::abi::{get_event, parse_tokens}; use foundry_config::Config; - use itertools::Itertools; - use std::str::FromStr; /// CLI arguments for `cast logs`. @@ -55,7 +53,7 @@ pub struct LogsArgs { } impl LogsArgs { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let LogsArgs { from_block, to_block, address, topics_or_args, sig_or_topic, json, eth, .. } = self; diff --git a/crates/cli/src/cast/cmd/run.rs b/crates/cli/src/cast/cmd/run.rs index e18175d1e0cdf..0576322d28a6b 100644 --- a/crates/cli/src/cast/cmd/run.rs +++ b/crates/cli/src/cast/cmd/run.rs @@ -1,6 +1,6 @@ use clap::Parser; use ethers::{prelude::Middleware, solc::EvmVersion, types::H160}; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use forge::{ executor::{inspector::cheatcodes::util::configure_tx_env, opts::EvmOpts}, revm::primitives::U256 as rU256, @@ -82,7 +82,7 @@ impl RunArgs { /// This replays the entire block the transaction was mined in unless `quick` is set to true /// /// Note: This executes the transaction(s) as is: Cheatcodes are disabled - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let figment = Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc); let evm_opts = figment.extract::()?; diff --git a/crates/cli/src/cast/cmd/send.rs b/crates/cli/src/cast/cmd/send.rs index 6a55d5a24c280..22e4f7d03c3a1 100644 --- a/crates/cli/src/cast/cmd/send.rs +++ b/crates/cli/src/cast/cmd/send.rs @@ -3,6 +3,7 @@ use clap::Parser; use ethers::{ prelude::MiddlewareBuilder, providers::Middleware, signers::Signer, types::NameOrAddress, }; +use eyre::Result; use foundry_cli::{ opts::{EthereumOpts, TransactionOpts}, utils, @@ -73,7 +74,7 @@ pub enum SendTxSubcommands { } impl SendTxArgs { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let SendTxArgs { eth, to, @@ -208,7 +209,7 @@ async fn cast_send, T: Into cast_async: bool, confs: usize, to_json: bool, -) -> eyre::Result<()> +) -> Result<()> where M::Error: 'static, { diff --git a/crates/cli/src/cast/cmd/wallet/mod.rs b/crates/cli/src/cast/cmd/wallet/mod.rs index 5755a2c5361fd..1fdaa923e25ea 100644 --- a/crates/cli/src/cast/cmd/wallet/mod.rs +++ b/crates/cli/src/cast/cmd/wallet/mod.rs @@ -5,11 +5,8 @@ use ethers::{ signers::{LocalWallet, Signer}, types::{transaction::eip712::TypedData, Address, Signature}, }; -use eyre::Context; -use foundry_cli::{ - opts::{RawWallet, Wallet}, - utils::Cmd, -}; +use eyre::{Context, Result}; +use foundry_cli::opts::{RawWallet, Wallet}; use foundry_common::fs; use foundry_config::Config; use std::path::Path; @@ -120,7 +117,7 @@ pub enum WalletSubcommands { } impl WalletSubcommands { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { match self { WalletSubcommands::New { path, unsafe_password, .. } => { let mut rng = thread_rng(); @@ -281,7 +278,7 @@ flag to set your key via: Ok(()) } - fn hex_str_to_bytes(s: &str) -> eyre::Result> { + fn hex_str_to_bytes(s: &str) -> Result> { Ok(match s.strip_prefix("0x") { Some(data) => hex::decode(data).wrap_err("Could not decode 0x-prefixed string.")?, None => s.as_bytes().to_vec(), diff --git a/crates/cli/src/cast/cmd/wallet/vanity.rs b/crates/cli/src/cast/cmd/wallet/vanity.rs index cafcd32468a28..9252c9b9c8959 100644 --- a/crates/cli/src/cast/cmd/wallet/vanity.rs +++ b/crates/cli/src/cast/cmd/wallet/vanity.rs @@ -6,7 +6,8 @@ use ethers::{ types::{H160, U256}, utils::{get_contract_address, secret_key_to_address}, }; -use foundry_cli::utils::Cmd; +use eyre::Result; + use rayon::iter::{self, ParallelIterator}; use regex::Regex; use std::time::Instant; @@ -37,10 +38,8 @@ pub struct VanityArgs { pub nonce: Option, } -impl Cmd for VanityArgs { - type Output = LocalWallet; - - fn run(self) -> eyre::Result { +impl VanityArgs { + pub fn run(self) -> Result { let Self { starts_with, ends_with, nonce } = self; let mut left_exact_hex = None; let mut left_regex = None; diff --git a/crates/cli/src/cast/main.rs b/crates/cli/src/cast/main.rs index b0b29d0b1f815..a431b9213b9f7 100644 --- a/crates/cli/src/cast/main.rs +++ b/crates/cli/src/cast/main.rs @@ -7,7 +7,8 @@ use ethers::{ types::Address, utils::keccak256, }; -use foundry_cli::{handler, prompt, stdin, utils, utils::Cmd}; +use eyre::Result; +use foundry_cli::{handler, prompt, stdin, utils}; use foundry_common::{ abi::{format_tokens, get_event}, fs, @@ -25,7 +26,7 @@ pub mod opts; use opts::{Opts, Subcommands, ToBaseArgs}; #[tokio::main] -async fn main() -> eyre::Result<()> { +async fn main() -> Result<()> { utils::load_dotenv(); handler::install()?; utils::subscriber(); diff --git a/crates/cli/src/cast/opts.rs b/crates/cli/src/cast/opts.rs index 37e08a538aaf7..4d0dae5af7d83 100644 --- a/crates/cli/src/cast/opts.rs +++ b/crates/cli/src/cast/opts.rs @@ -8,6 +8,7 @@ use ethers::{ abi::ethabi::ethereum_types::BigEndianHash, types::{serde_helpers::Numeric, Address, BlockId, NameOrAddress, H256, U256}, }; +use eyre::Result; use foundry_cli::{ opts::{EtherscanOpts, RpcOpts}, utils::parse_u256, @@ -862,7 +863,7 @@ pub struct ToBaseArgs { pub base_in: Option, } -pub fn parse_slot(s: &str) -> eyre::Result { +pub fn parse_slot(s: &str) -> Result { Numeric::from_str(s) .map_err(|e| eyre::eyre!("Could not parse slot number: {e}")) .map(|n| H256::from_uint(&n.into())) diff --git a/crates/cli/src/forge/cmd/bind.rs b/crates/cli/src/forge/cmd/bind.rs index 626c57399810b..237af98b87534 100644 --- a/crates/cli/src/forge/cmd/bind.rs +++ b/crates/cli/src/forge/cmd/bind.rs @@ -1,9 +1,7 @@ use clap::{Parser, ValueHint}; use ethers::contract::{Abigen, ContractFilter, ExcludeContracts, MultiAbigen, SelectContracts}; -use foundry_cli::{ - opts::CoreBuildArgs, - utils::{Cmd, LoadConfig}, -}; +use eyre::Result; +use foundry_cli::{opts::CoreBuildArgs, utils::LoadConfig}; use foundry_common::{compile, fs::json_files}; use foundry_config::impl_figment_convert; use std::{ @@ -121,7 +119,7 @@ impl BindArgs { } /// Instantiate the multi-abigen - fn get_multi(&self, artifacts: impl AsRef) -> eyre::Result { + fn get_multi(&self, artifacts: impl AsRef) -> Result { let abigens = json_files(artifacts.as_ref()) .into_iter() .filter_map(|path| { @@ -147,7 +145,7 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin } /// Check that the existing bindings match the expected abigen output - fn check_existing_bindings(&self, artifacts: impl AsRef) -> eyre::Result<()> { + fn check_existing_bindings(&self, artifacts: impl AsRef) -> Result<()> { let bindings = self.get_multi(&artifacts)?.build()?; println!("Checking bindings for {} contracts.", bindings.len()); if !self.module { @@ -166,7 +164,7 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin } /// Generate the bindings - fn generate_bindings(&self, artifacts: impl AsRef) -> eyre::Result<()> { + fn generate_bindings(&self, artifacts: impl AsRef) -> Result<()> { let bindings = self.get_multi(&artifacts)?.build()?; println!("Generating bindings for {} contracts", bindings.len()); if !self.module { @@ -181,12 +179,8 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin } Ok(()) } -} - -impl Cmd for BindArgs { - type Output = (); - fn run(self) -> eyre::Result { + pub fn run(self) -> Result<()> { if !self.skip_build { // run `forge build` let project = self.build_args.project()?; diff --git a/crates/cli/src/forge/cmd/build.rs b/crates/cli/src/forge/cmd/build.rs index 109a364302432..7c4e8fce2ca33 100644 --- a/crates/cli/src/forge/cmd/build.rs +++ b/crates/cli/src/forge/cmd/build.rs @@ -1,10 +1,8 @@ use super::{install, watch::WatchArgs}; use clap::Parser; use ethers::solc::{Project, ProjectCompileOutput}; -use foundry_cli::{ - opts::CoreBuildArgs, - utils::{Cmd, LoadConfig}, -}; +use eyre::Result; +use foundry_cli::{opts::CoreBuildArgs, utils::LoadConfig}; use foundry_common::{ compile, compile::{ProjectCompiler, SkipBuildFilter}, @@ -73,10 +71,8 @@ pub struct BuildArgs { pub watch: WatchArgs, } -impl Cmd for BuildArgs { - type Output = ProjectCompileOutput; - - fn run(self) -> eyre::Result { +impl BuildArgs { + pub fn run(self) -> Result { let mut config = self.try_load_config_emit_warnings()?; let mut project = config.project()?; @@ -97,15 +93,13 @@ impl Cmd for BuildArgs { compiler.compile(&project) } } -} -impl BuildArgs { /// Returns the `Project` for the current workspace /// /// This loads the `foundry_config::Config` for the current workspace (see /// [`utils::find_project_root_path`] and merges the cli `BuildArgs` into it before returning /// [`foundry_config::Config::project()`] - pub fn project(&self) -> eyre::Result { + pub fn project(&self) -> Result { self.args.project() } @@ -116,7 +110,7 @@ impl BuildArgs { /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to /// bootstrap a new [`watchexe::Watchexec`] loop. - pub(crate) fn watchexec_config(&self) -> eyre::Result<(InitConfig, RuntimeConfig)> { + pub(crate) fn watchexec_config(&self) -> Result<(InitConfig, RuntimeConfig)> { // use the path arguments or if none where provided the `src` dir self.watch.watchexec_config(|| { let config = Config::from(self); diff --git a/crates/cli/src/forge/cmd/cache.rs b/crates/cli/src/forge/cmd/cache.rs index d9b7b9440ccc9..e70a2c66f2c83 100644 --- a/crates/cli/src/forge/cmd/cache.rs +++ b/crates/cli/src/forge/cmd/cache.rs @@ -5,7 +5,6 @@ use clap::{ }; use ethers::prelude::Chain; use eyre::Result; -use foundry_cli::utils::Cmd; use foundry_config::{cache, Chain as FoundryConfigChain, Config}; use std::{ffi::OsStr, str::FromStr}; use strum::VariantNames; @@ -56,10 +55,8 @@ pub struct CleanArgs { etherscan: bool, } -impl Cmd for CleanArgs { - type Output = (); - - fn run(self) -> Result { +impl CleanArgs { + pub fn run(self) -> Result<()> { let CleanArgs { chains, blocks, etherscan } = self; for chain_or_all in chains { @@ -92,10 +89,8 @@ pub struct LsArgs { chains: Vec, } -impl Cmd for LsArgs { - type Output = (); - - fn run(self) -> Result { +impl LsArgs { + pub fn run(self) -> Result<()> { let LsArgs { chains } = self; let mut cache = Cache::default(); for chain_or_all in chains { diff --git a/crates/cli/src/forge/cmd/config.rs b/crates/cli/src/forge/cmd/config.rs index 2e7c6a3ab2441..a8e33cdba38ca 100644 --- a/crates/cli/src/forge/cmd/config.rs +++ b/crates/cli/src/forge/cmd/config.rs @@ -1,6 +1,7 @@ use super::build::BuildArgs; use clap::Parser; -use foundry_cli::utils::{Cmd, LoadConfig}; +use eyre::Result; +use foundry_cli::utils::LoadConfig; use foundry_common::{evm::EvmArgs, term::cli_warn}; use foundry_config::fix::fix_tomls; @@ -29,10 +30,8 @@ pub struct ConfigArgs { evm_opts: EvmArgs, } -impl Cmd for ConfigArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl ConfigArgs { + pub fn run(self) -> Result<()> { if self.fix { for warning in fix_tomls() { cli_warn!("{warning}"); diff --git a/crates/cli/src/forge/cmd/coverage.rs b/crates/cli/src/forge/cmd/coverage.rs index 92fe362051405..cab986aa2bfe8 100644 --- a/crates/cli/src/forge/cmd/coverage.rs +++ b/crates/cli/src/forge/cmd/coverage.rs @@ -8,7 +8,7 @@ use ethers::{ }, solc::{artifacts::contract::CompactContractBytecode, sourcemap::SourceMap}, }; -use eyre::Context; +use eyre::{Context, Result}; use forge::{ coverage::{ analysis::SourceAnalyzer, anchors::find_anchors, ContractId, CoverageReport, @@ -33,6 +33,9 @@ use std::{collections::HashMap, sync::mpsc::channel}; use tracing::trace; use yansi::Paint; +/// A map, keyed by contract ID, to a tuple of the deployment source map and the runtime source map. +type SourceMaps = HashMap; + // Loads project's figment and merges the build cli arguments into it foundry_config::impl_figment_convert!(CoverageArgs, opts, evm_opts); @@ -63,12 +66,7 @@ pub struct CoverageArgs { } impl CoverageArgs { - /// Returns the flattened [`CoreBuildArgs`] - pub fn build_args(&self) -> &CoreBuildArgs { - &self.opts - } - - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { let (mut config, evm_opts) = self.load_config_and_evm_opts_emit_warnings()?; // install missing dependencies @@ -89,15 +87,9 @@ impl CoverageArgs { p_println!(!self.opts.silent => "Running tests..."); self.collect(project, output, report, config, evm_opts).await } -} -/// A map, keyed by contract ID, to a tuple of the deployment source map and the runtime source map. -type SourceMaps = HashMap; - -// The main flow of the command itself -impl CoverageArgs { /// Builds the project. - fn build(&self, config: &Config) -> eyre::Result<(Project, ProjectCompileOutput)> { + fn build(&self, config: &Config) -> Result<(Project, ProjectCompileOutput)> { // Set up the project let project = { let mut project = config.ephemeral_no_artifacts_project()?; @@ -150,11 +142,7 @@ impl CoverageArgs { /// Builds the coverage report. #[tracing::instrument(name = "prepare coverage", skip_all)] - fn prepare( - &self, - config: &Config, - output: ProjectCompileOutput, - ) -> eyre::Result { + fn prepare(&self, config: &Config, output: ProjectCompileOutput) -> Result { let project_paths = config.project_paths(); // Extract artifacts @@ -294,7 +282,7 @@ impl CoverageArgs { mut report: CoverageReport, config: Config, evm_opts: EvmOpts, - ) -> eyre::Result<()> { + ) -> Result<()> { let root = project.paths.root; // Build the contract runner @@ -364,6 +352,11 @@ impl CoverageArgs { } Ok(()) } + + /// Returns the flattened [`CoreBuildArgs`] + pub fn build_args(&self) -> &CoreBuildArgs { + &self.opts + } } // TODO: HTML diff --git a/crates/cli/src/forge/cmd/create.rs b/crates/cli/src/forge/cmd/create.rs index dd0d44c5343c4..fb2abf16b23a4 100644 --- a/crates/cli/src/forge/cmd/create.rs +++ b/crates/cli/src/forge/cmd/create.rs @@ -7,7 +7,7 @@ use ethers::{ solc::{info::ContractInfo, utils::canonicalized}, types::{transaction::eip2718::TypedTransaction, Chain}, }; -use eyre::Context; +use eyre::{Context, Result}; use foundry_cli::{ opts::{CoreBuildArgs, EthereumOpts, EtherscanOpts, TransactionOpts}, utils::{self, read_constructor_args_file, remove_contract, LoadConfig}, @@ -69,7 +69,7 @@ pub struct CreateArgs { impl CreateArgs { /// Executes the command to create a contract - pub async fn run(mut self) -> eyre::Result<()> { + pub async fn run(mut self) -> Result<()> { // Find Project & Compile let project = self.opts.project()?; let mut output = if self.json || self.opts.silent { @@ -141,7 +141,7 @@ impl CreateArgs { &self, constructor_args: Option, chain: u64, - ) -> eyre::Result<()> { + ) -> Result<()> { // NOTE: this does not represent the same `VerifyArgs` that would be sent after deployment, // since we don't know the address yet. let verify = verify::VerifyArgs { @@ -176,7 +176,7 @@ impl CreateArgs { args: Vec, provider: M, chain: u64, - ) -> eyre::Result<()> { + ) -> Result<()> { let deployer_address = provider.default_sender().expect("no sender address set for provider"); let bin = bin.into_bytes().unwrap_or_else(|| { @@ -315,7 +315,7 @@ impl CreateArgs { &self, constructor: &Constructor, constructor_args: &[String], - ) -> eyre::Result> { + ) -> Result> { let params = constructor .inputs .iter() diff --git a/crates/cli/src/forge/cmd/debug.rs b/crates/cli/src/forge/cmd/debug.rs index 1bd5989985816..abd7362720870 100644 --- a/crates/cli/src/forge/cmd/debug.rs +++ b/crates/cli/src/forge/cmd/debug.rs @@ -1,5 +1,6 @@ use super::{build::BuildArgs, retry::RETRY_VERIFY_ON_CREATE, script::ScriptArgs}; use clap::{Parser, ValueHint}; +use eyre::Result; use foundry_cli::opts::CoreBuildArgs; use foundry_common::evm::{Breakpoints, EvmArgs}; use std::path::PathBuf; @@ -40,7 +41,7 @@ pub struct DebugArgs { } impl DebugArgs { - pub async fn debug(self, breakpoints: Breakpoints) -> eyre::Result<()> { + pub async fn debug(self, breakpoints: Breakpoints) -> Result<()> { let script = ScriptArgs { path: self.path.to_str().expect("Invalid path string.").to_string(), args: self.args, diff --git a/crates/cli/src/forge/cmd/doc.rs b/crates/cli/src/forge/cmd/doc.rs index 14a7a79432f00..04e3cc87a5584 100644 --- a/crates/cli/src/forge/cmd/doc.rs +++ b/crates/cli/src/forge/cmd/doc.rs @@ -1,6 +1,7 @@ use clap::{Parser, ValueHint}; +use eyre::Result; use forge_doc::{ContractInheritance, Deployments, DocBuilder, GitSource, Inheritdoc, Server}; -use foundry_cli::{opts::GH_REPO_PREFIX_REGEX, utils::Cmd}; +use foundry_cli::opts::GH_REPO_PREFIX_REGEX; use foundry_config::{find_project_root_path, load_config_with_root}; use std::{path::PathBuf, process::Command}; @@ -46,10 +47,8 @@ pub struct DocArgs { deployments: Option>, } -impl Cmd for DocArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl DocArgs { + pub fn run(self) -> Result<()> { let root = self.root.clone().unwrap_or(find_project_root_path(None)?); let config = load_config_with_root(Some(root.clone())); diff --git a/crates/cli/src/forge/cmd/flatten.rs b/crates/cli/src/forge/cmd/flatten.rs index c9c9ab393defb..2f750877694ea 100644 --- a/crates/cli/src/forge/cmd/flatten.rs +++ b/crates/cli/src/forge/cmd/flatten.rs @@ -1,7 +1,8 @@ use clap::{Parser, ValueHint}; +use eyre::Result; use foundry_cli::{ opts::{CoreBuildArgs, ProjectPathsArgs}, - utils::{Cmd, LoadConfig}, + utils::LoadConfig, }; use foundry_common::fs; use std::path::PathBuf; @@ -28,9 +29,8 @@ pub struct FlattenArgs { project_paths: ProjectPathsArgs, } -impl Cmd for FlattenArgs { - type Output = (); - fn run(self) -> eyre::Result { +impl FlattenArgs { + pub fn run(self) -> Result<()> { let FlattenArgs { target_path, output, project_paths } = self; // flatten is a subset of `BuildArgs` so we can reuse that to get the config diff --git a/crates/cli/src/forge/cmd/fmt.rs b/crates/cli/src/forge/cmd/fmt.rs index cb78c2f0c484c..bf8334d70b9fb 100644 --- a/crates/cli/src/forge/cmd/fmt.rs +++ b/crates/cli/src/forge/cmd/fmt.rs @@ -1,6 +1,7 @@ use clap::{Parser, ValueHint}; +use eyre::Result; use forge_fmt::{format, parse, print_diagnostics_report}; -use foundry_cli::utils::{Cmd, FoundryPathExt, LoadConfig}; +use foundry_cli::utils::{FoundryPathExt, LoadConfig}; use foundry_common::{fs, term::cli_warn}; use foundry_config::impl_figment_convert_basic; use foundry_utils::glob::expand_globs; @@ -45,10 +46,8 @@ impl_figment_convert_basic!(FmtArgs); // === impl FmtArgs === -impl Cmd for FmtArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl FmtArgs { + pub fn run(self) -> Result<()> { let config = self.try_load_config_emit_warnings()?; // Expand ignore globs and canonicalize from the get go @@ -95,7 +94,7 @@ impl Cmd for FmtArgs { } }; - let format = |source: String, path: Option<&Path>| -> eyre::Result<_> { + let format = |source: String, path: Option<&Path>| -> Result<_> { let name = match path { Some(path) => { path.strip_prefix(&config.__root.0).unwrap_or(path).display().to_string() diff --git a/crates/cli/src/forge/cmd/fourbyte.rs b/crates/cli/src/forge/cmd/fourbyte.rs index 6268f2e790ba2..86a889d6fe635 100644 --- a/crates/cli/src/forge/cmd/fourbyte.rs +++ b/crates/cli/src/forge/cmd/fourbyte.rs @@ -1,5 +1,6 @@ use clap::Parser; use ethers::prelude::artifacts::output_selection::ContractOutputSelection; +use eyre::Result; use foundry_cli::{ opts::{CompilerArgs, CoreBuildArgs, ProjectPathsArgs}, utils::FoundryPathExt, @@ -28,7 +29,7 @@ pub struct UploadSelectorsArgs { impl UploadSelectorsArgs { /// Builds a contract and uploads the ABI to selector database - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { shell::println(Paint::yellow("Warning! This command is deprecated and will be removed in v1, use `forge selectors upload` instead"))?; let UploadSelectorsArgs { contract, all, project_paths } = self; diff --git a/crates/cli/src/forge/cmd/geiger/find.rs b/crates/cli/src/forge/cmd/geiger/find.rs index c6f2887acef86..80a31c395dac8 100644 --- a/crates/cli/src/forge/cmd/geiger/find.rs +++ b/crates/cli/src/forge/cmd/geiger/find.rs @@ -1,4 +1,5 @@ use super::{error::ScanFileError, visitor::CheatcodeVisitor}; +use eyre::Result; use forge_fmt::{offset_to_line_column, parse, Visitable}; use foundry_common::fs; use solang_parser::{diagnostics::Diagnostic, pt::Loc}; diff --git a/crates/cli/src/forge/cmd/geiger/mod.rs b/crates/cli/src/forge/cmd/geiger/mod.rs index 3ec377cc4a7c6..6756a5921a939 100644 --- a/crates/cli/src/forge/cmd/geiger/mod.rs +++ b/crates/cli/src/forge/cmd/geiger/mod.rs @@ -1,7 +1,7 @@ use clap::{Parser, ValueHint}; use ethers::solc::Graph; -use eyre::WrapErr; -use foundry_cli::utils::{Cmd, LoadConfig}; +use eyre::{Result, WrapErr}; +use foundry_cli::utils::LoadConfig; use foundry_config::{impl_figment_convert_basic, Config}; use itertools::Itertools; use rayon::prelude::*; @@ -57,7 +57,7 @@ pub struct GeigerArgs { impl_figment_convert_basic!(GeigerArgs); impl GeigerArgs { - pub fn sources(&self, config: &Config) -> eyre::Result> { + pub fn sources(&self, config: &Config) -> Result> { let cwd = std::env::current_dir()?; let mut sources: Vec = { @@ -85,12 +85,8 @@ impl GeigerArgs { Ok(sources) } -} - -impl Cmd for GeigerArgs { - type Output = usize; - fn run(self) -> eyre::Result { + pub fn run(self) -> Result { let config = self.try_load_config_emit_warnings()?; let sources = self.sources(&config).wrap_err("Failed to resolve files")?; diff --git a/crates/cli/src/forge/cmd/geiger/visitor.rs b/crates/cli/src/forge/cmd/geiger/visitor.rs index 0452b723b05d3..70313089019ca 100644 --- a/crates/cli/src/forge/cmd/geiger/visitor.rs +++ b/crates/cli/src/forge/cmd/geiger/visitor.rs @@ -1,4 +1,5 @@ use super::find::UnsafeCheatcodes; +use eyre::Result; use forge_fmt::{Visitable, Visitor}; use solang_parser::pt::{ ContractDefinition, Expression, FunctionDefinition, IdentifierPath, Loc, Parameter, SourceUnit, diff --git a/crates/cli/src/forge/cmd/generate/mod.rs b/crates/cli/src/forge/cmd/generate/mod.rs index b806cc68da3cd..7f5ffbc5070b8 100644 --- a/crates/cli/src/forge/cmd/generate/mod.rs +++ b/crates/cli/src/forge/cmd/generate/mod.rs @@ -1,4 +1,5 @@ use clap::{Parser, Subcommand}; +use eyre::Result; use foundry_common::fs; use std::path::Path; use yansi::Paint; @@ -24,7 +25,7 @@ pub struct GenerateTestArgs { } impl GenerateTestArgs { - pub fn run(self) -> eyre::Result<()> { + pub fn run(self) -> Result<()> { let contract_name = format_identifier(&self.contract_name, true); let instance_name = format_identifier(&self.contract_name, false); diff --git a/crates/cli/src/forge/cmd/init.rs b/crates/cli/src/forge/cmd/init.rs index 5b14b43006eca..6bc8f80db76c3 100644 --- a/crates/cli/src/forge/cmd/init.rs +++ b/crates/cli/src/forge/cmd/init.rs @@ -1,10 +1,8 @@ use super::install::DependencyInstallOpts; use clap::{Parser, ValueHint}; use ethers::solc::remappings::Remapping; -use foundry_cli::{ - p_println, - utils::{Cmd, Git}, -}; +use eyre::Result; +use foundry_cli::{p_println, utils::Git}; use foundry_common::fs; use foundry_config::Config; use std::path::{Path, PathBuf}; @@ -38,10 +36,8 @@ pub struct InitArgs { opts: DependencyInstallOpts, } -impl Cmd for InitArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl InitArgs { + pub fn run(self) -> Result<()> { let InitArgs { root, template, opts, offline, force, vscode } = self; let DependencyInstallOpts { shallow, no_git, no_commit, quiet } = opts; @@ -161,7 +157,7 @@ pub fn get_commit_hash(root: &Path) -> Option { /// Creates `.gitignore` and `.github/workflows/test.yml`, if they don't exist already. /// /// Commits everything in `root` if `no_commit` is false. -fn init_git_repo(git: Git<'_>, no_commit: bool) -> eyre::Result<()> { +fn init_git_repo(git: Git<'_>, no_commit: bool) -> Result<()> { // git init if !git.is_in_repo()? { git.init()?; @@ -190,7 +186,7 @@ fn init_git_repo(git: Git<'_>, no_commit: bool) -> eyre::Result<()> { } /// initializes the `.vscode/settings.json` file -fn init_vscode(root: &Path) -> eyre::Result<()> { +fn init_vscode(root: &Path) -> Result<()> { let remappings_file = root.join("remappings.txt"); if !remappings_file.exists() { let mut remappings = Remapping::find_many(root.join("lib")) diff --git a/crates/cli/src/forge/cmd/inspect.rs b/crates/cli/src/forge/cmd/inspect.rs index f1ed09e21f678..c4c955f6486f2 100644 --- a/crates/cli/src/forge/cmd/inspect.rs +++ b/crates/cli/src/forge/cmd/inspect.rs @@ -14,10 +14,8 @@ use ethers::{ utils::canonicalize, }, }; -use foundry_cli::{ - opts::{CompilerArgs, CoreBuildArgs}, - utils::Cmd, -}; +use eyre::Result; +use foundry_cli::opts::{CompilerArgs, CoreBuildArgs}; use foundry_common::compile; use serde_json::{to_value, Value}; use std::fmt; @@ -42,10 +40,8 @@ pub struct InspectArgs { build: CoreBuildArgs, } -impl Cmd for InspectArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl InspectArgs { + pub fn run(self) -> Result<()> { let InspectArgs { mut contract, field, build, pretty } = self; trace!(target: "forge", ?field, ?contract, "running forge inspect"); @@ -207,7 +203,7 @@ impl Cmd for InspectArgs { } } -pub fn print_abi(abi: &LosslessAbi, pretty: bool) -> eyre::Result<()> { +pub fn print_abi(abi: &LosslessAbi, pretty: bool) -> Result<()> { let abi_json = to_value(abi)?; if !pretty { println!("{}", serde_json::to_string_pretty(&abi_json)?); @@ -221,10 +217,7 @@ pub fn print_abi(abi: &LosslessAbi, pretty: bool) -> eyre::Result<()> { Ok(()) } -pub fn print_storage_layout( - storage_layout: &Option, - pretty: bool, -) -> eyre::Result<()> { +pub fn print_storage_layout(storage_layout: &Option, pretty: bool) -> Result<()> { if storage_layout.is_none() { eyre::bail!("Could not get storage layout") } diff --git a/crates/cli/src/forge/cmd/install.rs b/crates/cli/src/forge/cmd/install.rs index 1f9a694b6dc56..945ddfc2155e8 100644 --- a/crates/cli/src/forge/cmd/install.rs +++ b/crates/cli/src/forge/cmd/install.rs @@ -3,7 +3,7 @@ use eyre::{Context, Result}; use foundry_cli::{ opts::Dependency, p_println, prompt, - utils::{Cmd, CommandUtils, Git, LoadConfig}, + utils::{CommandUtils, Git, LoadConfig}, }; use foundry_common::fs; use foundry_config::{impl_figment_convert_basic, Config}; @@ -56,10 +56,8 @@ pub struct InstallArgs { impl_figment_convert_basic!(InstallArgs); -impl Cmd for InstallArgs { - type Output = (); - - fn run(self) -> Result { +impl InstallArgs { + pub fn run(self) -> Result<()> { let mut config = self.try_load_config_emit_warnings()?; self.opts.install(&mut config, self.dependencies) } diff --git a/crates/cli/src/forge/cmd/remappings.rs b/crates/cli/src/forge/cmd/remappings.rs index fe4e525b6ad51..17277fd16b812 100644 --- a/crates/cli/src/forge/cmd/remappings.rs +++ b/crates/cli/src/forge/cmd/remappings.rs @@ -1,7 +1,8 @@ use cast::HashMap; use clap::{Parser, ValueHint}; use ethers::solc::remappings::RelativeRemapping; -use foundry_cli::utils::{Cmd, LoadConfig}; +use eyre::Result; +use foundry_cli::utils::LoadConfig; use foundry_config::impl_figment_convert_basic; use std::path::PathBuf; @@ -20,11 +21,9 @@ pub struct RemappingArgs { } impl_figment_convert_basic!(RemappingArgs); -impl Cmd for RemappingArgs { - type Output = (); - +impl RemappingArgs { // TODO: Do people use `forge remappings >> file`? - fn run(self) -> eyre::Result { + pub fn run(self) -> Result<()> { let config = self.try_load_config_emit_warnings()?; if self.pretty { diff --git a/crates/cli/src/forge/cmd/remove.rs b/crates/cli/src/forge/cmd/remove.rs index e488c9e24a533..f5deb00b2e1fa 100644 --- a/crates/cli/src/forge/cmd/remove.rs +++ b/crates/cli/src/forge/cmd/remove.rs @@ -1,7 +1,8 @@ use clap::{Parser, ValueHint}; +use eyre::Result; use foundry_cli::{ opts::Dependency, - utils::{Cmd, Git, LoadConfig}, + utils::{Git, LoadConfig}, }; use foundry_config::impl_figment_convert_basic; use std::path::PathBuf; @@ -25,10 +26,8 @@ pub struct RemoveArgs { } impl_figment_convert_basic!(RemoveArgs); -impl Cmd for RemoveArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl RemoveArgs { + pub fn run(self) -> Result<()> { let config = self.try_load_config_emit_warnings()?; let (root, paths) = super::update::dependencies_paths(&self.dependencies, &config)?; let git_modules = root.join(".git/modules"); diff --git a/crates/cli/src/forge/cmd/script/build.rs b/crates/cli/src/forge/cmd/script/build.rs index 75fc19f2741d8..c905662af0b1a 100644 --- a/crates/cli/src/forge/cmd/script/build.rs +++ b/crates/cli/src/forge/cmd/script/build.rs @@ -11,7 +11,7 @@ use ethers::{ }, types::{Address, U256}, }; -use eyre::{Context, ContextCompat}; +use eyre::{Context, ContextCompat, Result}; use foundry_cli::utils::get_cached_entry_by_name; use foundry_common::compile; use foundry_utils::{PostLinkInput, ResolvedDependency}; @@ -20,14 +20,14 @@ use tracing::{trace, warn}; impl ScriptArgs { /// Compiles the file or project and the verify metadata. - pub fn compile(&mut self, script_config: &mut ScriptConfig) -> eyre::Result { + pub fn compile(&mut self, script_config: &mut ScriptConfig) -> Result { trace!(target: "script", "compiling script"); self.build(script_config) } /// Compiles the file with auto-detection and compiler params. - pub fn build(&mut self, script_config: &mut ScriptConfig) -> eyre::Result { + pub fn build(&mut self, script_config: &mut ScriptConfig) -> Result { let (project, output) = self.get_project_and_output(script_config)?; let output = output.with_stripped_file_prefixes(project.root()); @@ -35,7 +35,7 @@ impl ScriptArgs { let contracts = output .into_artifacts() - .map(|(id, artifact)| -> eyre::Result<_> { + .map(|(id, artifact)| -> Result<_> { // Sources are only required for the debugger, but it *might* mean that there's // something wrong with the build and/or artifacts. if let Some(source) = artifact.source_file() { @@ -51,7 +51,7 @@ impl ScriptArgs { } Ok((id, artifact)) }) - .collect::>()?; + .collect::>()?; let mut output = self.link( project, @@ -74,7 +74,7 @@ impl ScriptArgs { libraries_addresses: Libraries, sender: Address, nonce: U256, - ) -> eyre::Result { + ) -> Result { let mut run_dependencies = vec![]; let mut contract = CompactContractBytecode::default(); let mut highlevel_known_contracts = BTreeMap::new(); @@ -202,7 +202,7 @@ impl ScriptArgs { pub fn get_project_and_output( &mut self, script_config: &ScriptConfig, - ) -> eyre::Result<(Project, ProjectCompileOutput)> { + ) -> Result<(Project, ProjectCompileOutput)> { let project = script_config.config.project()?; let filters = self.opts.skip.clone().unwrap_or_default(); @@ -266,7 +266,7 @@ pub fn filter_sources_and_artifacts( sources: BTreeMap, highlevel_known_contracts: ArtifactContracts, project: Project, -) -> eyre::Result<(BTreeMap, HashMap)> { +) -> Result<(BTreeMap, HashMap)> { // Find all imports let graph = Graph::resolve(&project.paths)?; let target_path = project.root().join(target); diff --git a/crates/cli/src/forge/cmd/script/cmd.rs b/crates/cli/src/forge/cmd/script/cmd.rs index cc61668e72fed..70c836877cdcb 100644 --- a/crates/cli/src/forge/cmd/script/cmd.rs +++ b/crates/cli/src/forge/cmd/script/cmd.rs @@ -3,6 +3,7 @@ use ethers::{ prelude::{Middleware, Signer}, types::{transaction::eip2718::TypedTransaction, U256}, }; +use eyre::Result; use foundry_cli::utils::LoadConfig; use foundry_common::{contracts::flatten_contracts, try_get_http_provider}; use std::sync::Arc; @@ -13,7 +14,7 @@ type NewSenderChanges = (CallTraceDecoder, Libraries, ArtifactContracts eyre::Result<()> { + pub async fn run_script(mut self, breakpoints: Breakpoints) -> Result<()> { trace!(target: "script", "executing script command"); let (config, evm_opts) = self.load_config_and_evm_opts_emit_warnings()?; @@ -129,7 +130,7 @@ impl ScriptArgs { default_known_contracts: ArtifactContracts, predeploy_libraries: Vec, result: &mut ScriptResult, - ) -> eyre::Result> { + ) -> Result> { if let Some(new_sender) = self.maybe_new_sender( &script_config.evm_opts, result.transactions.as_ref(), @@ -186,7 +187,7 @@ impl ScriptArgs { libraries: Libraries, result: ScriptResult, verify: VerifyBundle, - ) -> eyre::Result<()> { + ) -> Result<()> { if self.multi { return self .multi_chain_deployment( @@ -223,7 +224,7 @@ impl ScriptArgs { default_known_contracts: ArtifactContracts, result: ScriptResult, mut verify: VerifyBundle, - ) -> eyre::Result<()> { + ) -> Result<()> { trace!(target: "script", "resuming single deployment"); let fork_url = script_config @@ -292,7 +293,7 @@ impl ScriptArgs { new_sender: Address, first_run_result: &mut ScriptResult, default_known_contracts: ArtifactContracts, - ) -> eyre::Result<(Libraries, ArtifactContracts)> { + ) -> Result<(Libraries, ArtifactContracts)> { // if we had a new sender that requires relinking, we need to // get the nonce mainnet for accurate addresses for predeploy libs let nonce = foundry_utils::next_nonce( @@ -342,7 +343,7 @@ impl ScriptArgs { /// In case the user has loaded *only* one private-key, we can assume that he's using it as the /// `--sender` - fn maybe_load_private_key(&mut self, script_config: &mut ScriptConfig) -> eyre::Result<()> { + fn maybe_load_private_key(&mut self, script_config: &mut ScriptConfig) -> Result<()> { if let Some(ref private_key) = self.wallets.private_key { self.wallets.private_keys = Some(vec![private_key.clone()]); } diff --git a/crates/cli/src/forge/cmd/script/executor.rs b/crates/cli/src/forge/cmd/script/executor.rs index 824c0393ac3f5..faeb3147d3ead 100644 --- a/crates/cli/src/forge/cmd/script/executor.rs +++ b/crates/cli/src/forge/cmd/script/executor.rs @@ -8,6 +8,7 @@ use ethers::{ solc::artifacts::CompactContractBytecode, types::{transaction::eip2718::TypedTransaction, Address, U256}, }; +use eyre::Result; use forge::{ executor::{ inspector::{cheatcodes::util::BroadcastableTransactions, CheatsConfig}, @@ -37,7 +38,7 @@ impl ScriptArgs { contract: CompactContractBytecode, sender: Address, predeploy_libraries: &[ethers::types::Bytes], - ) -> eyre::Result { + ) -> Result { trace!(target: "script", "start executing script"); let CompactContractBytecode { abi, bytecode, .. } = contract; @@ -95,7 +96,7 @@ impl ScriptArgs { script_config: &ScriptConfig, decoder: &CallTraceDecoder, contracts: &ContractsByArtifact, - ) -> eyre::Result> { + ) -> Result> { trace!(target: "script", "executing onchain simulation"); let runners = Arc::new( @@ -210,7 +211,7 @@ impl ScriptArgs { let mut abort = false; for res in join_all(futs).await { // type hint - let res: eyre::Result = res; + let res: Result = res; let (tx, mut traces) = res?; diff --git a/crates/cli/src/forge/cmd/script/mod.rs b/crates/cli/src/forge/cmd/script/mod.rs index 633d9823b4a48..70d0ad354ec3c 100644 --- a/crates/cli/src/forge/cmd/script/mod.rs +++ b/crates/cli/src/forge/cmd/script/mod.rs @@ -26,7 +26,7 @@ use ethers::{ TransactionRequest, U256, }, }; -use eyre::{ContextCompat, WrapErr}; +use eyre::{ContextCompat, Result, WrapErr}; use forge::{ debug::DebugArena, decode::decode_console_logs, @@ -228,7 +228,7 @@ impl ScriptArgs { script_config: &ScriptConfig, result: &mut ScriptResult, known_contracts: &ContractsByArtifact, - ) -> eyre::Result { + ) -> Result { let verbosity = script_config.evm_opts.verbosity; let mut etherscan_identifier = EtherscanIdentifier::new( &script_config.config, @@ -264,7 +264,7 @@ impl ScriptArgs { &self, script_config: &ScriptConfig, returned: &bytes::Bytes, - ) -> eyre::Result> { + ) -> Result> { let func = script_config.called_function.as_ref().expect("There should be a function."); let mut returns = HashMap::new(); @@ -301,7 +301,7 @@ impl ScriptArgs { script_config: &ScriptConfig, decoder: &CallTraceDecoder, result: &mut ScriptResult, - ) -> eyre::Result<()> { + ) -> Result<()> { let verbosity = script_config.evm_opts.verbosity; let func = script_config.called_function.as_ref().expect("There should be a function."); @@ -378,11 +378,7 @@ impl ScriptArgs { Ok(()) } - pub fn show_json( - &self, - script_config: &ScriptConfig, - result: &ScriptResult, - ) -> eyre::Result<()> { + pub fn show_json(&self, script_config: &ScriptConfig, result: &ScriptResult) -> Result<()> { let returns = self.get_returns(script_config, &result.returned)?; let console_logs = decode_console_logs(&result.logs); @@ -402,7 +398,7 @@ impl ScriptArgs { evm_opts: &EvmOpts, transactions: Option<&BroadcastableTransactions>, predeploy_libraries: &[Bytes], - ) -> eyre::Result> { + ) -> Result> { let mut new_sender = None; if let Some(txs) = transactions { @@ -462,7 +458,7 @@ impl ScriptArgs { project: Project, highlevel_known_contracts: ArtifactContracts, breakpoints: Breakpoints, - ) -> eyre::Result<()> { + ) -> Result<()> { trace!(target: "script", "debugging script"); let (sources, artifacts) = filter_sources_and_artifacts( @@ -504,7 +500,7 @@ impl ScriptArgs { /// corresponding function by matching the selector, first 4 bytes in the calldata. /// /// Note: We assume that the `sig` is already stripped of its prefix, See [`ScriptArgs`] - pub fn get_method_and_calldata(&self, abi: &Abi) -> eyre::Result<(Function, Bytes)> { + pub fn get_method_and_calldata(&self, abi: &Abi) -> Result<(Function, Bytes)> { let (func, data) = if let Ok(func) = HumanReadableParser::parse_function(&self.sig) { ( abi.functions() @@ -543,7 +539,7 @@ impl ScriptArgs { &self, result: &ScriptResult, known_contracts: &BTreeMap, - ) -> eyre::Result<()> { + ) -> Result<()> { // (name, &init, &deployed)[] let mut bytecodes: Vec<(String, &[u8], &[u8])> = vec![]; @@ -722,7 +718,7 @@ impl ScriptConfig { /// Certain features are disabled for multi chain deployments, and if tried, will return /// error. [library support] - fn check_multi_chain_constraints(&self, libraries: &Libraries) -> eyre::Result<()> { + fn check_multi_chain_constraints(&self, libraries: &Libraries) -> Result<()> { if self.has_multiple_rpcs() || (self.missing_rpc && !self.total_rpcs.is_empty()) { shell::eprintln(format!( "{}", @@ -746,7 +742,7 @@ impl ScriptConfig { /// Checks if the RPCs used point to chains that support EIP-3855. /// If not, warns the user. - async fn check_shanghai_support(&self) -> eyre::Result<()> { + async fn check_shanghai_support(&self) -> Result<()> { let chain_ids = self.total_rpcs.iter().map(|rpc| async move { if let Ok(provider) = ethers::providers::Provider::::try_from(rpc) { match provider.get_chainid().await { diff --git a/crates/cli/src/forge/cmd/script/multi.rs b/crates/cli/src/forge/cmd/script/multi.rs index 5e597533ce9b2..04862b8389481 100644 --- a/crates/cli/src/forge/cmd/script/multi.rs +++ b/crates/cli/src/forge/cmd/script/multi.rs @@ -8,7 +8,7 @@ use ethers::{ prelude::{artifacts::Libraries, ArtifactId}, signers::LocalWallet, }; -use eyre::{ContextCompat, WrapErr}; +use eyre::{ContextCompat, Result, WrapErr}; use foundry_cli::utils::now; use foundry_common::{fs, get_http_provider}; use foundry_config::Config; @@ -43,7 +43,7 @@ impl MultiChainSequence { target: &ArtifactId, log_folder: &Path, broadcasted: bool, - ) -> eyre::Result { + ) -> Result { let path = MultiChainSequence::get_path(&log_folder.join("multi"), sig, target, broadcasted)?; @@ -56,7 +56,7 @@ impl MultiChainSequence { sig: &str, target: &ArtifactId, broadcasted: bool, - ) -> eyre::Result { + ) -> Result { let mut out = out.to_path_buf(); if !broadcasted { @@ -82,13 +82,13 @@ impl MultiChainSequence { } /// Loads the sequences for the multi chain deployment. - pub fn load(log_folder: &Path, sig: &str, target: &ArtifactId) -> eyre::Result { + pub fn load(log_folder: &Path, sig: &str, target: &ArtifactId) -> Result { let path = MultiChainSequence::get_path(&log_folder.join("multi"), sig, target, true)?; ethers::solc::utils::read_json_file(path).wrap_err("Multi-chain deployment not found.") } /// Saves the transactions as file if it's a standalone deployment. - pub fn save(&mut self) -> eyre::Result<()> { + pub fn save(&mut self) -> Result<()> { self.timestamp = now().as_secs(); //../Contract-latest/run.json @@ -118,7 +118,7 @@ impl ScriptArgs { config: &Config, script_wallets: Vec, verify: VerifyBundle, - ) -> eyre::Result<()> { + ) -> Result<()> { if !libraries.is_empty() { eyre::bail!("Libraries are currently not supported on multi deployment setups."); } diff --git a/crates/cli/src/forge/cmd/script/providers.rs b/crates/cli/src/forge/cmd/script/providers.rs index ef241182bdb33..df05b852c1a39 100644 --- a/crates/cli/src/forge/cmd/script/providers.rs +++ b/crates/cli/src/forge/cmd/script/providers.rs @@ -1,5 +1,5 @@ use ethers::prelude::{Http, Middleware, Provider, RetryClient, U256}; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use foundry_common::{get_http_provider, RpcUrl}; use foundry_config::Chain; use std::{ @@ -20,7 +20,7 @@ impl ProvidersManager { &mut self, rpc: &str, is_legacy: bool, - ) -> eyre::Result<&ProviderInfo> { + ) -> Result<&ProviderInfo> { Ok(match self.inner.entry(rpc.to_string()) { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => { @@ -51,12 +51,12 @@ pub struct ProviderInfo { /// Represents the outcome of a gas price request #[derive(Debug)] pub enum GasPrice { - Legacy(eyre::Result), - EIP1559(eyre::Result<(U256, U256)>), + Legacy(Result), + EIP1559(Result<(U256, U256)>), } impl ProviderInfo { - pub async fn new(rpc: &str, mut is_legacy: bool) -> eyre::Result { + pub async fn new(rpc: &str, mut is_legacy: bool) -> Result { let provider = Arc::new(get_http_provider(rpc)); let chain = provider.get_chainid().await?.as_u64(); @@ -78,7 +78,7 @@ impl ProviderInfo { } /// Returns the gas price to use - pub fn gas_price(&self) -> eyre::Result { + pub fn gas_price(&self) -> Result { let res = match &self.gas_price { GasPrice::Legacy(res) => res.as_ref(), GasPrice::EIP1559(res) => res.as_ref().map(|res| &res.0), diff --git a/crates/cli/src/forge/cmd/script/receipts.rs b/crates/cli/src/forge/cmd/script/receipts.rs index e051c023a2f30..57b531caf9f94 100644 --- a/crates/cli/src/forge/cmd/script/receipts.rs +++ b/crates/cli/src/forge/cmd/script/receipts.rs @@ -4,6 +4,7 @@ use ethers::{ providers::Middleware, types::TransactionReceipt, }; +use eyre::Result; use foundry_cli::{init_progress, update_progress, utils::print_receipt}; use foundry_common::RetryProvider; use futures::StreamExt; @@ -33,7 +34,7 @@ impl From for TxStatus { pub async fn wait_for_pending( provider: Arc, deployment_sequence: &mut ScriptSequence, -) -> eyre::Result<()> { +) -> Result<()> { if deployment_sequence.pending.is_empty() { return Ok(()) } @@ -56,7 +57,7 @@ pub async fn clear_pendings( provider: Arc, deployment_sequence: &mut ScriptSequence, tx_hashes: Option>, -) -> eyre::Result<()> { +) -> Result<()> { let to_query = tx_hashes.unwrap_or_else(|| deployment_sequence.pending.clone()); let count = deployment_sequence.pending.len(); diff --git a/crates/cli/src/forge/cmd/script/runner.rs b/crates/cli/src/forge/cmd/script/runner.rs index 761d967a9d427..338befa271c0d 100644 --- a/crates/cli/src/forge/cmd/script/runner.rs +++ b/crates/cli/src/forge/cmd/script/runner.rs @@ -1,5 +1,6 @@ use super::*; use ethers::types::{Address, Bytes, NameOrAddress, U256}; +use eyre::Result; use forge::{ executor::{CallResult, DeployResult, EvmError, ExecutionErr, Executor, RawCallResult}, revm::interpreter::{return_ok, InstructionResult}, @@ -36,7 +37,7 @@ impl ScriptRunner { sender_nonce: U256, is_broadcast: bool, need_create2_deployer: bool, - ) -> eyre::Result<(Address, ScriptResult)> { + ) -> Result<(Address, ScriptResult)> { trace!(target: "script", "executing setUP()"); if !is_broadcast { @@ -177,7 +178,7 @@ impl ScriptRunner { &mut self, sender_initial_nonce: U256, libraries_len: usize, - ) -> eyre::Result<()> { + ) -> Result<()> { if let Some(ref cheatcodes) = self.executor.inspector_config().cheatcodes { if !cheatcodes.corrected_nonce { self.executor @@ -194,7 +195,7 @@ impl ScriptRunner { } /// Executes the method that will collect all broadcastable transactions. - pub fn script(&mut self, address: Address, calldata: Bytes) -> eyre::Result { + pub fn script(&mut self, address: Address, calldata: Bytes) -> Result { self.call(self.sender, address, calldata, U256::zero(), false) } @@ -205,7 +206,7 @@ impl ScriptRunner { to: Option, calldata: Option, value: Option, - ) -> eyre::Result { + ) -> Result { if let Some(NameOrAddress::Address(to)) = to { self.call(from, to, calldata.unwrap_or_default(), value.unwrap_or(U256::zero()), true) } else if to.is_none() { @@ -263,7 +264,7 @@ impl ScriptRunner { calldata: Bytes, value: U256, commit: bool, - ) -> eyre::Result { + ) -> Result { let mut res = self.executor.call_raw(from, to, calldata.0.clone(), value)?; let mut gas_used = res.gas_used; @@ -322,7 +323,7 @@ impl ScriptRunner { to: Address, calldata: &Bytes, value: U256, - ) -> eyre::Result { + ) -> Result { let mut gas_used = res.gas_used; if matches!(res.exit_reason, return_ok!()) { // store the current gas limit and reset it later diff --git a/crates/cli/src/forge/cmd/script/sequence.rs b/crates/cli/src/forge/cmd/script/sequence.rs index 7098cafcc6168..0c9d0ad20bde3 100644 --- a/crates/cli/src/forge/cmd/script/sequence.rs +++ b/crates/cli/src/forge/cmd/script/sequence.rs @@ -12,7 +12,7 @@ use ethers::{ prelude::{artifacts::Libraries, ArtifactId, TransactionReceipt, TxHash}, types::transaction::eip2718::TypedTransaction, }; -use eyre::{ContextCompat, WrapErr}; +use eyre::{ContextCompat, Result, WrapErr}; use foundry_cli::utils::now; use foundry_common::{fs, shell, SELECTOR_LEN}; use foundry_config::Config; @@ -81,7 +81,7 @@ impl ScriptSequence { config: &Config, broadcasted: bool, is_multi: bool, - ) -> eyre::Result { + ) -> Result { let chain = config.chain_id.unwrap_or_default().id(); let (path, sensitive_path) = ScriptSequence::get_paths( @@ -117,7 +117,7 @@ impl ScriptSequence { target: &ArtifactId, chain_id: u64, broadcasted: bool, - ) -> eyre::Result { + ) -> Result { let (path, sensitive_path) = ScriptSequence::get_paths( &config.broadcast, &config.cache_path, @@ -148,7 +148,7 @@ impl ScriptSequence { } /// Saves the transactions as file if it's a standalone deployment. - pub fn save(&mut self) -> eyre::Result<()> { + pub fn save(&mut self) -> Result<()> { if self.multi || self.transactions.is_empty() { return Ok(()) } @@ -221,7 +221,7 @@ impl ScriptSequence { target: &ArtifactId, chain_id: u64, broadcasted: bool, - ) -> eyre::Result<(PathBuf, PathBuf)> { + ) -> Result<(PathBuf, PathBuf)> { let mut broadcast = broadcast.to_path_buf(); let mut cache = cache.to_path_buf(); let mut common = PathBuf::new(); @@ -254,7 +254,7 @@ impl ScriptSequence { &mut self, config: &Config, mut verify: VerifyBundle, - ) -> eyre::Result<()> { + ) -> Result<()> { trace!(target: "script", "verifying {} contracts [{}]", verify.known_contracts.len(), self.chain); verify.set_chain(config, self.chain.into()); diff --git a/crates/cli/src/forge/cmd/script/transaction.rs b/crates/cli/src/forge/cmd/script/transaction.rs index dff31f2235556..2f0bf4cf9a6c9 100644 --- a/crates/cli/src/forge/cmd/script/transaction.rs +++ b/crates/cli/src/forge/cmd/script/transaction.rs @@ -6,7 +6,7 @@ use ethers::{ prelude::{NameOrAddress, H256 as TxHash}, types::transaction::eip2718::TypedTransaction, }; -use eyre::{ContextCompat, WrapErr}; +use eyre::{ContextCompat, Result, WrapErr}; use foundry_common::{abi::format_token_raw, RpcUrl, SELECTOR_LEN}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; @@ -69,7 +69,7 @@ impl TransactionWithMetadata { decoder: &CallTraceDecoder, additional_contracts: Vec, is_fixed_gas_limit: bool, - ) -> eyre::Result { + ) -> Result { let mut metadata = Self { transaction, rpc, is_fixed_gas_limit, ..Default::default() }; // Specify if any contract was directly created with this transaction @@ -123,7 +123,7 @@ impl TransactionWithMetadata { address: Address, contracts: &BTreeMap, decoder: &CallTraceDecoder, - ) -> eyre::Result<()> { + ) -> Result<()> { if is_create2 { self.opcode = CallKind::Create2; } else { @@ -201,7 +201,7 @@ impl TransactionWithMetadata { target: Address, local_contracts: &BTreeMap, decoder: &CallTraceDecoder, - ) -> eyre::Result<()> { + ) -> Result<()> { self.opcode = CallKind::Call; if let Some(data) = self.transaction.data() { diff --git a/crates/cli/src/forge/cmd/selectors.rs b/crates/cli/src/forge/cmd/selectors.rs index ba7f2e8d771c0..b594081a72d11 100644 --- a/crates/cli/src/forge/cmd/selectors.rs +++ b/crates/cli/src/forge/cmd/selectors.rs @@ -1,6 +1,7 @@ use clap::Parser; use comfy_table::Table; use ethers::prelude::{artifacts::output_selection::ContractOutputSelection, info::ContractInfo}; +use eyre::Result; use foundry_cli::{ opts::{CompilerArgs, CoreBuildArgs, ProjectPathsArgs}, utils::FoundryPathExt, @@ -53,7 +54,7 @@ pub enum SelectorsSubcommands { } impl SelectorsSubcommands { - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { match self { SelectorsSubcommands::Upload { contract, all, project_paths } => { let build_args = CoreBuildArgs { diff --git a/crates/cli/src/forge/cmd/snapshot.rs b/crates/cli/src/forge/cmd/snapshot.rs index 3213aeb9f2ee5..ebc1f242cec74 100644 --- a/crates/cli/src/forge/cmd/snapshot.rs +++ b/crates/cli/src/forge/cmd/snapshot.rs @@ -4,7 +4,7 @@ use super::{ }; use clap::{builder::RangedU64ValueParser, Parser, ValueHint}; use ethers::types::U256; -use eyre::Context; +use eyre::{Context, Result}; use forge::result::TestKindReport; use foundry_cli::utils::STATIC_FUZZ_SEED; use once_cell::sync::Lazy; @@ -92,11 +92,11 @@ impl SnapshotArgs { /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to /// bootstrap a new [`watchexe::Watchexec`] loop. - pub(crate) fn watchexec_config(&self) -> eyre::Result<(InitConfig, RuntimeConfig)> { + pub(crate) fn watchexec_config(&self) -> Result<(InitConfig, RuntimeConfig)> { self.test.watchexec_config() } - pub async fn run(mut self) -> eyre::Result<()> { + pub async fn run(mut self) -> Result<()> { // Set fuzz seed so gas snapshots are deterministic self.test.fuzz_seed = Some(U256::from_big_endian(&STATIC_FUZZ_SEED)); @@ -258,7 +258,7 @@ impl FromStr for SnapshotEntry { } /// Reads a list of snapshot entries from a snapshot file -fn read_snapshot(path: impl AsRef) -> eyre::Result> { +fn read_snapshot(path: impl AsRef) -> Result> { let path = path.as_ref(); let mut entries = Vec::new(); for line in io::BufReader::new( @@ -277,7 +277,7 @@ fn write_to_snapshot_file( tests: &[Test], path: impl AsRef, _format: Option, -) -> eyre::Result<()> { +) -> Result<()> { let mut reports = tests .iter() .map(|test| { @@ -352,7 +352,7 @@ fn check(tests: Vec, snaps: Vec, tolerance: Option) -> } /// Compare the set of tests with an existing snapshot -fn diff(tests: Vec, snaps: Vec) -> eyre::Result<()> { +fn diff(tests: Vec, snaps: Vec) -> Result<()> { let snaps = snaps .into_iter() .map(|s| ((s.contract_name, s.signature), s.gas_used)) diff --git a/crates/cli/src/forge/cmd/test/mod.rs b/crates/cli/src/forge/cmd/test/mod.rs index 45ce77a5565b5..113903ca1e12d 100644 --- a/crates/cli/src/forge/cmd/test/mod.rs +++ b/crates/cli/src/forge/cmd/test/mod.rs @@ -2,6 +2,7 @@ use super::{debug::DebugArgs, install, test::filter::ProjectPathsAwareFilter, wa use cast::fuzz::CounterExample; use clap::Parser; use ethers::types::U256; +use eyre::Result; use forge::{ decode::decode_console_logs, executor::inspector::CheatsConfig, @@ -115,7 +116,7 @@ impl TestArgs { &self.opts } - pub async fn run(self) -> eyre::Result { + pub async fn run(self) -> Result { trace!(target: "forge::test", "executing test command"); shell::set_shell(shell::Shell::from_args(self.opts.silent, self.json))?; self.execute_tests().await @@ -127,7 +128,7 @@ impl TestArgs { /// configured filter will be executed /// /// Returns the test results for all matching tests. - pub async fn execute_tests(self) -> eyre::Result { + pub async fn execute_tests(self) -> Result { // Merge all configs let (mut config, mut evm_opts) = self.load_config_and_evm_opts_emit_warnings()?; @@ -268,7 +269,7 @@ impl TestArgs { /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to /// bootstrap a new [`watchexe::Watchexec`] loop. - pub(crate) fn watchexec_config(&self) -> eyre::Result<(InitConfig, RuntimeConfig)> { + pub(crate) fn watchexec_config(&self) -> Result<(InitConfig, RuntimeConfig)> { self.watch.watchexec_config(|| { let config = Config::from(self); vec![config.src, config.test] @@ -372,7 +373,7 @@ impl TestOutcome { } /// Checks if there are any failures and failures are disallowed - pub fn ensure_ok(&self) -> eyre::Result<()> { + pub fn ensure_ok(&self) -> Result<()> { let failures = self.failures().count(); if self.allow_failure || failures == 0 { return Ok(()) @@ -483,7 +484,7 @@ fn list( runner: MultiContractRunner, filter: ProjectPathsAwareFilter, json: bool, -) -> eyre::Result { +) -> Result { let results = runner.list(&filter); if json { @@ -512,7 +513,7 @@ async fn test( test_options: TestOptions, gas_reporting: bool, fail_fast: bool, -) -> eyre::Result { +) -> Result { trace!(target: "forge::test", "running all tests"); if runner.count_filtered_tests(&filter) == 0 { let filter_str = filter.to_string(); diff --git a/crates/cli/src/forge/cmd/tree.rs b/crates/cli/src/forge/cmd/tree.rs index b742bc4349a64..b7e7669510007 100644 --- a/crates/cli/src/forge/cmd/tree.rs +++ b/crates/cli/src/forge/cmd/tree.rs @@ -3,10 +3,8 @@ use ethers::solc::{ resolver::{Charset, TreeOptions}, Graph, }; -use foundry_cli::{ - opts::ProjectPathsArgs, - utils::{Cmd, LoadConfig}, -}; +use eyre::Result; +use foundry_cli::{opts::ProjectPathsArgs, utils::LoadConfig}; /// CLI arguments for `forge tree`. #[derive(Debug, Clone, Parser)] @@ -27,10 +25,8 @@ pub struct TreeArgs { foundry_config::impl_figment_convert!(TreeArgs, opts); -impl Cmd for TreeArgs { - type Output = (); - - fn run(self) -> eyre::Result { +impl TreeArgs { + pub fn run(self) -> Result<()> { let config = self.try_load_config_emit_warnings()?; let graph = Graph::resolve(&config.project_paths())?; let opts = TreeOptions { charset: self.charset, no_dedupe: self.no_dedupe }; diff --git a/crates/cli/src/forge/cmd/update.rs b/crates/cli/src/forge/cmd/update.rs index 4865d08fae782..9f1f2969a77d3 100644 --- a/crates/cli/src/forge/cmd/update.rs +++ b/crates/cli/src/forge/cmd/update.rs @@ -2,7 +2,7 @@ use clap::{Parser, ValueHint}; use eyre::{Context, Result}; use foundry_cli::{ opts::Dependency, - utils::{Cmd, Git, LoadConfig}, + utils::{Git, LoadConfig}, }; use foundry_config::{impl_figment_convert_basic, Config}; use std::path::PathBuf; @@ -26,10 +26,8 @@ pub struct UpdateArgs { } impl_figment_convert_basic!(UpdateArgs); -impl Cmd for UpdateArgs { - type Output = (); - - fn run(self) -> Result { +impl UpdateArgs { + pub fn run(self) -> Result<()> { let config = self.try_load_config_emit_warnings()?; let (root, paths) = dependencies_paths(&self.dependencies, &config)?; Git::new(&root).submodule_update(self.force, true, paths) diff --git a/crates/cli/src/forge/cmd/verify/etherscan/flatten.rs b/crates/cli/src/forge/cmd/verify/etherscan/flatten.rs index 0fafc99b16736..fb32057924b0b 100644 --- a/crates/cli/src/forge/cmd/verify/etherscan/flatten.rs +++ b/crates/cli/src/forge/cmd/verify/etherscan/flatten.rs @@ -6,7 +6,7 @@ use ethers::{ AggregatedCompilerOutput, CompilerInput, Project, Solc, }, }; -use eyre::Context; +use eyre::{Context, Result}; use semver::{BuildMetadata, Version}; use std::{collections::BTreeMap, path::Path}; @@ -19,7 +19,7 @@ impl EtherscanSourceProvider for EtherscanFlattenedSource { project: &Project, target: &Path, version: &Version, - ) -> eyre::Result<(String, String, CodeFormat)> { + ) -> Result<(String, String, CodeFormat)> { let metadata = project.solc_config.settings.metadata.as_ref(); let bch = metadata.and_then(|m| m.bytecode_hash).unwrap_or_default(); @@ -67,7 +67,7 @@ impl EtherscanFlattenedSource { content: impl Into, version: &Version, contract_path: &Path, - ) -> eyre::Result<()> { + ) -> Result<()> { let version = strip_build_meta(version.clone()); let solc = Solc::find_svm_installed_version(version.to_string())? .unwrap_or(Solc::blocking_install(&version)?); diff --git a/crates/cli/src/forge/cmd/verify/etherscan/mod.rs b/crates/cli/src/forge/cmd/verify/etherscan/mod.rs index 0d09e243f9225..38c287103e992 100644 --- a/crates/cli/src/forge/cmd/verify/etherscan/mod.rs +++ b/crates/cli/src/forge/cmd/verify/etherscan/mod.rs @@ -11,7 +11,7 @@ use ethers::{ prelude::errors::EtherscanError, solc::{artifacts::CompactContract, cache::CacheEntry, Project, Solc}, }; -use eyre::{eyre, Context}; +use eyre::{eyre, Context, Result}; use foundry_cli::utils::{get_cached_entry_by_name, read_constructor_args_file, LoadConfig}; use foundry_common::abi::encode_args; use foundry_config::{Chain, Config, SolcReq}; @@ -49,17 +49,17 @@ trait EtherscanSourceProvider: Send + Sync + Debug { project: &Project, target: &Path, version: &Version, - ) -> eyre::Result<(String, String, CodeFormat)>; + ) -> Result<(String, String, CodeFormat)>; } #[async_trait::async_trait] impl VerificationProvider for EtherscanVerificationProvider { - async fn preflight_check(&mut self, args: VerifyArgs) -> eyre::Result<()> { + async fn preflight_check(&mut self, args: VerifyArgs) -> Result<()> { let _ = self.prepare_request(&args).await?; Ok(()) } - async fn verify(&mut self, args: VerifyArgs) -> eyre::Result<()> { + async fn verify(&mut self, args: VerifyArgs) -> Result<()> { let (etherscan, verify_args) = self.prepare_request(&args).await?; if self.is_contract_verified(ðerscan, &verify_args).await? { @@ -140,7 +140,7 @@ impl VerificationProvider for EtherscanVerificationProvider { } /// Executes the command to check verification status on Etherscan - async fn check(&self, args: VerifyCheckArgs) -> eyre::Result<()> { + async fn check(&self, args: VerifyCheckArgs) -> Result<()> { let config = args.try_load_config_emit_warnings()?; let etherscan = self.client( args.etherscan.chain.unwrap_or_default(), @@ -211,7 +211,7 @@ impl EtherscanVerificationProvider { &mut self, project: &Project, contract_name: &str, - ) -> eyre::Result<&(PathBuf, CacheEntry, CompactContract)> { + ) -> Result<&(PathBuf, CacheEntry, CompactContract)> { if let Some(ref entry) = self.cached_entry { return Ok(entry) } @@ -223,10 +223,7 @@ impl EtherscanVerificationProvider { } /// Configures the API request to the etherscan API using the given [`VerifyArgs`]. - async fn prepare_request( - &mut self, - args: &VerifyArgs, - ) -> eyre::Result<(Client, VerifyContract)> { + async fn prepare_request(&mut self, args: &VerifyArgs) -> Result<(Client, VerifyContract)> { let config = args.try_load_config_emit_warnings()?; let etherscan = self.client( args.etherscan.chain.unwrap_or_default(), @@ -244,7 +241,7 @@ impl EtherscanVerificationProvider { &self, etherscan: &Client, verify_contract: &VerifyContract, - ) -> eyre::Result { + ) -> Result { let check = etherscan.contract_abi(verify_contract.address).await; if let Err(err) = check { @@ -264,7 +261,7 @@ impl EtherscanVerificationProvider { verifier_url: Option<&str>, etherscan_key: Option<&str>, config: &Config, - ) -> eyre::Result { + ) -> Result { let etherscan_config = config.get_etherscan_config_with_chain(Some(chain))?; let api_url = @@ -299,7 +296,7 @@ impl EtherscanVerificationProvider { &mut self, args: &VerifyArgs, config: Option, - ) -> eyre::Result { + ) -> Result { let mut config = if let Some(config) = config { config } else { args.try_load_config_emit_warnings()? }; @@ -334,7 +331,7 @@ impl EtherscanVerificationProvider { /// Get the target contract path. If it wasn't provided, attempt a lookup /// in cache. Validate the path indeed exists on disk. - fn contract_path(&mut self, args: &VerifyArgs, project: &Project) -> eyre::Result { + fn contract_path(&mut self, args: &VerifyArgs, project: &Project) -> Result { let path = match args.contract.path.as_ref() { Some(path) => project.root().join(path), None => { @@ -363,7 +360,7 @@ impl EtherscanVerificationProvider { args: &VerifyArgs, config: &Config, project: &Project, - ) -> eyre::Result { + ) -> Result { if let Some(ref version) = args.compiler_version { return Ok(version.trim_start_matches('v').parse()?) } @@ -405,11 +402,7 @@ impl EtherscanVerificationProvider { /// Return the optional encoded constructor arguments. If the path to /// constructor arguments was provided, read them and encode. Otherwise, /// return whatever was set in the [VerifyArgs] args. - fn constructor_args( - &mut self, - args: &VerifyArgs, - project: &Project, - ) -> eyre::Result> { + fn constructor_args(&mut self, args: &VerifyArgs, project: &Project) -> Result> { if let Some(ref constructor_args_path) = args.constructor_args_path { let (_, _, contract) = self.cache_entry(project, &args.contract.name).wrap_err( "Cache must be enabled in order to use the `--constructor-args-path` option", @@ -448,7 +441,7 @@ impl EtherscanVerificationProvider { /// let version = ensure_solc_build_metadata(version).await?; /// assert_ne!(version.build, BuildMetadata::EMPTY); /// ``` -async fn ensure_solc_build_metadata(version: Version) -> eyre::Result { +async fn ensure_solc_build_metadata(version: Version) -> Result { if version.build != BuildMetadata::EMPTY { Ok(version) } else { diff --git a/crates/cli/src/forge/cmd/verify/etherscan/standard_json.rs b/crates/cli/src/forge/cmd/verify/etherscan/standard_json.rs index eb64267a41b64..f79c76461abfd 100644 --- a/crates/cli/src/forge/cmd/verify/etherscan/standard_json.rs +++ b/crates/cli/src/forge/cmd/verify/etherscan/standard_json.rs @@ -2,7 +2,7 @@ use super::{EtherscanSourceProvider, VerifyArgs}; use ethers::{ etherscan::verify::CodeFormat, prelude::artifacts::StandardJsonCompilerInput, solc::Project, }; -use eyre::Context; +use eyre::{Context, Result}; use semver::Version; use std::path::Path; use tracing::trace; @@ -16,7 +16,7 @@ impl EtherscanSourceProvider for EtherscanStandardJsonSource { project: &Project, target: &Path, version: &Version, - ) -> eyre::Result<(String, String, CodeFormat)> { + ) -> Result<(String, String, CodeFormat)> { let mut input: StandardJsonCompilerInput = project .standard_json_input(target) .wrap_err("Failed to get standard json input")? diff --git a/crates/cli/src/forge/cmd/verify/mod.rs b/crates/cli/src/forge/cmd/verify/mod.rs index 5758c65e31f08..bd17d1418b9b7 100644 --- a/crates/cli/src/forge/cmd/verify/mod.rs +++ b/crates/cli/src/forge/cmd/verify/mod.rs @@ -1,6 +1,7 @@ use super::retry::RetryArgs; use clap::{Parser, ValueHint}; use ethers::{abi::Address, solc::info::ContractInfo}; +use eyre::Result; use foundry_cli::{opts::EtherscanOpts, utils::LoadConfig}; use foundry_config::{figment, impl_figment_convert, impl_figment_convert_cast, Config}; use provider::VerificationProviderType; @@ -124,7 +125,7 @@ impl figment::Provider for VerifyArgs { impl VerifyArgs { /// Run the verify command to submit the contract's source code for verification on etherscan - pub async fn run(mut self) -> eyre::Result<()> { + pub async fn run(mut self) -> Result<()> { let config = self.load_config_emit_warnings(); let chain = config.chain_id.unwrap_or_default(); self.etherscan.chain = Some(chain); @@ -162,7 +163,7 @@ impl VerifyArgs { } /// Returns the configured verification provider - pub fn verification_provider(&self) -> eyre::Result> { + pub fn verification_provider(&self) -> Result> { self.verifier.verifier.client(&self.etherscan.key) } } @@ -191,7 +192,7 @@ impl_figment_convert_cast!(VerifyCheckArgs); impl VerifyCheckArgs { /// Run the verify command to submit the contract's source code for verification on etherscan - pub async fn run(self) -> eyre::Result<()> { + pub async fn run(self) -> Result<()> { println!("Checking verification status on {}", self.etherscan.chain.unwrap_or_default()); self.verifier.verifier.client(&self.etherscan.key)?.check(self).await } diff --git a/crates/cli/src/forge/cmd/verify/provider.rs b/crates/cli/src/forge/cmd/verify/provider.rs index a210e501e0811..08f4a65e2146e 100644 --- a/crates/cli/src/forge/cmd/verify/provider.rs +++ b/crates/cli/src/forge/cmd/verify/provider.rs @@ -3,6 +3,7 @@ use super::{ VerifyCheckArgs, }; use async_trait::async_trait; +use eyre::Result; use std::{fmt, str::FromStr}; /// An abstraction for various verification providers such as etherscan, sourcify, blockscout @@ -15,13 +16,13 @@ pub trait VerificationProvider { /// [`VerifyArgs`] are valid to begin with. This should prevent situations where there's a /// contract deployment that's executed before the verify request and the subsequent verify task /// fails due to misconfiguration. - async fn preflight_check(&mut self, args: VerifyArgs) -> eyre::Result<()>; + async fn preflight_check(&mut self, args: VerifyArgs) -> Result<()>; /// Sends the actual verify request for the targeted contract. - async fn verify(&mut self, args: VerifyArgs) -> eyre::Result<()>; + async fn verify(&mut self, args: VerifyArgs) -> Result<()>; /// Checks whether the contract is verified. - async fn check(&self, args: VerifyCheckArgs) -> eyre::Result<()>; + async fn check(&self, args: VerifyCheckArgs) -> Result<()>; } impl FromStr for VerificationProviderType { @@ -64,7 +65,7 @@ pub enum VerificationProviderType { impl VerificationProviderType { /// Returns the corresponding `VerificationProvider` for the key - pub fn client(&self, key: &Option) -> eyre::Result> { + pub fn client(&self, key: &Option) -> Result> { match self { VerificationProviderType::Etherscan => { if key.as_ref().map_or(true, |key| key.is_empty()) { diff --git a/crates/cli/src/forge/cmd/verify/sourcify.rs b/crates/cli/src/forge/cmd/verify/sourcify.rs index ad93d5d2e8e84..af1a0dc30a7ff 100644 --- a/crates/cli/src/forge/cmd/verify/sourcify.rs +++ b/crates/cli/src/forge/cmd/verify/sourcify.rs @@ -2,6 +2,7 @@ use super::{provider::VerificationProvider, VerifyArgs, VerifyCheckArgs}; use async_trait::async_trait; use cast::SimpleCast; use ethers::solc::ConfigurableContractArtifact; +use eyre::Result; use foundry_cli::utils::{get_cached_entry_by_name, LoadConfig}; use foundry_common::fs; use foundry_utils::Retry; @@ -19,12 +20,12 @@ pub struct SourcifyVerificationProvider; #[async_trait] impl VerificationProvider for SourcifyVerificationProvider { - async fn preflight_check(&mut self, args: VerifyArgs) -> eyre::Result<()> { + async fn preflight_check(&mut self, args: VerifyArgs) -> Result<()> { let _ = self.prepare_request(&args)?; Ok(()) } - async fn verify(&mut self, args: VerifyArgs) -> eyre::Result<()> { + async fn verify(&mut self, args: VerifyArgs) -> Result<()> { let body = self.prepare_request(&args)?; trace!("submitting verification request {:?}", body); @@ -71,7 +72,7 @@ impl VerificationProvider for SourcifyVerificationProvider { Ok(()) } - async fn check(&self, args: VerifyCheckArgs) -> eyre::Result<()> { + async fn check(&self, args: VerifyCheckArgs) -> Result<()> { let retry: Retry = args.retry.into(); let resp = retry .run_async(|| { @@ -105,7 +106,7 @@ impl VerificationProvider for SourcifyVerificationProvider { impl SourcifyVerificationProvider { /// Configures the API request to the sourcify API using the given [`VerifyArgs`]. - fn prepare_request(&self, args: &VerifyArgs) -> eyre::Result { + fn prepare_request(&self, args: &VerifyArgs) -> Result { let mut config = args.try_load_config_emit_warnings()?; config.libraries.extend(args.libraries.clone()); diff --git a/crates/cli/src/forge/cmd/watch.rs b/crates/cli/src/forge/cmd/watch.rs index a6b99c33a51e2..bdee1e3d0456c 100644 --- a/crates/cli/src/forge/cmd/watch.rs +++ b/crates/cli/src/forge/cmd/watch.rs @@ -1,5 +1,6 @@ use super::{build::BuildArgs, snapshot::SnapshotArgs, test::TestArgs}; use clap::Parser; +use eyre::Result; use foundry_cli::utils::{self, FoundryPathExt}; use foundry_config::Config; use std::{collections::HashSet, convert::Infallible, path::PathBuf, sync::Arc}; @@ -64,7 +65,7 @@ impl WatchArgs { pub fn watchexec_config( &self, f: impl FnOnce() -> Vec, - ) -> eyre::Result<(InitConfig, RuntimeConfig)> { + ) -> Result<(InitConfig, RuntimeConfig)> { let init = init()?; let mut runtime = runtime(self)?; @@ -81,7 +82,7 @@ impl WatchArgs { /// Executes a [`Watchexec`] that listens for changes in the project's src dir and reruns `forge /// build` -pub async fn watch_build(args: BuildArgs) -> eyre::Result<()> { +pub async fn watch_build(args: BuildArgs) -> Result<()> { let (init, mut runtime) = args.watchexec_config()?; let cmd = cmd_args(args.watch.watch.as_ref().map(|paths| paths.len()).unwrap_or_default()); @@ -100,7 +101,7 @@ pub async fn watch_build(args: BuildArgs) -> eyre::Result<()> { /// Executes a [`Watchexec`] that listens for changes in the project's src dir and reruns `forge /// snapshot` -pub async fn watch_snapshot(args: SnapshotArgs) -> eyre::Result<()> { +pub async fn watch_snapshot(args: SnapshotArgs) -> Result<()> { let (init, mut runtime) = args.watchexec_config()?; let cmd = cmd_args(args.test.watch.watch.as_ref().map(|paths| paths.len()).unwrap_or_default()); @@ -119,7 +120,7 @@ pub async fn watch_snapshot(args: SnapshotArgs) -> eyre::Result<()> { /// Executes a [`Watchexec`] that listens for changes in the project's src dir and reruns `forge /// test` -pub async fn watch_test(args: TestArgs) -> eyre::Result<()> { +pub async fn watch_test(args: TestArgs) -> Result<()> { let (init, mut runtime) = args.watchexec_config()?; let cmd = cmd_args(args.watch.watch.as_ref().map(|paths| paths.len()).unwrap_or_default()); trace!("watch test cmd={:?}", cmd); @@ -272,7 +273,7 @@ fn cmd_args(num: usize) -> Vec { } /// Returns the Initialisation configuration for [`Watchexec`]. -pub fn init() -> eyre::Result { +pub fn init() -> Result { let mut config = InitConfig::default(); config.on_error(SyncFnHandler::from(|data| -> std::result::Result<(), Infallible> { trace!("[[{:?}]]", data); @@ -390,7 +391,7 @@ fn on_action( } /// Returns the Runtime configuration for [`Watchexec`]. -pub fn runtime(args: &WatchArgs) -> eyre::Result { +pub fn runtime(args: &WatchArgs) -> Result { let mut config = RuntimeConfig::default(); config.pathset(args.watch.clone().unwrap_or_default()); diff --git a/crates/cli/src/forge/main.rs b/crates/cli/src/forge/main.rs index aa697dcb4658e..633b7b8002ef0 100644 --- a/crates/cli/src/forge/main.rs +++ b/crates/cli/src/forge/main.rs @@ -1,6 +1,7 @@ use clap::{CommandFactory, Parser}; use clap_complete::generate; -use foundry_cli::{handler, utils, utils::Cmd}; +use eyre::Result; +use foundry_cli::{handler, utils}; mod cmd; mod opts; @@ -8,7 +9,7 @@ mod opts; use cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch}; use opts::{Opts, Subcommands}; -fn main() -> eyre::Result<()> { +fn main() -> Result<()> { utils::load_dotenv(); handler::install()?; utils::subscriber(); diff --git a/crates/cli/src/handler.rs b/crates/cli/src/handler.rs index febf634bffbbc..c1ee8fe29a95f 100644 --- a/crates/cli/src/handler.rs +++ b/crates/cli/src/handler.rs @@ -1,4 +1,4 @@ -use eyre::EyreHandler; +use eyre::{EyreHandler, Result}; use std::error::Error; use tracing::error; use yansi::Paint; @@ -49,7 +49,7 @@ impl EyreHandler for Handler { /// /// Panics are always caught by the more debug-centric handler. #[cfg_attr(windows, inline(never))] -pub fn install() -> eyre::Result<()> { +pub fn install() -> Result<()> { let debug_enabled = std::env::var("FOUNDRY_DEBUG").is_ok(); if debug_enabled { diff --git a/crates/cli/src/opts/build/core.rs b/crates/cli/src/opts/build/core.rs index d726be2354a77..a9fbffabb16b3 100644 --- a/crates/cli/src/opts/build/core.rs +++ b/crates/cli/src/opts/build/core.rs @@ -4,6 +4,7 @@ use clap::{Parser, ValueHint}; use ethers::solc::{ artifacts::RevertStrings, remappings::Remapping, utils::canonicalized, Project, }; +use eyre::Result; use foundry_config::{ figment, figment::{ @@ -119,7 +120,7 @@ impl CoreBuildArgs { /// This loads the `foundry_config::Config` for the current workspace (see /// [`utils::find_project_root_path`] and merges the cli `BuildArgs` into it before returning /// [`foundry_config::Config::project()`] - pub fn project(&self) -> eyre::Result { + pub fn project(&self) -> Result { let config = self.try_load_config_emit_warnings()?; Ok(config.project()?) } diff --git a/crates/cli/src/opts/build/paths.rs b/crates/cli/src/opts/build/paths.rs index e55f8a93a03dc..b067f39517ed2 100644 --- a/crates/cli/src/opts/build/paths.rs +++ b/crates/cli/src/opts/build/paths.rs @@ -1,5 +1,6 @@ use clap::{Parser, ValueHint}; use ethers::solc::remappings::Remapping; +use eyre::Result; use foundry_config::{ figment, figment::{ diff --git a/crates/cli/src/opts/chain.rs b/crates/cli/src/opts/chain.rs index ed3bf05ab9f48..1649c6fa586b2 100644 --- a/crates/cli/src/opts/chain.rs +++ b/crates/cli/src/opts/chain.rs @@ -1,5 +1,6 @@ use clap::builder::{PossibleValuesParser, TypedValueParser}; use ethers::types::Chain as NamedChain; +use eyre::Result; use foundry_config::Chain; use std::ffi::OsStr; use strum::VariantNames; diff --git a/crates/cli/src/opts/dependency.rs b/crates/cli/src/opts/dependency.rs index 791529b152fcd..ee6b0ee99021f 100644 --- a/crates/cli/src/opts/dependency.rs +++ b/crates/cli/src/opts/dependency.rs @@ -1,5 +1,6 @@ //! CLI dependency parsing +use eyre::Result; use once_cell::sync::Lazy; use regex::Regex; use std::str::FromStr; @@ -129,7 +130,7 @@ impl Dependency { } /// Returns the URL of the dependency if it exists, or an error if not. - pub fn require_url(&self) -> eyre::Result<&str> { + pub fn require_url(&self) -> Result<&str> { self.url.as_deref().ok_or_else(|| eyre::eyre!("dependency {} has no url", self.name())) } } diff --git a/crates/cli/src/opts/transaction.rs b/crates/cli/src/opts/transaction.rs index 1084fa1922e33..d32cff8a80588 100644 --- a/crates/cli/src/opts/transaction.rs +++ b/crates/cli/src/opts/transaction.rs @@ -2,6 +2,7 @@ use crate::utils::{parse_ether_value, parse_u256}; use clap::Parser; use ethers::types::U256; use serde::Serialize; + #[derive(Parser, Debug, Clone, Serialize)] #[clap(next_help_heading = "Transaction options")] pub struct TransactionOpts { diff --git a/crates/cli/src/opts/wallet/mod.rs b/crates/cli/src/opts/wallet/mod.rs index d28b0fd82df94..82e60e6d41cf8 100644 --- a/crates/cli/src/opts/wallet/mod.rs +++ b/crates/cli/src/opts/wallet/mod.rs @@ -216,7 +216,7 @@ impl Wallet { } /// Returns a [Signer] corresponding to the provided private key, mnemonic or hardware signer. #[instrument(skip(self), level = "trace")] - pub async fn signer(&self, chain_id: u64) -> eyre::Result { + pub async fn signer(&self, chain_id: u64) -> Result { trace!("start finding signer"); if self.ledger { diff --git a/crates/cli/src/stdin.rs b/crates/cli/src/stdin.rs index e6491bcbc8b2d..8242cc8057724 100644 --- a/crates/cli/src/stdin.rs +++ b/crates/cli/src/stdin.rs @@ -9,7 +9,7 @@ use std::{ /// Prints a message to [`stdout`][io::stdout] and [reads a line from stdin into a String](read). /// -/// Returns `eyre::Result`, so sometimes `T` must be explicitly specified, like in `str::parse`. +/// Returns `Result`, so sometimes `T` must be explicitly specified, like in `str::parse`. /// /// # Examples /// @@ -39,7 +39,7 @@ macro_rules! prompt { } /// Unwraps the given `Option` or [reads stdin into a String](read) and parses it as `T`. -pub fn unwrap(value: Option, read_line: bool) -> eyre::Result +pub fn unwrap(value: Option, read_line: bool) -> Result where T: FromStr, T::Err: StdError + Send + Sync + 'static, @@ -66,7 +66,7 @@ where /// [Reads stdin into a String](read) and parses it as `Vec` using whitespaces as delimiters if /// the given `Vec` is empty. -pub fn unwrap_vec(mut value: Vec) -> eyre::Result> +pub fn unwrap_vec(mut value: Vec) -> Result> where T: FromStr, T::Err: StdError + Send + Sync + 'static, @@ -81,7 +81,7 @@ where /// Short-hand for `unwrap(value, true)`. #[inline] -pub fn unwrap_line(value: Option) -> eyre::Result +pub fn unwrap_line(value: Option) -> Result where T: FromStr, T::Err: StdError + Send + Sync + 'static, diff --git a/crates/cli/src/utils/cmd.rs b/crates/cli/src/utils/cmd.rs index 0e5534aa441b0..914cdab436866 100644 --- a/crates/cli/src/utils/cmd.rs +++ b/crates/cli/src/utils/cmd.rs @@ -9,7 +9,7 @@ use ethers::{ Artifact, ArtifactId, ProjectCompileOutput, }, }; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use forge::executor::opts::EvmOpts; use foundry_common::{cli_warn, fs, TestFunctionExt}; use foundry_config::{error::ExtractConfigError, figment::Figment, Chain as ConfigChain, Config}; @@ -26,19 +26,13 @@ use tracing::trace; use ui::{TUIExitReason, Tui, Ui}; use yansi::Paint; -/// Common trait for all cli commands -pub trait Cmd: clap::Parser + Sized { - type Output; - fn run(self) -> eyre::Result; -} - /// Given a `Project`'s output, removes the matching ABI, Bytecode and /// Runtime Bytecode of the given contract. #[track_caller] pub fn remove_contract( output: &mut ProjectCompileOutput, info: &ContractInfo, -) -> eyre::Result<(Abi, CompactBytecode, CompactDeployedBytecode)> { +) -> Result<(Abi, CompactBytecode, CompactDeployedBytecode)> { let contract = if let Some(contract) = output.remove_contract(info) { contract } else { @@ -81,7 +75,7 @@ pub fn remove_contract( pub fn get_cached_entry_by_name( cache: &SolFilesCache, name: &str, -) -> eyre::Result<(PathBuf, CacheEntry)> { +) -> Result<(PathBuf, CacheEntry)> { let mut cached_entry = None; let mut alternatives = Vec::new(); @@ -117,7 +111,7 @@ pub fn get_cached_entry_by_name( } /// Returns error if constructor has arguments. -pub fn ensure_clean_constructor(abi: &Abi) -> eyre::Result<()> { +pub fn ensure_clean_constructor(abi: &Abi) -> Result<()> { if let Some(constructor) = &abi.constructor { if !constructor.inputs.is_empty() { eyre::bail!("Contract constructor should have no arguments. Add those arguments to `run(...)` instead, and call it with `--sig run(...)`."); @@ -203,7 +197,7 @@ pub trait LoadConfig { /// Load and sanitize the [`Config`] based on the options provided in self fn load_config(self) -> Config; /// Load and sanitize the [`Config`], as well as extract [`EvmOpts`] from self - fn load_config_and_evm_opts(self) -> eyre::Result<(Config, EvmOpts)>; + fn load_config_and_evm_opts(self) -> Result<(Config, EvmOpts)>; /// Load [`Config`] but do not sanitize. See [`Config::sanitized`] for more information fn load_config_unsanitized(self) -> Config; /// Load [`Config`] but do not sanitize. See [`Config::sanitized`] for more information. @@ -217,7 +211,7 @@ pub trait LoadConfig { /// Returns an error if loading failed fn try_load_config_emit_warnings(self) -> Result; /// Same as [`LoadConfig::load_config_and_evm_opts`] but also emits warnings generated - fn load_config_and_evm_opts_emit_warnings(self) -> eyre::Result<(Config, EvmOpts)>; + fn load_config_and_evm_opts_emit_warnings(self) -> Result<(Config, EvmOpts)>; /// Same as [`LoadConfig::load_config_unsanitized`] but also emits warnings generated fn load_config_unsanitized_emit_warnings(self) -> Config; fn try_load_config_unsanitized_emit_warnings(self) -> Result; @@ -236,7 +230,7 @@ where self.into() } - fn load_config_and_evm_opts(self) -> eyre::Result<(Config, EvmOpts)> { + fn load_config_and_evm_opts(self) -> Result<(Config, EvmOpts)> { let figment: Figment = self.into(); let mut evm_opts = figment.extract::().map_err(ExtractConfigError::new)?; @@ -273,7 +267,7 @@ where Ok(config) } - fn load_config_and_evm_opts_emit_warnings(self) -> eyre::Result<(Config, EvmOpts)> { + fn load_config_and_evm_opts_emit_warnings(self) -> Result<(Config, EvmOpts)> { let (config, evm_opts) = self.load_config_and_evm_opts()?; config.__warnings.iter().for_each(|w| cli_warn!("{w}")); Ok((config, evm_opts)) @@ -293,7 +287,7 @@ where } /// Read contract constructor arguments from the given file. -pub fn read_constructor_args_file(constructor_args_path: PathBuf) -> eyre::Result> { +pub fn read_constructor_args_file(constructor_args_path: PathBuf) -> Result> { if !constructor_args_path.exists() { eyre::bail!("Constructor args file \"{}\" not found", constructor_args_path.display()); } @@ -369,7 +363,7 @@ pub async fn handle_traces( labels: Vec, verbose: bool, debug: bool, -) -> eyre::Result<()> { +) -> Result<()> { let mut etherscan_identifier = EtherscanIdentifier::new(config, chain)?; let labeled_addresses = labels.iter().filter_map(|label_str| { @@ -410,7 +404,7 @@ pub async fn print_traces( result: &mut TraceResult, decoder: CallTraceDecoder, verbose: bool, -) -> eyre::Result<()> { +) -> Result<()> { if result.traces.is_empty() { panic!("No traces found") } @@ -441,7 +435,7 @@ pub fn run_debugger( decoder: CallTraceDecoder, known_contracts: BTreeMap, sources: BTreeMap, -) -> eyre::Result<()> { +) -> Result<()> { let calls: Vec = vec![result.debug]; let flattened = calls.last().expect("we should have collected debug info").flatten(0); let tui = Tui::new( diff --git a/crates/cli/test-utils/src/script.rs b/crates/cli/test-utils/src/script.rs index 16e74c8e81259..4ac44ebf70100 100644 --- a/crates/cli/test-utils/src/script.rs +++ b/crates/cli/test-utils/src/script.rs @@ -4,6 +4,7 @@ use ethers::{ prelude::{Middleware, NameOrAddress, U256}, utils::hex, }; +use eyre::Result; use foundry_common::{get_http_provider, RetryProvider}; use std::{collections::BTreeMap, path::Path, str::FromStr}; @@ -96,7 +97,7 @@ impl ScriptTester { } /// Initialises the test contracts by copying them into the workspace - fn copy_testdata(current_dir: &Path) -> eyre::Result<()> { + fn copy_testdata(current_dir: &Path) -> Result<()> { let testdata = Self::testdata_path(); std::fs::copy(testdata.clone() + "/cheats/Vm.sol", current_dir.join("src/Vm.sol"))?; std::fs::copy(testdata + "/lib/ds-test/src/test.sol", current_dir.join("lib/test.sol"))?; diff --git a/crates/cli/test-utils/src/util.rs b/crates/cli/test-utils/src/util.rs index b51d915bc3958..58b085e56d3b3 100644 --- a/crates/cli/test-utils/src/util.rs +++ b/crates/cli/test-utils/src/util.rs @@ -3,7 +3,7 @@ use ethers_solc::{ project_util::{copy_dir, TempProject}, ArtifactOutput, ConfigurableArtifacts, PathStyle, ProjectPathsConfig, Solc, }; -use eyre::WrapErr; +use eyre::{Result, WrapErr}; use foundry_config::Config; use once_cell::sync::Lazy; use parking_lot::Mutex; @@ -148,7 +148,7 @@ pub fn setup_forge_remote(prj: impl Into) -> (TestProject, TestCo /// Same as `setup_forge_remote` but not panicing pub fn try_setup_forge_remote( config: impl Into, -) -> eyre::Result<(TestProject, TestCommand)> { +) -> Result<(TestProject, TestCommand)> { let config = config.into(); let mut tmp = TempProject::checkout(&config.id).wrap_err("failed to checkout project")?; tmp.project_mut().paths = config.path_style.paths(tmp.root())?; @@ -620,7 +620,7 @@ impl TestCommand { /// Executes command and expects an successful result #[track_caller] - pub fn ensure_execute_success(&mut self) -> eyre::Result { + pub fn ensure_execute_success(&mut self) -> Result { let out = self.try_execute()?; self.ensure_success(out) } @@ -735,7 +735,7 @@ impl TestCommand { } #[track_caller] - pub fn ensure_success(&self, out: process::Output) -> eyre::Result { + pub fn ensure_success(&self, out: process::Output) -> Result { if !out.status.success() { let suggest = if out.stderr.is_empty() { "\n\nDid your forge command end up with no output?".to_string()