Skip to content

Commit

Permalink
fix nonce-related unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Aug 27, 2024
1 parent 542eff0 commit ab87385
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
30 changes: 11 additions & 19 deletions svm/src/account_saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod tests {
message::Message,
native_loader,
nonce::{
state::{Data as NonceData, Versions as NonceVersions},
state::{Data as NonceData, DurableNonce, Versions as NonceVersions},
State as NonceState,
},
nonce_account,
Expand Down Expand Up @@ -259,14 +259,14 @@ mod tests {
};

let txs = vec![tx0.clone(), tx1.clone()];
let mut processing_results = vec![
let processing_results = vec![
new_executed_processing_result(Ok(()), loaded0),
new_executed_processing_result(Ok(()), loaded1),
];
let max_collected_accounts = max_number_of_accounts_to_collect(&txs, &processing_results);
assert_eq!(max_collected_accounts, 2);
let (collected_accounts, transactions) =
collect_accounts_to_store(&txs, &mut processing_results, &DurableNonce::default(), 0);
collect_accounts_to_store(&txs, &processing_results);
assert_eq!(collected_accounts.len(), 2);
assert!(collected_accounts
.iter()
Expand Down Expand Up @@ -313,7 +313,7 @@ mod tests {
};

let txs = vec![tx];
let mut processing_results = vec![new_executed_processing_result(
let processing_results = vec![new_executed_processing_result(
Err(TransactionError::InstructionError(
1,
InstructionError::InvalidArgument,
Expand All @@ -322,9 +322,7 @@ mod tests {
)];
let max_collected_accounts = max_number_of_accounts_to_collect(&txs, &processing_results);
assert_eq!(max_collected_accounts, 1);
let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let (collected_accounts, _) =
collect_accounts_to_store(&txs, &mut processing_results, &durable_nonce, 0);
let (collected_accounts, _) = collect_accounts_to_store(&txs, &processing_results);
assert_eq!(collected_accounts.len(), 1);
assert_eq!(
collected_accounts
Expand Down Expand Up @@ -397,9 +395,8 @@ mod tests {
loaded_accounts_data_size: 0,
};

let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let txs = vec![tx];
let mut processing_results = vec![new_executed_processing_result(
let processing_results = vec![new_executed_processing_result(
Err(TransactionError::InstructionError(
1,
InstructionError::InvalidArgument,
Expand All @@ -408,8 +405,7 @@ mod tests {
)];
let max_collected_accounts = max_number_of_accounts_to_collect(&txs, &processing_results);
assert_eq!(max_collected_accounts, 2);
let (collected_accounts, _) =
collect_accounts_to_store(&txs, &mut processing_results, &durable_nonce, 0);
let (collected_accounts, _) = collect_accounts_to_store(&txs, &processing_results);
assert_eq!(collected_accounts.len(), 2);
assert_eq!(
collected_accounts
Expand Down Expand Up @@ -495,9 +491,8 @@ mod tests {
loaded_accounts_data_size: 0,
};

let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let txs = vec![tx];
let mut processing_results = vec![new_executed_processing_result(
let processing_results = vec![new_executed_processing_result(
Err(TransactionError::InstructionError(
1,
InstructionError::InvalidArgument,
Expand All @@ -506,8 +501,7 @@ mod tests {
)];
let max_collected_accounts = max_number_of_accounts_to_collect(&txs, &processing_results);
assert_eq!(max_collected_accounts, 1);
let (collected_accounts, _) =
collect_accounts_to_store(&txs, &mut processing_results, &durable_nonce, 0);
let (collected_accounts, _) = collect_accounts_to_store(&txs, &processing_results);
assert_eq!(collected_accounts.len(), 1);
let collected_nonce_account = collected_accounts
.iter()
Expand Down Expand Up @@ -540,7 +534,7 @@ mod tests {
let from_account_pre = AccountSharedData::new(4242, 0, &Pubkey::default());

let txs = vec![tx];
let mut processing_results = vec![Ok(ProcessedTransaction::FeesOnly(Box::new(
let processing_results = vec![Ok(ProcessedTransaction::FeesOnly(Box::new(
FeesOnlyTransaction {
load_error: TransactionError::InvalidProgramForExecution,
fee_details: FeeDetails::default(),
Expand All @@ -551,9 +545,7 @@ mod tests {
)))];
let max_collected_accounts = max_number_of_accounts_to_collect(&txs, &processing_results);
assert_eq!(max_collected_accounts, 1);
let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let (collected_accounts, _) =
collect_accounts_to_store(&txs, &mut processing_results, &durable_nonce, 0);
let (collected_accounts, _) = collect_accounts_to_store(&txs, &processing_results);
assert_eq!(collected_accounts.len(), 1);
assert_eq!(
collected_accounts
Expand Down
25 changes: 20 additions & 5 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -1960,6 +1961,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2011,6 +2013,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2044,6 +2047,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2081,6 +2085,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2116,6 +2121,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2148,6 +2154,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&RentCollector::default(),
&DurableNonce::default(),
&mut error_counters,
);

Expand All @@ -2161,13 +2168,14 @@ mod tests {
let lamports_per_signature = 5000;
let rent_collector = RentCollector::default();
let compute_unit_limit = 2 * solana_compute_budget_program::DEFAULT_COMPUTE_UNITS;
let last_blockhash = Hash::new_unique();
let message = new_unchecked_sanitized_message(Message::new_with_blockhash(
&[
ComputeBudgetInstruction::set_compute_unit_limit(compute_unit_limit as u32),
ComputeBudgetInstruction::set_compute_unit_price(1_000_000),
],
Some(&Pubkey::new_unique()),
&Hash::new_unique(),
&last_blockhash,
));
let compute_budget_limits =
process_compute_budget_instructions(SVMMessage::program_instructions_iter(&message))
Expand Down Expand Up @@ -2196,10 +2204,14 @@ mod tests {

let mut error_counters = TransactionErrorMetrics::default();
let batch_processor = TransactionBatchProcessor::<TestForkGraph>::default();
let nonce = Some(NonceInfo::new(
*fee_payer_address,
fee_payer_account.clone(),
));

let durable_nonce = DurableNonce::from_blockhash(&last_blockhash);
let mut nonce_info = NonceInfo::new(*fee_payer_address, fee_payer_account.clone());
nonce_info
.try_advance_nonce(durable_nonce, lamports_per_signature)
.unwrap();
let nonce = Some(nonce_info);

let result = batch_processor.validate_transaction_fee_payer(
&mock_bank,
None,
Expand All @@ -2211,6 +2223,7 @@ mod tests {
&feature_set,
&FeeStructure::default(),
&rent_collector,
&durable_nonce,
&mut error_counters,
);

Expand Down Expand Up @@ -2272,6 +2285,7 @@ mod tests {
&feature_set,
&FeeStructure::default(),
&rent_collector,
&DurableNonce::default(),
&mut error_counters,
);

Expand Down Expand Up @@ -2325,6 +2339,7 @@ mod tests {
&FeatureSet::default(),
&FeeStructure::default(),
&rent_collector,
&DurableNonce::default(),
&mut error_counters,
);
assert!(
Expand Down

0 comments on commit ab87385

Please sign in to comment.