From 24562c21f86afb4680712a5a965cfc37b7a05d74 Mon Sep 17 00:00:00 2001 From: hana <81144685+2501babe@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:32:20 -0800 Subject: [PATCH] fix unit tests --- svm/src/account_loader.rs | 12 ++++-- svm/src/transaction_processor.rs | 64 +------------------------------- 2 files changed, 10 insertions(+), 66 deletions(-) diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 82228e72f552a1..cad2c7c56d98f1 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -790,12 +790,13 @@ mod tests { impl<'a> From<&'a TestCallbacks> for AccountLoader<'a, TestCallbacks> { fn from(callbacks: &'a TestCallbacks) -> AccountLoader<'a, TestCallbacks> { - AccountLoader::new( + AccountLoader::new_with_account_cache_capacity( None, ProgramCacheForTxBatch::default(), HashMap::default(), callbacks, Arc::::default(), + 0, ) } } @@ -1134,12 +1135,13 @@ mod tests { accounts_map, ..Default::default() }; - let mut account_loader = AccountLoader::new( + let mut account_loader = AccountLoader::new_with_account_cache_capacity( account_overrides, ProgramCacheForTxBatch::default(), HashMap::default(), &callbacks, Arc::new(FeatureSet::all_enabled()), + 0, ); load_transaction( &mut account_loader, @@ -1581,12 +1583,13 @@ mod tests { )), ); - let mut account_loader = AccountLoader::new( + let mut account_loader = AccountLoader::new_with_account_cache_capacity( None, loaded_programs, program_accounts, &mock_bank, Arc::::default(), + 0, ); let mut error_metrics = TransactionErrorMetrics::default(); @@ -2580,12 +2583,13 @@ mod tests { program_cache.replenish(program2, Arc::new(program2_entry)); let test_transaction_data_size = |transaction, expected_size| { - let mut account_loader = AccountLoader::new( + let mut account_loader = AccountLoader::new_with_account_cache_capacity( None, program_cache.clone(), program_accounts.clone(), &mock_bank, Arc::::default(), + 0, ); let loaded_transaction_accounts = load_transaction_accounts( diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index 9de79301f41eaa..14541bad19ffbb 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -1303,12 +1303,13 @@ mod tests { impl<'a> From<&'a MockBankCallback> for AccountLoader<'a, MockBankCallback> { fn from(callbacks: &'a MockBankCallback) -> AccountLoader<'a, MockBankCallback> { - AccountLoader::new( + AccountLoader::new_with_account_cache_capacity( None, ProgramCacheForTxBatch::default(), HashMap::default(), callbacks, Arc::::default(), + 0, ) } } @@ -2568,67 +2569,6 @@ mod tests { } } - #[test] - fn test_validate_account_override_usage_on_validate_fee() { - /* - The test setups an account override with enough lamport to pass validate fee. - The account_db has the account with minimum rent amount thus would fail the validate_free. - The test verify that the override is used with a passing test of validate fee. - */ - let lamports_per_signature = 5000; - - let message = - new_unchecked_sanitized_message(Message::new(&[], Some(&Pubkey::new_unique()))); - - let fee_payer_address = message.fee_payer(); - let transaction_fee = lamports_per_signature; - let rent_collector = RentCollector::default(); - let min_balance = rent_collector.rent.minimum_balance(0); - - let fee_payer_account = AccountSharedData::new(min_balance, 0, &Pubkey::default()); - let mut mock_accounts = HashMap::new(); - mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); - - let necessary_balance = min_balance + transaction_fee; - let mut account_overrides = AccountOverrides::default(); - let fee_payer_account_override = - AccountSharedData::new(necessary_balance, 0, &Pubkey::default()); - account_overrides.set_account(fee_payer_address, Some(fee_payer_account_override)); - - let mock_bank = MockBankCallback { - account_shared_data: Arc::new(RwLock::new(mock_accounts)), - ..Default::default() - }; - let mut account_loader = AccountLoader::new( - Some(&account_overrides), - ProgramCacheForTxBatch::default(), - HashMap::default(), - &mock_bank, - Arc::::default(), - ); - - let mut error_counters = TransactionErrorMetrics::default(); - - let result = - TransactionBatchProcessor::::validate_transaction_nonce_and_fee_payer( - &mut account_loader, - &message, - CheckedTransactionDetails { - nonce: None, - lamports_per_signature, - }, - &Hash::default(), - FeeStructure::default().lamports_per_signature, - &rent_collector, - &mut error_counters, - ); - assert!( - result.is_ok(), - "test_account_override_used: {:?}", - result.err() - ); - } - // Ensure `TransactionProcessingCallback::inspect_account()` is called when // validating the fee payer, since that's when the fee payer account is loaded. #[test]