fix(chain): TxDescendants performs a BFS

This commit also changes test_descendants_no_repeat to check
the order of the transactions returned
This commit is contained in:
Daniela Brozzoni
2023-09-29 18:42:49 +02:00
parent 486e0e1437
commit 2f26eca607
2 changed files with 15 additions and 20 deletions

View File

@@ -610,7 +610,7 @@ fn test_descendants_no_repeat() {
.collect::<Vec<_>>();
let mut graph = TxGraph::<()>::default();
let mut expected_txids = BTreeSet::new();
let mut expected_txids = Vec::new();
// these are NOT descendants of `tx_a`
for tx in txs_not_connected {
@@ -625,19 +625,14 @@ fn test_descendants_no_repeat() {
.chain(core::iter::once(&tx_e))
{
let _ = graph.insert_tx(tx.clone());
assert!(expected_txids.insert(tx.txid()));
expected_txids.push(tx.txid());
}
let descendants = graph
.walk_descendants(tx_a.txid(), |_, txid| Some(txid))
.collect::<Vec<_>>();
assert_eq!(descendants.len(), expected_txids.len());
for txid in descendants {
assert!(expected_txids.remove(&txid));
}
assert!(expected_txids.is_empty());
assert_eq!(descendants, expected_txids);
}
#[test]