From 79d8bfb864840ebd338429629ed6d31dcc1547de Mon Sep 17 00:00:00 2001 From: Rostyslav Tyshko Date: Fri, 30 May 2025 16:19:40 -0400 Subject: [PATCH] fix test_open_db_restart --- node_core/src/chain_storage/block_store.rs | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/node_core/src/chain_storage/block_store.rs b/node_core/src/chain_storage/block_store.rs index 649b13f..56b3ef0 100644 --- a/node_core/src/chain_storage/block_store.rs +++ b/node_core/src/chain_storage/block_store.rs @@ -27,9 +27,9 @@ impl NodeBlockStore { } ///Reopening existing database - pub fn open_db_restart(location: &Path) -> Result { + pub fn open_db_restart(location: &Path, genesis_block: Block) -> Result { NodeBlockStore::db_destroy(location)?; - NodeBlockStore::open_db_with_genesis(location, None) + NodeBlockStore::open_db_with_genesis(location, Some(genesis_block)) } ///Reloading existing database @@ -139,13 +139,25 @@ mod tests { let path = temp_dir.path(); let genesis_block = create_genesis_block(); - let _ = NodeBlockStore::open_db_with_genesis(path, Some(genesis_block)).unwrap(); + { + let node_store_old = NodeBlockStore::open_db_with_genesis(path, Some(genesis_block.clone())).unwrap(); + + let block = create_sample_block(1, 0); + node_store_old.put_block_at_id(block.clone()).unwrap(); + } + + // Check that the first block is still in the old database + { + let node_store_old = NodeBlockStore::open_db_reload(path).unwrap(); + let result = node_store_old.get_block_at_id(1); + assert!(result.is_ok()); + } // Restart the database - let node_store = NodeBlockStore::open_db_restart(path).unwrap(); + let node_store = NodeBlockStore::open_db_restart(path, genesis_block).unwrap(); - // The block should no longer be available since no genesis block is set on restart - let result = node_store.get_block_at_id(0); + // The block should no longer be available since no first block is set on restart + let result = node_store.get_block_at_id(1); assert!(result.is_err()); }