diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index c5ee2442e1cd61..d8dad3e24a053c 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -14600,6 +14600,18 @@ pub mod tests { .is_none()); } + impl AccountsDb { + fn get_and_assert_single_storage(&self, slot: Slot) -> Arc { + let mut storage_maps: SnapshotStorage = self + .storage + .get_slot_storage_entries(slot) + .unwrap_or_default(); + + assert_eq!(storage_maps.len(), 1); + storage_maps.pop().unwrap() + } + } + #[test] fn test_alive_bytes() { let accounts_db = AccountsDb::new_with_config_for_tests( @@ -14619,14 +14631,8 @@ pub mod tests { accounts_db.add_root(slot); accounts_db.flush_accounts_cache(true, None); - let mut storage_maps: SnapshotStorage = accounts_db - .storage - .get_slot_storage_entries(slot) - .unwrap_or_default(); - // Flushing cache should only create one storage entry - assert_eq!(storage_maps.len(), 1); - let storage0 = storage_maps.pop().unwrap(); + let storage0 = accounts_db.get_and_assert_single_storage(slot); let accounts = storage0.all_accounts(); for account in accounts { @@ -15104,9 +15110,7 @@ pub mod tests { db.clean_accounts(Some(1), false, None); // Shrink Slot 0 - let mut slot0_stores = db.storage.get_slot_storage_entries(0).unwrap(); - assert_eq!(slot0_stores.len(), 1); - let slot0_store = slot0_stores.pop().unwrap(); + let slot0_store = db.get_and_assert_single_storage(0); { let mut shrink_candidate_slots = db.shrink_candidate_slots.lock().unwrap(); shrink_candidate_slots @@ -15124,7 +15128,7 @@ pub mod tests { db.flush_accounts_cache(true, None); // Should be one store before clean for slot 0 - assert_eq!(db.storage.get_slot_storage_entries(0).unwrap().len(), 1); + db.get_and_assert_single_storage(0); db.get_accounts_delta_hash(2); db.clean_accounts(Some(2), false, None); @@ -15442,9 +15446,7 @@ pub mod tests { return; } // Simulate adding shrink candidates from clean_accounts() - let stores = db.storage.get_slot_storage_entries(slot).unwrap(); - assert_eq!(stores.len(), 1); - let store = &stores[0]; + let store = db.get_and_assert_single_storage(slot); let store_id = store.append_vec_id(); db.shrink_candidate_slots .lock()