diff --git a/crates/forge/bin/main.rs b/crates/forge/bin/main.rs index 82463d64e72a1..2e4fdedde505e 100644 --- a/crates/forge/bin/main.rs +++ b/crates/forge/bin/main.rs @@ -1,21 +1,4 @@ -use clap::{CommandFactory, Parser}; -use clap_complete::generate; -use eyre::Result; -use foundry_cli::{handler, utils}; -use foundry_common::shell; -use foundry_evm::inspectors::cheatcodes::{set_execution_context, ForgeContext}; - -mod cmd; -use cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch}; - -mod opts; -use opts::{Forge, ForgeSubcommand}; - -#[macro_use] -extern crate foundry_common; - -#[macro_use] -extern crate tracing; +use forge::args::run; #[cfg(all(feature = "jemalloc", unix))] #[global_allocator] @@ -27,138 +10,3 @@ fn main() { std::process::exit(1); } } - -fn run() -> Result<()> { - handler::install(); - utils::load_dotenv(); - utils::subscriber(); - utils::enable_paint(); - - let args = Forge::parse(); - args.global.init()?; - init_execution_context(&args.cmd); - - match args.cmd { - ForgeSubcommand::Test(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_test(cmd)) - } else { - let silent = cmd.junit || shell::is_json(); - let outcome = utils::block_on(cmd.run())?; - outcome.ensure_ok(silent) - } - } - ForgeSubcommand::Script(cmd) => utils::block_on(cmd.run_script()), - ForgeSubcommand::Coverage(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_coverage(cmd)) - } else { - utils::block_on(cmd.run()) - } - } - ForgeSubcommand::Bind(cmd) => cmd.run(), - ForgeSubcommand::Build(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_build(cmd)) - } else { - cmd.run().map(drop) - } - } - ForgeSubcommand::VerifyContract(args) => utils::block_on(args.run()), - ForgeSubcommand::VerifyCheck(args) => utils::block_on(args.run()), - ForgeSubcommand::VerifyBytecode(cmd) => utils::block_on(cmd.run()), - ForgeSubcommand::Clone(cmd) => utils::block_on(cmd.run()), - ForgeSubcommand::Cache(cmd) => match cmd.sub { - CacheSubcommands::Clean(cmd) => cmd.run(), - CacheSubcommands::Ls(cmd) => cmd.run(), - }, - ForgeSubcommand::Create(cmd) => utils::block_on(cmd.run()), - ForgeSubcommand::Update(cmd) => cmd.run(), - ForgeSubcommand::Install(cmd) => cmd.run(), - ForgeSubcommand::Remove(cmd) => cmd.run(), - ForgeSubcommand::Remappings(cmd) => cmd.run(), - ForgeSubcommand::Init(cmd) => cmd.run(), - ForgeSubcommand::Completions { shell } => { - generate(shell, &mut Forge::command(), "forge", &mut std::io::stdout()); - Ok(()) - } - ForgeSubcommand::GenerateFigSpec => { - clap_complete::generate( - clap_complete_fig::Fig, - &mut Forge::command(), - "forge", - &mut std::io::stdout(), - ); - Ok(()) - } - ForgeSubcommand::Clean { root } => { - let config = utils::load_config_with_root(root.as_deref())?; - let project = config.project()?; - config.cleanup(&project)?; - Ok(()) - } - ForgeSubcommand::Snapshot(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_gas_snapshot(cmd)) - } else { - utils::block_on(cmd.run()) - } - } - ForgeSubcommand::Fmt(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_fmt(cmd)) - } else { - cmd.run() - } - } - ForgeSubcommand::Config(cmd) => cmd.run(), - ForgeSubcommand::Flatten(cmd) => cmd.run(), - ForgeSubcommand::Inspect(cmd) => cmd.run(), - ForgeSubcommand::Tree(cmd) => cmd.run(), - ForgeSubcommand::Geiger(cmd) => { - let n = cmd.run()?; - if n > 0 { - std::process::exit(n as i32); - } - Ok(()) - } - ForgeSubcommand::Doc(cmd) => { - if cmd.is_watch() { - utils::block_on(watch::watch_doc(cmd)) - } else { - utils::block_on(cmd.run())?; - Ok(()) - } - } - ForgeSubcommand::Selectors { command } => utils::block_on(command.run()), - ForgeSubcommand::Generate(cmd) => match cmd.sub { - GenerateSubcommands::Test(cmd) => cmd.run(), - }, - ForgeSubcommand::Compiler(cmd) => cmd.run(), - ForgeSubcommand::Soldeer(cmd) => utils::block_on(cmd.run()), - ForgeSubcommand::Eip712(cmd) => cmd.run(), - ForgeSubcommand::BindJson(cmd) => cmd.run(), - } -} - -/// Set the program execution context based on `forge` subcommand used. -/// The execution context can be set only once per program, and it can be checked by using -/// cheatcodes. -fn init_execution_context(subcommand: &ForgeSubcommand) { - let context = match subcommand { - ForgeSubcommand::Test(_) => ForgeContext::Test, - ForgeSubcommand::Coverage(_) => ForgeContext::Coverage, - ForgeSubcommand::Snapshot(_) => ForgeContext::Snapshot, - ForgeSubcommand::Script(cmd) => { - if cmd.broadcast { - ForgeContext::ScriptBroadcast - } else if cmd.resume { - ForgeContext::ScriptResume - } else { - ForgeContext::ScriptDryRun - } - } - _ => ForgeContext::Unknown, - }; - set_execution_context(context); -} diff --git a/crates/forge/src/args.rs b/crates/forge/src/args.rs new file mode 100644 index 0000000000000..88928a63b1cda --- /dev/null +++ b/crates/forge/src/args.rs @@ -0,0 +1,154 @@ +use crate::{ + cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch}, + opts::{Forge, ForgeSubcommand}, +}; +use clap::{CommandFactory, Parser}; +use clap_complete::generate; +use eyre::Result; +use foundry_cli::{handler, utils}; +use foundry_common::shell; +use foundry_evm::inspectors::cheatcodes::{set_execution_context, ForgeContext}; + +/// Run the `forge` command line interface. +pub fn run() -> Result<()> { + setup()?; + + let args = Forge::parse(); + args.global.init()?; + + run_command(args) +} + +/// Setup the global logger and other utilities. +pub fn setup() -> Result<()> { + handler::install(); + utils::load_dotenv(); + utils::subscriber(); + utils::enable_paint(); + + Ok(()) +} + +/// Run the subcommand. +pub fn run_command(args: Forge) -> Result<()> { + // Set the execution context based on the subcommand. + let context = match &args.cmd { + ForgeSubcommand::Test(_) => ForgeContext::Test, + ForgeSubcommand::Coverage(_) => ForgeContext::Coverage, + ForgeSubcommand::Snapshot(_) => ForgeContext::Snapshot, + ForgeSubcommand::Script(cmd) => { + if cmd.broadcast { + ForgeContext::ScriptBroadcast + } else if cmd.resume { + ForgeContext::ScriptResume + } else { + ForgeContext::ScriptDryRun + } + } + _ => ForgeContext::Unknown, + }; + set_execution_context(context); + + // Run the subcommand. + match args.cmd { + ForgeSubcommand::Test(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_test(cmd)) + } else { + let silent = cmd.junit || shell::is_json(); + let outcome = utils::block_on(cmd.run())?; + outcome.ensure_ok(silent) + } + } + ForgeSubcommand::Script(cmd) => utils::block_on(cmd.run_script()), + ForgeSubcommand::Coverage(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_coverage(cmd)) + } else { + utils::block_on(cmd.run()) + } + } + ForgeSubcommand::Bind(cmd) => cmd.run(), + ForgeSubcommand::Build(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_build(cmd)) + } else { + cmd.run().map(drop) + } + } + ForgeSubcommand::VerifyContract(args) => utils::block_on(args.run()), + ForgeSubcommand::VerifyCheck(args) => utils::block_on(args.run()), + ForgeSubcommand::VerifyBytecode(cmd) => utils::block_on(cmd.run()), + ForgeSubcommand::Clone(cmd) => utils::block_on(cmd.run()), + ForgeSubcommand::Cache(cmd) => match cmd.sub { + CacheSubcommands::Clean(cmd) => cmd.run(), + CacheSubcommands::Ls(cmd) => cmd.run(), + }, + ForgeSubcommand::Create(cmd) => utils::block_on(cmd.run()), + ForgeSubcommand::Update(cmd) => cmd.run(), + ForgeSubcommand::Install(cmd) => cmd.run(), + ForgeSubcommand::Remove(cmd) => cmd.run(), + ForgeSubcommand::Remappings(cmd) => cmd.run(), + ForgeSubcommand::Init(cmd) => cmd.run(), + ForgeSubcommand::Completions { shell } => { + generate(shell, &mut Forge::command(), "forge", &mut std::io::stdout()); + Ok(()) + } + ForgeSubcommand::GenerateFigSpec => { + clap_complete::generate( + clap_complete_fig::Fig, + &mut Forge::command(), + "forge", + &mut std::io::stdout(), + ); + Ok(()) + } + ForgeSubcommand::Clean { root } => { + let config = utils::load_config_with_root(root.as_deref())?; + let project = config.project()?; + config.cleanup(&project)?; + Ok(()) + } + ForgeSubcommand::Snapshot(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_gas_snapshot(cmd)) + } else { + utils::block_on(cmd.run()) + } + } + ForgeSubcommand::Fmt(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_fmt(cmd)) + } else { + cmd.run() + } + } + ForgeSubcommand::Config(cmd) => cmd.run(), + ForgeSubcommand::Flatten(cmd) => cmd.run(), + ForgeSubcommand::Inspect(cmd) => cmd.run(), + ForgeSubcommand::Tree(cmd) => cmd.run(), + ForgeSubcommand::Geiger(cmd) => { + let n = cmd.run()?; + if n > 0 { + std::process::exit(n as i32); + } + Ok(()) + } + ForgeSubcommand::Doc(cmd) => { + if cmd.is_watch() { + utils::block_on(watch::watch_doc(cmd)) + } else { + utils::block_on(cmd.run())?; + Ok(()) + } + } + ForgeSubcommand::Selectors { command } => utils::block_on(command.run()), + ForgeSubcommand::Generate(cmd) => match cmd.sub { + GenerateSubcommands::Test(cmd) => cmd.run(), + }, + ForgeSubcommand::Compiler(cmd) => cmd.run(), + ForgeSubcommand::Soldeer(cmd) => utils::block_on(cmd.run()), + ForgeSubcommand::Eip712(cmd) => cmd.run(), + ForgeSubcommand::BindJson(cmd) => cmd.run(), + } +} diff --git a/crates/forge/bin/cmd/bind.rs b/crates/forge/src/cmd/bind.rs similarity index 100% rename from crates/forge/bin/cmd/bind.rs rename to crates/forge/src/cmd/bind.rs diff --git a/crates/forge/bin/cmd/bind_json.rs b/crates/forge/src/cmd/bind_json.rs similarity index 100% rename from crates/forge/bin/cmd/bind_json.rs rename to crates/forge/src/cmd/bind_json.rs diff --git a/crates/forge/bin/cmd/build.rs b/crates/forge/src/cmd/build.rs similarity index 94% rename from crates/forge/bin/cmd/build.rs rename to crates/forge/src/cmd/build.rs index 133e2f9ad70ca..3b55aa13fef63 100644 --- a/crates/forge/bin/cmd/build.rs +++ b/crates/forge/src/cmd/build.rs @@ -109,8 +109,8 @@ impl BuildArgs { /// Returns the `Project` for the current workspace /// /// This loads the `foundry_config::Config` for the current workspace (see - /// [`utils::find_project_root`] and merges the cli `BuildArgs` into it before returning - /// [`foundry_config::Config::project()`] + /// [`foundry_config::utils::find_project_root`] and merges the cli `BuildArgs` into it before + /// returning [`foundry_config::Config::project()`] pub fn project(&self) -> Result { self.build.project() } @@ -120,8 +120,7 @@ impl BuildArgs { self.watch.watch.is_some() } - /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to - /// bootstrap a new [`watchexe::Watchexec`] loop. + /// Returns the [`watchexec::Config`] necessary to bootstrap a new watch loop. pub(crate) fn watchexec_config(&self) -> Result { // Use the path arguments or if none where provided the `src`, `test` and `script` // directories as well as the `foundry.toml` configuration file. diff --git a/crates/forge/bin/cmd/cache.rs b/crates/forge/src/cmd/cache.rs similarity index 100% rename from crates/forge/bin/cmd/cache.rs rename to crates/forge/src/cmd/cache.rs diff --git a/crates/forge/bin/cmd/clone.rs b/crates/forge/src/cmd/clone.rs similarity index 99% rename from crates/forge/bin/cmd/clone.rs rename to crates/forge/src/cmd/clone.rs index 7a9e831f1eda4..2aac27c36bad7 100644 --- a/crates/forge/bin/cmd/clone.rs +++ b/crates/forge/src/cmd/clone.rs @@ -306,8 +306,8 @@ impl CloneArgs { /// - `model_checker`, `debug`, and `output_selection` are ignored for now /// /// Detailed information can be found from the following link: -/// - https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options -/// - https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description +/// - +/// - fn update_config_by_metadata( config: &Config, doc: &mut toml_edit::DocumentMut, diff --git a/crates/forge/bin/cmd/compiler.rs b/crates/forge/src/cmd/compiler.rs similarity index 100% rename from crates/forge/bin/cmd/compiler.rs rename to crates/forge/src/cmd/compiler.rs diff --git a/crates/forge/bin/cmd/config.rs b/crates/forge/src/cmd/config.rs similarity index 100% rename from crates/forge/bin/cmd/config.rs rename to crates/forge/src/cmd/config.rs diff --git a/crates/forge/bin/cmd/coverage.rs b/crates/forge/src/cmd/coverage.rs similarity index 99% rename from crates/forge/bin/cmd/coverage.rs rename to crates/forge/src/cmd/coverage.rs index cb9a1a3d783ea..2b656c0be493f 100644 --- a/crates/forge/bin/cmd/coverage.rs +++ b/crates/forge/src/cmd/coverage.rs @@ -1,18 +1,17 @@ use super::{install, test::TestArgs, watch::WatchArgs}; -use alloy_primitives::{map::HashMap, Address, Bytes, U256}; -use clap::{Parser, ValueEnum, ValueHint}; -use eyre::{Context, Result}; -use forge::{ +use crate::{ coverage::{ analysis::{SourceAnalysis, SourceFile, SourceFiles}, anchors::find_anchors, BytecodeReporter, ContractId, CoverageReport, CoverageReporter, CoverageSummaryReporter, DebugReporter, ItemAnchor, LcovReporter, }, - opts::EvmOpts, utils::IcPcMap, MultiContractRunnerBuilder, }; +use alloy_primitives::{map::HashMap, Address, Bytes, U256}; +use clap::{Parser, ValueEnum, ValueHint}; +use eyre::{Context, Result}; use foundry_cli::utils::{LoadConfig, STATIC_FUZZ_SEED}; use foundry_common::compile::ProjectCompiler; use foundry_compilers::{ @@ -23,6 +22,7 @@ use foundry_compilers::{ Artifact, ArtifactId, Project, ProjectCompileOutput, ProjectPathsConfig, }; use foundry_config::Config; +use foundry_evm::opts::EvmOpts; use rayon::prelude::*; use semver::{Version, VersionReq}; use std::{ @@ -330,11 +330,11 @@ impl CoverageArgs { Ok(()) } - pub(crate) fn is_watch(&self) -> bool { + pub fn is_watch(&self) -> bool { self.test.is_watch() } - pub(crate) fn watch(&self) -> &WatchArgs { + pub fn watch(&self) -> &WatchArgs { &self.test.watch } } diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/src/cmd/create.rs similarity index 94% rename from crates/forge/bin/cmd/create.rs rename to crates/forge/src/cmd/create.rs index 18973754cfce6..84e73f6d851ba 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/src/cmd/create.rs @@ -475,8 +475,6 @@ pub type ContractFactory

