Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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("error: the following required arguments were not provided:\n --broadcast\n\nUsage: forge script [OPTIONS] <PATH> [ARGS]...\n\nFor more information, try '--help'.");
});
6 changes: 3 additions & 3 deletions crates/script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub struct ScriptArgs {
pub etherscan_api_key: Option<String>,

/// 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
Expand Down Expand Up @@ -248,10 +248,10 @@ 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 || (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
Loading