Skip to content

Commit

Permalink
feat(script): make dry-run as the default behavior
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa committed Jan 11, 2025
1 parent d6c1013 commit 5def5bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
2 changes: 0 additions & 2 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,8 +2483,6 @@ contract DryRunTest is Script {
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&handle.http_endpoint(),
"--dry-run",
"--broadcast",
])
.execute()
.stdout_lossy();
Expand Down
24 changes: 3 additions & 21 deletions crates/script/src/broadcast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
build::LinkedBuildData, dryrun::format_transaction_details, progress::ScriptProgress,
sequence::ScriptSequenceKind, verify::BroadcastedState, ScriptArgs, ScriptConfig,
build::LinkedBuildData, progress::ScriptProgress, sequence::ScriptSequenceKind,
verify::BroadcastedState, ScriptArgs, ScriptConfig,
};
use alloy_chains::Chain;
use alloy_consensus::TxEnvelope;
Expand All @@ -21,7 +21,7 @@ use foundry_cheatcodes::Wallets;
use foundry_cli::utils::{has_batch_support, has_different_gas_calc};
use foundry_common::{
provider::{get_http_provider, try_get_http_provider, RetryProvider},
sh_print, shell, TransactionMaybeSigned,
shell, TransactionMaybeSigned,
};
use foundry_config::Config;
use futures::{future::join_all, StreamExt};
Expand Down Expand Up @@ -207,24 +207,6 @@ impl BundledState {
Ok(self)
}

/// Show the transactions that will be broadcasted.
pub fn show_transactions(self) -> Result<()> {
if !shell::is_json() {
sh_println!("\n=== Transactions that will be broadcast ===\n")?;

for sequence in self.sequence.sequences() {
if !sequence.transactions.is_empty() {
sh_println!("\nChain {}\n", sequence.chain)?;

for (i, tx) in sequence.transactions.iter().enumerate() {
sh_print!("{}", format_transaction_details(i + 1, tx))?;
}
}
}
}
Ok(())
}

/// Broadcasts transactions from all sequences.
pub async fn broadcast(mut self) -> Result<BroadcastedState> {
let required_addresses = self
Expand Down
28 changes: 14 additions & 14 deletions crates/script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ pub struct ScriptArgs {
#[arg(long)]
pub broadcast: bool,

/// Only shows the transactions that would be sent without actually broadcasting them.
#[arg(long)]
pub dry_run: bool,

/// Batch size of transactions.
///
/// This is ignored and set to 1 if batching is not available or `--slow` is enabled.
Expand Down Expand Up @@ -305,10 +301,21 @@ impl ScriptArgs {
pre_simulation.fill_metadata().await?.bundle().await?
};

let dry_run = bundled.args.dry_run;
// Exit early in case user didn't provide any broadcast/verify related flags.
if !bundled.args.should_broadcast() && !dry_run {
if !bundled.args.should_broadcast() {
if !shell::is_json() {
sh_println!("\n=== Transactions that will be broadcast ===\n")?;

for sequence in bundled.sequence.sequences() {
if !sequence.transactions.is_empty() {
sh_println!("\nChain {}\n", sequence.chain)?;

for (i, tx) in sequence.transactions.iter().enumerate() {
sh_print!("{}", dryrun::format_transaction_details(i + 1, tx))?;
}
}
}

sh_println!("\nSIMULATION COMPLETE. To broadcast these transactions, add --broadcast and wallet configuration(s) to the previous command. See forge script --help for more.")?;
}
return Ok(());
Expand All @@ -320,15 +327,8 @@ impl ScriptArgs {
}

// Wait for pending txes and broadcast others.
let bundle_state = bundled.wait_for_pending().await?;

// Print all transactions if --dry-run is set
if dry_run {
bundle_state.show_transactions()?;
return Ok(());
}
let broadcasted = bundled.wait_for_pending().await?.broadcast().await?;

let broadcasted = bundle_state.broadcast().await?;
if broadcasted.args.verify {
broadcasted.verify().await?;
}
Expand Down

0 comments on commit 5def5bb

Please sign in to comment.