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

fix(config): enable optimizer when optimizer_runs set in config #9673

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ impl Config {
add_profile(&Self::DEFAULT_PROFILE);
add_profile(&config.profile);

// Ref: https://github.com/foundry-rs/foundry/issues/9665
// Enables the optimizer if the `optimizer_runs` has been set.
let optimizer = config.optimizer();
if optimizer.runs.is_some_and(|runs| runs > 0) && !config.optimizer {
yash-atreya marked this conversation as resolved.
Show resolved Hide resolved
config.optimizer = true;
}
Ok(config)
}

Expand Down
11 changes: 11 additions & 0 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ forgetest!(can_set_optimizer_runs, |prj, cmd| {
assert_eq!(config.optimizer_runs, 300);
});

// <https://github.com/foundry-rs/foundry/issues/9665>
forgetest!(enable_optimizer_when_runs_set, |prj, cmd| {
// explicitly set optimizer runs
let config = Config { optimizer_runs: 1337, ..Default::default() };
assert!(!config.optimizer);
prj.write_config(config);

let config = cmd.config();
assert!(config.optimizer);
});

// test that gas_price can be set
forgetest!(can_set_gas_price, |prj, cmd| {
// explicitly set gas_price
Expand Down
Loading