Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions crates/storage/qmdb/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,83 @@ impl StoreBatches {
self.accounts.len() + self.storage.len() + self.code.len()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_new_creates_empty_batches() {
let batches = StoreBatches::new();
assert!(batches.is_empty());
assert_eq!(batches.len(), 0);
}

#[test]
fn test_default_creates_empty_batches() {
let batches = StoreBatches::default();
assert!(batches.is_empty());
assert_eq!(batches.len(), 0);
}

#[test]
fn test_is_empty_with_accounts() {
let mut batches = StoreBatches::new();
batches.accounts.push((Address::ZERO, Some([0u8; 80])));
assert!(!batches.is_empty());
}

#[test]
fn test_is_empty_with_storage() {
let mut batches = StoreBatches::new();
let key = StorageKey::new(Address::ZERO, 0, U256::ZERO);
batches.storage.push((key, Some(U256::from(100))));
assert!(!batches.is_empty());
}

#[test]
fn test_is_empty_with_code() {
let mut batches = StoreBatches::new();
batches.code.push((B256::ZERO, Some(vec![0x60, 0x00])));
assert!(!batches.is_empty());
}

#[test]
fn test_len_counts_all_operations() {
let mut batches = StoreBatches::new();

batches.accounts.push((Address::ZERO, Some([0u8; 80])));
batches.accounts.push((Address::repeat_byte(0x01), None));

let key1 = StorageKey::new(Address::ZERO, 0, U256::from(1));
let key2 = StorageKey::new(Address::ZERO, 0, U256::from(2));
let key3 = StorageKey::new(Address::ZERO, 0, U256::from(3));
batches.storage.push((key1, Some(U256::from(100))));
batches.storage.push((key2, Some(U256::from(200))));
batches.storage.push((key3, None));

batches.code.push((B256::ZERO, Some(vec![0x60, 0x00])));

assert_eq!(batches.len(), 6);
}

#[test]
fn test_deletion_operations() {
let mut batches = StoreBatches::new();

batches.accounts.push((Address::ZERO, None));
let key = StorageKey::new(Address::ZERO, 0, U256::ZERO);
batches.storage.push((key, None));
batches.code.push((B256::ZERO, None));

assert!(!batches.is_empty());
assert_eq!(batches.len(), 3);
}

#[test]
fn test_debug_impl() {
let batches = StoreBatches::new();
let debug_str = format!("{:?}", batches);
assert!(debug_str.contains("StoreBatches"));
}
}