Skip to content

Commit c19a479

Browse files
authored
feat: add --use and --no-auto-detect flags to verify-contract (#11743)
* feat: add --use and --no-auto-detect flags to verify-contract * include the new fields no_auto_detect and use_solc * feat: add --use and --no-auto-detect flags to verify-contract
1 parent 0c07e98 commit c19a479

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

crates/forge/src/cmd/create.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ impl CreateArgs {
228228
compiler_version: Some(id.version.to_string()),
229229
constructor_args,
230230
constructor_args_path: None,
231+
no_auto_detect: false,
232+
use_solc: None,
231233
num_of_optimizations: None,
232234
etherscan: EtherscanOpts {
233235
key: self.eth.etherscan.key.clone(),
@@ -418,6 +420,8 @@ impl CreateArgs {
418420
compiler_version: Some(id.version.to_string()),
419421
constructor_args,
420422
constructor_args_path: None,
423+
no_auto_detect: false,
424+
use_solc: None,
421425
num_of_optimizations,
422426
etherscan: EtherscanOpts { key: self.eth.etherscan.key(), chain: Some(chain.into()) },
423427
rpc: Default::default(),

crates/script/src/verify.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ impl VerifyBundle {
146146
compiler_version: Some(version.to_string()),
147147
constructor_args: Some(hex::encode(constructor_args)),
148148
constructor_args_path: None,
149+
no_auto_detect: false,
150+
use_solc: None,
149151
num_of_optimizations: self.num_of_optimizations,
150152
etherscan: self.etherscan.clone(),
151153
rpc: Default::default(),

crates/verify/src/verify.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ pub struct VerifyArgs {
145145
#[arg(long)]
146146
pub evm_version: Option<EvmVersion>,
147147

148+
/// Do not auto-detect the `solc` version.
149+
#[arg(long, help_heading = "Compiler options")]
150+
pub no_auto_detect: bool,
151+
152+
/// Specify the solc version, or a path to a local solc, to build with.
153+
///
154+
/// Valid values are in the format `x.y.z`, `solc:x.y.z` or `path/to/solc`.
155+
#[arg(long = "use", help_heading = "Compiler options", value_name = "SOLC_VERSION")]
156+
pub use_solc: Option<String>,
157+
148158
#[command(flatten)]
149159
pub etherscan: EtherscanOpts,
150160

@@ -194,6 +204,15 @@ impl figment::Provider for VerifyArgs {
194204
dict.insert("via_ir".to_string(), figment::value::Value::serialize(self.via_ir)?);
195205
}
196206

207+
if self.no_auto_detect {
208+
dict.insert("auto_detect_solc".to_string(), figment::value::Value::serialize(false)?);
209+
}
210+
211+
if let Some(ref solc) = self.use_solc {
212+
let solc = solc.trim_start_matches("solc:");
213+
dict.insert("solc".to_string(), figment::value::Value::serialize(solc)?);
214+
}
215+
197216
if let Some(api_key) = &self.verifier.verifier_api_key {
198217
dict.insert("etherscan_api_key".into(), api_key.as_str().into());
199218
}
@@ -523,4 +542,18 @@ mod tests {
523542
]);
524543
assert!(args.via_ir);
525544
}
545+
546+
#[test]
547+
fn can_parse_new_compiler_flags() {
548+
let args: VerifyArgs = VerifyArgs::parse_from([
549+
"foundry-cli",
550+
"0x0000000000000000000000000000000000000000",
551+
"src/Domains.sol:Domains",
552+
"--no-auto-detect",
553+
"--use",
554+
"0.8.23",
555+
]);
556+
assert!(args.no_auto_detect);
557+
assert_eq!(args.use_solc.as_deref(), Some("0.8.23"));
558+
}
526559
}

0 commit comments

Comments
 (0)