Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jun 12, 2024
1 parent d3b930b commit cc8befa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
4 changes: 4 additions & 0 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ mod tests {
program_indices: vec![],
nonce: None,
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand All @@ -1582,6 +1583,7 @@ mod tests {
program_indices: vec![],
nonce: None,
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1858,6 +1860,7 @@ mod tests {
program_indices: vec![],
nonce: nonce.clone(),
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1964,6 +1967,7 @@ mod tests {
program_indices: vec![],
nonce: nonce.clone(),
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down
25 changes: 11 additions & 14 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,9 @@ mod tests {
&mock_bank,
sanitized_transaction.message(),
ValidatedTransactionDetails {
nonce: None,
fee_details,
fee_payer_account: fee_payer_account_data,
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
},
&mut error_metrics,
None,
Expand All @@ -1207,6 +1206,7 @@ mod tests {
program_indices: vec![vec![]],
nonce: None,
fee_details,
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1385,10 +1385,9 @@ mod tests {
&mock_bank,
sanitized_transaction.message(),
ValidatedTransactionDetails {
nonce: None,
fee_details,
fee_payer_account: fee_payer_account_data,
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
},
&mut error_metrics,
None,
Expand All @@ -1410,6 +1409,7 @@ mod tests {
],
nonce: None,
fee_details,
compute_budget_limits: ComputeBudgetLimits::default(),
program_indices: vec![vec![1]],
rent: 0,
rent_debits: RentDebits::default(),
Expand Down Expand Up @@ -1565,10 +1565,9 @@ mod tests {
&mock_bank,
sanitized_transaction.message(),
ValidatedTransactionDetails {
nonce: None,
fee_details,
fee_payer_account: fee_payer_account_data,
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
},
&mut error_metrics,
None,
Expand All @@ -1595,6 +1594,7 @@ mod tests {
program_indices: vec![vec![2, 1]],
nonce: None,
fee_details,
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1658,10 +1658,9 @@ mod tests {
&mock_bank,
sanitized_transaction.message(),
ValidatedTransactionDetails {
nonce: None,
fee_details,
fee_payer_account: fee_payer_account_data,
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
},
&mut error_metrics,
None,
Expand Down Expand Up @@ -1691,6 +1690,7 @@ mod tests {
program_indices: vec![vec![3, 1], vec![3, 1]],
nonce: None,
fee_details,
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1809,10 +1809,8 @@ mod tests {
false,
);
let validation_result = Ok(ValidatedTransactionDetails {
nonce: None,
fee_details: FeeDetails::default(),
fee_payer_account: fee_payer_account_data,
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
});

let results = load_accounts(
Expand Down Expand Up @@ -1850,6 +1848,7 @@ mod tests {
program_indices: vec![vec![3, 1], vec![3, 1]],
nonce: None,
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand Down Expand Up @@ -1880,9 +1879,7 @@ mod tests {

let validation_result = Ok(ValidatedTransactionDetails {
nonce: Some(NonceFull::default()),
fee_details: FeeDetails::default(),
fee_payer_account: AccountSharedData::default(),
fee_payer_rent_debit: 0,
..ValidatedTransactionDetails::default()
});

let result = load_accounts(
Expand Down
40 changes: 36 additions & 4 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ mod tests {
program_indices: vec![vec![0]],
nonce: None,
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 32,
Expand All @@ -1167,7 +1168,6 @@ mod tests {
&mock_bank,
&sanitized_transaction,
&mut loaded_transaction,
ComputeBudget::default(),
&mut ExecuteTimings::default(),
&mut TransactionErrorMetrics::default(),
&program_cache_for_tx_batch,
Expand All @@ -1189,7 +1189,6 @@ mod tests {
&mock_bank,
&sanitized_transaction,
&mut loaded_transaction,
ComputeBudget::default(),
&mut ExecuteTimings::default(),
&mut TransactionErrorMetrics::default(),
&program_cache_for_tx_batch,
Expand Down Expand Up @@ -1219,7 +1218,6 @@ mod tests {
&mock_bank,
&sanitized_transaction,
&mut loaded_transaction,
ComputeBudget::default(),
&mut ExecuteTimings::default(),
&mut TransactionErrorMetrics::default(),
&program_cache_for_tx_batch,
Expand Down Expand Up @@ -1281,6 +1279,7 @@ mod tests {
program_indices: vec![vec![0]],
nonce: None,
fee_details: FeeDetails::default(),
compute_budget_limits: ComputeBudgetLimits::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
Expand All @@ -1296,7 +1295,6 @@ mod tests {
&mock_bank,
&sanitized_transaction,
&mut loaded_transaction,
ComputeBudget::default(),
&mut ExecuteTimings::default(),
&mut error_metrics,
&program_cache_for_tx_batch,
Expand Down Expand Up @@ -1965,6 +1963,8 @@ mod tests {
Some(&Pubkey::new_unique()),
&Hash::new_unique(),
));
let compute_budget_limits =
process_compute_budget_instructions(message.program_instructions_iter()).unwrap();
let fee_payer_address = message.fee_payer();
let rent_collector = RentCollector::default();
let min_balance = rent_collector.rent.minimum_balance(nonce::State::size());
Expand Down Expand Up @@ -2005,6 +2005,7 @@ mod tests {
assert_eq!(
result,
Ok((
compute_budget_limits,
FeeDetails::new_for_tests(transaction_fee, priority_fee, false),
post_validation_fee_payer_account,
0 // rent due
Expand All @@ -2020,6 +2021,8 @@ mod tests {
Some(&Pubkey::new_unique()),
&Hash::new_unique(),
));
let compute_budget_limits =
process_compute_budget_instructions(message.program_instructions_iter()).unwrap();
let fee_payer_address = message.fee_payer();
let mut rent_collector = RentCollector::default();
rent_collector.rent.lamports_per_byte_year = 1_000_000;
Expand Down Expand Up @@ -2063,6 +2066,7 @@ mod tests {
assert_eq!(
result,
Ok((
compute_budget_limits,
FeeDetails::new_for_tests(transaction_fee, 0, false),
post_validation_fee_payer_account,
rent_due,
Expand Down Expand Up @@ -2178,6 +2182,31 @@ mod tests {
assert_eq!(result, Err(TransactionError::InvalidAccountForFee));
}

#[test]
fn test_validate_transaction_fee_payer_invalid_compute_budget() {
let lamports_per_signature = 5000;
let message = new_unchecked_sanitized_message(Message::new(
&[
ComputeBudgetInstruction::set_compute_unit_limit(2000u32),
ComputeBudgetInstruction::set_compute_unit_limit(42u32),
],
Some(&Pubkey::new_unique()),
));

let mock_bank = MockBankCallback::default();
let mut error_counters = TransactionErrorMetrics::default();
let batch_processor = TransactionBatchProcessor::<TestForkGraph>::default();
let result = batch_processor.validate_transaction_fee_payer(
&mock_bank,
&message,
lamports_per_signature,
&mut error_counters,
);

assert_eq!(error_counters.invalid_compute_budget, 1);
assert_eq!(result, Err(TransactionError::DuplicateInstruction(1u8)));
}

#[test]
fn test_validate_transaction_fee_payer_is_nonce() {
let lamports_per_signature = 5000;
Expand All @@ -2190,6 +2219,8 @@ mod tests {
Some(&Pubkey::new_unique()),
&Hash::new_unique(),
));
let compute_budget_limits =
process_compute_budget_instructions(message.program_instructions_iter()).unwrap();
let fee_payer_address = message.fee_payer();
let min_balance = Rent::default().minimum_balance(nonce::State::size());
let transaction_fee = lamports_per_signature;
Expand Down Expand Up @@ -2232,6 +2263,7 @@ mod tests {
assert_eq!(
result,
Ok((
compute_budget_limits,
FeeDetails::new_for_tests(transaction_fee, priority_fee, false),
post_validation_fee_payer_account,
0 // rent due
Expand Down

0 comments on commit cc8befa

Please sign in to comment.