13
13
//! * Users should be able to easily distinct folders or directories from reported offenders
14
14
//! * Reported list should be ordered so running twice with the same offenders yield the same message
15
15
//! * Should take in particularities:
16
- //! * networks: immutables file numbers start at 1 on most network, but 0 on devnet
17
16
//! * ancillaries' inclusion: it adds another immutables trio to the downloaded files
18
17
//!
19
18
use std:: collections:: HashSet ;
@@ -48,15 +47,13 @@ impl UnexpectedDownloadedFileVerifier {
48
47
/// `UnexpectedDownloadedFileVerifier` factory
49
48
pub fn new < P : AsRef < Path > > (
50
49
target_cardano_db_dir : P ,
51
- network_kind : & str ,
52
50
include_ancillary : bool ,
53
51
last_downloaded_immutable_file_number : ImmutableFileNumber ,
54
52
logger : & Logger ,
55
53
) -> Self {
56
54
Self {
57
55
target_cardano_db_dir : target_cardano_db_dir. as_ref ( ) . to_path_buf ( ) ,
58
56
immutable_files_range_to_expect : compute_immutable_files_range_to_expect (
59
- network_kind,
60
57
include_ancillary,
61
58
last_downloaded_immutable_file_number,
62
59
) ,
@@ -103,19 +100,16 @@ impl UnexpectedDownloadedFileVerifier {
103
100
}
104
101
105
102
fn compute_immutable_files_range_to_expect (
106
- network_kind : & str ,
107
103
include_ancillary : bool ,
108
104
last_downloaded_immutable_file_number : ImmutableFileNumber ,
109
105
) -> RangeInclusive < ImmutableFileNumber > {
110
- let is_devnet_network = network_kind. contains ( "devnet" ) ;
111
- let lower_bound = if is_devnet_network { 0 } else { 1 } ;
112
106
let upper_bound = if include_ancillary {
113
107
last_downloaded_immutable_file_number + 1
114
108
} else {
115
109
last_downloaded_immutable_file_number
116
110
} ;
117
111
118
- lower_bound ..=upper_bound
112
+ 0 ..=upper_bound
119
113
}
120
114
121
115
impl ExpectedFilesAfterDownload {
@@ -218,128 +212,56 @@ mod tests {
218
212
#[ test]
219
213
fn test_compute_immutable_files_range_to_expect ( ) {
220
214
// Specs:
221
- // - start at 1 on all networks except 0 for devnet
222
215
// - if ancillaries are included, the end bound must be increased by one (to take in an
223
216
// account the additional immutable trio downloaded with them)
224
217
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 ) ;
236
220
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 ) ;
248
223
}
249
224
250
225
mod compute_expected_state_after_download {
251
226
use super :: * ;
252
227
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
+ ] )
273
235
}
274
236
275
237
#[ 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 ( ) {
277
239
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 ( ) ;
288
245
289
246
assert_eq ! (
290
247
existing_files. expected_filenames_in_immutable_dir,
291
- HashSet :: < OsString > :: new ( )
248
+ minimal_expected_set ( )
292
249
) ;
293
250
}
294
251
295
252
#[ 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 ( ) {
323
254
let temp_dir = temp_dir_create ! ( ) ;
324
255
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 ( ) ;
335
261
336
262
assert_eq ! (
337
263
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( )
343
265
) ;
344
266
}
345
267
@@ -353,25 +275,25 @@ mod tests {
353
275
File :: create ( immutable_files_dir. join ( "file_2.txt" ) ) . unwrap ( ) ;
354
276
File :: create ( immutable_files_dir. join ( "dir_2" ) . join ( "file_3.txt" ) ) . unwrap ( ) ;
355
277
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 ( ) ;
366
283
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 ( [
370
287
OsString :: from ( "dir_1" ) ,
371
288
OsString :: from ( "dir_2" ) ,
372
289
OsString :: from ( "file_1.txt" ) ,
373
290
OsString :: from ( "file_2.txt" ) ,
374
- ] )
291
+ ] ) ;
292
+ set
293
+ } ;
294
+ assert_eq ! (
295
+ existing_files. expected_filenames_in_immutable_dir,
296
+ expected_set
375
297
) ;
376
298
}
377
299
}
@@ -483,13 +405,8 @@ mod tests {
483
405
#[ tokio:: test]
484
406
async fn checking_unexpected_file_against_a_large_immutable_directory ( ) {
485
407
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 ( ) ) ;
493
410
494
411
let immutable_files_dir = create_immutable_files_dir ( & temp_dir) ;
495
412
for immutable_file_number in 0 ..=30000 {
0 commit comments