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 5, 2024
1 parent 15663fa commit 81d1b7c
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 @@ -2051,18 +2051,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 @@ -2128,18 +2130,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 @@ -2178,18 +2182,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 @@ -2211,18 +2217,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 @@ -2248,18 +2256,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 @@ -2283,18 +2293,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 @@ -2314,18 +2326,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 @@ -2389,20 +2403,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 @@ -2457,13 +2462,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 @@ -2514,18 +2520,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 @@ -2560,13 +2568,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 81d1b7c

Please sign in to comment.