Skip to content

Commit 297ff34

Browse files
ValuedMammalevanlinjin
authored andcommitted
test(chain): add test insert_anchor_without_tx
1 parent e69d10e commit 297ff34

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/chain/tests/test_tx_graph.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,37 @@ fn transactions_inserted_into_tx_graph_are_not_canonical_until_they_have_an_anch
10551055
assert!(graph.txs_with_no_anchor_or_last_seen().next().is_none());
10561056
}
10571057

1058+
#[test]
1059+
fn insert_anchor_without_tx() {
1060+
let mut graph = TxGraph::<BlockId>::default();
1061+
1062+
let tx = new_tx(21);
1063+
let txid = tx.compute_txid();
1064+
1065+
let anchor = BlockId {
1066+
height: 100,
1067+
hash: hash!("A"),
1068+
};
1069+
1070+
// insert anchor with no corresponding tx
1071+
let mut changeset = graph.insert_anchor(txid, anchor);
1072+
assert!(changeset.anchors.contains(&(anchor, txid)));
1073+
// recover from changeset
1074+
let mut recovered = TxGraph::default();
1075+
recovered.apply_changeset(changeset.clone());
1076+
assert_eq!(recovered, graph);
1077+
1078+
// now insert tx
1079+
let tx = Arc::new(tx);
1080+
let graph_changeset = graph.insert_tx(tx.clone());
1081+
assert!(graph_changeset.txs.contains(&tx));
1082+
changeset.merge(graph_changeset);
1083+
// recover from changeset again
1084+
let mut recovered = TxGraph::default();
1085+
recovered.apply_changeset(changeset);
1086+
assert_eq!(recovered, graph);
1087+
}
1088+
10581089
#[test]
10591090
/// The `map_anchors` allow a caller to pass a function to reconstruct the [`TxGraph`] with any [`Anchor`],
10601091
/// even though the function is non-deterministic.

0 commit comments

Comments
 (0)