Skip to content

Commit 72ce20d

Browse files
committed
BlockhashQueue: Add is_empty() method
Fixes anza-xyz#9291
1 parent d8c1e2b commit 72ce20d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

accounts-db/src/blockhash_queue.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ impl BlockhashQueue {
6363
self.last_hash.expect("no hash has been set")
6464
}
6565

66+
pub fn is_empty(&self) -> bool {
67+
self.hashes.is_empty()
68+
69+
}
70+
6671
pub fn get_lamports_per_signature(&self, hash: &Hash) -> Option<u64> {
6772
self.hashes
6873
.get(hash)
@@ -153,7 +158,20 @@ mod tests {
153158
super::*, bincode::serialize, solana_clock::MAX_RECENT_BLOCKHASHES,
154159
solana_sha256_hasher::hash,
155160
};
156-
161+
#[test]
162+
fn test_is_empty() {
163+
// Проверяем, что новый метод `is_empty` работает правильно.
164+
let mut blockhash_queue = BlockhashQueue::new(10); // <--- ДОБАВЬТЕ `mut`
165+
assert!(blockhash_queue.is_empty());
166+
167+
// Используем register_hash, передавая Hash и lamports_per_signature (например, 100)
168+
let new_hash = Hash::new_unique();
169+
let lamports_fee = 100;
170+
171+
blockhash_queue.register_hash(&new_hash, lamports_fee); // <--- ИСПРАВЛЕННЫЙ ВЫЗОВ
172+
173+
assert!(!blockhash_queue.is_empty());
174+
}
157175
#[test]
158176
fn test_register_hash() {
159177
let last_hash = Hash::default();
@@ -326,3 +344,4 @@ mod tests {
326344
.is_none());
327345
}
328346
}
347+

0 commit comments

Comments
 (0)