Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

add AccountStorage.is_empty_entry for tests #29489

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: consider putting this with the other #[cfg(test)] fns (at the bottom of the impl block)

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());
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16529,7 +16529,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));
}
}

Expand Down Expand Up @@ -17579,7 +17579,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);
Expand Down