From 8e6c7a3b06778d33c5006ee8f5c3e3ce63db6bda Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Tue, 29 Oct 2024 20:42:27 +0100 Subject: [PATCH] test: fix tests --- crates/provider/src/ext/anvil.rs | 70 +++++++++++++++++++-------- crates/provider/src/provider/trait.rs | 18 +++++-- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index b9b6d2dbf3f..dfb411331fd 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -323,6 +323,7 @@ mod tests { use crate::ProviderBuilder; use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; + use alloy_network_primitives::BlockTransactionsKind; use alloy_primitives::B256; use alloy_rpc_types_eth::TransactionRequest; @@ -615,8 +616,11 @@ mod tests { provider.evm_mine(None).await.unwrap(); - let block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(block.header.base_fee_per_gas, Some(basefee.to::())); } @@ -630,8 +634,11 @@ mod tests { provider.evm_mine(None).await.unwrap(); - let block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(block.header.beneficiary, coinbase); } @@ -652,8 +659,11 @@ mod tests { async fn test_anvil_node_info() { let provider = ProviderBuilder::new().on_anvil(); - let latest_block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let latest_block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); provider.evm_mine(None).await.unwrap(); @@ -745,7 +755,7 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider - .get_block_by_number(BlockNumberOrTag::Latest, false) + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) .await .unwrap() .unwrap() @@ -762,7 +772,7 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider - .get_block_by_number(BlockNumberOrTag::Latest, false) + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) .await .unwrap() .unwrap() @@ -773,8 +783,11 @@ mod tests { provider.evm_mine(None).await.unwrap(); - let latest_block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let latest_block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(latest_block.header.timestamp, timestamp + 1337); } @@ -798,8 +811,11 @@ mod tests { provider.evm_mine(None).await.unwrap(); - let latest_block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let latest_block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(block_gas_limit.to::(), latest_block.header.gas_limit); } @@ -810,7 +826,7 @@ mod tests { provider.anvil_set_block_timestamp_interval(1).await.unwrap(); let start_timestamp = provider - .get_block_by_number(BlockNumberOrTag::Latest, false) + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) .await .unwrap() .unwrap() @@ -821,8 +837,11 @@ mod tests { provider.evm_mine(None).await.unwrap(); - let latest_block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let latest_block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(latest_block.header.timestamp, start_timestamp + 1); @@ -831,7 +850,7 @@ mod tests { provider.evm_mine(None).await.unwrap(); let start_timestamp = provider - .get_block_by_number(BlockNumberOrTag::Latest, false) + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) .await .unwrap() .unwrap() @@ -840,8 +859,11 @@ mod tests { tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; - let latest_block = - provider.get_block_by_number(BlockNumberOrTag::Latest, false).await.unwrap().unwrap(); + let latest_block = provider + .get_block_by_number(BlockNumberOrTag::Latest, BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(latest_block.header.timestamp, start_timestamp); } @@ -932,10 +954,18 @@ mod tests { // Mine two blocks provider.anvil_mine(Some(U256::from(2)), None).await.unwrap(); - let reorged_block = provider.get_block_by_number(2.into(), false).await.unwrap().unwrap(); + let reorged_block = provider + .get_block_by_number(2.into(), BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); provider.anvil_reorg(ReorgOptions { depth: 1, tx_block_pairs: Vec::new() }).await.unwrap(); - let new_block = provider.get_block_by_number(2.into(), false).await.unwrap().unwrap(); + let new_block = provider + .get_block_by_number(2.into(), BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert_eq!(reorged_block.header.number, new_block.header.number); assert_ne!(reorged_block.header.hash, new_block.header.hash); diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 4bda40517d1..f12a15c643a 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1517,7 +1517,8 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); - let block = provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); + let block = + provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); let hash = block.header.hash; let block = provider.get_block_by_hash(hash, BlockTransactionsKind::Full).await.unwrap().unwrap(); @@ -1529,7 +1530,8 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); - let block = provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); + let block = + provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); let hash = block.header.hash; let block: Block = provider .raw_request::<(B256, bool), Block>("eth_getBlockByHash".into(), (hash, true)) @@ -1543,7 +1545,8 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); - let block = provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); + let block = + provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); assert_eq!(block.header.number, num); } @@ -1552,7 +1555,8 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); - let block = provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); + let block = + provider.get_block_by_number(tag, BlockTransactionsKind::Full).await.unwrap().unwrap(); assert_eq!(block.header.number, num); } @@ -1776,7 +1780,11 @@ mod tests { async fn test_empty_transactions() { let provider = ProviderBuilder::new().on_anvil(); - let block = provider.get_block_by_number(0.into(), BlockTransactionsKind::Hashes).await.unwrap().unwrap(); + let block = provider + .get_block_by_number(0.into(), BlockTransactionsKind::Hashes) + .await + .unwrap() + .unwrap(); assert!(block.transactions.is_hashes()); } }