Skip to content

Commit 32d36ba

Browse files
authored
test(qmdb): add unit tests for StoreBatches type (#62)
* test(qmdb): add unit tests for StoreBatches type Add comprehensive tests for the StoreBatches struct: - new() and default() create empty batches - is_empty() checks all batch types - len() counts total operations across batches - Deletion operations (None values) - Debug implementation * style: fix formatting in batch.rs tests
1 parent b53a0d6 commit 32d36ba

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

crates/storage/qmdb/src/batch.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,83 @@ impl StoreBatches {
3232
self.accounts.len() + self.storage.len() + self.code.len()
3333
}
3434
}
35+
36+
#[cfg(test)]
37+
mod tests {
38+
use super::*;
39+
40+
#[test]
41+
fn test_new_creates_empty_batches() {
42+
let batches = StoreBatches::new();
43+
assert!(batches.is_empty());
44+
assert_eq!(batches.len(), 0);
45+
}
46+
47+
#[test]
48+
fn test_default_creates_empty_batches() {
49+
let batches = StoreBatches::default();
50+
assert!(batches.is_empty());
51+
assert_eq!(batches.len(), 0);
52+
}
53+
54+
#[test]
55+
fn test_is_empty_with_accounts() {
56+
let mut batches = StoreBatches::new();
57+
batches.accounts.push((Address::ZERO, Some([0u8; 80])));
58+
assert!(!batches.is_empty());
59+
}
60+
61+
#[test]
62+
fn test_is_empty_with_storage() {
63+
let mut batches = StoreBatches::new();
64+
let key = StorageKey::new(Address::ZERO, 0, U256::ZERO);
65+
batches.storage.push((key, Some(U256::from(100))));
66+
assert!(!batches.is_empty());
67+
}
68+
69+
#[test]
70+
fn test_is_empty_with_code() {
71+
let mut batches = StoreBatches::new();
72+
batches.code.push((B256::ZERO, Some(vec![0x60, 0x00])));
73+
assert!(!batches.is_empty());
74+
}
75+
76+
#[test]
77+
fn test_len_counts_all_operations() {
78+
let mut batches = StoreBatches::new();
79+
80+
batches.accounts.push((Address::ZERO, Some([0u8; 80])));
81+
batches.accounts.push((Address::repeat_byte(0x01), None));
82+
83+
let key1 = StorageKey::new(Address::ZERO, 0, U256::from(1));
84+
let key2 = StorageKey::new(Address::ZERO, 0, U256::from(2));
85+
let key3 = StorageKey::new(Address::ZERO, 0, U256::from(3));
86+
batches.storage.push((key1, Some(U256::from(100))));
87+
batches.storage.push((key2, Some(U256::from(200))));
88+
batches.storage.push((key3, None));
89+
90+
batches.code.push((B256::ZERO, Some(vec![0x60, 0x00])));
91+
92+
assert_eq!(batches.len(), 6);
93+
}
94+
95+
#[test]
96+
fn test_deletion_operations() {
97+
let mut batches = StoreBatches::new();
98+
99+
batches.accounts.push((Address::ZERO, None));
100+
let key = StorageKey::new(Address::ZERO, 0, U256::ZERO);
101+
batches.storage.push((key, None));
102+
batches.code.push((B256::ZERO, None));
103+
104+
assert!(!batches.is_empty());
105+
assert_eq!(batches.len(), 3);
106+
}
107+
108+
#[test]
109+
fn test_debug_impl() {
110+
let batches = StoreBatches::new();
111+
let debug_str = format!("{:?}", batches);
112+
assert!(debug_str.contains("StoreBatches"));
113+
}
114+
}

0 commit comments

Comments
 (0)