Skip to content

Commit

Permalink
add AccountStorage.is_empty_entry for tests (solana-labs#29489)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored and gnapoli23 committed Jan 10, 2023
1 parent cbc7364 commit 9c0984a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
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 @@ -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));
}
}

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

0 comments on commit 9c0984a

Please sign in to comment.