Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
38 changes: 36 additions & 2 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,40 @@ 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(str![[r#"
error: the following required arguments were not provided:
--broadcast

Usage: forge script --broadcast --verify --fork-url <URL> <PATH> [ARGS]...

For 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 @@ -3229,10 +3263,10 @@ Script ran successfully.
==========================
Simulated On-chain Traces:

[..] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3
[96345] → new Counter@0x5FbDB2315678afecb367f032d93F642f64180aa3
└─ ← [Return] 481 bytes of code

[..] Counter::increment()
[22418] Counter::increment()
Copy link
Contributor

Choose a reason for hiding this comment

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

please change this to dots again (the gas usage isn't relevant):)

└─ ← [Stop]


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