Skip to content

Commit

Permalink
use combined validation function for all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Nov 4, 2024
1 parent 42ef120 commit 5a772ba
Showing 1 changed file with 118 additions and 109 deletions.
227 changes: 118 additions & 109 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,18 +2041,20 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);

let post_validation_fee_payer_account = {
let mut account = fee_payer_account.clone();
Expand Down Expand Up @@ -2118,18 +2120,20 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);

let post_validation_fee_payer_account = {
let mut account = fee_payer_account.clone();
Expand Down Expand Up @@ -2168,18 +2172,20 @@ mod tests {
let mock_bank = MockBankCallback::default();
let mut account_loader = (&mock_bank).into();
let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);

assert_eq!(error_counters.account_not_found, 1);
assert_eq!(result, Err(TransactionError::AccountNotFound));
Expand All @@ -2201,18 +2207,20 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);

assert_eq!(error_counters.insufficient_funds, 1);
assert_eq!(result, Err(TransactionError::InsufficientFundsForFee));
Expand All @@ -2238,18 +2246,20 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);

assert_eq!(
result,
Expand All @@ -2273,18 +2283,20 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);

assert_eq!(error_counters.invalid_account_for_fee, 1);
assert_eq!(result, Err(TransactionError::InvalidAccountForFee));
Expand All @@ -2304,18 +2316,20 @@ mod tests {
let mock_bank = MockBankCallback::default();
let mut account_loader = (&mock_bank).into();
let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&mut error_counters,
);

assert_eq!(error_counters.invalid_compute_budget, 1);
assert_eq!(result, Err(TransactionError::DuplicateInstruction(1u8)));
Expand Down Expand Up @@ -2379,20 +2393,11 @@ mod tests {
lamports_per_signature,
};

let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce(
&mut account_loader,
&message,
&tx_details,
&environment_blockhash,
&mut error_counters,
);

assert_eq!(result, Ok(()));

let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
tx_details,
&environment_blockhash,
&feature_set,
&FeeStructure::default(),
&rent_collector,
Expand Down Expand Up @@ -2447,13 +2452,14 @@ mod tests {
let mut account_loader = (&mock_bank).into();

let mut error_counters = TransactionErrorMetrics::default();
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&feature_set,
&FeeStructure::default(),
&rent_collector,
Expand Down Expand Up @@ -2504,18 +2510,20 @@ mod tests {

let mut error_counters = TransactionErrorMetrics::default();

let result = TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);
let result =
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&mut error_counters,
);
assert!(
result.is_ok(),
"test_account_override_used: {:?}",
Expand Down Expand Up @@ -2550,13 +2558,14 @@ mod tests {
Some(&fee_payer_address),
&Hash::new_unique(),
));
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_fee_payer(
TransactionBatchProcessor::<TestForkGraph>::validate_transaction_nonce_and_fee_payer(
&mut account_loader,
&message,
CheckedTransactionDetails {
nonce: None,
lamports_per_signature: 5000,
},
&Hash::default(),
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
Expand Down

0 comments on commit 5a772ba

Please sign in to comment.