Skip to content

Commit 780dcf9

Browse files
authored
fix(forge): makes forge script match correctly run function signature from source (#11244)
1 parent 8b53e43 commit 780dcf9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

crates/forge/tests/cli/script.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,41 @@ Script ran successfully.
422422
"#]]);
423423
});
424424

425+
// Tests that the run command can run functions with arguments without specifying the signature
426+
// <https://github.com/foundry-rs/foundry/issues/11240>
427+
forgetest!(can_execute_script_command_with_args_no_sig, |prj, cmd| {
428+
let script = prj
429+
.add_source(
430+
"Foo",
431+
r#"
432+
contract Demo {
433+
event log_string(string);
434+
event log_uint(uint);
435+
function run(uint256 a, uint256 b) external {
436+
emit log_string("script ran");
437+
emit log_uint(a);
438+
emit log_uint(b);
439+
}
440+
}
441+
"#,
442+
)
443+
.unwrap();
444+
445+
cmd.arg("script").arg(script).arg("1").arg("2").assert_success().stdout_eq(str![[r#"
446+
[COMPILING_FILES] with [SOLC_VERSION]
447+
[SOLC_VERSION] [ELAPSED]
448+
Compiler run successful!
449+
Script ran successfully.
450+
[GAS]
451+
452+
== Logs ==
453+
script ran
454+
1
455+
2
456+
457+
"#]]);
458+
});
459+
425460
// Tests that the run command can run functions with return values
426461
forgetest!(can_execute_script_command_with_returned, |prj, cmd| {
427462
let script = prj

crates/script/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct ScriptArgs {
9696
pub target_contract: Option<String>,
9797

9898
/// The signature of the function you want to call in the contract, or raw calldata.
99-
#[arg(long, short, default_value = "run()")]
99+
#[arg(long, short, default_value = "run")]
100100
pub sig: String,
101101

102102
/// Max priority fee per gas for EIP1559 transactions.

0 commit comments

Comments
 (0)