@@ -375,3 +375,51 @@ pub fn test_config() -> Config {
375375
376376 Config { sequencing, rpc, dev, chain : ChainSpec :: Dev ( chain) . into ( ) , grpc, ..Default :: default ( ) }
377377}
378+
379+ #[ cfg( test) ]
380+ mod tests {
381+ use std:: path:: PathBuf ;
382+
383+ use super :: copy_db_dir;
384+
385+ /// Verifies that the spawn_and_move database fixture can be opened without corruption.
386+ ///
387+ /// This test catches the bug where `generate_migration_db` produced corrupted snapshots
388+ /// by archiving the MDBX database files while the environment was still open under
389+ /// `SyncMode::UtterlyNoSync`.
390+ #[ test]
391+ fn open_spawn_and_move_db_fixture ( ) {
392+ let fixture_path = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) )
393+ . join ( "../../tests/fixtures/db/spawn_and_move" ) ;
394+
395+ if !fixture_path. exists ( ) {
396+ // Skip if fixtures haven't been extracted (e.g. local dev without `make fixtures`)
397+ eprintln ! ( "Skipping: fixture not found at {}" , fixture_path. display( ) ) ;
398+ return ;
399+ }
400+
401+ let temp_dir = tempfile:: tempdir ( ) . expect ( "failed to create temp dir" ) ;
402+ copy_db_dir ( & fixture_path, temp_dir. path ( ) ) . expect ( "failed to copy db files" ) ;
403+
404+ // This is the exact call that fails with MDBX_CORRUPTED when the fixture is bad.
405+ let db = katana_db:: Db :: open_no_sync ( temp_dir. path ( ) ) ;
406+ assert ! ( db. is_ok( ) , "fixture database is corrupted: {}" , db. unwrap_err( ) ) ;
407+ }
408+
409+ #[ test]
410+ fn open_simple_db_fixture ( ) {
411+ let fixture_path =
412+ PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../tests/fixtures/db/simple" ) ;
413+
414+ if !fixture_path. exists ( ) {
415+ eprintln ! ( "Skipping: fixture not found at {}" , fixture_path. display( ) ) ;
416+ return ;
417+ }
418+
419+ let temp_dir = tempfile:: tempdir ( ) . expect ( "failed to create temp dir" ) ;
420+ copy_db_dir ( & fixture_path, temp_dir. path ( ) ) . expect ( "failed to copy db files" ) ;
421+
422+ let db = katana_db:: Db :: open_no_sync ( temp_dir. path ( ) ) ;
423+ assert ! ( db. is_ok( ) , "fixture database is corrupted: {}" , db. unwrap_err( ) ) ;
424+ }
425+ }
0 commit comments