Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
});
10 changes: 8 additions & 2 deletions crates/script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do this with requires on verify: https://docs.rs/clap/latest/clap/struct.Arg.html#method.requires


// 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.
Expand Down