Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix tests #1583

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 50 additions & 20 deletions crates/provider/src/ext/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<u64>()));
}
Expand All @@ -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);
}

Expand All @@ -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();

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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);
}

Expand All @@ -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::<u64>(), latest_block.header.gas_limit);
}

Expand All @@ -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()
Expand All @@ -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);

Expand All @@ -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()
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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))
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
}
}