Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 24 additions & 4 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] <PATH> [ARGS]...\n+ Usage: forge script --broadcast --verify --fork-url <URL> <PATH> [ARGS]...\n\nFor more information, try '--help'.");
// <https://github.com/foundry-rs/foundry/issues/11855>
forgetest_async!(can_broadcast_from_deploy_code_cheatcode, |prj, cmd| {
foundry_test_utils::util::initialize(prj.root());
Expand Down Expand Up @@ -3226,7 +3250,6 @@ Traces:
Script ran successfully.

## Setting up 1 EVM.
==========================
Simulated On-chain Traces:

[..] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3
Expand All @@ -3236,7 +3259,6 @@ Simulated On-chain Traces:
└─ ← [Stop]


==========================

Chain 31337

Expand All @@ -3246,10 +3268,8 @@ Chain 31337

[ESTIMATED_AMOUNT_REQUIRED]

==========================


==========================

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.

Expand Down
9 changes: 4 additions & 5 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 @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down
Loading