Skip to content

Commit

Permalink
fix(chain): tx_graph::ChangeSet::is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn committed Feb 9, 2024
1 parent 7aca884 commit e12aedb
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,10 @@ impl<A> Default for ChangeSet<A> {
impl<A> ChangeSet<A> {
/// Returns true if the [`ChangeSet`] is empty (no transactions or txouts).
pub fn is_empty(&self) -> bool {
self.txs.is_empty() && self.txouts.is_empty()
self.txs.is_empty()
&& self.txouts.is_empty()
&& self.anchors.is_empty()
&& self.last_seen.is_empty()
}

/// Iterates over all outpoints contained within [`ChangeSet`].
Expand Down Expand Up @@ -1539,3 +1542,35 @@ where
fn tx_outpoint_range(txid: Txid) -> RangeInclusive<OutPoint> {
OutPoint::new(txid, u32::MIN)..=OutPoint::new(txid, u32::MAX)
}

#[cfg(test)]
mod test {
use bitcoin::hashes::Hash;

use super::*;
use crate::ConfirmationHeightAnchor;

#[test]
fn tx_graph_changeset_is_empty() {
let mut changeset = ChangeSet::<ConfirmationHeightAnchor> {
txs: Default::default(),
txouts: Default::default(),
anchors: Default::default(),
last_seen: Default::default(),
};

assert!(changeset.is_empty());
changeset.anchors.insert((
ConfirmationHeightAnchor {
confirmation_height: 0,
anchor_block: Default::default(),
},
Txid::all_zeros(),
));

assert!(!changeset.is_empty());
changeset.anchors.clear();
changeset.last_seen.insert(Txid::all_zeros(), 0);
assert!(!changeset.is_empty());
}
}

0 comments on commit e12aedb

Please sign in to comment.