From 67f2457d05c2226b43e8aab75382a7e6543995ad Mon Sep 17 00:00:00 2001 From: James Date: Mon, 30 Sep 2024 09:49:08 -0400 Subject: [PATCH] tests: fix more ci only --- crates/provider/Cargo.toml | 1 + crates/provider/src/blocks.rs | 8 - crates/provider/src/ext/admin.rs | 52 +++--- crates/provider/src/ext/debug.rs | 243 ++++++++++++++------------ crates/provider/src/ext/mod.rs | 14 ++ crates/provider/src/ext/net.rs | 46 +++-- crates/provider/src/ext/trace.rs | 96 +++++----- crates/provider/src/ext/txpool.rs | 55 +++--- crates/provider/src/fillers/gas.rs | 12 -- crates/provider/src/provider/trait.rs | 89 +++------- 10 files changed, 308 insertions(+), 308 deletions(-) diff --git a/crates/provider/Cargo.toml b/crates/provider/Cargo.toml index a78f5a15128..bf76c08a002 100644 --- a/crates/provider/Cargo.toml +++ b/crates/provider/Cargo.toml @@ -84,6 +84,7 @@ tower-http = { workspace = true, features = [ http-body-util.workspace = true http.workspace = true alloy-rpc-types-engine = { workspace = true, features = ["jwt"] } +ci_info.workspace = true [features] default = ["reqwest", "reqwest-default-tls"] diff --git a/crates/provider/src/blocks.rs b/crates/provider/src/blocks.rs index a6ddede0e7d..05d095fa7d3 100644 --- a/crates/provider/src/blocks.rs +++ b/crates/provider/src/blocks.rs @@ -185,10 +185,6 @@ mod tests { use alloy_primitives::U256; use std::{future::Future, time::Duration}; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - async fn timeout(future: T) -> T::Output { try_timeout(future).await.expect("Timeout") } @@ -207,8 +203,6 @@ mod tests { yield_block(true).await; } async fn yield_block(ws: bool) { - init_tracing(); - let anvil = Anvil::new().spawn(); let url = if ws { anvil.ws_endpoint() } else { anvil.endpoint() }; @@ -240,8 +234,6 @@ mod tests { // Make sure that we can process more blocks than fits in the cache. const BLOCKS_TO_MINE: usize = BLOCK_CACHE_SIZE.get() + 1; - init_tracing(); - let anvil = Anvil::new().spawn(); let url = if ws { anvil.ws_endpoint() } else { anvil.endpoint() }; diff --git a/crates/provider/src/ext/admin.rs b/crates/provider/src/ext/admin.rs index 87471c8064d..6f2c1a73c8e 100644 --- a/crates/provider/src/ext/admin.rs +++ b/crates/provider/src/ext/admin.rs @@ -86,39 +86,45 @@ where #[cfg(test)] mod test { use super::*; - use crate::ProviderBuilder; + use crate::{ext::test::async_ci_only, ProviderBuilder}; use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn node_info() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let node_info = provider.node_info().await.unwrap(); - assert!(node_info.enode.starts_with("enode://")); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let node_info = provider.node_info().await.unwrap(); + assert!(node_info.enode.starts_with("enode://")); + }) + .await; }) .await; } #[tokio::test] async fn admin_peers() { - run_with_tempdir("geth-test-1", |temp_dir_1| async move { - run_with_tempdir("geth-test-2", |temp_dir_2| async move { - let geth1 = Geth::new().disable_discovery().data_dir(&temp_dir_1).spawn(); - let mut geth2 = - Geth::new().disable_discovery().port(0u16).data_dir(&temp_dir_2).spawn(); - - let provider1 = ProviderBuilder::new().on_http(geth1.endpoint_url()); - let provider2 = ProviderBuilder::new().on_http(geth2.endpoint_url()); - let node1_info = provider1.node_info().await.unwrap(); - let node1_id = node1_info.id; - let node1_enode = node1_info.enode; - - let added = provider2.add_peer(&node1_enode).await.unwrap(); - assert!(added); - geth2.wait_to_add_peer(&node1_id).unwrap(); - let peers = provider2.peers().await.unwrap(); - assert_eq!(peers[0].enode, node1_enode); + async_ci_only(|| async move { + run_with_tempdir("geth-test-1", |temp_dir_1| async move { + run_with_tempdir("geth-test-2", |temp_dir_2| async move { + let geth1 = Geth::new().disable_discovery().data_dir(&temp_dir_1).spawn(); + let mut geth2 = + Geth::new().disable_discovery().port(0u16).data_dir(&temp_dir_2).spawn(); + + let provider1 = ProviderBuilder::new().on_http(geth1.endpoint_url()); + let provider2 = ProviderBuilder::new().on_http(geth2.endpoint_url()); + let node1_info = provider1.node_info().await.unwrap(); + let node1_id = node1_info.id; + let node1_enode = node1_info.enode; + + let added = provider2.add_peer(&node1_enode).await.unwrap(); + assert!(added); + geth2.wait_to_add_peer(&node1_id).unwrap(); + let peers = provider2.peers().await.unwrap(); + assert_eq!(peers[0].enode, node1_enode); + }) + .await; }) .await; }) diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index 8ad57b7228a..0e726d68991 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -220,153 +220,166 @@ where #[cfg(test)] mod test { - use crate::{ProviderBuilder, WalletProvider}; - use super::*; + use crate::{ext::test::async_ci_only, ProviderBuilder, WalletProvider}; use alloy_network::TransactionBuilder; use alloy_node_bindings::{utils::run_with_tempdir, Geth, Reth}; use alloy_primitives::{address, U256}; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn test_debug_trace_transaction() { - init_tracing(); - let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); - let from = provider.default_signer_address(); - - let gas_price = provider.get_gas_price().await.unwrap(); - let tx = TransactionRequest::default() - .from(from) - .to(address!("deadbeef00000000deadbeef00000000deadbeef")) - .value(U256::from(100)) - .max_fee_per_gas(gas_price + 1) - .max_priority_fee_per_gas(gas_price + 1); - let pending = provider.send_transaction(tx).await.unwrap(); - let receipt = pending.get_receipt().await.unwrap(); - - let hash = receipt.transaction_hash; - let trace_options = GethDebugTracingOptions::default(); - - let trace = provider.debug_trace_transaction(hash, trace_options).await.unwrap(); - - if let GethTrace::Default(trace) = trace { - assert_eq!(trace.gas, 21000) - } + async_ci_only(|| async move { + let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); + let from = provider.default_signer_address(); + + let gas_price = provider.get_gas_price().await.unwrap(); + let tx = TransactionRequest::default() + .from(from) + .to(address!("deadbeef00000000deadbeef00000000deadbeef")) + .value(U256::from(100)) + .max_fee_per_gas(gas_price + 1) + .max_priority_fee_per_gas(gas_price + 1); + let pending = provider.send_transaction(tx).await.unwrap(); + let receipt = pending.get_receipt().await.unwrap(); + + let hash = receipt.transaction_hash; + let trace_options = GethDebugTracingOptions::default(); + + let trace = provider.debug_trace_transaction(hash, trace_options).await.unwrap(); + + if let GethTrace::Default(trace) = trace { + assert_eq!(trace.gas, 21000) + } + }) + .await; } #[tokio::test] async fn test_debug_trace_call() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil_with_wallet(); - let from = provider.default_signer_address(); - let gas_price = provider.get_gas_price().await.unwrap(); - let tx = TransactionRequest::default() - .from(from) - .with_input("0xdeadbeef") - .max_fee_per_gas(gas_price + 1) - .max_priority_fee_per_gas(gas_price + 1); - - let trace = provider - .debug_trace_call( - tx, - BlockNumberOrTag::Latest.into(), - GethDebugTracingCallOptions::default(), - ) - .await - .unwrap(); - - if let GethTrace::Default(trace) = trace { - assert!(!trace.struct_logs.is_empty()); - } + async_ci_only(|| async move { + let provider = ProviderBuilder::new().on_anvil_with_wallet(); + let from = provider.default_signer_address(); + let gas_price = provider.get_gas_price().await.unwrap(); + let tx = TransactionRequest::default() + .from(from) + .with_input("0xdeadbeef") + .max_fee_per_gas(gas_price + 1) + .max_priority_fee_per_gas(gas_price + 1); + + let trace = provider + .debug_trace_call( + tx, + BlockNumberOrTag::Latest.into(), + GethDebugTracingCallOptions::default(), + ) + .await + .unwrap(); + + if let GethTrace::Default(trace) = trace { + assert!(!trace.struct_logs.is_empty()); + } + }) + .await; } #[tokio::test] async fn call_debug_get_raw_header() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let rlp_header = provider - .debug_get_raw_header(BlockId::Number(BlockNumberOrTag::Latest)) - .await - .expect("debug_getRawHeader call should succeed"); - - assert!(!rlp_header.is_empty()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let rlp_header = provider + .debug_get_raw_header(BlockId::Number(BlockNumberOrTag::Latest)) + .await + .expect("debug_getRawHeader call should succeed"); + + assert!(!rlp_header.is_empty()); + }) + .await; }) - .await + .await; } #[tokio::test] async fn call_debug_get_raw_block() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let rlp_block = provider - .debug_get_raw_block(BlockId::Number(BlockNumberOrTag::Latest)) - .await - .expect("debug_getRawBlock call should succeed"); - - assert!(!rlp_block.is_empty()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let rlp_block = provider + .debug_get_raw_block(BlockId::Number(BlockNumberOrTag::Latest)) + .await + .expect("debug_getRawBlock call should succeed"); + + assert!(!rlp_block.is_empty()); + }) + .await; }) - .await + .await; } #[tokio::test] async fn call_debug_get_raw_receipts() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let result = - provider.debug_get_raw_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await; - assert!(result.is_ok()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let result = provider + .debug_get_raw_receipts(BlockId::Number(BlockNumberOrTag::Latest)) + .await; + assert!(result.is_ok()); + }) + .await; }) - .await + .await; } #[tokio::test] async fn call_debug_get_bad_blocks() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let result = provider.debug_get_bad_blocks().await; - assert!(result.is_ok()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let result = provider.debug_get_bad_blocks().await; + assert!(result.is_ok()); + }) + .await; }) - .await + .await; } #[tokio::test] #[cfg(not(windows))] async fn debug_trace_call_many() { - run_with_tempdir("reth-test-", |temp_dir| async move { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); - let provider = - ProviderBuilder::new().with_recommended_fillers().on_http(reth.endpoint_url()); - - let tx1 = TransactionRequest::default() - .with_from(address!("0000000000000000000000000000000000000123")) - .with_to(address!("0000000000000000000000000000000000000456")); - - let tx2 = TransactionRequest::default() - .with_from(address!("0000000000000000000000000000000000000456")) - .with_to(address!("0000000000000000000000000000000000000789")); - - let bundles = vec![Bundle { transactions: vec![tx1, tx2], block_override: None }]; - let state_context = StateContext::default(); - let trace_options = GethDebugTracingCallOptions::default(); - let result = - provider.debug_trace_call_many(bundles, state_context, trace_options).await; - assert!(result.is_ok()); - - let traces = result.unwrap(); - assert_eq!( - serde_json::to_string_pretty(&traces).unwrap().trim(), - r#" + async_ci_only(|| async move { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = + ProviderBuilder::new().with_recommended_fillers().on_http(reth.endpoint_url()); + + let tx1 = TransactionRequest::default() + .with_from(address!("0000000000000000000000000000000000000123")) + .with_to(address!("0000000000000000000000000000000000000456")); + + let tx2 = TransactionRequest::default() + .with_from(address!("0000000000000000000000000000000000000456")) + .with_to(address!("0000000000000000000000000000000000000789")); + + let bundles = vec![Bundle { transactions: vec![tx1, tx2], block_override: None }]; + let state_context = StateContext::default(); + let trace_options = GethDebugTracingCallOptions::default(); + let result = + provider.debug_trace_call_many(bundles, state_context, trace_options).await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" [ [ { @@ -384,9 +397,11 @@ mod test { ] ] "# - .trim(), - ); + .trim(), + ); + }) + .await; }) - .await + .await; } } diff --git a/crates/provider/src/ext/mod.rs b/crates/provider/src/ext/mod.rs index a5f5c185a20..7358fe0010e 100644 --- a/crates/provider/src/ext/mod.rs +++ b/crates/provider/src/ext/mod.rs @@ -44,3 +44,17 @@ pub use txpool::TxPoolApi; mod erc4337; #[cfg(feature = "erc4337-api")] pub use erc4337::Erc4337Api; + +#[cfg(test)] +pub(crate) mod test { + /// Run the given function only if we are in a CI environment. + pub(crate) async fn async_ci_only(f: F) + where + F: FnOnce() -> Fut, + Fut: std::future::Future, + { + if ci_info::is_ci() { + f().await; + } + } +} diff --git a/crates/provider/src/ext/net.rs b/crates/provider/src/ext/net.rs index 633d58fd59e..449f1772ed4 100644 --- a/crates/provider/src/ext/net.rs +++ b/crates/provider/src/ext/net.rs @@ -38,44 +38,54 @@ where #[cfg(test)] mod test { - use crate::ProviderBuilder; - use super::*; + use crate::{ext::test::async_ci_only, ProviderBuilder}; use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn call_net_version() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let version = provider.net_version().await.expect("net_version call should succeed"); - assert_eq!(version, 1); + let version = + provider.net_version().await.expect("net_version call should succeed"); + assert_eq!(version, 1); + }) + .await; }) .await; } #[tokio::test] async fn call_net_peer_count() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let count = provider.net_peer_count().await.expect("net_peerCount call should succeed"); - assert_eq!(count, 0); + let count = + provider.net_peer_count().await.expect("net_peerCount call should succeed"); + assert_eq!(count, 0); + }) + .await; }) .await; } #[tokio::test] async fn call_net_listening() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let listening = - provider.net_listening().await.expect("net_listening call should succeed"); - assert!(listening); + let listening = + provider.net_listening().await.expect("net_listening call should succeed"); + assert!(listening); + }) + .await; }) .await; } diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 58944e8963d..35e1caa825d 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -176,22 +176,16 @@ where #[cfg(test)] mod test { - use crate::ProviderBuilder; + use super::*; + use crate::{ext::test::async_ci_only, ProviderBuilder}; use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; use alloy_node_bindings::{utils::run_with_tempdir, Reth}; use alloy_primitives::address; use alloy_rpc_types_eth::TransactionRequest; - use super::*; - - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn trace_block() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let traces = provider.trace_block(BlockId::Number(BlockNumberOrTag::Latest)).await.unwrap(); assert_eq!(traces.len(), 0); @@ -200,21 +194,22 @@ mod test { #[tokio::test] #[cfg(not(windows))] async fn trace_call() { - run_with_tempdir("reth-test-", |temp_dir| async move { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); - - let tx = TransactionRequest::default() - .with_from(address!("0000000000000000000000000000000000000123")) - .with_to(address!("0000000000000000000000000000000000000456")); - - let result = provider.trace_call(&tx, &[TraceType::Trace]).await; - assert!(result.is_ok()); - - let traces = result.unwrap(); - assert_eq!( - serde_json::to_string_pretty(&traces).unwrap().trim(), - r#" + async_ci_only(|| async move { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + + let tx = TransactionRequest::default() + .with_from(address!("0000000000000000000000000000000000000123")) + .with_to(address!("0000000000000000000000000000000000000456")); + + let result = provider.trace_call(&tx, &[TraceType::Trace]).await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" { "output": "0x", "stateDiff": null, @@ -240,8 +235,10 @@ mod test { "vmTrace": null } "# - .trim(), - ); + .trim(), + ); + }) + .await; }) .await; } @@ -249,27 +246,28 @@ mod test { #[tokio::test] #[cfg(not(windows))] async fn trace_call_many() { - run_with_tempdir("reth-test-", |temp_dir| async move { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); - - let tx1 = TransactionRequest::default() - .with_from(address!("0000000000000000000000000000000000000123")) - .with_to(address!("0000000000000000000000000000000000000456")); - - let tx2 = TransactionRequest::default() - .with_from(address!("0000000000000000000000000000000000000456")) - .with_to(address!("0000000000000000000000000000000000000789")); - - let result = provider - .trace_call_many(&[(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])]) - .await; - assert!(result.is_ok()); - - let traces = result.unwrap(); - assert_eq!( - serde_json::to_string_pretty(&traces).unwrap().trim(), - r#" + async_ci_only(|| async move { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + + let tx1 = TransactionRequest::default() + .with_from(address!("0000000000000000000000000000000000000123")) + .with_to(address!("0000000000000000000000000000000000000456")); + + let tx2 = TransactionRequest::default() + .with_from(address!("0000000000000000000000000000000000000456")) + .with_to(address!("0000000000000000000000000000000000000789")); + + let result = provider + .trace_call_many(&[(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])]) + .await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" [ { "output": "0x", @@ -321,8 +319,10 @@ mod test { } ] "# - .trim() - ); + .trim() + ); + }) + .await; }) .await; } diff --git a/crates/provider/src/ext/txpool.rs b/crates/provider/src/ext/txpool.rs index 5326ae5922c..0250c2f468b 100644 --- a/crates/provider/src/ext/txpool.rs +++ b/crates/provider/src/ext/txpool.rs @@ -75,51 +75,62 @@ where #[cfg(test)] mod tests { - use crate::ProviderBuilder; - use super::*; + use crate::{ext::test::async_ci_only, ProviderBuilder}; use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn test_txpool_content() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_content().await.unwrap(); - assert_eq!(content, TxpoolContent::default()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_content().await.unwrap(); + assert_eq!(content, TxpoolContent::default()); + }) + .await; }) .await; } #[tokio::test] async fn test_txpool_content_from() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_content_from(Address::default()).await.unwrap(); - assert_eq!(content, TxpoolContentFrom::default()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_content_from(Address::default()).await.unwrap(); + assert_eq!(content, TxpoolContentFrom::default()); + }) + .await; }) .await; } #[tokio::test] async fn test_txpool_inspect() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_inspect().await.unwrap(); - assert_eq!(content, TxpoolInspect::default()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_inspect().await.unwrap(); + assert_eq!(content, TxpoolInspect::default()); + }) + .await; }) .await; } #[tokio::test] async fn test_txpool_status() { - run_with_tempdir("geth-test-", |temp_dir| async move { - let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_status().await.unwrap(); - assert_eq!(content, TxpoolStatus::default()); + async_ci_only(|| async move { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_status().await.unwrap(); + assert_eq!(content, TxpoolStatus::default()); + }) + .await; }) .await; } diff --git a/crates/provider/src/fillers/gas.rs b/crates/provider/src/fillers/gas.rs index ab92b4c5a21..ec79d56a820 100644 --- a/crates/provider/src/fillers/gas.rs +++ b/crates/provider/src/fillers/gas.rs @@ -257,14 +257,8 @@ mod tests { use alloy_primitives::{address, U256}; use alloy_rpc_types_eth::TransactionRequest; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn no_gas_price_or_limit() { - init_tracing(); - let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); // GasEstimationLayer requires chain_id to be set to handle EIP-1559 tx @@ -285,8 +279,6 @@ mod tests { #[tokio::test] async fn no_gas_limit() { - init_tracing(); - let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let gas_price = provider.get_gas_price().await.unwrap(); @@ -306,8 +298,6 @@ mod tests { #[tokio::test] async fn no_max_fee_per_blob_gas() { - init_tracing(); - let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let sidecar: SidecarBuilder = SidecarBuilder::from_slice(b"Hello World"); @@ -335,8 +325,6 @@ mod tests { #[tokio::test] async fn zero_max_fee_per_blob_gas() { - init_tracing(); - let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let sidecar: SidecarBuilder = SidecarBuilder::from_slice(b"Hello World"); diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 6563997c81a..06a8c7ad4b6 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1054,13 +1054,8 @@ mod tests { #[cfg(feature = "hyper")] use tower::{Layer, Service}; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn test_provider_builder() { - init_tracing(); let provider = RootProvider::::builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); @@ -1069,7 +1064,6 @@ mod tests { #[tokio::test] async fn test_builder_helper_fn() { - init_tracing(); let provider = builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num); @@ -1078,7 +1072,6 @@ mod tests { #[cfg(feature = "hyper")] #[tokio::test] async fn test_default_hyper_transport() { - init_tracing(); let anvil = Anvil::new().spawn(); let hyper_t = alloy_transport_http::HyperTransport::new_hyper(anvil.endpoint_url()); @@ -1141,7 +1134,6 @@ mod tests { use tower_http::{ sensitive_headers::SetSensitiveRequestHeadersLayer, set_header::SetRequestHeaderLayer, }; - init_tracing(); let anvil = Anvil::new().spawn(); let hyper_client = Client::builder(TokioExecutor::new()).build_http::>(); @@ -1187,43 +1179,46 @@ mod tests { #[cfg(all(feature = "hyper", not(windows)))] #[tokio::test] async fn test_auth_layer_transport() { - use alloy_node_bindings::Reth; - use alloy_rpc_types_engine::JwtSecret; - use alloy_transport_http::{AuthLayer, AuthService, Http, HyperClient}; + crate::ext::test::async_ci_only(|| async move { + use alloy_node_bindings::Reth; + use alloy_rpc_types_engine::JwtSecret; + use alloy_transport_http::{AuthLayer, AuthService, Http, HyperClient}; - init_tracing(); - let secret = JwtSecret::random(); + let secret = JwtSecret::random(); - let reth = Reth::new().arg("--rpc.jwtsecret").arg(hex::encode(secret.as_bytes())).spawn(); + let reth = + Reth::new().arg("--rpc.jwtsecret").arg(hex::encode(secret.as_bytes())).spawn(); - let hyper_client = Client::builder(TokioExecutor::new()).build_http::>(); + let hyper_client = + Client::builder(TokioExecutor::new()).build_http::>(); - let service = - tower::ServiceBuilder::new().layer(AuthLayer::new(secret)).service(hyper_client); + let service = + tower::ServiceBuilder::new().layer(AuthLayer::new(secret)).service(hyper_client); - let layer_transport: HyperClient< - Full, - AuthService< - Client< - alloy_transport_http::hyper_util::client::legacy::connect::HttpConnector, - Full, + let layer_transport: HyperClient< + Full, + AuthService< + Client< + alloy_transport_http::hyper_util::client::legacy::connect::HttpConnector, + Full, + >, >, - >, - > = HyperClient::with_service(service); + > = HyperClient::with_service(service); - let http_hyper = Http::with_client(layer_transport, reth.endpoint_url()); + let http_hyper = Http::with_client(layer_transport, reth.endpoint_url()); - let rpc_client = alloy_rpc_client::RpcClient::new(http_hyper, true); + let rpc_client = alloy_rpc_client::RpcClient::new(http_hyper, true); - let provider = RootProvider::<_, Ethereum>::new(rpc_client); + let provider = RootProvider::<_, Ethereum>::new(rpc_client); - let num = provider.get_block_number().await.unwrap(); - assert_eq!(0, num); + let num = provider.get_block_number().await.unwrap(); + assert_eq!(0, num); + }) + .await; } #[tokio::test] async fn test_builder_helper_fn_any_network() { - init_tracing(); let anvil = Anvil::new().spawn(); let provider = builder::().with_recommended_fillers().on_http(anvil.endpoint_url()); @@ -1234,7 +1229,6 @@ mod tests { #[cfg(feature = "reqwest")] #[tokio::test] async fn object_safety() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); // These blocks are not necessary. @@ -1270,8 +1264,6 @@ mod tests { #[cfg(feature = "ws")] #[tokio::test] async fn subscribe_blocks_http() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil_with_config(|a| a.block_time(1)); let err = provider.subscribe_blocks().await.unwrap_err(); @@ -1300,7 +1292,6 @@ mod tests { async fn subscribe_blocks_ws() { use futures::stream::StreamExt; - init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1321,7 +1312,6 @@ mod tests { async fn subscribe_blocks_ws_boxed() { use futures::stream::StreamExt; - init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1343,7 +1333,6 @@ mod tests { async fn subscribe_blocks_ws_remote() { use futures::stream::StreamExt; - init_tracing(); let url = "wss://eth-mainnet.g.alchemy.com/v2/viFmeVzhg6bWKVMIWWS8MhmzREB-D4f7"; let ws = alloy_rpc_client::WsConnect::new(url); let Ok(client) = alloy_rpc_client::RpcClient::connect_pubsub(ws).await else { return }; @@ -1358,7 +1347,6 @@ mod tests { #[tokio::test] async fn test_send_tx() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1382,7 +1370,6 @@ mod tests { #[tokio::test] async fn test_watch_confirmed_tx() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1430,7 +1417,6 @@ mod tests { #[tokio::test] async fn gets_block_number() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num) @@ -1438,7 +1424,6 @@ mod tests { #[tokio::test] async fn gets_block_number_with_raw_req() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num: U64 = provider.raw_request("eth_blockNumber".into(), NoParams::default()).await.unwrap(); @@ -1448,7 +1433,6 @@ mod tests { #[cfg(feature = "anvil-api")] #[tokio::test] async fn gets_transaction_count() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let accounts = provider.get_accounts().await.unwrap(); let sender = accounts[0]; @@ -1479,7 +1463,6 @@ mod tests { #[tokio::test] async fn gets_block_by_hash() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1492,7 +1475,6 @@ mod tests { #[tokio::test] async fn gets_block_by_hash_with_raw_req() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1507,7 +1489,6 @@ mod tests { #[tokio::test] async fn gets_block_by_number_full() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1517,7 +1498,6 @@ mod tests { #[tokio::test] async fn gets_block_by_number() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1527,7 +1507,6 @@ mod tests { #[tokio::test] async fn gets_client_version() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let version = provider.get_client_version().await.unwrap(); assert!(version.contains("anvil"), "{version}"); @@ -1535,7 +1514,6 @@ mod tests { #[tokio::test] async fn gets_sha3() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let data = b"alloy"; let hash = provider.get_sha3(data).await.unwrap(); @@ -1563,7 +1541,6 @@ mod tests { #[tokio::test] async fn gets_storage_at() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let addr = Address::with_last_byte(16); let storage = provider.get_storage_at(addr, U256::ZERO).await.unwrap(); @@ -1572,8 +1549,6 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash_not_found() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil(); let tx_hash = b256!("5c03fab9114ceb98994b43892ade87ddfd9ae7e8f293935c3bd29d435dc9fd95"); let tx = provider.get_transaction_by_hash(tx_hash).await.expect("failed to fetch tx"); @@ -1583,7 +1558,6 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash() { - init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let req = TransactionRequest::default() @@ -1605,7 +1579,6 @@ mod tests { #[tokio::test] #[ignore] async fn gets_logs() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let filter = Filter::new() .at_block_hash(b256!( @@ -1621,7 +1594,6 @@ mod tests { #[tokio::test] #[ignore] async fn gets_tx_receipt() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipt = provider .get_transaction_receipt(b256!( @@ -1639,14 +1611,12 @@ mod tests { #[tokio::test] async fn gets_max_priority_fee_per_gas() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let _fee = provider.get_max_priority_fee_per_gas().await.unwrap(); } #[tokio::test] async fn gets_fee_history() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block_number = provider.get_block_number().await.unwrap(); let fee_history = provider @@ -1662,7 +1632,6 @@ mod tests { #[tokio::test] async fn gets_block_receipts() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipts = provider.get_block_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await.unwrap(); @@ -1671,7 +1640,6 @@ mod tests { #[tokio::test] async fn sends_raw_transaction() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let pending = provider .send_raw_transaction( @@ -1687,7 +1655,6 @@ mod tests { #[tokio::test] async fn connect_boxed() { - init_tracing(); let anvil = Anvil::new().spawn(); let provider = @@ -1710,7 +1677,6 @@ mod tests { #[tokio::test] async fn builtin_connect_boxed() { - init_tracing(); let anvil = Anvil::new().spawn(); let conn: BuiltInConnectionString = anvil.endpoint().parse().unwrap(); @@ -1727,7 +1693,6 @@ mod tests { #[tokio::test] async fn test_uncle_count() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let count = provider.get_uncle_count(0.into()).await.unwrap(); @@ -1744,7 +1709,6 @@ mod tests { use alloy_network::TransactionBuilder; use alloy_sol_types::SolValue; - init_tracing(); let url = "https://eth-mainnet.alchemyapi.io/v2/jGiK5vwDfC3F4r0bqukm-W2GqgdrxdSr"; let provider = ProviderBuilder::new().on_http(url.parse().unwrap()); let req = TransactionRequest::default() @@ -1759,7 +1723,6 @@ mod tests { #[tokio::test] async fn test_empty_transactions() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block = provider.get_block_by_number(0.into(), false).await.unwrap().unwrap();