1313//! * Users should be able to easily distinct folders or directories from reported offenders
1414//! * Reported list should be ordered so running twice with the same offenders yield the same message
1515//! * Should take in particularities:
16- //! * networks: immutables file numbers start at 1 on most network, but 0 on devnet
1716//! * ancillaries' inclusion: it adds another immutables trio to the downloaded files
1817//!
1918use std:: collections:: HashSet ;
@@ -48,15 +47,13 @@ impl UnexpectedDownloadedFileVerifier {
4847 /// `UnexpectedDownloadedFileVerifier` factory
4948 pub fn new < P : AsRef < Path > > (
5049 target_cardano_db_dir : P ,
51- network_kind : & str ,
5250 include_ancillary : bool ,
5351 last_downloaded_immutable_file_number : ImmutableFileNumber ,
5452 logger : & Logger ,
5553 ) -> Self {
5654 Self {
5755 target_cardano_db_dir : target_cardano_db_dir. as_ref ( ) . to_path_buf ( ) ,
5856 immutable_files_range_to_expect : compute_immutable_files_range_to_expect (
59- network_kind,
6057 include_ancillary,
6158 last_downloaded_immutable_file_number,
6259 ) ,
@@ -103,19 +100,16 @@ impl UnexpectedDownloadedFileVerifier {
103100}
104101
105102fn compute_immutable_files_range_to_expect (
106- network_kind : & str ,
107103 include_ancillary : bool ,
108104 last_downloaded_immutable_file_number : ImmutableFileNumber ,
109105) -> RangeInclusive < ImmutableFileNumber > {
110- let is_devnet_network = network_kind. contains ( "devnet" ) ;
111- let lower_bound = if is_devnet_network { 0 } else { 1 } ;
112106 let upper_bound = if include_ancillary {
113107 last_downloaded_immutable_file_number + 1
114108 } else {
115109 last_downloaded_immutable_file_number
116110 } ;
117111
118- lower_bound ..=upper_bound
112+ 0 ..=upper_bound
119113}
120114
121115impl ExpectedFilesAfterDownload {
@@ -218,128 +212,56 @@ mod tests {
218212 #[ test]
219213 fn test_compute_immutable_files_range_to_expect ( ) {
220214 // Specs:
221- // - start at 1 on all networks except 0 for devnet
222215 // - if ancillaries are included, the end bound must be increased by one (to take in an
223216 // account the additional immutable trio downloaded with them)
224217
225- // Without ancillaries, network is not devnet
226- assert_eq ! (
227- compute_immutable_files_range_to_expect( "network" , false , 143 ) ,
228- 1 ..=143
229- ) ;
230-
231- // Without ancillaries, network is devnet
232- assert_eq ! (
233- compute_immutable_files_range_to_expect( "devnet" , false , 143 ) ,
234- 0 ..=143
235- ) ;
218+ // Without ancillaries
219+ assert_eq ! ( compute_immutable_files_range_to_expect( false , 143 ) , 0 ..=143 ) ;
236220
237- // With ancillaries, network is not devnet
238- assert_eq ! (
239- compute_immutable_files_range_to_expect( "network" , true , 143 ) ,
240- 1 ..=144
241- ) ;
242-
243- // With ancillaries, network is devnet
244- assert_eq ! (
245- compute_immutable_files_range_to_expect( "devnet" , true , 143 ) ,
246- 0 ..=144
247- ) ;
221+ // With ancillaries
222+ assert_eq ! ( compute_immutable_files_range_to_expect( true , 143 ) , 0 ..=144 ) ;
248223 }
249224
250225 mod compute_expected_state_after_download {
251226 use super :: * ;
252227
253- #[ tokio:: test]
254- async fn when_dir_empty_return_empty_if_immutable_files_dir_does_not_exist_and_range_is_empty (
255- ) {
256- let temp_dir = temp_dir_create ! ( ) ;
257- create_immutable_files_dir ( & temp_dir) ;
258- let existing_files = UnexpectedDownloadedFileVerifier :: new (
259- & temp_dir,
260- "network" ,
261- false ,
262- 0 ,
263- & TestLogger :: stdout ( ) ,
264- )
265- . compute_expected_state_after_download ( )
266- . await
267- . unwrap ( ) ;
268-
269- assert_eq ! (
270- existing_files. expected_filenames_in_immutable_dir,
271- HashSet :: <OsString >:: new( )
272- ) ;
228+ /// Minimal set, containing the immutable files trios for number 0
229+ fn minimal_expected_set ( ) -> HashSet < OsString > {
230+ HashSet :: from ( [
231+ OsString :: from ( "00000.chunk" ) ,
232+ OsString :: from ( "00000.primary" ) ,
233+ OsString :: from ( "00000.secondary" ) ,
234+ ] )
273235 }
274236
275237 #[ tokio:: test]
276- async fn when_dir_empty_return_empty_if_immutable_files_dir_exist_and_range_is_empty ( ) {
238+ async fn when_db_dir_empty_return_minimal_set ( ) {
277239 let temp_dir = temp_dir_create ! ( ) ;
278- let existing_files = UnexpectedDownloadedFileVerifier :: new (
279- & temp_dir,
280- "network" ,
281- false ,
282- 0 ,
283- & TestLogger :: stdout ( ) ,
284- )
285- . compute_expected_state_after_download ( )
286- . await
287- . unwrap ( ) ;
240+ let existing_files =
241+ UnexpectedDownloadedFileVerifier :: new ( & temp_dir, false , 0 , & TestLogger :: stdout ( ) )
242+ . compute_expected_state_after_download ( )
243+ . await
244+ . unwrap ( ) ;
288245
289246 assert_eq ! (
290247 existing_files. expected_filenames_in_immutable_dir,
291- HashSet :: < OsString > :: new ( )
248+ minimal_expected_set ( )
292249 ) ;
293250 }
294251
295252 #[ tokio:: test]
296- async fn when_immutable_files_dir_does_not_exist_return_immutables_trios_if_immutable_files_range_is_not_empty (
297- ) {
298- let temp_dir = temp_dir_create ! ( ) ;
299- let existing_files = UnexpectedDownloadedFileVerifier :: new (
300- & temp_dir,
301- "network" ,
302- false ,
303- 1 ,
304- & TestLogger :: stdout ( ) ,
305- )
306- . compute_expected_state_after_download ( )
307- . await
308- . unwrap ( ) ;
309-
310- assert_eq ! (
311- existing_files. expected_filenames_in_immutable_dir,
312- HashSet :: from( [
313- OsString :: from( "00001.chunk" ) ,
314- OsString :: from( "00001.primary" ) ,
315- OsString :: from( "00001.secondary" ) ,
316- ] )
317- ) ;
318- }
319-
320- #[ tokio:: test]
321- async fn when_immutable_files_dir_empty_return_immutables_trios_if_immutable_files_range_is_not_empty (
322- ) {
253+ async fn when_db_dir_contains_empty_immutable_dir_return_minimal_set ( ) {
323254 let temp_dir = temp_dir_create ! ( ) ;
324255 create_immutable_files_dir ( & temp_dir) ;
325- let existing_files = UnexpectedDownloadedFileVerifier :: new (
326- & temp_dir,
327- "network" ,
328- false ,
329- 1 ,
330- & TestLogger :: stdout ( ) ,
331- )
332- . compute_expected_state_after_download ( )
333- . await
334- . unwrap ( ) ;
256+ let existing_files =
257+ UnexpectedDownloadedFileVerifier :: new ( & temp_dir, false , 0 , & TestLogger :: stdout ( ) )
258+ . compute_expected_state_after_download ( )
259+ . await
260+ . unwrap ( ) ;
335261
336262 assert_eq ! (
337263 existing_files. expected_filenames_in_immutable_dir,
338- HashSet :: from( [
339- OsString :: from( "00001.chunk" ) ,
340- OsString :: from( "00001.primary" ) ,
341- OsString :: from( "00001.secondary" ) ,
342- ] )
264+ minimal_expected_set( )
343265 ) ;
344266 }
345267
@@ -353,25 +275,25 @@ mod tests {
353275 File :: create ( immutable_files_dir. join ( "file_2.txt" ) ) . unwrap ( ) ;
354276 File :: create ( immutable_files_dir. join ( "dir_2" ) . join ( "file_3.txt" ) ) . unwrap ( ) ;
355277
356- let existing_files = UnexpectedDownloadedFileVerifier :: new (
357- & temp_dir,
358- "network" ,
359- false ,
360- 0 ,
361- & TestLogger :: stdout ( ) ,
362- )
363- . compute_expected_state_after_download ( )
364- . await
365- . unwrap ( ) ;
278+ let existing_files =
279+ UnexpectedDownloadedFileVerifier :: new ( & temp_dir, false , 0 , & TestLogger :: stdout ( ) )
280+ . compute_expected_state_after_download ( )
281+ . await
282+ . unwrap ( ) ;
366283
367- assert_eq ! (
368- existing_files . expected_filenames_in_immutable_dir ,
369- HashSet :: from ( [
284+ let expected_set = {
285+ let mut set = minimal_expected_set ( ) ;
286+ set . extend ( [
370287 OsString :: from ( "dir_1" ) ,
371288 OsString :: from ( "dir_2" ) ,
372289 OsString :: from ( "file_1.txt" ) ,
373290 OsString :: from ( "file_2.txt" ) ,
374- ] )
291+ ] ) ;
292+ set
293+ } ;
294+ assert_eq ! (
295+ existing_files. expected_filenames_in_immutable_dir,
296+ expected_set
375297 ) ;
376298 }
377299 }
@@ -483,13 +405,8 @@ mod tests {
483405 #[ tokio:: test]
484406 async fn checking_unexpected_file_against_a_large_immutable_directory ( ) {
485407 let temp_dir = temp_dir_create ! ( ) ;
486- let verifier = UnexpectedDownloadedFileVerifier :: new (
487- & temp_dir,
488- "network" ,
489- false ,
490- 19999 ,
491- & TestLogger :: stdout ( ) ,
492- ) ;
408+ let verifier =
409+ UnexpectedDownloadedFileVerifier :: new ( & temp_dir, false , 19999 , & TestLogger :: stdout ( ) ) ;
493410
494411 let immutable_files_dir = create_immutable_files_dir ( & temp_dir) ;
495412 for immutable_file_number in 0 ..=30000 {
0 commit comments