Skip to content

Commit

Permalink
test(chain): add test insert_anchor_without_tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ValuedMammal authored and evanlinjin committed Nov 25, 2024
1 parent e69d10e commit 297ff34
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/chain/tests/test_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,37 @@ fn transactions_inserted_into_tx_graph_are_not_canonical_until_they_have_an_anch
assert!(graph.txs_with_no_anchor_or_last_seen().next().is_none());
}

#[test]
fn insert_anchor_without_tx() {
let mut graph = TxGraph::<BlockId>::default();

let tx = new_tx(21);
let txid = tx.compute_txid();

let anchor = BlockId {
height: 100,
hash: hash!("A"),
};

// insert anchor with no corresponding tx
let mut changeset = graph.insert_anchor(txid, anchor);
assert!(changeset.anchors.contains(&(anchor, txid)));
// recover from changeset
let mut recovered = TxGraph::default();
recovered.apply_changeset(changeset.clone());
assert_eq!(recovered, graph);

// now insert tx
let tx = Arc::new(tx);
let graph_changeset = graph.insert_tx(tx.clone());
assert!(graph_changeset.txs.contains(&tx));
changeset.merge(graph_changeset);
// recover from changeset again
let mut recovered = TxGraph::default();
recovered.apply_changeset(changeset);
assert_eq!(recovered, graph);
}

#[test]
/// The `map_anchors` allow a caller to pass a function to reconstruct the [`TxGraph`] with any [`Anchor`],
/// even though the function is non-deterministic.
Expand Down

0 comments on commit 297ff34

Please sign in to comment.