Add tests to Bank for accounts data size (#25816)
This commit is contained in:
parent
48d034b69d
commit
d4e4871c47
|
@ -7636,6 +7636,7 @@ pub(crate) mod tests {
|
|||
hash,
|
||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||
message::{Message, MessageHeader},
|
||||
native_token::LAMPORTS_PER_SOL,
|
||||
nonce,
|
||||
poh_config::PohConfig,
|
||||
program::MAX_RETURN_DATA,
|
||||
|
@ -17457,7 +17458,6 @@ pub(crate) mod tests {
|
|||
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);
|
||||
|
@ -17474,13 +17474,19 @@ pub(crate) mod tests {
|
|||
&solana_sdk::system_program::id(),
|
||||
);
|
||||
|
||||
let accounts_data_size_before = bank.load_accounts_data_size();
|
||||
let result = bank.process_transaction(&txn);
|
||||
assert!(bank.load_accounts_data_size() <= MAX_ACCOUNTS_DATA_LEN);
|
||||
let accounts_data_size_after = bank.load_accounts_data_size();
|
||||
assert!(accounts_data_size_after <= MAX_ACCOUNTS_DATA_LEN);
|
||||
if result.is_err() {
|
||||
assert_eq!(i, NUM_ACCOUNTS);
|
||||
break result;
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
accounts_data_size_after - accounts_data_size_before,
|
||||
ACCOUNT_SIZE,
|
||||
);
|
||||
assert!(
|
||||
i <= NUM_ACCOUNTS,
|
||||
"test must complete within bounded limits"
|
||||
|
@ -17497,6 +17503,83 @@ pub(crate) mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
/// Test processing a good transaction correctly modifies the accounts data size
|
||||
#[test]
|
||||
fn test_accounts_data_size_with_good_transaction() {
|
||||
const ACCOUNT_SIZE: u64 = MAX_PERMITTED_DATA_LENGTH;
|
||||
let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000);
|
||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||
bank.activate_feature(&feature_set::cap_accounts_data_len::id());
|
||||
let transaction = system_transaction::create_account(
|
||||
&mint_keypair,
|
||||
&Keypair::new(),
|
||||
bank.last_blockhash(),
|
||||
LAMPORTS_PER_SOL,
|
||||
ACCOUNT_SIZE,
|
||||
&solana_sdk::system_program::id(),
|
||||
);
|
||||
|
||||
let accounts_data_size_before = bank.load_accounts_data_size();
|
||||
let accounts_data_size_delta_before = bank.load_accounts_data_size_delta();
|
||||
let accounts_data_size_delta_on_chain_before =
|
||||
bank.load_accounts_data_size_delta_on_chain();
|
||||
let result = bank.process_transaction(&transaction);
|
||||
let accounts_data_size_after = bank.load_accounts_data_size();
|
||||
let accounts_data_size_delta_after = bank.load_accounts_data_size_delta();
|
||||
let accounts_data_size_delta_on_chain_after = bank.load_accounts_data_size_delta_on_chain();
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(
|
||||
accounts_data_size_after - accounts_data_size_before,
|
||||
ACCOUNT_SIZE,
|
||||
);
|
||||
assert_eq!(
|
||||
accounts_data_size_delta_after - accounts_data_size_delta_before,
|
||||
ACCOUNT_SIZE as i64,
|
||||
);
|
||||
assert_eq!(
|
||||
accounts_data_size_delta_on_chain_after - accounts_data_size_delta_on_chain_before,
|
||||
ACCOUNT_SIZE as i64,
|
||||
);
|
||||
}
|
||||
|
||||
/// Test processing a bad transaction correctly modifies the accounts data size
|
||||
#[test]
|
||||
fn test_accounts_data_size_with_bad_transaction() {
|
||||
const ACCOUNT_SIZE: u64 = MAX_PERMITTED_DATA_LENGTH;
|
||||
let (genesis_config, _mint_keypair) = create_genesis_config(1_000_000_000_000);
|
||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||
bank.activate_feature(&feature_set::cap_accounts_data_len::id());
|
||||
let transaction = system_transaction::create_account(
|
||||
&Keypair::new(),
|
||||
&Keypair::new(),
|
||||
bank.last_blockhash(),
|
||||
LAMPORTS_PER_SOL,
|
||||
ACCOUNT_SIZE,
|
||||
&solana_sdk::system_program::id(),
|
||||
);
|
||||
|
||||
let accounts_data_size_before = bank.load_accounts_data_size();
|
||||
let accounts_data_size_delta_before = bank.load_accounts_data_size_delta();
|
||||
let accounts_data_size_delta_on_chain_before =
|
||||
bank.load_accounts_data_size_delta_on_chain();
|
||||
let result = bank.process_transaction(&transaction);
|
||||
let accounts_data_size_after = bank.load_accounts_data_size();
|
||||
let accounts_data_size_delta_after = bank.load_accounts_data_size_delta();
|
||||
let accounts_data_size_delta_on_chain_after = bank.load_accounts_data_size_delta_on_chain();
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(accounts_data_size_after, accounts_data_size_before,);
|
||||
assert_eq!(
|
||||
accounts_data_size_delta_after,
|
||||
accounts_data_size_delta_before,
|
||||
);
|
||||
assert_eq!(
|
||||
accounts_data_size_delta_on_chain_after,
|
||||
accounts_data_size_delta_on_chain_before,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_executor_cache_get_primer_count_upper_bound_inclusive() {
|
||||
let pubkey = Pubkey::default();
|
||||
|
|
Loading…
Reference in New Issue