Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 82 #84

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ pub fn define_config_file() -> Result<String, ConfigError> {

// check if the foundry.toml has the dependencies defined, if so then we setup the foundry.toml as the config file
if fs::metadata(&filename).is_ok() {
let contents = read_file_to_string(&filename.clone());
let doc: DocumentMut = contents.parse::<DocumentMut>().expect("invalid doc");

if doc.get("dependencies").is_some() {
return Ok(filename);
}
return Ok(filename);
}

filename = String::from(SOLDEER_CONFIG_FILE.to_str().unwrap());
Expand Down Expand Up @@ -1148,6 +1143,60 @@ old_dep = "1.0.0"
Ok(())
}

#[test]
fn add_to_config_foundry_not_altering_the_existing_contents() -> Result<(), ConfigError> {
let mut content = r#"
# Full reference https://github.com/foundry-rs/foundry/tree/master/crates/config

[profile.default]
script = "script"
solc = "0.8.26"
src = "src"
test = "test"
libs = ["dependencies"]
gas_reports = ['*']

# we don't have [dependencies] declared
"#;

let target_config = define_config(true);

write_to_config(&target_config, content);

add_to_config(
"dep1",
"1.0.0",
"http://custom_url.com/custom.zip",
false,
target_config.to_str().unwrap(),
)
.unwrap();
content = r#"
# Full reference https://github.com/foundry-rs/foundry/tree/master/crates/config

[profile.default]
script = "script"
solc = "0.8.26"
src = "src"
test = "test"
libs = ["dependencies"]
gas_reports = ['*']

# we don't have [dependencies] declared

[dependencies]
dep1 = "1.0.0"
"#;

assert_eq!(
read_file_to_string(&String::from(target_config.to_str().unwrap())),
content
);

let _ = remove_file(target_config);
Ok(())
}

#[test]
fn add_to_config_soldeer_no_custom_url_first_dependency() -> Result<(), ConfigError> {
let mut content = r#"
Expand Down