Skip to content

Commit

Permalink
accounts tests use store_for_tests (solana-labs#29555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored and gnapoli23 committed Jan 10, 2023
1 parent 6df7638 commit 2a36830
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ mod tests {
AccountShrinkThreshold::default(),
);
for ka in ka.iter() {
accounts.store_slow_uncached(0, &ka.0, &ka.1);
accounts.store_for_tests(0, &ka.0, &ka.1);
}

let ancestors = vec![(0, 0)].into_iter().collect();
Expand Down Expand Up @@ -2578,7 +2578,7 @@ mod tests {
let keypair = Keypair::new();
let mut account = AccountSharedData::new(1, 0, &Pubkey::default());
account.set_executable(true);
accounts.store_slow_uncached(0, &keypair.pubkey(), &account);
accounts.store_for_tests(0, &keypair.pubkey(), &account);

assert_eq!(
accounts.load_executable_accounts(
Expand Down Expand Up @@ -2897,10 +2897,10 @@ mod tests {
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
accounts.store_slow_uncached(0, &keypair0.pubkey(), &account0);
accounts.store_slow_uncached(0, &keypair1.pubkey(), &account1);
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
accounts.store_for_tests(0, &keypair2.pubkey(), &account2);
accounts.store_for_tests(0, &keypair3.pubkey(), &account3);

let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
let message = Message::new_with_compiled_instructions(
Expand Down Expand Up @@ -2942,10 +2942,17 @@ mod tests {
}

impl Accounts {
/// callers use to call store_uncached. But, this is not allowed anymore.
/// callers used to call store_uncached. But, this is not allowed anymore.
pub fn store_for_tests(&self, slot: Slot, pubkey: &Pubkey, account: &AccountSharedData) {
self.accounts_db.store_for_tests(slot, &[(pubkey, account)])
}

/// useful to adapt tests written prior to introduction of the write cache
/// to use the write cache
pub fn add_root_and_flush_write_cache(&self, slot: Slot) {
self.add_root(slot);
self.accounts_db.flush_accounts_cache_slot_for_tests(slot);
}
}

#[test]
Expand Down Expand Up @@ -3188,10 +3195,11 @@ mod tests {
for i in 0..2_000 {
let pubkey = solana_sdk::pubkey::new_rand();
let account = AccountSharedData::new(i + 1, 0, AccountSharedData::default().owner());
accounts.store_slow_uncached(i, &pubkey, &account);
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
accounts.store_for_tests(i, &pubkey, &account);
accounts.store_for_tests(i, &old_pubkey, &zero_account);
old_pubkey = pubkey;
accounts.add_root(i);
accounts.add_root_and_flush_write_cache(i);

if i % 1_000 == 0 {
info!(" store {}", i);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16039,7 +16039,7 @@ pub mod tests {
self.flush_accounts_cache(true, Some(root));
}

/// callers use to call store_uncached. But, this is not allowed anymore.
/// callers used to call store_uncached. But, this is not allowed anymore.
pub fn store_for_tests(&self, slot: Slot, accounts: &[(&Pubkey, &AccountSharedData)]) {
self.store(
(slot, accounts, INCLUDE_SLOT_IN_HASH_TESTS),
Expand Down

0 comments on commit 2a36830

Please sign in to comment.