= DeploymentTxFactory

; /// Helper which manages the deployment transaction of a smart contract. It /// wraps a deployment transaction, and retrieves the contract address output /// by it. -/// -/// Currently, we recommend using the [`ContractDeployer`] type alias. #[derive(Debug)] #[must_use = "ContractDeploymentTx does nothing unless you `send` it"] pub struct ContractDeploymentTx { @@ -513,9 +511,8 @@ pub struct Deployer

{ impl> Deployer

{ /// Broadcasts the contract deployment transaction and after waiting for it to - /// be sufficiently confirmed (default: 1), it returns a tuple with - /// the [`Contract`](crate::Contract) struct at the deployed contract's address - /// and the corresponding [`AnyReceipt`]. + /// be sufficiently confirmed (default: 1), it returns a tuple with the [`Address`] at the + /// deployed contract's address and the corresponding [`AnyTransactionReceipt`]. pub async fn send_with_receipt( self, ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { @@ -536,42 +533,9 @@ impl> Deployer

{ } } -/// To deploy a contract to the Ethereum network, a `ContractFactory` can be +/// To deploy a contract to the Ethereum network, a [`ContractFactory`] can be /// created which manages the Contract bytecode and Application Binary Interface /// (ABI), usually generated from the Solidity compiler. -/// -/// Once the factory's deployment transaction is mined with sufficient confirmations, -/// the [`Contract`](crate::Contract) object is returned. -/// -/// # Example -/// -/// ``` -/// # async fn foo() -> Result<(), Box> { -/// use alloy_primitives::Bytes; -/// use ethers_contract::ContractFactory; -/// use ethers_providers::{Provider, Http}; -/// -/// // get the contract ABI and bytecode -/// let abi = Default::default(); -/// let bytecode = Bytes::from_static(b"..."); -/// -/// // connect to the network -/// let client = Provider::::try_from("http://localhost:8545").unwrap(); -/// let client = std::sync::Arc::new(client); -/// -/// // create a factory which will be used to deploy instances of the contract -/// let factory = ContractFactory::new(abi, bytecode, client); -/// -/// // The deployer created by the `deploy` call exposes a builder which gets consumed -/// // by the async `send` call -/// let contract = factory -/// .deploy("initial value".to_string())? -/// .confirmations(0usize) -/// .send() -/// .await?; -/// println!("{}", contract.address()); -/// # Ok(()) -/// # } #[derive(Clone, Debug)] pub struct DeploymentTxFactory

{ client: P, diff --git a/crates/forge/bin/cmd/doc/mod.rs b/crates/forge/src/cmd/doc/mod.rs similarity index 100% rename from crates/forge/bin/cmd/doc/mod.rs rename to crates/forge/src/cmd/doc/mod.rs diff --git a/crates/forge/bin/cmd/doc/server.rs b/crates/forge/src/cmd/doc/server.rs similarity index 100% rename from crates/forge/bin/cmd/doc/server.rs rename to crates/forge/src/cmd/doc/server.rs diff --git a/crates/forge/bin/cmd/eip712.rs b/crates/forge/src/cmd/eip712.rs similarity index 99% rename from crates/forge/bin/cmd/eip712.rs rename to crates/forge/src/cmd/eip712.rs index 57e21749c8e45..3c85840673d6a 100644 --- a/crates/forge/bin/cmd/eip712.rs +++ b/crates/forge/src/cmd/eip712.rs @@ -176,7 +176,8 @@ impl Resolver { Ok(Some(result)) } - /// Converts given [TypeName] into a type which can be converted to [DynSolType]. + /// Converts given [TypeName] into a type which can be converted to + /// [`alloy_dyn_abi::DynSolType`]. /// /// Returns `None` if the type is not supported for EIP712 encoding. pub fn resolve_type( diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/src/cmd/flatten.rs similarity index 100% rename from crates/forge/bin/cmd/flatten.rs rename to crates/forge/src/cmd/flatten.rs diff --git a/crates/forge/bin/cmd/fmt.rs b/crates/forge/src/cmd/fmt.rs similarity index 100% rename from crates/forge/bin/cmd/fmt.rs rename to crates/forge/src/cmd/fmt.rs diff --git a/crates/forge/bin/cmd/geiger.rs b/crates/forge/src/cmd/geiger.rs similarity index 100% rename from crates/forge/bin/cmd/geiger.rs rename to crates/forge/src/cmd/geiger.rs diff --git a/crates/forge/bin/cmd/generate/mod.rs b/crates/forge/src/cmd/generate/mod.rs similarity index 100% rename from crates/forge/bin/cmd/generate/mod.rs rename to crates/forge/src/cmd/generate/mod.rs diff --git a/crates/forge/bin/cmd/init.rs b/crates/forge/src/cmd/init.rs similarity index 100% rename from crates/forge/bin/cmd/init.rs rename to crates/forge/src/cmd/init.rs diff --git a/crates/forge/bin/cmd/inspect.rs b/crates/forge/src/cmd/inspect.rs similarity index 99% rename from crates/forge/bin/cmd/inspect.rs rename to crates/forge/src/cmd/inspect.rs index b8aa0286bb01a..32daac06f6172 100644 --- a/crates/forge/bin/cmd/inspect.rs +++ b/crates/forge/src/cmd/inspect.rs @@ -1,9 +1,9 @@ +use crate::revm::primitives::Eof; use alloy_json_abi::{EventParam, InternalType, JsonAbi, Param}; use alloy_primitives::{hex, keccak256, Address}; use clap::Parser; use comfy_table::{modifiers::UTF8_ROUND_CORNERS, Cell, Table}; use eyre::{Context, Result}; -use forge::revm::primitives::Eof; use foundry_cli::opts::{BuildOpts, CompilerOpts}; use foundry_common::{ compile::{PathOrContractInfo, ProjectCompiler}, diff --git a/crates/forge/bin/cmd/install.rs b/crates/forge/src/cmd/install.rs similarity index 100% rename from crates/forge/bin/cmd/install.rs rename to crates/forge/src/cmd/install.rs diff --git a/crates/forge/bin/cmd/mod.rs b/crates/forge/src/cmd/mod.rs similarity index 100% rename from crates/forge/bin/cmd/mod.rs rename to crates/forge/src/cmd/mod.rs diff --git a/crates/forge/bin/cmd/remappings.rs b/crates/forge/src/cmd/remappings.rs similarity index 100% rename from crates/forge/bin/cmd/remappings.rs rename to crates/forge/src/cmd/remappings.rs diff --git a/crates/forge/bin/cmd/remove.rs b/crates/forge/src/cmd/remove.rs similarity index 100% rename from crates/forge/bin/cmd/remove.rs rename to crates/forge/src/cmd/remove.rs diff --git a/crates/forge/bin/cmd/selectors.rs b/crates/forge/src/cmd/selectors.rs similarity index 100% rename from crates/forge/bin/cmd/selectors.rs rename to crates/forge/src/cmd/selectors.rs diff --git a/crates/forge/bin/cmd/snapshot.rs b/crates/forge/src/cmd/snapshot.rs similarity index 98% rename from crates/forge/bin/cmd/snapshot.rs rename to crates/forge/src/cmd/snapshot.rs index aa0f0d94d95ee..da642bd1241be 100644 --- a/crates/forge/bin/cmd/snapshot.rs +++ b/crates/forge/src/cmd/snapshot.rs @@ -1,8 +1,8 @@ use super::test; +use crate::result::{SuiteTestResult, TestKindReport, TestOutcome}; use alloy_primitives::{map::HashMap, U256}; use clap::{builder::RangedU64ValueParser, Parser, ValueHint}; use eyre::{Context, Result}; -use forge::result::{SuiteTestResult, TestKindReport, TestOutcome}; use foundry_cli::utils::STATIC_FUZZ_SEED; use regex::Regex; use std::{ @@ -85,8 +85,7 @@ impl GasSnapshotArgs { self.test.is_watch() } - /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to - /// bootstrap a new [`watchexe::Watchexec`] loop. + /// Returns the [`watchexec::Config`] necessary to bootstrap a new watch loop. pub(crate) fn watchexec_config(&self) -> Result { self.test.watchexec_config() } diff --git a/crates/forge/bin/cmd/soldeer.rs b/crates/forge/src/cmd/soldeer.rs similarity index 100% rename from crates/forge/bin/cmd/soldeer.rs rename to crates/forge/src/cmd/soldeer.rs diff --git a/crates/forge/bin/cmd/test/filter.rs b/crates/forge/src/cmd/test/filter.rs similarity index 100% rename from crates/forge/bin/cmd/test/filter.rs rename to crates/forge/src/cmd/test/filter.rs diff --git a/crates/forge/bin/cmd/test/mod.rs b/crates/forge/src/cmd/test/mod.rs similarity index 99% rename from crates/forge/bin/cmd/test/mod.rs rename to crates/forge/src/cmd/test/mod.rs index 1a6d88631955b..09637529b308d 100644 --- a/crates/forge/bin/cmd/test/mod.rs +++ b/crates/forge/src/cmd/test/mod.rs @@ -1,9 +1,5 @@ use super::{install, test::filter::ProjectPathsAwareFilter, watch::WatchArgs}; -use alloy_primitives::U256; -use chrono::Utc; -use clap::{Parser, ValueHint}; -use eyre::{bail, Context, OptionExt, Result}; -use forge::{ +use crate::{ decode::decode_console_logs, gas_report::GasReport, multi_runner::matches_contract, @@ -16,6 +12,10 @@ use forge::{ }, MultiContractRunner, MultiContractRunnerBuilder, TestFilter, }; +use alloy_primitives::U256; +use chrono::Utc; +use clap::{Parser, ValueHint}; +use eyre::{bail, Context, OptionExt, Result}; use foundry_cli::{ opts::{BuildOpts, GlobalArgs}, utils::{self, LoadConfig}, @@ -53,8 +53,8 @@ use yansi::Paint; mod filter; mod summary; +use crate::{result::TestKind, traces::render_trace_arena_inner}; pub use filter::FilterArgs; -use forge::{result::TestKind, traces::render_trace_arena_inner}; use quick_junit::{NonSuccessKind, Report, TestCase, TestCaseStatus, TestSuite}; use summary::{format_invariant_metrics_table, TestSummaryReport}; @@ -835,8 +835,7 @@ impl TestArgs { self.watch.watch.is_some() } - /// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to - /// bootstrap a new [`watchexe::Watchexec`] loop. + /// Returns the [`watchexec::Config`] necessary to bootstrap a new watch loop. pub(crate) fn watchexec_config(&self) -> Result { self.watch.watchexec_config(|| { let config = self.load_config()?; diff --git a/crates/forge/bin/cmd/test/summary.rs b/crates/forge/src/cmd/test/summary.rs similarity index 100% rename from crates/forge/bin/cmd/test/summary.rs rename to crates/forge/src/cmd/test/summary.rs diff --git a/crates/forge/bin/cmd/tree.rs b/crates/forge/src/cmd/tree.rs similarity index 100% rename from crates/forge/bin/cmd/tree.rs rename to crates/forge/src/cmd/tree.rs diff --git a/crates/forge/bin/cmd/update.rs b/crates/forge/src/cmd/update.rs similarity index 100% rename from crates/forge/bin/cmd/update.rs rename to crates/forge/src/cmd/update.rs diff --git a/crates/forge/bin/cmd/watch.rs b/crates/forge/src/cmd/watch.rs similarity index 100% rename from crates/forge/bin/cmd/watch.rs rename to crates/forge/src/cmd/watch.rs diff --git a/crates/forge/src/lib.rs b/crates/forge/src/lib.rs index 27dd63738f2ee..4c7d135767719 100644 --- a/crates/forge/src/lib.rs +++ b/crates/forge/src/lib.rs @@ -8,6 +8,10 @@ extern crate foundry_common; #[macro_use] extern crate tracing; +pub mod args; +pub mod cmd; +pub mod opts; + pub mod coverage; pub mod gas_report; diff --git a/crates/forge/bin/opts.rs b/crates/forge/src/opts.rs similarity index 100% rename from crates/forge/bin/opts.rs rename to crates/forge/src/opts.rs