Skip to content

Commit

Permalink
fix: add back silent option in Anvil's NodeConfig (foundry-rs#9181)
Browse files Browse the repository at this point in the history
* add quiet handling for Anvil tests using NodeConfig

* add back `silent` flag, inheriting default from global shell --quiet setting, overrides as true in test

* fix unrelated failing test

* revert fix, moved to foundry-rs#9182
  • Loading branch information
zerosnacks authored and rplusq committed Nov 29, 2024
1 parent 9a62c26 commit 4c169f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use alloy_signer_local::coins_bip39::{English, Mnemonic};
use anvil_server::ServerConfig;
use clap::Parser;
use core::fmt;
use foundry_common::shell;
use foundry_config::{Chain, Config, FigmentProviders};
use futures::FutureExt;
use rand::{rngs::StdRng, SeedableRng};
Expand Down Expand Up @@ -254,6 +255,7 @@ impl NodeArgs {
.with_storage_caching(self.evm_opts.no_storage_caching)
.with_server_config(self.server_config)
.with_host(self.host)
.set_silent(shell::is_quiet())
.set_config_out(self.config_out)
.with_chain_id(self.evm_opts.chain_id)
.with_transaction_order(self.order)
Expand Down
21 changes: 20 additions & 1 deletion crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ pub struct NodeConfig {
pub precompile_factory: Option<Arc<dyn PrecompileFactory>>,
/// Enable Alphanet features.
pub alphanet: bool,
/// Do not print log messages.
pub silent: bool,
}

impl NodeConfig {
Expand Down Expand Up @@ -392,7 +394,7 @@ impl NodeConfig {
/// random, free port by setting it to `0`
#[doc(hidden)]
pub fn test() -> Self {
Self { enable_tracing: true, port: 0, ..Default::default() }
Self { enable_tracing: true, port: 0, silent: true, ..Default::default() }
}

/// Returns a new config which does not initialize any accounts on node startup.
Expand Down Expand Up @@ -462,6 +464,7 @@ impl Default for NodeConfig {
memory_limit: None,
precompile_factory: None,
alphanet: false,
silent: false,
}
}
}
Expand Down Expand Up @@ -907,6 +910,10 @@ impl NodeConfig {
.expect("Failed writing json");
}

if self.silent {
return;
}

let _ = sh_println!("{}", self.as_string(fork));
}

Expand Down Expand Up @@ -950,6 +957,18 @@ impl NodeConfig {
self
}

/// Makes the node silent to not emit anything on stdout
#[must_use]
pub fn silent(self) -> Self {
self.set_silent(true)
}

#[must_use]
pub fn set_silent(mut self, silent: bool) -> Self {
self.silent = silent;
self
}

/// Configures everything related to env, backend and database and returns the
/// [Backend](mem::Backend)
///
Expand Down

0 comments on commit 4c169f2

Please sign in to comment.