From 4f3075cd1463764ec0b87331665dde5b03b85b60 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Mon, 16 Jun 2025 13:25:42 -0500 Subject: [PATCH 1/4] chore: refactor phoundry crate --- bin/pcl/src/main.rs | 2 +- crates/core/src/assertion_da.rs | 2 +- crates/phoundry/src/build.rs | 0 .../src/{phorge.rs => build_and_flatten.rs} | 49 ------------ crates/phoundry/src/error.rs | 23 +++++- crates/phoundry/src/lib.rs | 5 +- crates/phoundry/src/test.rs | 75 +++++++++++++++++++ 7 files changed, 103 insertions(+), 53 deletions(-) create mode 100644 crates/phoundry/src/build.rs rename crates/phoundry/src/{phorge.rs => build_and_flatten.rs} (85%) create mode 100644 crates/phoundry/src/test.rs diff --git a/bin/pcl/src/main.rs b/bin/pcl/src/main.rs index a071e07..ba021c4 100644 --- a/bin/pcl/src/main.rs +++ b/bin/pcl/src/main.rs @@ -14,7 +14,7 @@ use pcl_core::{ ConfigArgs, }, }; -use pcl_phoundry::phorge::PhorgeTest; +use pcl_phoundry::test::PhorgeTest; use serde_json::json; const VERSION_MESSAGE: &str = concat!( diff --git a/crates/core/src/assertion_da.rs b/crates/core/src/assertion_da.rs index 1097a60..8545d3a 100644 --- a/crates/core/src/assertion_da.rs +++ b/crates/core/src/assertion_da.rs @@ -15,7 +15,7 @@ use indicatif::{ ProgressStyle, }; use pcl_common::args::CliArgs; -use pcl_phoundry::phorge::{ +use pcl_phoundry::build_and_flatten::{ BuildAndFlatOutput, BuildAndFlattenArgs, }; diff --git a/crates/phoundry/src/build.rs b/crates/phoundry/src/build.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/phoundry/src/phorge.rs b/crates/phoundry/src/build_and_flatten.rs similarity index 85% rename from crates/phoundry/src/phorge.rs rename to crates/phoundry/src/build_and_flatten.rs index d013693..cf6c734 100644 --- a/crates/phoundry/src/phorge.rs +++ b/crates/phoundry/src/build_and_flatten.rs @@ -42,15 +42,6 @@ use tokio::task::spawn_blocking; use crate::error::PhoundryError; -/// Command-line interface for running Phorge tests. -/// This struct wraps the standard Foundry test arguments. -#[derive(Debug, Parser, Clone)] -#[clap(about = "Run tests using Phorge")] -pub struct PhorgeTest { - #[clap(flatten)] - pub test_args: TestArgs, -} - /// Output from building and flattening a Solidity contract. /// Contains the compiler version used and the flattened source code. #[derive(Debug, Default)] @@ -243,46 +234,6 @@ impl BuildAndFlattenArgs { } } -impl PhorgeTest { - /// Runs the test command in a separate blocking task. - /// This prevents blocking the current runtime while executing the forge command. - pub async fn run(self) -> Result<(), Box> { - // Extract the Send-safe parts of the test args - let test_args = self.test_args; - let global_opts = test_args.global.clone(); - global_opts.init()?; - // Spawn the blocking operation in a separate task - spawn_blocking(move || { - // Reconstruct the Forge struct inside the closure - let forge = Forge { - cmd: ForgeSubcommand::Test(test_args), - global: global_opts, - }; - forge::args::run_command(forge) - }) - .await - .map_err(|e| Box::new(PhoundryError::ForgeCommandFailed(e.into())))??; - Ok(()) - } -} - -impl From for Box { - fn from(error: ExtractConfigError) -> Self { - Box::new(PhoundryError::FoundryConfigError(error)) - } -} - -impl From for Box { - fn from(error: std::io::Error) -> Self { - Box::new(PhoundryError::from(error)) - } -} - -impl From for Box { - fn from(error: Report) -> Self { - Box::new(PhoundryError::ForgeCommandFailed(error)) - } -} #[cfg(test)] mod tests { diff --git a/crates/phoundry/src/error.rs b/crates/phoundry/src/error.rs index cc2feff..4733e19 100644 --- a/crates/phoundry/src/error.rs +++ b/crates/phoundry/src/error.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre; +use color_eyre::{eyre, Report}; use foundry_compilers::{ error::SolcError, flatten::FlattenerError, @@ -9,6 +9,8 @@ use std::{ }; use thiserror::Error; +use foundry_config::error::ExtractConfigError; + #[derive(Error, Debug)] pub enum PhoundryError { #[error("forge is not installed or not available in PATH")] @@ -40,3 +42,22 @@ pub enum PhoundryError { #[error("Compilation failed:\n{0}")] CompilationError(eyre::Report), } + + +impl From for Box { + fn from(error: ExtractConfigError) -> Self { + Box::new(PhoundryError::FoundryConfigError(error)) + } +} + +impl From for Box { + fn from(error: std::io::Error) -> Self { + Box::new(PhoundryError::from(error)) + } +} + +impl From for Box { + fn from(error: Report) -> Self { + Box::new(PhoundryError::ForgeCommandFailed(error)) + } +} diff --git a/crates/phoundry/src/lib.rs b/crates/phoundry/src/lib.rs index cac1f62..a798a75 100644 --- a/crates/phoundry/src/lib.rs +++ b/crates/phoundry/src/lib.rs @@ -1,2 +1,5 @@ pub mod error; -pub mod phorge; +pub mod test; +pub mod build; +pub mod build_and_flatten; + diff --git a/crates/phoundry/src/test.rs b/crates/phoundry/src/test.rs new file mode 100644 index 0000000..6a35699 --- /dev/null +++ b/crates/phoundry/src/test.rs @@ -0,0 +1,75 @@ +use clap::{ + Parser, + ValueHint, +}; +use color_eyre::Report; +use forge::{ + cmd::{ + build::BuildArgs, + test::TestArgs, + }, + opts::{ + Forge, + ForgeSubcommand, + }, +}; +use foundry_cli::{ + opts::{ + BuildOpts, + ProjectPathOpts, + }, + utils::LoadConfig, +}; +use foundry_common::compile::ProjectCompiler; +use foundry_compilers::{ + flatten::{ + Flattener, + FlattenerError, + }, + info::ContractInfo, + solc::SolcLanguage, + ProjectCompileOutput, +}; + +use alloy_json_abi::JsonAbi; + +use foundry_config::{ + error::ExtractConfigError, + find_project_root, +}; +use std::path::PathBuf; +use tokio::task::spawn_blocking; + +use crate::error::PhoundryError; + +/// Command-line interface for running Phorge tests. +/// This struct wraps the standard Foundry test arguments. +#[derive(Debug, Parser, Clone)] +#[clap(about = "Run tests using Phorge")] +pub struct PhorgeTest { + #[clap(flatten)] + pub test_args: TestArgs, +} + +impl PhorgeTest { + /// Runs the test command in a separate blocking task. + /// This prevents blocking the current runtime while executing the forge command. + pub async fn run(self) -> Result<(), Box> { + // Extract the Send-safe parts of the test args + let test_args = self.test_args; + let global_opts = test_args.global.clone(); + global_opts.init()?; + // Spawn the blocking operation in a separate task + spawn_blocking(move || { + // Reconstruct the Forge struct inside the closure + let forge = Forge { + cmd: ForgeSubcommand::Test(test_args), + global: global_opts, + }; + forge::args::run_command(forge) + }) + .await + .map_err(|e| Box::new(PhoundryError::ForgeCommandFailed(e.into())))??; + Ok(()) + } +} \ No newline at end of file From 47a9a205e4db7cbfa61d2ff8dd9426548e76cba2 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Mon, 16 Jun 2025 14:19:34 -0500 Subject: [PATCH 2/4] feat: add build args --- bin/pcl/src/main.rs | 2 +- crates/core/tests/common/da_store_harness.rs | 2 +- crates/phoundry/src/build.rs | 249 ++++++++++++++++++ crates/phoundry/src/build_and_flatten.rs | 59 +---- crates/phoundry/src/compile.rs | 44 ++++ crates/phoundry/src/error.rs | 6 +- crates/phoundry/src/lib.rs | 6 +- .../phoundry/src/{test.rs => phorge_test.rs} | 37 +-- 8 files changed, 310 insertions(+), 95 deletions(-) create mode 100644 crates/phoundry/src/compile.rs rename crates/phoundry/src/{test.rs => phorge_test.rs} (68%) diff --git a/bin/pcl/src/main.rs b/bin/pcl/src/main.rs index ba021c4..e8ebbc8 100644 --- a/bin/pcl/src/main.rs +++ b/bin/pcl/src/main.rs @@ -14,7 +14,7 @@ use pcl_core::{ ConfigArgs, }, }; -use pcl_phoundry::test::PhorgeTest; +use pcl_phoundry::phorge_test::PhorgeTest; use serde_json::json; const VERSION_MESSAGE: &str = concat!( diff --git a/crates/core/tests/common/da_store_harness.rs b/crates/core/tests/common/da_store_harness.rs index aa34ba2..c12d995 100644 --- a/crates/core/tests/common/da_store_harness.rs +++ b/crates/core/tests/common/da_store_harness.rs @@ -10,7 +10,7 @@ use pcl_core::{ assertion_da::DaStoreArgs, error::DaSubmitError, }; -use pcl_phoundry::phorge::BuildAndFlattenArgs; +use pcl_phoundry::build_and_flatten::BuildAndFlattenArgs; use std::{ collections::HashMap, path::PathBuf, diff --git a/crates/phoundry/src/build.rs b/crates/phoundry/src/build.rs index e69de29..ad1e3f9 100644 --- a/crates/phoundry/src/build.rs +++ b/crates/phoundry/src/build.rs @@ -0,0 +1,249 @@ +use clap::{ + Parser, + ValueHint, +}; +use foundry_cli::opts::{ + BuildOpts, + ProjectPathOpts, +}; + +use std::path::PathBuf; + +use crate::compile::compile; +use crate::error::PhoundryError; + +/// Command-line arguments for building assertion contracts and tests. +#[derive(Debug, Default, Parser)] +#[clap(about = "Build contracts using Phorge")] +pub struct BuildArgs { + /// Root directory of the project + #[clap( + short = 'r', + long, + value_hint = ValueHint::DirPath, + help = "Root directory of the project" + )] + pub root: Option, +} + +impl BuildArgs { + /// Builds the assertion contract and tests + /// + /// # Returns + /// + /// - `Ok(())` + /// - `Err(PhoundryError)` if any step in the process fails + pub fn run(&self) -> Result<(), Box> { + let build_cmd = BuildOpts { + project_paths: ProjectPathOpts { + root: self.root.clone(), + // FIXME(Odysseas): this essentially hard-codes the location of the assertions to live in + // assertions/src + contracts: Some(PathBuf::from("assertions/src")), + ..Default::default() + }, + ..Default::default() + }; + + foundry_cli::utils::load_dotenv(); + + compile(build_cmd)?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs; + use tempfile::TempDir; + + // Helper function to create a temporary Solidity project with valid contracts + fn setup_valid_test_project() -> (TempDir, PathBuf) { + let temp_dir = TempDir::new().unwrap(); + let project_root = temp_dir.path().join("test_project"); + fs::create_dir_all(&project_root).unwrap(); + + // Create assertions/src directory structure + let contract_dir = project_root.join("assertions").join("src"); + fs::create_dir_all(&contract_dir).unwrap(); + + // Create a valid test contract + let contract_path = contract_dir.join("ValidContract.sol"); + fs::write( + &contract_path, + r#"// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract ValidContract { + function test() public pure returns (bool) { + return true; + } +}"#, + ) + .unwrap(); + + (temp_dir, project_root) + } + + // Helper function to create a temporary Solidity project with compilation errors + fn setup_invalid_test_project() -> (TempDir, PathBuf) { + let temp_dir = TempDir::new().unwrap(); + let project_root = temp_dir.path().join("test_project"); + fs::create_dir_all(&project_root).unwrap(); + + // Create assertions/src directory structure + let contract_dir = project_root.join("assertions").join("src"); + fs::create_dir_all(&contract_dir).unwrap(); + + // Create a contract with compilation errors + let contract_path = contract_dir.join("InvalidContract.sol"); + fs::write( + &contract_path, + r#"// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract InvalidContract { + // Missing semicolon - syntax error + uint256 public value = 42 + + // Invalid function syntax - missing parentheses + function test public pure returns (bool) { + // Type mismatch error + return "not a boolean"; + } + + // Undefined variable error + function anotherTest() public pure returns (uint256) { + return undefinedVariable; + } + + // Missing closing brace +}"#, + ) + .unwrap(); + + (temp_dir, project_root) + } + + // Helper function to create an empty project (no source files) + fn setup_empty_test_project() -> (TempDir, PathBuf) { + let temp_dir = TempDir::new().unwrap(); + let project_root = temp_dir.path().join("test_project"); + fs::create_dir_all(&project_root).unwrap(); + + // Create assertions/src directory but leave it empty + let contract_dir = project_root.join("assertions").join("src"); + fs::create_dir_all(&contract_dir).unwrap(); + + (temp_dir, project_root) + } + + #[test] + fn test_build_args_new() { + let args = BuildArgs { root: None }; + + assert!(args.root.is_none()); + } + + #[test] + fn test_build_args_with_root() { + let root_path = PathBuf::from("/test/path"); + let args = BuildArgs { + root: Some(root_path.clone()), + }; + + assert_eq!(args.root, Some(root_path)); + } + + #[test] + fn test_compilation_with_invalid_contract() { + let (_temp_dir, project_root) = setup_invalid_test_project(); + + let args = BuildArgs { + root: Some(project_root), + }; + + let result = args.run(); + + // Compilation should fail due to syntax errors + assert!( + result.is_err(), + "Expected compilation to fail with invalid contract" + ); + + // Verify it's a compilation error + if let Err(error) = result { + // The error should be a compilation error or related error type + // We can't check the exact error type without knowing the PhoundryError variants, + // but the compilation should definitely fail + println!("Compilation failed as expected with error: {:?}", error); + } + } + + #[test] + fn test_compilation_with_empty_directory() { + let (_temp_dir, project_root) = setup_empty_test_project(); + + let args = BuildArgs { + root: Some(project_root), + }; + + let result = args.run(); + + // Compilation should fail due to no source files + assert!( + result.is_err(), + "Expected compilation to fail with empty directory" + ); + + if let Err(error) = result { + println!("Compilation failed as expected with error: {:?}", error); + } + } + + #[test] + fn test_compilation_with_nonexistent_directory() { + let temp_dir = TempDir::new().unwrap(); + let nonexistent_path = temp_dir.path().join("nonexistent_project"); + + let args = BuildArgs { + root: Some(nonexistent_path), + }; + + let result = args.run(); + + // Compilation should fail due to nonexistent directory + assert!( + result.is_err(), + "Expected compilation to fail with nonexistent directory" + ); + + if let Err(error) = result { + println!("Compilation failed as expected with error: {:?}", error); + } + } + + #[tokio::test(flavor = "multi_thread")] + async fn test_build_integration_with_valid_contract() { + let (_temp_dir, project_root) = setup_valid_test_project(); + + let args = BuildArgs { + root: Some(project_root), + }; + + let result = args.run(); + + // This test might succeed or fail depending on the environment and dependencies + // In a real test environment with proper setup, it should succeed with valid contracts + match result { + Ok(_) => println!("Compilation succeeded as expected"), + Err(error) => { + println!( + "Compilation failed (might be expected in test environment): {:?}", + error + ) + } + } + } +} diff --git a/crates/phoundry/src/build_and_flatten.rs b/crates/phoundry/src/build_and_flatten.rs index cf6c734..fac50bf 100644 --- a/crates/phoundry/src/build_and_flatten.rs +++ b/crates/phoundry/src/build_and_flatten.rs @@ -2,17 +2,6 @@ use clap::{ Parser, ValueHint, }; -use color_eyre::Report; -use forge::{ - cmd::{ - build::BuildArgs, - test::TestArgs, - }, - opts::{ - Forge, - ForgeSubcommand, - }, -}; use foundry_cli::{ opts::{ BuildOpts, @@ -20,7 +9,6 @@ use foundry_cli::{ }, utils::LoadConfig, }; -use foundry_common::compile::ProjectCompiler; use foundry_compilers::{ flatten::{ Flattener, @@ -33,12 +21,8 @@ use foundry_compilers::{ use alloy_json_abi::JsonAbi; -use foundry_config::{ - error::ExtractConfigError, - find_project_root, -}; +use foundry_config::find_project_root; use std::path::PathBuf; -use tokio::task::spawn_blocking; use crate::error::PhoundryError; @@ -151,8 +135,8 @@ impl BuildAndFlattenArgs { /// Builds the project and returns the compilation output. fn build(&self) -> Result> { - let build_cmd = BuildArgs { - build: BuildOpts { + let build_opts = + BuildOpts { project_paths: ProjectPathOpts { root: self.root.clone(), // FIXME(Odysseas): this essentially hard-codes the location of the assertions to live in @@ -161,41 +145,9 @@ impl BuildAndFlattenArgs { ..Default::default() }, ..Default::default() - }, - ..Default::default() - }; + }; - let config = build_cmd.load_config()?; - - let project = config.project().map_err(PhoundryError::SolcError)?; - let contracts = project.sources_path(); - - match std::fs::read_dir(contracts) { - Ok(mut files) => { - // Check if the directory is empty - if files.next().is_none() { - return Err(Box::new(PhoundryError::NoSourceFilesFound)); - } - } - Err(_) => { - return Err(Box::new(PhoundryError::DirectoryNotFound( - contracts.to_path_buf(), - ))); - } - } - - let compiler = ProjectCompiler::new() - .dynamic_test_linking(config.dynamic_test_linking) - .print_names(build_cmd.names) - .print_sizes(build_cmd.sizes) - .ignore_eip_3860(build_cmd.ignore_eip_3860) - .bail(true) - .quiet(true); - - let res = compiler - .compile(&project) - .map_err(PhoundryError::CompilationError)?; - Ok(res) + crate::compile::compile(build_opts) } /// Flattens the contract source code. @@ -234,7 +186,6 @@ impl BuildAndFlattenArgs { } } - #[cfg(test)] mod tests { use super::*; diff --git a/crates/phoundry/src/compile.rs b/crates/phoundry/src/compile.rs new file mode 100644 index 0000000..8780f29 --- /dev/null +++ b/crates/phoundry/src/compile.rs @@ -0,0 +1,44 @@ +use forge::cmd::build::BuildArgs; +use foundry_cli::opts::BuildOpts; +use foundry_cli::utils::LoadConfig; +use foundry_common::compile::ProjectCompiler; +use foundry_compilers::ProjectCompileOutput; + +use crate::error::PhoundryError; + +/// Compiles the project and returns the compilation output. +pub fn compile(build_opts: BuildOpts) -> Result> { + let build_cmd = BuildArgs { build: build_opts, ..Default::default() }; + + let config = build_cmd.load_config()?; + + let project = config.project().map_err(PhoundryError::SolcError)?; + let contracts = project.sources_path(); + + match std::fs::read_dir(contracts) { + Ok(mut files) => { + // Check if the directory is empty + if files.next().is_none() { + return Err(Box::new(PhoundryError::NoSourceFilesFound)); + } + } + Err(_) => { + return Err(Box::new(PhoundryError::DirectoryNotFound( + contracts.to_path_buf(), + ))); + } + } + + let compiler = ProjectCompiler::new() + .dynamic_test_linking(config.dynamic_test_linking) + .print_names(build_cmd.names) + .print_sizes(build_cmd.sizes) + .ignore_eip_3860(build_cmd.ignore_eip_3860) + .bail(true) + .quiet(true); + + let res = compiler + .compile(&project) + .map_err(PhoundryError::CompilationError)?; + Ok(res) +} diff --git a/crates/phoundry/src/error.rs b/crates/phoundry/src/error.rs index 4733e19..636ee75 100644 --- a/crates/phoundry/src/error.rs +++ b/crates/phoundry/src/error.rs @@ -1,4 +1,7 @@ -use color_eyre::{eyre, Report}; +use color_eyre::{ + eyre, + Report, +}; use foundry_compilers::{ error::SolcError, flatten::FlattenerError, @@ -43,7 +46,6 @@ pub enum PhoundryError { CompilationError(eyre::Report), } - impl From for Box { fn from(error: ExtractConfigError) -> Self { Box::new(PhoundryError::FoundryConfigError(error)) diff --git a/crates/phoundry/src/lib.rs b/crates/phoundry/src/lib.rs index a798a75..2c88018 100644 --- a/crates/phoundry/src/lib.rs +++ b/crates/phoundry/src/lib.rs @@ -1,5 +1,5 @@ -pub mod error; -pub mod test; pub mod build; pub mod build_and_flatten; - +pub mod error; +pub mod phorge_test; +pub mod compile; diff --git a/crates/phoundry/src/test.rs b/crates/phoundry/src/phorge_test.rs similarity index 68% rename from crates/phoundry/src/test.rs rename to crates/phoundry/src/phorge_test.rs index 6a35699..937699f 100644 --- a/crates/phoundry/src/test.rs +++ b/crates/phoundry/src/phorge_test.rs @@ -1,43 +1,12 @@ -use clap::{ - Parser, - ValueHint, -}; -use color_eyre::Report; +use clap::Parser; use forge::{ - cmd::{ - build::BuildArgs, - test::TestArgs, - }, + cmd::test::TestArgs, opts::{ Forge, ForgeSubcommand, }, }; -use foundry_cli::{ - opts::{ - BuildOpts, - ProjectPathOpts, - }, - utils::LoadConfig, -}; -use foundry_common::compile::ProjectCompiler; -use foundry_compilers::{ - flatten::{ - Flattener, - FlattenerError, - }, - info::ContractInfo, - solc::SolcLanguage, - ProjectCompileOutput, -}; - -use alloy_json_abi::JsonAbi; -use foundry_config::{ - error::ExtractConfigError, - find_project_root, -}; -use std::path::PathBuf; use tokio::task::spawn_blocking; use crate::error::PhoundryError; @@ -72,4 +41,4 @@ impl PhorgeTest { .map_err(|e| Box::new(PhoundryError::ForgeCommandFailed(e.into())))??; Ok(()) } -} \ No newline at end of file +} From 232139e9619558990f15872d92151dba3574ede1 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Mon, 16 Jun 2025 14:21:41 -0500 Subject: [PATCH 3/4] feat:add command to main and format --- bin/pcl/src/main.rs | 10 +++++++++- crates/phoundry/src/build_and_flatten.rs | 19 +++++++++---------- crates/phoundry/src/compile.rs | 5 ++++- crates/phoundry/src/lib.rs | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/bin/pcl/src/main.rs b/bin/pcl/src/main.rs index e8ebbc8..6f73e8a 100644 --- a/bin/pcl/src/main.rs +++ b/bin/pcl/src/main.rs @@ -14,7 +14,10 @@ use pcl_core::{ ConfigArgs, }, }; -use pcl_phoundry::phorge_test::PhorgeTest; +use pcl_phoundry::{ + build::BuildArgs, + phorge_test::PhorgeTest, +}; use serde_json::json; const VERSION_MESSAGE: &str = concat!( @@ -50,6 +53,8 @@ enum Commands { Auth(AuthCommand), #[command(about = "Manage configuration")] Config(ConfigArgs), + #[command(name = "build")] + Build(BuildArgs), } #[tokio::main] @@ -85,6 +90,9 @@ async fn main() -> Result<()> { Commands::Config(config_cmd) => { config_cmd.run(&mut config)?; } + Commands::Build(build_cmd) => { + build_cmd.run()?; + } }; config.write_to_file(&cli.args)?; Ok::<_, Report>(()) diff --git a/crates/phoundry/src/build_and_flatten.rs b/crates/phoundry/src/build_and_flatten.rs index fac50bf..b3927fc 100644 --- a/crates/phoundry/src/build_and_flatten.rs +++ b/crates/phoundry/src/build_and_flatten.rs @@ -135,17 +135,16 @@ impl BuildAndFlattenArgs { /// Builds the project and returns the compilation output. fn build(&self) -> Result> { - let build_opts = - BuildOpts { - project_paths: ProjectPathOpts { - root: self.root.clone(), - // FIXME(Odysseas): this essentially hard-codes the location of the assertions to live in - // assertions/src - contracts: Some(PathBuf::from("assertions/src")), - ..Default::default() - }, + let build_opts = BuildOpts { + project_paths: ProjectPathOpts { + root: self.root.clone(), + // FIXME(Odysseas): this essentially hard-codes the location of the assertions to live in + // assertions/src + contracts: Some(PathBuf::from("assertions/src")), ..Default::default() - }; + }, + ..Default::default() + }; crate::compile::compile(build_opts) } diff --git a/crates/phoundry/src/compile.rs b/crates/phoundry/src/compile.rs index 8780f29..462d527 100644 --- a/crates/phoundry/src/compile.rs +++ b/crates/phoundry/src/compile.rs @@ -8,7 +8,10 @@ use crate::error::PhoundryError; /// Compiles the project and returns the compilation output. pub fn compile(build_opts: BuildOpts) -> Result> { - let build_cmd = BuildArgs { build: build_opts, ..Default::default() }; + let build_cmd = BuildArgs { + build: build_opts, + ..Default::default() + }; let config = build_cmd.load_config()?; diff --git a/crates/phoundry/src/lib.rs b/crates/phoundry/src/lib.rs index 2c88018..c85364c 100644 --- a/crates/phoundry/src/lib.rs +++ b/crates/phoundry/src/lib.rs @@ -1,5 +1,5 @@ pub mod build; pub mod build_and_flatten; +pub mod compile; pub mod error; pub mod phorge_test; -pub mod compile; From d279afd985bed8ef09ce9ce56d5b78621b478556 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Mon, 16 Jun 2025 14:30:23 -0500 Subject: [PATCH 4/4] chore: cleanup tests --- crates/phoundry/src/build.rs | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/crates/phoundry/src/build.rs b/crates/phoundry/src/build.rs index ad1e3f9..337f304 100644 --- a/crates/phoundry/src/build.rs +++ b/crates/phoundry/src/build.rs @@ -171,14 +171,6 @@ contract InvalidContract { result.is_err(), "Expected compilation to fail with invalid contract" ); - - // Verify it's a compilation error - if let Err(error) = result { - // The error should be a compilation error or related error type - // We can't check the exact error type without knowing the PhoundryError variants, - // but the compilation should definitely fail - println!("Compilation failed as expected with error: {:?}", error); - } } #[test] @@ -196,10 +188,6 @@ contract InvalidContract { result.is_err(), "Expected compilation to fail with empty directory" ); - - if let Err(error) = result { - println!("Compilation failed as expected with error: {:?}", error); - } } #[test] @@ -213,15 +201,10 @@ contract InvalidContract { let result = args.run(); - // Compilation should fail due to nonexistent directory assert!( result.is_err(), "Expected compilation to fail with nonexistent directory" ); - - if let Err(error) = result { - println!("Compilation failed as expected with error: {:?}", error); - } } #[tokio::test(flavor = "multi_thread")] @@ -234,16 +217,6 @@ contract InvalidContract { let result = args.run(); - // This test might succeed or fail depending on the environment and dependencies - // In a real test environment with proper setup, it should succeed with valid contracts - match result { - Ok(_) => println!("Compilation succeeded as expected"), - Err(error) => { - println!( - "Compilation failed (might be expected in test environment): {:?}", - error - ) - } - } + assert!(result.is_ok()); } }