add test accounts with custom data size (#30089)

This commit is contained in:
Jeff Washington (jwash) 2023-02-02 12:47:12 -06:00 committed by GitHub
parent 890f29be0c
commit ae7803a55e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 9 deletions

View File

@ -10455,8 +10455,13 @@ pub mod tests {
pubkey: &Pubkey, pubkey: &Pubkey,
write_version: StoredMetaWriteVersion, write_version: StoredMetaWriteVersion,
mark_alive: bool, mark_alive: bool,
account_data_size: Option<u64>,
) { ) {
let acc = AccountSharedData::new(1, 48, AccountSharedData::default().owner()); let acc = AccountSharedData::new(
1,
account_data_size.unwrap_or(48) as usize,
AccountSharedData::default().owner(),
);
append_single_account_with_default_hash(storage, pubkey, &acc, write_version, mark_alive); append_single_account_with_default_hash(storage, pubkey, &acc, write_version, mark_alive);
} }
@ -10467,7 +10472,7 @@ pub mod tests {
pubkey: &Pubkey, pubkey: &Pubkey,
mark_alive: bool, mark_alive: bool,
) -> Arc<AccountStorageEntry> { ) -> Arc<AccountStorageEntry> {
sample_storage_with_entries_id(tf, write_version, slot, pubkey, 0, mark_alive) sample_storage_with_entries_id(tf, write_version, slot, pubkey, 0, mark_alive, None)
} }
fn sample_storage_with_entries_id( fn sample_storage_with_entries_id(
@ -10477,6 +10482,7 @@ pub mod tests {
pubkey: &Pubkey, pubkey: &Pubkey,
id: AppendVecId, id: AppendVecId,
mark_alive: bool, mark_alive: bool,
account_data_size: Option<u64>,
) -> Arc<AccountStorageEntry> { ) -> Arc<AccountStorageEntry> {
let (_temp_dirs, paths) = get_temp_accounts_paths(1).unwrap(); let (_temp_dirs, paths) = get_temp_accounts_paths(1).unwrap();
let size: usize = 123; let size: usize = 123;
@ -10485,7 +10491,7 @@ pub mod tests {
data.accounts = av; data.accounts = av;
let arc = Arc::new(data); let arc = Arc::new(data);
append_sample_data_to_storage(&arc, pubkey, write_version, mark_alive); append_sample_data_to_storage(&arc, pubkey, write_version, mark_alive, account_data_size);
arc arc
} }
@ -16792,6 +16798,7 @@ pub mod tests {
&solana_sdk::pubkey::new_rand(), &solana_sdk::pubkey::new_rand(),
write_version1, write_version1,
false, false,
None,
); );
let load = AccountsDb::hash_storage_info(&mut hasher, Some(&storage), slot); let load = AccountsDb::hash_storage_info(&mut hasher, Some(&storage), slot);
let hash3 = hasher.finish(); let hash3 = hasher.finish();
@ -17299,7 +17306,7 @@ pub mod tests {
// create a 2nd ancient append vec at 'next_slot' // create a 2nd ancient append vec at 'next_slot'
let tf = crate::append_vec::test_utils::get_append_vec_path("test_shrink_ancient"); let tf = crate::append_vec::test_utils::get_append_vec_path("test_shrink_ancient");
let next_slot = max_slot_inclusive + 1; let next_slot = max_slot_inclusive + 1;
create_storages_and_update_index(&db, &tf, next_slot, num_normal_slots, true); create_storages_and_update_index(&db, &tf, next_slot, num_normal_slots, true, None);
let max_slot_inclusive = next_slot + (num_normal_slots as Slot); let max_slot_inclusive = next_slot + (num_normal_slots as Slot);
let initial_accounts = get_all_accounts(&db, ancient_slot..(max_slot_inclusive + 1)); let initial_accounts = get_all_accounts(&db, ancient_slot..(max_slot_inclusive + 1));
@ -17474,13 +17481,17 @@ pub mod tests {
}) })
} }
fn create_storages_and_update_index( pub(crate) fn create_storages_and_update_index(
db: &AccountsDb, db: &AccountsDb,
tf: &TempFile, tf: &TempFile,
starting_slot: Slot, starting_slot: Slot,
num_slots: usize, num_slots: usize,
alive: bool, alive: bool,
account_data_size: Option<u64>,
) { ) {
if num_slots == 0 {
return;
}
let write_version1 = 0; let write_version1 = 0;
let starting_id = 999; let starting_id = 999;
for i in 0..num_slots { for i in 0..num_slots {
@ -17493,6 +17504,7 @@ pub mod tests {
&pubkey1, &pubkey1,
id, id,
alive, alive,
account_data_size,
); );
insert_store(db, Arc::clone(&storage)); insert_store(db, Arc::clone(&storage));
} }
@ -17506,7 +17518,11 @@ pub mod tests {
} }
} }
fn create_db_with_storages_and_index(alive: bool, num_slots: usize) -> (AccountsDb, Slot) { pub(crate) fn create_db_with_storages_and_index(
alive: bool,
num_slots: usize,
account_data_size: Option<u64>,
) -> (AccountsDb, Slot) {
solana_logger::setup(); solana_logger::setup();
let db = AccountsDb::new_single_for_tests(); let db = AccountsDb::new_single_for_tests();
@ -17520,7 +17536,7 @@ pub mod tests {
let tf = crate::append_vec::test_utils::get_append_vec_path( let tf = crate::append_vec::test_utils::get_append_vec_path(
"get_one_ancient_append_vec_and_others", "get_one_ancient_append_vec_and_others",
); );
create_storages_and_update_index(&db, &tf, slot1, num_slots, alive); create_storages_and_update_index(&db, &tf, slot1, num_slots, alive, account_data_size);
let slot1 = slot1 as Slot; let slot1 = slot1 as Slot;
(db, slot1) (db, slot1)
@ -17530,7 +17546,7 @@ pub mod tests {
alive: bool, alive: bool,
num_normal_slots: usize, num_normal_slots: usize,
) -> (AccountsDb, Slot) { ) -> (AccountsDb, Slot) {
let (db, slot1) = create_db_with_storages_and_index(alive, num_normal_slots + 1); let (db, slot1) = create_db_with_storages_and_index(alive, num_normal_slots + 1, None);
let storage = db.get_storage_for_slot(slot1).unwrap(); let storage = db.get_storage_for_slot(slot1).unwrap();
let created_accounts = db.get_unique_accounts_from_storage(&storage); let created_accounts = db.get_unique_accounts_from_storage(&storage);
@ -17752,7 +17768,7 @@ pub mod tests {
fn make_ancient_append_vec_full(ancient: &Arc<AccountStorageEntry>, mark_alive: bool) { fn make_ancient_append_vec_full(ancient: &Arc<AccountStorageEntry>, mark_alive: bool) {
for _ in 0..100 { for _ in 0..100 {
append_sample_data_to_storage(ancient, &Pubkey::default(), 0, mark_alive); append_sample_data_to_storage(ancient, &Pubkey::default(), 0, mark_alive, None);
} }
// since we're not adding to the index, this is how we specify that all these accounts are alive // since we're not adding to the index, this is how we specify that all these accounts are alive
adjust_alive_bytes(ancient, ancient.capacity() as usize); adjust_alive_bytes(ancient, ancient.capacity() as usize);