diff --git a/crates/config/src/providers/remappings.rs b/crates/config/src/providers/remappings.rs index 343fde697859..1d8a7b16368c 100644 --- a/crates/config/src/providers/remappings.rs +++ b/crates/config/src/providers/remappings.rs @@ -1,7 +1,4 @@ -use crate::{ - foundry_toml_dirs, remappings_from_env_var, remappings_from_newline, utils::get_dir_remapping, - Config, -}; +use crate::{foundry_toml_dirs, remappings_from_env_var, remappings_from_newline, Config}; use figment::{ value::{Dict, Map}, Error, Figment, Metadata, Profile, Provider, @@ -39,7 +36,12 @@ impl Remappings { pub fn with_figment(mut self, figment: &Figment) -> Self { let mut add_project_remapping = |path: &str| { if let Ok(path) = figment.find_value(path) { - if let Some(remapping) = path.into_string().and_then(get_dir_remapping) { + if let Some(path) = path.into_string() { + let remapping = Remapping { + context: None, + name: format!("{path}/"), + path: format!("{path}/"), + }; self.project_paths.push(remapping); } } diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index 02ff2fce8536..6f70f845c045 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -856,3 +856,36 @@ contract MyScript is BaseScript { pretty_err(&lib_toml_file, fs::write(&lib_toml_file, lib_config.to_string_pretty().unwrap())); cmd.forge_fuse().args(["build"]).assert_success(); }); + +// Tests that project remappings use config paths. +// For `src=src/contracts` config, remapping should be `src/contracts/ = src/contracts/`. +// For `src=src` config, remapping should be `src/ = src/`. +// +forgetest!(test_project_remappings, |prj, cmd| { + foundry_test_utils::util::initialize(prj.root()); + let config = Config { + src: "src/contracts".into(), + remappings: vec![Remapping::from_str("contracts/=src/contracts/").unwrap().into()], + ..Default::default() + }; + prj.write_config(config); + + // Add Counter.sol in `src/contracts` project dir. + let src_dir = &prj.root().join("src/contracts"); + pretty_err(src_dir, fs::create_dir_all(src_dir)); + pretty_err( + src_dir.join("Counter.sol"), + fs::write(src_dir.join("Counter.sol"), "contract Counter{}"), + ); + prj.add_test( + "CounterTest.sol", + r#" +import "contracts/Counter.sol"; + +contract CounterTest { +} + "#, + ) + .unwrap(); + cmd.forge_fuse().args(["build"]).assert_success(); +});