]> Untitled Git - bdk/commitdiff
fix(chain): tx_graph::ChangeSet::is_empty
authorLLFourn <lloyd.fourn@gmail.com>
Fri, 9 Feb 2024 08:43:26 +0000 (19:43 +1100)
committerLLFourn <lloyd.fourn@gmail.com>
Fri, 9 Feb 2024 09:03:57 +0000 (20:03 +1100)
crates/chain/src/tx_graph.rs
crates/chain/tests/test_tx_graph.rs

index 66d1e9502f5b5119c34b3eb5b800b70543167b8f..cfa9d5f5c745e0a4ec91af230f08f51062200ea5 100644 (file)
@@ -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`].
index a71e24f99b2b6adfcb45f2b0fce778aa165d6314..4afdd66e6d1421954b8a3ba58158b85a1aac9434 100644 (file)
@@ -213,7 +213,8 @@ fn insert_tx_graph_doesnt_count_coinbase_as_spent() {
     };
 
     let mut graph = TxGraph::<()>::default();
-    let _ = graph.insert_tx(tx);
+    let changeset = graph.insert_tx(tx);
+    assert!(!changeset.is_empty());
     assert!(graph.outspends(OutPoint::null()).is_empty());
     assert!(graph.tx_spends(Txid::all_zeros()).next().is_none());
 }
@@ -289,7 +290,7 @@ fn insert_tx_displaces_txouts() {
         }],
     };
 
-    let _ = tx_graph.insert_txout(
+    let changeset = tx_graph.insert_txout(
         OutPoint {
             txid: tx.txid(),
             vout: 0,
@@ -300,6 +301,8 @@ fn insert_tx_displaces_txouts() {
         },
     );
 
+    assert!(!changeset.is_empty());
+
     let _ = tx_graph.insert_txout(
         OutPoint {
             txid: tx.txid(),
@@ -653,7 +656,8 @@ fn test_walk_ancestors() {
     ]);
 
     [&tx_a0, &tx_b1].iter().for_each(|&tx| {
-        let _ = graph.insert_anchor(tx.txid(), tip.block_id());
+        let changeset = graph.insert_anchor(tx.txid(), tip.block_id());
+        assert!(!changeset.is_empty());
     });
 
     let ancestors = [
@@ -1027,10 +1031,12 @@ fn test_changeset_last_seen_append() {
             last_seen: original_ls.map(|ls| (txid, ls)).into_iter().collect(),
             ..Default::default()
         };
+        assert!(!original.is_empty() || original_ls.is_none());
         let update = ChangeSet::<()> {
             last_seen: update_ls.map(|ls| (txid, ls)).into_iter().collect(),
             ..Default::default()
         };
+        assert!(!update.is_empty() || update_ls.is_none());
 
         original.append(update);
         assert_eq!(