Skip to content

Commit ae00e1e

Browse files
committed
fix(chain): tx_graph::ChangeSet::is_empty
1 parent 7aca884 commit ae00e1e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,10 @@ impl<A> Default for ChangeSet<A> {
12141214
impl<A> ChangeSet<A> {
12151215
/// Returns true if the [`ChangeSet`] is empty (no transactions or txouts).
12161216
pub fn is_empty(&self) -> bool {
1217-
self.txs.is_empty() && self.txouts.is_empty()
1217+
self.txs.is_empty()
1218+
&& self.txouts.is_empty()
1219+
&& self.anchors.is_empty()
1220+
&& self.last_seen.is_empty()
12181221
}
12191222

12201223
/// Iterates over all outpoints contained within [`ChangeSet`].

crates/chain/tests/test_tx_graph.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ fn insert_tx_graph_doesnt_count_coinbase_as_spent() {
213213
};
214214

215215
let mut graph = TxGraph::<()>::default();
216-
let _ = graph.insert_tx(tx);
216+
let changeset = graph.insert_tx(tx);
217+
assert!(!changeset.is_empty());
217218
assert!(graph.outspends(OutPoint::null()).is_empty());
218219
assert!(graph.tx_spends(Txid::all_zeros()).next().is_none());
219220
}
@@ -289,7 +290,7 @@ fn insert_tx_displaces_txouts() {
289290
}],
290291
};
291292

292-
let _ = tx_graph.insert_txout(
293+
let changeset = tx_graph.insert_txout(
293294
OutPoint {
294295
txid: tx.txid(),
295296
vout: 0,
@@ -300,6 +301,8 @@ fn insert_tx_displaces_txouts() {
300301
},
301302
);
302303

304+
assert!(!changeset.is_empty());
305+
303306
let _ = tx_graph.insert_txout(
304307
OutPoint {
305308
txid: tx.txid(),
@@ -653,7 +656,8 @@ fn test_walk_ancestors() {
653656
]);
654657

655658
[&tx_a0, &tx_b1].iter().for_each(|&tx| {
656-
let _ = graph.insert_anchor(tx.txid(), tip.block_id());
659+
let changeset = graph.insert_anchor(tx.txid(), tip.block_id());
660+
assert!(!changeset.is_empty());
657661
});
658662

659663
let ancestors = [
@@ -1027,10 +1031,12 @@ fn test_changeset_last_seen_append() {
10271031
last_seen: original_ls.map(|ls| (txid, ls)).into_iter().collect(),
10281032
..Default::default()
10291033
};
1034+
assert!(!original.is_empty() || original_ls.is_none());
10301035
let update = ChangeSet::<()> {
10311036
last_seen: update_ls.map(|ls| (txid, ls)).into_iter().collect(),
10321037
..Default::default()
10331038
};
1039+
assert!(!update.is_empty() || update_ls.is_none());
10341040

10351041
original.append(update);
10361042
assert_eq!(

0 commit comments

Comments
 (0)