diff --git a/src/journal/update.rs b/src/journal/update.rs index 89eddf7..3cc4ad7 100644 --- a/src/journal/update.rs +++ b/src/journal/update.rs @@ -3,7 +3,7 @@ use alloy::primitives::{keccak256, Bytes, B256}; use std::sync::OnceLock; /// Journal associated with a block -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct BlockUpdate<'a> { /// The height of the block. height: u64, @@ -95,3 +95,33 @@ impl JournalDecode for BlockUpdate<'static> { }) } } + +impl PartialEq for BlockUpdate<'_> { + fn eq(&self, other: &Self) -> bool { + match (self.hash.get(), other.hash.get()) { + (Some(lhs), Some(rhs)) => lhs == rhs, + _ => { + self.height == other.height + && self.prev_journal_hash == other.prev_journal_hash + && self.journal == other.journal + } + } + } +} + +impl Eq for BlockUpdate<'_> {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn block_update_eq_with_one_populated_hash() { + let update_a = BlockUpdate::new(1, B256::ZERO, BundleStateIndex::default()); + let update_b = BlockUpdate::new(1, B256::ZERO, BundleStateIndex::default()); + update_a.journal_hash(); + assert!(update_a.hash.get().is_some()); + assert!(update_b.hash.get().is_none()); + assert_eq!(update_a, update_b); + } +} diff --git a/src/lifecycle/output.rs b/src/lifecycle/output.rs index 8987d56..587fd8b 100644 --- a/src/lifecycle/output.rs +++ b/src/lifecycle/output.rs @@ -8,7 +8,7 @@ use std::sync::OnceLock; /// /// This struct is used to collect the results of executing a block of /// transactions. It accumulates the receipts and senders of the transactions. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct BlockOutput { /// The receipts of the transactions in the block, in order. receipts: Vec, @@ -119,3 +119,26 @@ impl> BlockOutput { (self.receipts, self.senders, bloom) } } + +impl PartialEq for BlockOutput { + fn eq(&self, other: &Self) -> bool { + self.receipts == other.receipts && self.senders == other.senders + } +} + +impl Eq for BlockOutput {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn block_output_eq_with_one_populated_bloom() { + let output_a = BlockOutput::default(); + let output_b = BlockOutput::default(); + output_a.logs_bloom(); + assert!(output_a.bloom.get().is_some()); + assert!(output_b.bloom.get().is_none()); + assert_eq!(output_a, output_b); + } +}