Skip to content

Commit

Permalink
tests: fix more ci only (#1402)
Browse files Browse the repository at this point in the history
* tests: fix more ci only

* lint: allow dead
  • Loading branch information
prestwich authored Oct 19, 2024
1 parent 1ad42f9 commit 25d2cf8
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 308 deletions.
1 change: 1 addition & 0 deletions crates/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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"]
Expand Down
8 changes: 0 additions & 8 deletions crates/provider/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Future>(future: T) -> T::Output {
try_timeout(future).await.expect("Timeout")
}
Expand All @@ -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() };
Expand Down Expand Up @@ -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() };
Expand Down
52 changes: 29 additions & 23 deletions crates/provider/src/ext/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Expand Down
243 changes: 129 additions & 114 deletions crates/provider/src/ext/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
[
[
{
Expand All @@ -384,9 +397,11 @@ mod test {
]
]
"#
.trim(),
);
.trim(),
);
})
.await;
})
.await
.await;
}
}
Loading

0 comments on commit 25d2cf8

Please sign in to comment.