@@ -1087,139 +1087,6 @@ fn update_last_seen_unconfirmed() {
10871087 assert_eq ! ( graph. full_txs( ) . next( ) . unwrap( ) . last_seen_unconfirmed, 2 ) ;
10881088}
10891089
1090- #[ test]
1091- fn test_missing_blocks ( ) {
1092- /// An anchor implementation for testing, made up of `(the_anchor_block, random_data)`.
1093- #[ derive( Debug , Clone , Eq , PartialEq , PartialOrd , Ord , core:: hash:: Hash ) ]
1094- struct TestAnchor ( BlockId ) ;
1095-
1096- impl Anchor for TestAnchor {
1097- fn anchor_block ( & self ) -> BlockId {
1098- self . 0
1099- }
1100- }
1101-
1102- struct Scenario < ' a > {
1103- name : & ' a str ,
1104- graph : TxGraph < TestAnchor > ,
1105- chain : LocalChain ,
1106- exp_heights : & ' a [ u32 ] ,
1107- }
1108-
1109- const fn new_anchor ( height : u32 , hash : BlockHash ) -> TestAnchor {
1110- TestAnchor ( BlockId { height, hash } )
1111- }
1112-
1113- fn new_scenario < ' a > (
1114- name : & ' a str ,
1115- graph_anchors : & ' a [ ( Txid , TestAnchor ) ] ,
1116- chain : & ' a [ ( u32 , BlockHash ) ] ,
1117- exp_heights : & ' a [ u32 ] ,
1118- ) -> Scenario < ' a > {
1119- Scenario {
1120- name,
1121- graph : {
1122- let mut g = TxGraph :: default ( ) ;
1123- for ( txid, anchor) in graph_anchors {
1124- let _ = g. insert_anchor ( * txid, anchor. clone ( ) ) ;
1125- }
1126- g
1127- } ,
1128- chain : {
1129- let ( mut c, _) = LocalChain :: from_genesis_hash ( h ! ( "genesis" ) ) ;
1130- for ( height, hash) in chain {
1131- let _ = c. insert_block ( BlockId {
1132- height : * height,
1133- hash : * hash,
1134- } ) ;
1135- }
1136- c
1137- } ,
1138- exp_heights,
1139- }
1140- }
1141-
1142- fn run ( scenarios : & [ Scenario ] ) {
1143- for scenario in scenarios {
1144- let Scenario {
1145- name,
1146- graph,
1147- chain,
1148- exp_heights,
1149- } = scenario;
1150-
1151- let heights = graph. missing_heights ( chain) . collect :: < Vec < _ > > ( ) ;
1152- assert_eq ! ( & heights, exp_heights, "scenario: {}" , name) ;
1153- }
1154- }
1155-
1156- run ( & [
1157- new_scenario (
1158- "2 txs with the same anchor (2:B) which is missing from chain" ,
1159- & [
1160- ( h ! ( "tx_1" ) , new_anchor ( 2 , h ! ( "B" ) ) ) ,
1161- ( h ! ( "tx_2" ) , new_anchor ( 2 , h ! ( "B" ) ) ) ,
1162- ] ,
1163- & [ ( 1 , h ! ( "A" ) ) , ( 3 , h ! ( "C" ) ) ] ,
1164- & [ 2 ] ,
1165- ) ,
1166- new_scenario (
1167- "2 txs with different anchors at the same height, one of the anchors is missing" ,
1168- & [
1169- ( h ! ( "tx_1" ) , new_anchor ( 2 , h ! ( "B1" ) ) ) ,
1170- ( h ! ( "tx_2" ) , new_anchor ( 2 , h ! ( "B2" ) ) ) ,
1171- ] ,
1172- & [ ( 1 , h ! ( "A" ) ) , ( 2 , h ! ( "B1" ) ) ] ,
1173- & [ ] ,
1174- ) ,
1175- new_scenario (
1176- "tx with 2 anchors of same height which are missing from the chain" ,
1177- & [
1178- ( h ! ( "tx" ) , new_anchor ( 3 , h ! ( "C1" ) ) ) ,
1179- ( h ! ( "tx" ) , new_anchor ( 3 , h ! ( "C2" ) ) ) ,
1180- ] ,
1181- & [ ( 1 , h ! ( "A" ) ) , ( 4 , h ! ( "D" ) ) ] ,
1182- & [ 3 ] ,
1183- ) ,
1184- new_scenario (
1185- "tx with 2 anchors at the same height, chain has this height but does not match either anchor" ,
1186- & [
1187- ( h ! ( "tx" ) , new_anchor ( 4 , h ! ( "D1" ) ) ) ,
1188- ( h ! ( "tx" ) , new_anchor ( 4 , h ! ( "D2" ) ) ) ,
1189- ] ,
1190- & [ ( 4 , h ! ( "D3" ) ) , ( 5 , h ! ( "E" ) ) ] ,
1191- & [ ] ,
1192- ) ,
1193- new_scenario (
1194- "tx with 2 anchors at different heights, one anchor exists in chain, should return nothing" ,
1195- & [
1196- ( h ! ( "tx" ) , new_anchor ( 3 , h ! ( "C" ) ) ) ,
1197- ( h ! ( "tx" ) , new_anchor ( 4 , h ! ( "D" ) ) ) ,
1198- ] ,
1199- & [ ( 4 , h ! ( "D" ) ) , ( 5 , h ! ( "E" ) ) ] ,
1200- & [ ] ,
1201- ) ,
1202- new_scenario (
1203- "tx with 2 anchors at different heights, first height is already in chain with different hash, iterator should only return 2nd height" ,
1204- & [
1205- ( h ! ( "tx" ) , new_anchor ( 5 , h ! ( "E1" ) ) ) ,
1206- ( h ! ( "tx" ) , new_anchor ( 6 , h ! ( "F1" ) ) ) ,
1207- ] ,
1208- & [ ( 4 , h ! ( "D" ) ) , ( 5 , h ! ( "E" ) ) , ( 7 , h ! ( "G" ) ) ] ,
1209- & [ 6 ] ,
1210- ) ,
1211- new_scenario (
1212- "tx with 2 anchors at different heights, neither height is in chain, both heights should be returned" ,
1213- & [
1214- ( h ! ( "tx" ) , new_anchor ( 3 , h ! ( "C" ) ) ) ,
1215- ( h ! ( "tx" ) , new_anchor ( 4 , h ! ( "D" ) ) ) ,
1216- ] ,
1217- & [ ( 1 , h ! ( "A" ) ) , ( 2 , h ! ( "B" ) ) ] ,
1218- & [ 3 , 4 ] ,
1219- ) ,
1220- ] ) ;
1221- }
1222-
12231090#[ test]
12241091/// The `map_anchors` allow a caller to pass a function to reconstruct the [`TxGraph`] with any [`Anchor`],
12251092/// even though the function is non-deterministic.
0 commit comments