From 9c0984a6e0bf8abd8f90dc9efcb754db2c50688c Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 3 Jan 2023 14:36:31 -0600 Subject: [PATCH] add AccountStorage.is_empty_entry for tests (#29489) --- runtime/src/account_storage.rs | 8 ++++++++ runtime/src/accounts_db.rs | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/src/account_storage.rs b/runtime/src/account_storage.rs index 974224ea34aaa3..2941d8ca0c6b66 100644 --- a/runtime/src/account_storage.rs +++ b/runtime/src/account_storage.rs @@ -59,6 +59,14 @@ impl AccountStorage { .unwrap_or(true) } + /// returns true if there is an entry in the map for 'slot', but it contains no append vec + #[cfg(test)] + pub(crate) fn is_empty_entry(&self, slot: Slot) -> bool { + self.get_slot_stores(slot) + .map(|storages| storages.read().unwrap().is_empty()) + .unwrap_or(false) + } + /// initialize the storage map to 'all_storages' pub(crate) fn initialize(&mut self, all_storages: AccountStorageMap) { assert!(self.map.is_empty()); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 6e2d09665b2325..17c48021356730 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -16509,7 +16509,7 @@ pub mod tests { } else { assert!(db.dirty_stores.is_empty()); } - assert!(db.get_storages_for_slot(slot).unwrap().is_empty()); + assert!(db.storage.is_empty_entry(slot)); } } @@ -17538,7 +17538,7 @@ pub mod tests { &mut AncientSlotPubkeys::default(), &mut dropped_roots, ); - assert!(db.get_storages_for_slot(next_slot).unwrap().is_empty()); + assert!(db.storage.is_empty_entry(next_slot)); // this removes the storages entry completely from the hashmap for 'next_slot'. // Otherwise, we have a zero length vec in that hashmap db.handle_dropped_roots_for_ancient(dropped_roots);