Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Apr 3, 2024
1 parent ace6d16 commit 2587601
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 6 additions & 6 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const LMDB_DB_HEADERS: &str = "headers";
const LMDB_DB_HEADER_ACCUMULATED_DATA: &str = "header_accumulated_data";
const LMDB_DB_BLOCK_ACCUMULATED_DATA: &str = "mmr_peak_data";
const LMDB_DB_BLOCK_HASHES: &str = "block_hashes";
const LMDB_DB_UTXOS: &str = "utxos";
pub const LMDB_DB_UTXOS: &str = "utxos";
const LMDB_DB_INPUTS: &str = "inputs";
const LMDB_DB_TXOS_HASH_TO_INDEX: &str = "txos_hash_to_index";
const LMDB_DB_KERNELS: &str = "kernels";
Expand Down Expand Up @@ -578,7 +578,7 @@ impl LMDBDatabase {
mined_height: header_height,
mined_timestamp: header_timestamp,
},
"utxos_db",
LMDB_DB_UTXOS,
)?;

Ok(())
Expand Down Expand Up @@ -1533,7 +1533,7 @@ impl LMDBDatabase {
buffer.copy_from_slice(&key_bytes[0..32]);
let key = OutputKey::new(&FixedHash::from(buffer), &input.output_hash())?;
debug!(target: LOG_TARGET, "Pruning output from 'utxos_db': key '{}'", key.0);
lmdb_delete(write_txn, &self.utxos_db, &key.convert_to_comp_key(), "utxos_db")?;
lmdb_delete(write_txn, &self.utxos_db, &key.convert_to_comp_key(), LMDB_DB_UTXOS)?;
};
// From 'txos_hash_to_index_db::utxos_db'
debug!(
Expand All @@ -1545,7 +1545,7 @@ impl LMDBDatabase {
write_txn,
&self.txos_hash_to_index_db,
input.output_hash().as_slice(),
"utxos_db",
LMDB_DB_UTXOS,
)?;
}

Expand Down Expand Up @@ -1575,14 +1575,14 @@ impl LMDBDatabase {
write_txn,
&self.txos_hash_to_index_db,
output_hash.as_slice(),
"utxos_db",
LMDB_DB_UTXOS,
)?;

let mut buffer = [0u8; 32];
buffer.copy_from_slice(&key_bytes[0..32]);
let key = OutputKey::new(&FixedHash::from(buffer), output_hash)?;
debug!(target: LOG_TARGET, "Pruning output from 'utxos_db': key '{}'", key.0);
lmdb_delete(write_txn, &self.utxos_db, &key.convert_to_comp_key(), "utxos_db")?;
lmdb_delete(write_txn, &self.utxos_db, &key.convert_to_comp_key(), LMDB_DB_UTXOS)?;
},
None => return Err(ChainStorageError::InvalidOperation("Output key not found".to_string())),
}
Expand Down
1 change: 1 addition & 0 deletions base_layer/core/src/chain_storage/lmdb_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) mod helpers;
mod lmdb;
#[allow(clippy::module_inception)]
mod lmdb_db;
pub use lmdb_db::LMDB_DB_UTXOS;
mod validator_node_store;

#[derive(Serialize, Deserialize, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod get_stats {

mod fetch_total_size_stats {
use super::*;
use crate::transactions::key_manager::create_memory_db_key_manager;
use crate::{chain_storage::lmdb_db::LMDB_DB_UTXOS, transactions::key_manager::create_memory_db_key_manager};

#[tokio::test]
async fn it_measures_the_number_of_entries() {
Expand All @@ -428,7 +428,12 @@ mod fetch_total_size_stats {
let _block_and_outputs = add_many_chained_blocks(2, &db, &key_manager).await;
let stats = db.fetch_total_size_stats().unwrap();
assert_eq!(
stats.sizes().iter().find(|s| s.name == "utxos_db").unwrap().num_entries,
stats
.sizes()
.iter()
.find(|s| s.name == LMDB_DB_UTXOS)
.unwrap()
.num_entries,
genesis_output_count + 2
);
}
Expand Down

0 comments on commit 2587601

Please sign in to comment.