Speed up bank::tests::test_max_accounts_data_size_exceeded() (#25523)

This commit is contained in:
Brooks Prumo 2022-05-25 22:22:30 -04:00 committed by GitHub
parent 3bc8664a82
commit 7384c41ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -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},
@ -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,
@ -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;
@ -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;