From 50a324708518844e30121a71907dba455bdf73b1 Mon Sep 17 00:00:00 2001 From: varun-doshi Date: Fri, 10 Oct 2025 11:34:14 +0530 Subject: [PATCH 1/3] feat(tests): Add tests for Checkpoint and CheckpointExt --- src/payload/checkpoint.rs | 67 ++++++++++++++++++++++ src/payload/ext/checkpoint.rs | 105 ++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/src/payload/checkpoint.rs b/src/payload/checkpoint.rs index 2ad0ea5..1905d50 100644 --- a/src/payload/checkpoint.rs +++ b/src/payload/checkpoint.rs @@ -546,3 +546,70 @@ impl Display for Checkpoint

{ } } } + +#[cfg(test)] +mod tests { + use { + rblib::{prelude::*, test_utils::BlockContextMocked}, + std::time::Instant, + }; + + #[test] + fn test_barrier_depth_and_is_barrier() { + let (block, _) = BlockContext::::mocked(); + + let checkpoint = block.start(); + + // Expected: initial checkpoint is depth 0 and is barrier + assert_eq!(checkpoint.depth(), 0); + assert!(checkpoint.is_barrier()); + assert!(checkpoint.prev().is_none()); + } + + #[test] + fn test_named_barrier_and_prev_depth() { + // Outline: + // 1. create initial checkpoint (depth 0) + // 2. create named barrier on top + // 3. verify new depth is 1, prev is initial, and is_named_barrier returns + // true + let root = { + let (block, _) = BlockContext::::mocked(); + + let cp = block.start(); + cp + }; + + let named = root.named_barrier("sequencer-synced"); + assert_eq!(named.depth(), root.depth() + 1); + assert!(named.is_named_barrier("sequencer-synced")); + assert!(matches!(named.prev(), Some(_))); + assert_eq!(named.prev().unwrap().depth(), root.depth()); + } + + #[test] + fn test_created_at() { + let (block, _) = BlockContext::::mocked(); + + let checkpoint = block.start(); + + let now = Instant::now(); + assert!(checkpoint.created_at() <= now); + } + + #[test] + fn test_iter() { + let (block, _) = BlockContext::::mocked(); + + let checkpoint = block.start(); + + let checkpoint2 = checkpoint.barrier(); + let checkpoint3 = checkpoint2.barrier(); + + let history: Vec<_> = checkpoint3.into_iter().collect(); + assert_eq!(history.len(), 3); + assert_eq!(history[0].depth(), 2); + assert_eq!(history[1].depth(), 1); + assert_eq!(history[2].depth(), 0); + } +} diff --git a/src/payload/ext/checkpoint.rs b/src/payload/ext/checkpoint.rs index a40657e..e71370e 100644 --- a/src/payload/ext/checkpoint.rs +++ b/src/payload/ext/checkpoint.rs @@ -327,3 +327,108 @@ impl CheckpointExt

for Checkpoint

