File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1055,6 +1055,37 @@ fn transactions_inserted_into_tx_graph_are_not_canonical_until_they_have_an_anch
1055
1055
assert ! ( graph. txs_with_no_anchor_or_last_seen( ) . next( ) . is_none( ) ) ;
1056
1056
}
1057
1057
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
+
1058
1089
#[ test]
1059
1090
/// The `map_anchors` allow a caller to pass a function to reconstruct the [`TxGraph`] with any [`Anchor`],
1060
1091
/// even though the function is non-deterministic.
You can’t perform that action at this time.
0 commit comments