Skip to content

Commit

Permalink
use get_storage_for_slot() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jan 4, 2023
1 parent 093b1a5 commit a38fe24
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9558,6 +9558,11 @@ pub mod tests {
LoadZeroLamports::SomeWithZeroLamportAccountForTests,
)
}

fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.storage
.get_slot_storage_entry(slot)
}
}

/// This impl exists until this feature is activated:
Expand Down Expand Up @@ -17416,9 +17421,8 @@ pub mod tests {

// the append vec at max_slot_inclusive-1 should NOT have been removed since we created an ancient append vec there
assert!(is_ancient(
&db.get_storages_for_slot(max_slot_inclusive - 1)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(max_slot_inclusive - 1)
.unwrap()
.accounts
));
Expand All @@ -17438,16 +17442,14 @@ pub mod tests {

// 2 ancients and then missing (because combined into 2nd ancient)
assert!(is_ancient(
&db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(ancient_slot)
.unwrap()
.accounts
));
assert!(is_ancient(
&db.get_storages_for_slot(max_slot_inclusive - 1)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(max_slot_inclusive - 1)
.unwrap()
.accounts
));
Expand Down Expand Up @@ -17505,12 +17507,7 @@ pub mod tests {
// now, shrink the second ancient append vec into the first one
let mut current_ancient = CurrentAncientAppendVec::new(
ancient_slot,
Arc::clone(
db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
.unwrap(),
),
db.get_storage_for_slot(ancient_slot).unwrap(),
);
let mut dropped_roots = Vec::default();
db.combine_one_store_into_ancient(
Expand Down Expand Up @@ -17539,9 +17536,8 @@ pub mod tests {
// make sure there is only 1 ancient append vec at the ancient slot
assert_eq!(db.get_storages_for_slot(ancient_slot).unwrap().len(), 1);
assert!(is_ancient(
&db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(ancient_slot)
.unwrap()
.accounts
));
Expand All @@ -17565,7 +17561,7 @@ pub mod tests {
let max_slot_inclusive = ancient_slot + (num_normal_slots as Slot);

for slot in ancient_slot..=max_slot_inclusive {
originals.push(db.get_storages_for_slot(slot).unwrap());
originals.push(db.get_storage_for_slot(slot).unwrap());
}

{
Expand All @@ -17575,7 +17571,6 @@ pub mod tests {
if count_marked_dead >= dead_accounts {
break;
}
let original = original.first().unwrap();
let original = original.accounts.account_iter().next().unwrap();
let slot = ancient_slot + 1 + (count_marked_dead as Slot);
_ = db.purge_keys_exact(
Expand All @@ -17600,12 +17595,7 @@ pub mod tests {

// normal slots should have been appended to the ancient append vec in the first slot
assert_eq!(1, db.get_storages_for_slot(ancient_slot).unwrap().len());
let ancient = Arc::clone(
db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
.unwrap(),
);
let ancient = db.get_storage_for_slot(ancient_slot).unwrap();
assert!(is_ancient(&ancient.accounts));
for slot in (ancient_slot + 1)..=max_slot_inclusive {
assert!(db.get_storages_for_slot(slot).is_none());
Expand All @@ -17621,7 +17611,6 @@ pub mod tests {
"normal_slots: {num_normal_slots}, dead_accounts: {dead_accounts}"
);
for original in &originals {
let original = original.first().unwrap();
let original = original.accounts.account_iter().next().unwrap();

let i = after_stored_accounts
Expand Down Expand Up @@ -17735,7 +17724,7 @@ pub mod tests {

db.combine_ancient_slots(vec![slot1], CAN_RANDOMLY_SHRINK_FALSE);
assert_eq!(1, db.get_storages_for_slot(slot1).unwrap().len());
let ancient = Arc::clone(db.get_storages_for_slot(slot1).unwrap().first().unwrap());
let ancient = db.get_storage_for_slot(slot1).unwrap();
assert!(is_ancient(&ancient.accounts));
let after_stores = db.get_storages_for_slot(slot1).unwrap();
let GetUniqueAccountsResult {
Expand Down

0 comments on commit a38fe24

Please sign in to comment.