From 2371797ee4f5a11a4813fb28721f3924b1e9dcea Mon Sep 17 00:00:00 2001 From: Ragnar Date: Sat, 20 Sep 2025 23:10:30 +0200 Subject: [PATCH 01/10] Update lib.rs --- crates/script/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index a521702fa2629..eecccc3ec1226 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -248,10 +248,16 @@ impl ScriptArgs { let create2_deployer = state.script_config.evm_opts.create2_deployer; let compiled = state.compile()?; + // Validate that --verify is only used with --broadcast + if compiled.args.verify && !compiled.args.should_broadcast() { + eyre::bail!( + "The --verify flag requires --broadcast to be specified. Verification without broadcasting is not meaningful." + ); + } + // Move from `CompiledState` to `BundledState` either by resuming or executing and // simulating script. - let bundled = if compiled.args.resume || (compiled.args.verify && !compiled.args.broadcast) - { + let bundled = if compiled.args.resume { compiled.resume().await? } else { // Drive state machine to point at which we have everything needed for simulation. From 9af200097d4907f992676812a650a343beceff0f Mon Sep 17 00:00:00 2001 From: Ragnar Date: Sat, 20 Sep 2025 23:10:51 +0200 Subject: [PATCH 02/10] Update script.rs --- crates/forge/tests/cli/script.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 41f6fdbeeddeb..f259913c8f568 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3169,3 +3169,29 @@ Traces: Error: script failed: call to non-contract address [..] "#]]); }); + +// Test that --verify without --broadcast fails with a clear error message +forgetest!(verify_without_broadcast_fails, |prj, cmd| { + let script = prj.add_source( + "Counter", + r#" +import "forge-std/Script.sol"; + +contract CounterScript is Script { + function run() external { + // Simple script that does nothing + } +} + "#, + ); + + cmd.args([ + "script", + script.to_str().unwrap(), + "--verify", + "--rpc-url", + "https://sepolia.infura.io/v3/test", + ]) + .assert_failure() + .stderr_matches("The --verify flag requires --broadcast to be specified. Verification without broadcasting is not meaningful."); +}); From 4424c225f620c1c73c5f759cef5455f5b781184e Mon Sep 17 00:00:00 2001 From: Ragnar Date: Sun, 21 Sep 2025 13:37:22 +0200 Subject: [PATCH 03/10] Update lib.rs --- crates/script/src/lib.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index eecccc3ec1226..84dbc8ab2d937 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -190,7 +190,7 @@ pub struct ScriptArgs { pub etherscan_api_key: Option, /// Verifies all the contracts found in the receipts of a script, if any. - #[arg(long)] + #[arg(long, requires = "broadcast")] pub verify: bool, /// Gas price for legacy transactions, or max fee per gas for EIP1559 transactions, either @@ -248,12 +248,6 @@ impl ScriptArgs { let create2_deployer = state.script_config.evm_opts.create2_deployer; let compiled = state.compile()?; - // Validate that --verify is only used with --broadcast - if compiled.args.verify && !compiled.args.should_broadcast() { - eyre::bail!( - "The --verify flag requires --broadcast to be specified. Verification without broadcasting is not meaningful." - ); - } // Move from `CompiledState` to `BundledState` either by resuming or executing and // simulating script. From 5e01eeb052aaa7de783c2967a57ff52bb4c6b04d Mon Sep 17 00:00:00 2001 From: Ragnar Date: Sun, 21 Sep 2025 13:37:51 +0200 Subject: [PATCH 04/10] Update script.rs --- crates/forge/tests/cli/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index f259913c8f568..f59067703e398 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3193,5 +3193,5 @@ contract CounterScript is Script { "https://sepolia.infura.io/v3/test", ]) .assert_failure() - .stderr_matches("The --verify flag requires --broadcast to be specified. Verification without broadcasting is not meaningful."); + .stderr_matches("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n\nFor more information, try '--help'."); }); From 96dba6068b55bc5960c7d7a18f3c603e428637ca Mon Sep 17 00:00:00 2001 From: Ragnar Date: Tue, 23 Sep 2025 17:50:16 +0200 Subject: [PATCH 05/10] Update lib.rs --- crates/script/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index 84dbc8ab2d937..bf982d5921d6a 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -489,9 +489,9 @@ impl ScriptArgs { Ok(()) } - /// We only broadcast transactions if --broadcast or --resume was passed. + /// We only broadcast transactions if --broadcast, --resume, or --verify was passed. fn should_broadcast(&self) -> bool { - self.broadcast || self.resume + self.broadcast || self.resume || self.verify } } From 1e9250780b1c180fe1ad9194b189f399f214352c Mon Sep 17 00:00:00 2001 From: Ragnar Date: Tue, 23 Sep 2025 17:55:20 +0200 Subject: [PATCH 06/10] Update script.rs --- crates/forge/tests/cli/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index f59067703e398..797a9a8a274b9 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3193,5 +3193,5 @@ contract CounterScript is Script { "https://sepolia.infura.io/v3/test", ]) .assert_failure() - .stderr_matches("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n\nFor more information, try '--help'."); + .stderr_eq("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n\nFor more information, try '--help'."); }); From e8d91af0d254774e5defe273a50619d24f7ba337 Mon Sep 17 00:00:00 2001 From: Ragnar Date: Tue, 23 Sep 2025 20:07:55 +0200 Subject: [PATCH 07/10] Update script.rs --- crates/forge/tests/cli/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 797a9a8a274b9..5e03defcb31b9 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3193,5 +3193,5 @@ contract CounterScript is Script { "https://sepolia.infura.io/v3/test", ]) .assert_failure() - .stderr_eq("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n\nFor more information, try '--help'."); + .stderr_eq("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n+ Usage: forge script --broadcast --verify --fork-url [ARGS]...\n\nFor more information, try '--help'."); }); From cbb980c92de70e3559adf645f50caf15d8a832a0 Mon Sep 17 00:00:00 2001 From: Ragnar Date: Tue, 23 Sep 2025 18:20:27 +0000 Subject: [PATCH 08/10] cargo fmt --- crates/script/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index be7957cecf2b5..2e79f05da3b13 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -248,7 +248,6 @@ impl ScriptArgs { let create2_deployer = state.script_config.evm_opts.create2_deployer; let compiled = state.compile()?; - // Move from `CompiledState` to `BundledState` either by resuming or executing and // simulating script. let bundled = if compiled.args.resume { From d20c0be928baf0821f61ee7d124bc73512baf669 Mon Sep 17 00:00:00 2001 From: Ragnar Date: Thu, 9 Oct 2025 12:35:05 +0200 Subject: [PATCH 09/10] Update script.rs --- crates/forge/tests/cli/script.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 73dea18d47b71..e649f9a392835 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3193,7 +3193,17 @@ contract CounterScript is Script { "https://sepolia.infura.io/v3/test", ]) .assert_failure() - .stderr_eq("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] [ARGS]...\n+ Usage: forge script --broadcast --verify --fork-url [ARGS]...\n\nFor more information, try '--help'."); + .stderr_eq(str![[r#" +error: the following required arguments were not provided: + --broadcast + +Usage: forge script --broadcast --verify --fork-url [ARGS]... + +For more information, try '--help'. + +"#]]); +}); + // forgetest_async!(can_broadcast_from_deploy_code_cheatcode, |prj, cmd| { foundry_test_utils::util::initialize(prj.root()); @@ -3250,15 +3260,17 @@ Traces: Script ran successfully. ## Setting up 1 EVM. +========================== Simulated On-chain Traces: - [..] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3 + [96345] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3 └─ ← [Return] 481 bytes of code - [..] Counter::increment() + [22418] Counter::increment() └─ ← [Stop] +========================== Chain 31337 @@ -3268,8 +3280,10 @@ Chain 31337 [ESTIMATED_AMOUNT_REQUIRED] +========================== +========================== ONCHAIN EXECUTION COMPLETE & SUCCESSFUL. From 98041a7689f2d61b7b65eb5c8b0e3ef248139a58 Mon Sep 17 00:00:00 2001 From: Ragnar Date: Thu, 9 Oct 2025 16:00:01 +0200 Subject: [PATCH 10/10] Update script.rs --- crates/forge/tests/cli/script.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 2d6e5f4187ff0..49d893dcc07d8 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3263,10 +3263,10 @@ Script ran successfully. ========================== Simulated On-chain Traces: - [96345] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3 + [..] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3 └─ ← [Return] 481 bytes of code - [22418] Counter::increment() + [..] Counter::increment() └─ ← [Stop]