Skip to content

Commit

Permalink
Speed up bank::tests::test_max_accounts_data_size_exceeded() (solana-…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 26, 2022
1 parent 3bc8664 commit 7384c41
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7357,6 +7357,7 @@ pub(crate) mod tests {
},
crossbeam_channel::{bounded, unbounded},
solana_program_runtime::{
accounts_data_meter::MAX_ACCOUNTS_DATA_LEN,
compute_budget::MAX_COMPUTE_UNIT_LIMIT,
invoke_context::InvokeContext,
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
Expand All @@ -7382,7 +7383,7 @@ pub(crate) mod tests {
instruction as stake_instruction,
state::{Authorized, Delegation, Lockup, Stake},
},
system_instruction::{self, SystemError},
system_instruction::{self, SystemError, MAX_PERMITTED_DATA_LENGTH},
system_program,
timing::duration_as_s,
transaction::MAX_TX_ACCOUNT_LOCKS,
Expand Down Expand Up @@ -17004,14 +17005,16 @@ pub(crate) mod tests {
/// Test exceeding the max accounts data size by creating accounts in a loop
#[test]
fn test_max_accounts_data_size_exceeded() {
use {
solana_program_runtime::accounts_data_meter::MAX_ACCOUNTS_DATA_LEN,
solana_sdk::system_instruction::MAX_PERMITTED_DATA_LENGTH,
};
const NUM_ACCOUNTS: u64 = 20;
const ACCOUNT_SIZE: u64 = MAX_PERMITTED_DATA_LENGTH / (NUM_ACCOUNTS + 1);
const REMAINING_ACCOUNTS_DATA_SIZE: u64 = NUM_ACCOUNTS * ACCOUNT_SIZE;
const INITIAL_ACCOUNTS_DATA_SIZE: u64 =
MAX_ACCOUNTS_DATA_LEN - REMAINING_ACCOUNTS_DATA_SIZE;

solana_logger::setup();
let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000);
let mut bank = Bank::new_for_tests(&genesis_config);
bank.set_accounts_data_size_initial_for_tests(INITIAL_ACCOUNTS_DATA_SIZE);
bank.activate_feature(&feature_set::cap_accounts_data_len::id());

let mut i = 0;
Expand All @@ -17021,18 +17024,19 @@ pub(crate) mod tests {
&Keypair::new(),
bank.last_blockhash(),
1,
MAX_PERMITTED_DATA_LENGTH,
ACCOUNT_SIZE,
&solana_sdk::system_program::id(),
);

let result = bank.process_transaction(&txn);
assert!(bank.load_accounts_data_size() <= MAX_ACCOUNTS_DATA_LEN);
if result.is_err() {
assert_eq!(i, NUM_ACCOUNTS);
break result;
}

assert!(
i < MAX_ACCOUNTS_DATA_LEN / MAX_PERMITTED_DATA_LENGTH,
i <= NUM_ACCOUNTS,
"test must complete within bounded limits"
);
i += 1;
Expand Down

0 comments on commit 7384c41

Please sign in to comment.