{ self.root().created_at() } } + +#[cfg(test)] +mod tests { + use { + crate::alloy::primitives::Address, + alloy_origin::primitives::{TxHash, U256}, + rblib::{prelude::*, test_utils::BlockContextMocked}, + std::{ + thread, + time::{Duration, Instant}, + }, + }; + + #[test] + fn test_is_empty_and_root() { + let (block, _) = BlockContext::::mocked(); + let root = block.start(); + let mid = root.barrier(); + let leaf = mid.barrier(); + + assert!(root.is_empty()); + assert_eq!(leaf.root(), root); + } + + #[test] + fn test_gas_used_and_cumulative_gas_used() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + assert_eq!(cp.gas_used(), 0); + assert_eq!(cp.cumulative_gas_used(), 0); + } + + #[test] + fn test_effective_tip_and_blob_gas() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + assert_eq!(cp.effective_tip_per_gas(), 0); + assert!(!cp.has_blobs()); + assert_eq!(cp.blob_gas_used(), Some(0)); + assert_eq!(cp.cumulative_blob_gas_used(), 0); + } + + #[test] + fn test_to_between_linear_history() { + let (block, _) = BlockContext::::mocked(); + let a = block.start(); + let b = a.barrier(); + let c = b.barrier(); + + let span1 = c.to(&a).unwrap(); + let span2 = a.to(&c).unwrap(); + + assert_eq!(span1.len(), 3); + assert_eq!(span2.len(), 3); + } + + #[test] + fn test_balance_and_nonce_defaults() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + + let addr = Address::ZERO; + assert_eq!(cp.balance_of(addr).unwrap(), U256::ZERO); + assert_eq!(cp.nonce_of(addr).unwrap(), 0); + } + + #[test] + fn test_signers_and_nonces_are_empty() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + + assert!(cp.signers().is_empty()); + assert!(cp.nonces().is_empty()); + } + + #[test] + fn test_hash_and_is_bundle_and_has_failures_defaults() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + + assert_eq!(cp.hash(), None); + assert!(!cp.is_bundle()); + assert!(!cp.has_failures()); + assert_eq!(cp.failed_txs().count(), 0); + } + + #[test] + fn test_contains_is_false_without_txs() { + let (block, _) = BlockContext::::mocked(); + let cp = block.start(); + + let fake_hash = TxHash::repeat_byte(0x42); + assert!(!cp.contains(fake_hash)); + } + + #[test] + fn test_history_timestamps() { + let (block, _) = BlockContext::::mocked(); + let cp1 = block.start(); + thread::sleep(Duration::from_millis(5)); + let cp2 = cp1.barrier(); + assert!(cp2.building_since() <= Instant::now()); + assert!(cp2.building_since() >= cp1.created_at()); + } +} From 1ab91fc1ee8e1a14da116dc13220cb52d6e62337 Mon Sep 17 00:00:00 2001 From: varun-doshi Date: Fri, 17 Oct 2025 01:46:01 +0530 Subject: [PATCH 2/3] fix: more detailed tests --- examples/checkpoints-eth.rs | 39 +----- src/payload/checkpoint.rs | 28 ++-- src/payload/ext/checkpoint.rs | 232 +++++++++++++++++++++++++-------- src/test_utils/mod.rs | 2 + src/test_utils/transactions.rs | 37 ++++++ 5 files changed, 241 insertions(+), 97 deletions(-) create mode 100644 src/test_utils/transactions.rs diff --git a/examples/checkpoints-eth.rs b/examples/checkpoints-eth.rs index 1368465..7344bd5 100644 --- a/examples/checkpoints-eth.rs +++ b/examples/checkpoints-eth.rs @@ -4,22 +4,11 @@ //! test-utils provided helpers for creating mock instances. use { - alloy::{ - consensus::{EthereumTxEnvelope, Transaction, TxEip4844}, - network::{TransactionBuilder, TxSignerSync}, - primitives::{Address, U256}, - signers::local::PrivateKeySigner, - }, + alloy::{consensus::Transaction, primitives::U256}, rblib::{ alloy, prelude::*, - reth, - test_utils::{BlockContextMocked, FundedAccounts}, - }, - reth::{ - ethereum::{TransactionSigned, primitives::SignedTransaction}, - primitives::Recovered, - rpc::types::TransactionRequest, + test_utils::{BlockContextMocked, FundedAccounts, transfer_tx}, }, }; @@ -69,27 +58,3 @@ fn main() -> eyre::Result<()> { Ok(()) } - -fn transfer_tx( - signer: &PrivateKeySigner, - nonce: u64, - value: U256, -) -> Recovered> { - let mut tx = TransactionRequest::default() - .with_nonce(nonce) - .with_to(Address::random()) - .value(value) - .with_gas_price(1_000_000_000) - .with_gas_limit(21_000) - .with_max_priority_fee_per_gas(1_000_000) - .with_max_fee_per_gas(2_000_000) - .build_unsigned() - .expect("valid transaction request"); - - let sig = signer - .sign_transaction_sync(&mut tx) - .expect("signing should succeed"); - - TransactionSigned::new_unhashed(tx.into(), sig) // - .with_signer(signer.address()) -} diff --git a/src/payload/checkpoint.rs b/src/payload/checkpoint.rs index 1905d50..30993c6 100644 --- a/src/payload/checkpoint.rs +++ b/src/payload/checkpoint.rs @@ -550,6 +550,8 @@ impl Display for Checkpoint

