Skip to content

Commit

Permalink
Removes unnecessary AccountsDb::new_with_config_for_tests() (#34485)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Dec 18, 2023
1 parent 1015488 commit cbe8a02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 157 deletions.
122 changes: 17 additions & 105 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,6 @@ mod tests {
use {
super::*,
crate::{
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
rent_collector::RentCollector,
transaction_results::{DurableNonceFee, TransactionExecutionDetails},
},
Expand All @@ -834,7 +832,6 @@ mod tests {
solana_sdk::{
account::{AccountSharedData, WritableAccount},
address_lookup_table::state::LookupTableMeta,
genesis_config::ClusterType,
hash::Hash,
instruction::{CompiledInstruction, InstructionError},
message::{Message, MessageHeader},
Expand Down Expand Up @@ -939,12 +936,7 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_account_not_found() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let invalid_table_key = Pubkey::new_unique();
Expand All @@ -967,12 +959,7 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_invalid_account_owner() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let invalid_table_key = Pubkey::new_unique();
Expand All @@ -999,12 +986,7 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_invalid_account_data() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let invalid_table_key = Pubkey::new_unique();
Expand All @@ -1031,12 +1013,7 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses() {
let ancestors = vec![(1, 1), (0, 0)].into_iter().collect();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let table_key = Pubkey::new_unique();
Expand Down Expand Up @@ -1077,12 +1054,7 @@ mod tests {

#[test]
fn test_load_by_program_slot() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

// Load accounts owned by various programs into AccountsDb
Expand All @@ -1106,25 +1078,15 @@ mod tests {

#[test]
fn test_accounts_empty_bank_hash_stats() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
assert!(accounts.accounts_db.get_bank_hash_stats(0).is_some());
assert!(accounts.accounts_db.get_bank_hash_stats(1).is_none());
}

#[test]
fn test_lock_accounts_with_duplicates() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let keypair = Keypair::new();
Expand All @@ -1144,12 +1106,7 @@ mod tests {

#[test]
fn test_lock_accounts_with_too_many_accounts() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let keypair = Keypair::new();
Expand Down Expand Up @@ -1210,12 +1167,7 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());

let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -1320,12 +1272,7 @@ mod tests {
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());

let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -1402,12 +1349,7 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());

let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -1479,12 +1421,7 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());

let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -1639,12 +1576,7 @@ mod tests {

let mut loaded = vec![loaded0, loaded1];

let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
{
accounts
Expand Down Expand Up @@ -1691,12 +1623,7 @@ mod tests {
#[test]
fn huge_clean() {
solana_logger::setup();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
let mut old_pubkey = Pubkey::default();
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
Expand Down Expand Up @@ -2031,12 +1958,7 @@ mod tests {
let mut loaded = vec![loaded];

let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
let txs = vec![tx];
let execution_results = vec![new_execution_result(
Expand Down Expand Up @@ -2145,12 +2067,7 @@ mod tests {
let mut loaded = vec![loaded];

let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
let txs = vec![tx];
let execution_results = vec![new_execution_result(
Expand Down Expand Up @@ -2187,12 +2104,7 @@ mod tests {

#[test]
fn test_load_largest_accounts() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

/* This test assumes pubkey0 < pubkey1 < pubkey2.
Expand Down
27 changes: 4 additions & 23 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9522,23 +9522,6 @@ pub(crate) enum UpdateIndexThreadSelection {
// These functions/fields are only usable from a dev context (i.e. tests and benches)
#[cfg(feature = "dev-context-only-utils")]
impl AccountsDb {
pub fn new_with_config_for_tests(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
}

pub fn new_with_config_for_benches(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
Expand Down Expand Up @@ -11965,12 +11948,10 @@ pub mod tests {
fn test_clean_old_with_both_normal_and_zero_lamport_accounts() {
solana_logger::setup();

let mut accounts = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
spl_token_mint_index_enabled(),
AccountShrinkThreshold::default(),
);
let mut accounts = AccountsDb {
account_indexes: spl_token_mint_index_enabled(),
..AccountsDb::new_single_for_tests()
};
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey2 = solana_sdk::pubkey::new_rand();

Expand Down
27 changes: 4 additions & 23 deletions runtime/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,7 @@ mod tests {
use {
super::*,
nonce::state::Versions as NonceVersions,
solana_accounts_db::{
accounts::Accounts, accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes, rent_collector::RentCollector,
},
solana_accounts_db::{accounts::Accounts, rent_collector::RentCollector},
solana_program_runtime::{
compute_budget_processor,
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
Expand All @@ -548,7 +545,6 @@ mod tests {
account::{AccountSharedData, WritableAccount},
compute_budget::ComputeBudgetInstruction,
epoch_schedule::EpochSchedule,
genesis_config::ClusterType,
hash::Hash,
instruction::CompiledInstruction,
message::{Message, SanitizedMessage},
Expand All @@ -573,12 +569,7 @@ mod tests {
) -> Vec<TransactionLoadResult> {
let mut hash_queue = BlockhashQueue::new(100);
hash_queue.register_hash(&tx.message().recent_blockhash, lamports_per_signature);
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
for ka in ka.iter() {
accounts.accounts_db.store_for_tests(0, &[(&ka.0, &ka.1)]);
Expand Down Expand Up @@ -1384,12 +1375,7 @@ mod tests {
#[test]
fn test_instructions() {
solana_logger::setup();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));

let instructions_key = solana_sdk::sysvar::instructions::id();
Expand All @@ -1411,12 +1397,7 @@ mod tests {
#[test]
fn test_overrides() {
solana_logger::setup();
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
let mut account_overrides = AccountOverrides::default();
let slot_history_id = sysvar::slot_history::id();
Expand Down
7 changes: 1 addition & 6 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ mod serde_snapshot_tests {
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
solana_logger::setup();
let (_accounts_dir, paths) = get_temp_accounts_paths(4).unwrap();
let accounts_db = AccountsDb::new_with_config_for_tests(
paths,
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts_db = AccountsDb::new_for_tests(paths, &ClusterType::Development);
let accounts = Accounts::new(Arc::new(accounts_db));

let slot = 0;
Expand Down

0 comments on commit cbe8a02

Please sign in to comment.