Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Nov 13, 2024
1 parent 4a8311a commit 24562c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 66 deletions.
12 changes: 8 additions & 4 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FeatureSet>::default(),
0,
)
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::<FeatureSet>::default(),
0,
);

let mut error_metrics = TransactionErrorMetrics::default();
Expand Down Expand Up @@ -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::<FeatureSet>::default(),
0,
);

let loaded_transaction_accounts = load_transaction_accounts(
Expand Down
64 changes: 2 additions & 62 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FeatureSet>::default(),
0,
)
}
}
Expand Down Expand Up @@ -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::<FeatureSet>::default(),
);

let mut error_counters = TransactionErrorMetrics::default();

let result =
TransactionBatchProcessor::<TestForkGraph>::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]
Expand Down

0 comments on commit 24562c2

Please sign in to comment.