Skip to content
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
32 changes: 31 additions & 1 deletion src/journal/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
25 changes: 24 additions & 1 deletion src/lifecycle/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: TxReceipt = ReceiptEnvelope> {
/// The receipts of the transactions in the block, in order.
receipts: Vec<T>,
Expand Down Expand Up @@ -119,3 +119,26 @@ impl<T: TxReceipt<Log = alloy::primitives::Log>> BlockOutput<T> {
(self.receipts, self.senders, bloom)
}
}

impl<T: TxReceipt + PartialEq> PartialEq for BlockOutput<T> {
fn eq(&self, other: &Self) -> bool {
self.receipts == other.receipts && self.senders == other.senders
}
}

impl<T: TxReceipt + Eq> Eq for BlockOutput<T> {}

#[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);
}
}