Skip to content

Commit

Permalink
fix: allow_hyphen_values for constructor args (#9225)
Browse files Browse the repository at this point in the history
* fix: unescape ints

* use allow_hyp
  • Loading branch information
mattsse authored Oct 30, 2024
1 parent 9501589 commit 4012ade
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct CreateArgs {
num_args(1..),
conflicts_with = "constructor_args_path",
value_name = "ARGS",
allow_hyphen_values = true,
)]
constructor_args: Vec<String>,

Expand Down Expand Up @@ -633,6 +634,7 @@ impl From<PendingTransactionError> for ContractDeploymentError {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::I256;

#[test]
fn can_parse_create() {
Expand Down Expand Up @@ -688,4 +690,17 @@ mod tests {
let constructor: Constructor = serde_json::from_str(r#"{"type":"constructor","inputs":[{"name":"_points","type":"tuple[]","internalType":"struct Point[]","components":[{"name":"x","type":"uint256","internalType":"uint256"},{"name":"y","type":"uint256","internalType":"uint256"}]}],"stateMutability":"nonpayable"}"#).unwrap();
let _params = args.parse_constructor_args(&constructor, &args.constructor_args).unwrap();
}

#[test]
fn test_parse_int_constructor_args() {
let args: CreateArgs = CreateArgs::parse_from([
"foundry-cli",
"src/Domains.sol:Domains",
"--constructor-args",
"-5",
]);
let constructor: Constructor = serde_json::from_str(r#"{"type":"constructor","inputs":[{"name":"_name","type":"int256","internalType":"int256"}],"stateMutability":"nonpayable"}"#).unwrap();
let params = args.parse_constructor_args(&constructor, &args.constructor_args).unwrap();
assert_eq!(params, vec![DynSolValue::Int(I256::unchecked_from(-5), 256)]);
}
}

0 comments on commit 4012ade

Please sign in to comment.