diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 9fc502f47eac1..73dea18d47b71 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -3170,6 +3170,30 @@ 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_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'."); // forgetest_async!(can_broadcast_from_deploy_code_cheatcode, |prj, cmd| { foundry_test_utils::util::initialize(prj.root()); @@ -3226,7 +3250,6 @@ Traces: Script ran successfully. ## Setting up 1 EVM. -========================== Simulated On-chain Traces: [..] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3 @@ -3236,7 +3259,6 @@ Simulated On-chain Traces: └─ ← [Stop] -========================== Chain 31337 @@ -3246,10 +3268,8 @@ Chain 31337 [ESTIMATED_AMOUNT_REQUIRED] -========================== -========================== ONCHAIN EXECUTION COMPLETE & SUCCESSFUL. diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index 6a90aef307c19..69884805bf5c4 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 @@ -250,8 +250,7 @@ impl ScriptArgs { // 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. @@ -489,9 +488,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 } }