{ #[cfg(test)] mod tests { use { + crate::test_utils::{FundedAccounts, transfer_tx}, + alloy_origin::primitives::U256, rblib::{prelude::*, test_utils::BlockContextMocked}, std::time::Instant, }; @@ -591,10 +593,10 @@ mod tests { fn test_created_at() { let (block, _) = BlockContext::::mocked(); - let checkpoint = block.start(); - - let now = Instant::now(); - assert!(checkpoint.created_at() <= now); + let before = Instant::now(); + let cp = block.start(); + let after = Instant::now(); + assert!((before..=after).contains(&cp.created_at())); } #[test] @@ -606,10 +608,18 @@ mod tests { let checkpoint2 = checkpoint.barrier(); let checkpoint3 = checkpoint2.barrier(); - let history: Vec<_> = checkpoint3.into_iter().collect(); - assert_eq!(history.len(), 3); - assert_eq!(history[0].depth(), 2); - assert_eq!(history[1].depth(), 1); - assert_eq!(history[2].depth(), 0); + let tx = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(10u64)); + let checkpoint4 = checkpoint3.apply(tx).unwrap(); + + let history: Vec<_> = checkpoint4.into_iter().collect(); + assert_eq!(history.len(), 4); + assert_eq!(history[0], checkpoint4); + assert_eq!(history[0].depth(), 3); + assert_eq!(history[1], checkpoint3); + assert_eq!(history[1].depth(), 2); + assert_eq!(history[2], checkpoint2); + assert_eq!(history[2].depth(), 1); + assert_eq!(history[3], checkpoint); + assert_eq!(history[3].depth(), 0); } } diff --git a/src/payload/ext/checkpoint.rs b/src/payload/ext/checkpoint.rs index e71370e..499fe7e 100644 --- a/src/payload/ext/checkpoint.rs +++ b/src/payload/ext/checkpoint.rs @@ -331,9 +331,13 @@ impl CheckpointExt

for Checkpoint

{ #[cfg(test)] mod tests { use { - crate::alloy::primitives::Address, - alloy_origin::primitives::{TxHash, U256}, - rblib::{prelude::*, test_utils::BlockContextMocked}, + crate::{ + alloy::primitives::Address, + payload::{Checkpoint, CheckpointExt}, + prelude::{BlockContext, Ethereum}, + test_utils::{BlockContextMocked, FundedAccounts, transfer_tx}, + }, + alloy_origin::primitives::U256, std::{ thread, time::{Duration, Instant}, @@ -341,94 +345,220 @@ mod tests { }; #[test] - fn test_is_empty_and_root() { + fn test_new_at_block() { let (block, _) = BlockContext::::mocked(); - let root = block.start(); - let mid = root.barrier(); - let leaf = mid.barrier(); + let cp = Checkpoint::new_at_block(block); - assert!(root.is_empty()); - assert_eq!(leaf.root(), root); - } + let cp2 = cp.barrier(); + let cp3 = cp2.barrier(); + + assert!(cp.is_empty()); + assert_eq!(cp2.root(), cp); + assert_eq!(cp3.root(), cp); - #[test] - fn test_gas_used_and_cumulative_gas_used() { - let (block, _) = BlockContext::::mocked(); - let cp = block.start(); assert_eq!(cp.gas_used(), 0); assert_eq!(cp.cumulative_gas_used(), 0); - } - #[test] - fn test_effective_tip_and_blob_gas() { - let (block, _) = BlockContext::::mocked(); - let cp = block.start(); assert_eq!(cp.effective_tip_per_gas(), 0); assert!(!cp.has_blobs()); assert_eq!(cp.blob_gas_used(), Some(0)); assert_eq!(cp.cumulative_blob_gas_used(), 0); - } - - #[test] - fn test_to_between_linear_history() { - let (block, _) = BlockContext::::mocked(); - let a = block.start(); - let b = a.barrier(); - let c = b.barrier(); - let span1 = c.to(&a).unwrap(); - let span2 = a.to(&c).unwrap(); + let span1 = cp3.to(&cp).unwrap(); + let span2 = cp.to(&cp3).unwrap(); + assert_eq!(span1.len(), span2.len()); + for i in 0..span2.len() { + assert_eq!(span1.at(i), span2.at(i)); + } assert_eq!(span1.len(), 3); assert_eq!(span2.len(), 3); - } - - #[test] - fn test_balance_and_nonce_defaults() { - let (block, _) = BlockContext::::mocked(); - let cp = block.start(); let addr = Address::ZERO; assert_eq!(cp.balance_of(addr).unwrap(), U256::ZERO); assert_eq!(cp.nonce_of(addr).unwrap(), 0); - } - - #[test] - fn test_signers_and_nonces_are_empty() { - let (block, _) = BlockContext::::mocked(); - let cp = block.start(); assert!(cp.signers().is_empty()); assert!(cp.nonces().is_empty()); - } - - #[test] - fn test_hash_and_is_bundle_and_has_failures_defaults() { - let (block, _) = BlockContext::::mocked(); - let cp = block.start(); assert_eq!(cp.hash(), None); assert!(!cp.is_bundle()); assert!(!cp.has_failures()); assert_eq!(cp.failed_txs().count(), 0); + + let random_addr = Address::random(); + assert_eq!( + cp.balance_of(random_addr).unwrap(), + U256::ZERO, + "Nonexistent account should have zero balance" + ); + + assert_eq!( + cp.nonce_of(random_addr).unwrap(), + 0, + "Nonexistent account should have zero nonce" + ); } #[test] fn test_contains_is_false_without_txs() { let (block, _) = BlockContext::::mocked(); - let cp = block.start(); + let cp1 = Checkpoint::new_at_block(block); + + let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50_000u64)); + let tx1_hash = tx1.hash().clone(); + assert!(!cp1.contains(tx1_hash)); + let cp2 = cp1.apply(tx1).unwrap(); - let fake_hash = TxHash::repeat_byte(0x42); - assert!(!cp.contains(fake_hash)); + assert!(cp2.contains(tx1_hash)); } #[test] fn test_history_timestamps() { let (block, _) = BlockContext::::mocked(); - let cp1 = block.start(); + let cp1 = Checkpoint::new_at_block(block); + thread::sleep(Duration::from_millis(5)); + let cp2 = cp1.barrier(); + assert!(cp2.building_since() <= Instant::now()); assert!(cp2.building_since() >= cp1.created_at()); } + + #[test] + fn test_to_self() { + let (block, _) = BlockContext::::mocked(); + let cp = Checkpoint::new_at_block(block); + + // to(self, self) should produce a span of length 1 containing the + // checkpoint itself + let span = cp.to(&cp).expect("to(self,self) must succeed"); + assert_eq!(span.len(), 1); + assert_eq!(*span.at(0).unwrap(), cp); + } + + #[test] + fn test_to_non_linear_error() { + let (block_a, _) = BlockContext::::mocked(); + let (block_b, _) = BlockContext::::mocked(); + + let cp_a = Checkpoint::new_at_block(block_a); + let cp_b = Checkpoint::new_at_block(block_b); + + // They are not on the same linear history, so to should return an Err. + assert!(cp_a.to(&cp_b).is_err()); + assert!(cp_b.to(&cp_a).is_err()); + } + + #[test] + fn test_to_includes_all_intermediates_and_is_linear() { + let (block, _) = BlockContext::::mocked(); + let base = Checkpoint::new_at_block(block); + + // base -> x -> y + let tx_x = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(10u64)); + let x = base.apply(tx_x).unwrap(); + + let tx_y = transfer_tx(&FundedAccounts::signer(1), 0, U256::from(20u64)); + let y = x.apply(tx_y).unwrap(); + + let x_barrier = x.barrier(); + let y_barrier = y.barrier(); + + // `to` between base and y_barrier should include `base``, `x` (or + // x_barrier), `y` (or y_barrier) + let span_by = y_barrier + .to(&base) + .expect("to should succeed for linear history"); + let collected: Vec> = (0..span_by.len()) + .map(|i| span_by.at(i).unwrap().clone()) + .collect(); + + assert!(collected.contains(&base)); + assert!(collected.contains(&y_barrier)); + assert!(collected.iter().any(|cp| *cp == x || *cp == x_barrier)); + } + + #[test] + fn test_to_different_roots_error() { + let (block1, _) = BlockContext::::mocked(); + let (block2, _) = BlockContext::::mocked(); + + let root1 = Checkpoint::new_at_block(block1); + let root2 = Checkpoint::new_at_block(block2); + + let tx = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(5u64)); + let root1_child = root1.apply(tx).unwrap(); + + assert!(root1_child.to(&root2).is_err()); + assert!(root2.to(&root1_child).is_err()); + } + + #[test] + fn test_effective_tip_checkpoint() { + let (block, _) = BlockContext::::mocked(); + let cp = Checkpoint::new_at_block(block); + assert_eq!( + cp.effective_tip_per_gas(), + 0, + "Empty checkpoint should have zero tip" + ); + + let tx = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(100u64)); + let cp2 = cp.apply(tx.clone()).unwrap(); + + let tip = cp2.effective_tip_per_gas(); + assert!(tip > 0, "Transaction should have positive effective tip"); + } + + #[test] + fn test_history_staging_no_barrier() { + let (block, _) = BlockContext::::mocked(); + let base = Checkpoint::new_at_block(block); + + let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50u64)); + let cp1 = base.apply(tx1).unwrap(); + + let tx2 = transfer_tx(&FundedAccounts::signer(1), 0, U256::from(75u64)); + let cp2 = cp1.apply(tx2).unwrap(); + + let staging = cp2.history_staging(); + let full = cp2.history(); + + assert_eq!( + staging.len(), + full.len(), + "Without barriers, staging should equal full history" + ); + } + + #[test] + fn test_history_staging_with_barrier() { + let (block, _) = BlockContext::::mocked(); + let base = Checkpoint::new_at_block(block); + + let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50u64)); + let cp1 = base.apply(tx1).unwrap(); + + let barrier = cp1.barrier(); + + let tx2 = transfer_tx(&FundedAccounts::signer(1), 0, U256::from(75u64)); + let cp2 = barrier.apply(tx2).unwrap(); + + let staging = cp2.history_staging(); + + // Staging should only include checkpoints after the barrier + assert!( + staging.len() < cp2.history().len(), + "Staging should be shorter than full history" + ); + let sealed = cp2.history_sealed(); + + // Sealed should include everything up to and including the barrier + assert!( + sealed.len() > 0, + "Sealed should include checkpoints up to barrier" + ); + } } diff --git a/src/test_utils/mod.rs b/src/test_utils/mod.rs index ee31cf9..7944f6b 100644 --- a/src/test_utils/mod.rs +++ b/src/test_utils/mod.rs @@ -20,6 +20,7 @@ mod mock; mod node; mod platform; mod step; +mod transactions; #[allow(unused_imports)] pub(crate) use step::fake_step; @@ -32,6 +33,7 @@ pub use { platform::{TestNodeFactory, TestablePlatform}, rblib_tests_macros::{assert_is_dyn_safe, if_platform, rblib_test}, step::{AlwaysBreakStep, AlwaysFailStep, AlwaysOkStep, OneStep}, + transactions::transfer_tx, }; #[cfg(feature = "optimism")] diff --git a/src/test_utils/transactions.rs b/src/test_utils/transactions.rs new file mode 100644 index 0000000..575b55a --- /dev/null +++ b/src/test_utils/transactions.rs @@ -0,0 +1,37 @@ +use { + crate::{alloy, reth}, + alloy::{ + consensus::{EthereumTxEnvelope, TxEip4844}, + network::{TransactionBuilder, TxSignerSync}, + primitives::{Address, U256}, + signers::local::PrivateKeySigner, + }, + reth::{ + ethereum::{TransactionSigned, primitives::SignedTransaction}, + primitives::Recovered, + rpc::types::TransactionRequest, + }, +}; +pub fn transfer_tx( + signer: &PrivateKeySigner, + nonce: u64, + value: U256, +) -> Recovered> { + let mut tx = TransactionRequest::default() + .with_nonce(nonce) + .with_to(Address::random()) + .value(value) + .with_gas_price(1_000_000_000) + .with_gas_limit(21_000) + .with_max_priority_fee_per_gas(1_000_000) + .with_max_fee_per_gas(2_000_000) + .build_unsigned() + .expect("valid transaction request"); + + let sig = signer + .sign_transaction_sync(&mut tx) + .expect("signing should succeed"); + + TransactionSigned::new_unhashed(tx.into(), sig) // + .with_signer(signer.address()) +} From ec94d538cc0c987ecda76a293e4c60a3846bd956 Mon Sep 17 00:00:00 2001 From: julio4 <30329843+julio4@users.noreply.github.com> Date: Tue, 4 Nov 2025 14:20:55 +0900 Subject: [PATCH 3/3] test: checkpoints --- src/payload/checkpoint.rs | 28 ++++++++++++++-------------- src/payload/ext/checkpoint.rs | 31 +++++++++++++++---------------- src/test_utils/transactions.rs | 2 ++ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/payload/checkpoint.rs b/src/payload/checkpoint.rs index 30993c6..68eab10 100644 --- a/src/payload/checkpoint.rs +++ b/src/payload/checkpoint.rs @@ -550,15 +550,17 @@ impl Display for Checkpoint

{ #[cfg(test)] mod tests { use { - crate::test_utils::{FundedAccounts, transfer_tx}, - alloy_origin::primitives::U256, - rblib::{prelude::*, test_utils::BlockContextMocked}, + crate::{ + alloy::primitives::U256, + prelude::{BlockContext, Ethereum}, + test_utils::{BlockContextMocked, FundedAccounts, transfer_tx}, + }, std::time::Instant, }; #[test] fn test_barrier_depth_and_is_barrier() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let checkpoint = block.start(); @@ -575,23 +577,21 @@ mod tests { // 2. create named barrier on top // 3. verify new depth is 1, prev is initial, and is_named_barrier returns // true - let root = { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); - let cp = block.start(); - cp - }; + let root = block.start(); + + let named = root.barrier_with_tag("sequencer-synced"); - let named = root.named_barrier("sequencer-synced"); assert_eq!(named.depth(), root.depth() + 1); - assert!(named.is_named_barrier("sequencer-synced")); - assert!(matches!(named.prev(), Some(_))); + assert_eq!(named.tag(), Some("sequencer-synced")); + assert!(named.prev().is_some()); assert_eq!(named.prev().unwrap().depth(), root.depth()); } #[test] fn test_created_at() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let before = Instant::now(); let cp = block.start(); @@ -601,7 +601,7 @@ mod tests { #[test] fn test_iter() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let checkpoint = block.start(); diff --git a/src/payload/ext/checkpoint.rs b/src/payload/ext/checkpoint.rs index 499fe7e..27b33e1 100644 --- a/src/payload/ext/checkpoint.rs +++ b/src/payload/ext/checkpoint.rs @@ -332,12 +332,11 @@ impl CheckpointExt

for Checkpoint

{ mod tests { use { crate::{ - alloy::primitives::Address, + alloy::primitives::{Address, U256}, payload::{Checkpoint, CheckpointExt}, prelude::{BlockContext, Ethereum}, test_utils::{BlockContextMocked, FundedAccounts, transfer_tx}, }, - alloy_origin::primitives::U256, std::{ thread, time::{Duration, Instant}, @@ -346,7 +345,7 @@ mod tests { #[test] fn test_new_at_block() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let cp = Checkpoint::new_at_block(block); let cp2 = cp.barrier(); @@ -402,11 +401,11 @@ mod tests { #[test] fn test_contains_is_false_without_txs() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let cp1 = Checkpoint::new_at_block(block); let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50_000u64)); - let tx1_hash = tx1.hash().clone(); + let tx1_hash = *tx1.hash(); assert!(!cp1.contains(tx1_hash)); let cp2 = cp1.apply(tx1).unwrap(); @@ -415,7 +414,7 @@ mod tests { #[test] fn test_history_timestamps() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let cp1 = Checkpoint::new_at_block(block); thread::sleep(Duration::from_millis(5)); @@ -428,7 +427,7 @@ mod tests { #[test] fn test_to_self() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let cp = Checkpoint::new_at_block(block); // to(self, self) should produce a span of length 1 containing the @@ -440,8 +439,8 @@ mod tests { #[test] fn test_to_non_linear_error() { - let (block_a, _) = BlockContext::::mocked(); - let (block_b, _) = BlockContext::::mocked(); + let block_a = BlockContext::::mocked(); + let block_b = BlockContext::::mocked(); let cp_a = Checkpoint::new_at_block(block_a); let cp_b = Checkpoint::new_at_block(block_b); @@ -453,7 +452,7 @@ mod tests { #[test] fn test_to_includes_all_intermediates_and_is_linear() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let base = Checkpoint::new_at_block(block); // base -> x -> y @@ -482,8 +481,8 @@ mod tests { #[test] fn test_to_different_roots_error() { - let (block1, _) = BlockContext::::mocked(); - let (block2, _) = BlockContext::::mocked(); + let block1 = BlockContext::::mocked(); + let block2 = BlockContext::::mocked(); let root1 = Checkpoint::new_at_block(block1); let root2 = Checkpoint::new_at_block(block2); @@ -497,7 +496,7 @@ mod tests { #[test] fn test_effective_tip_checkpoint() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let cp = Checkpoint::new_at_block(block); assert_eq!( cp.effective_tip_per_gas(), @@ -514,7 +513,7 @@ mod tests { #[test] fn test_history_staging_no_barrier() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let base = Checkpoint::new_at_block(block); let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50u64)); @@ -535,7 +534,7 @@ mod tests { #[test] fn test_history_staging_with_barrier() { - let (block, _) = BlockContext::::mocked(); + let block = BlockContext::::mocked(); let base = Checkpoint::new_at_block(block); let tx1 = transfer_tx(&FundedAccounts::signer(0), 0, U256::from(50u64)); @@ -557,7 +556,7 @@ mod tests { // Sealed should include everything up to and including the barrier assert!( - sealed.len() > 0, + !sealed.is_empty(), "Sealed should include checkpoints up to barrier" ); } diff --git a/src/test_utils/transactions.rs b/src/test_utils/transactions.rs index 575b55a..a0db458 100644 --- a/src/test_utils/transactions.rs +++ b/src/test_utils/transactions.rs @@ -12,6 +12,8 @@ use { rpc::types::TransactionRequest, }, }; + +#[allow(clippy::missing_panics_doc)] pub fn transfer_tx( signer: &PrivateKeySigner, nonce: u64,