Skip to content

Commit

Permalink
fix rest of bank tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Jan 13, 2025
1 parent 36f57af commit e3c0b2f
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3111,41 +3111,51 @@ fn test_filter_program_errors_and_collect_priority_fee() {
);
}

// HANA NOTE the original version of this test means well but is unsound
// it seems like the idea is that in an entry the second tx should be invalid because the txes are *not serialized*
// but in reality the only reason it fails is because of locks. ie it would fail even if keypair had a balance
// on the other hand it is a perfectly valid simd83 batch because the first transaction funds the second
// i wanted to change rather than delete it tho since i dunno how much coverage the tx count functions have
#[test]
fn test_debits_before_credits() {
let (genesis_config, mint_keypair) =
create_genesis_config_no_tx_fee_no_rent(sol_to_lamports(2.));
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let keypair = Keypair::new();
let tx0 = system_transaction::transfer(
&mint_keypair,
&keypair.pubkey(),
sol_to_lamports(2.),
genesis_config.hash(),
);
let tx1 = system_transaction::transfer(
&keypair,
&mint_keypair.pubkey(),
sol_to_lamports(1.),
genesis_config.hash(),
);
let tx1 = system_transaction::transfer(
&mint_keypair,
&keypair.pubkey(),
sol_to_lamports(2.),
genesis_config.hash(),
);
let txs = vec![tx0, tx1];
let results = bank.process_transactions(txs.iter());
assert!(results[1].is_err());
assert!(results[0].is_err());

// Assert bad transactions aren't counted.
assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.non_vote_transaction_count_since_restart(), 1);
}

#[test]
fn test_readonly_accounts() {
#[test_case(false; "old")]
#[test_case(true; "simd83")]
fn test_readonly_accounts(disable_intrabatch_account_locks: bool) {
let GenesisConfigInfo {
genesis_config,
mint_keypair,
..
} = create_genesis_config_with_leader(500, &solana_pubkey::new_rand(), 0);
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let mut bank = Bank::new_for_tests(&genesis_config);
if !disable_intrabatch_account_locks {
bank.deactivate_feature(&feature_set::disable_intrabatch_account_locks::id());
}
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();

let vote_pubkey0 = solana_pubkey::new_rand();
let vote_pubkey1 = solana_pubkey::new_rand();
Expand Down Expand Up @@ -3209,9 +3219,16 @@ fn test_readonly_accounts() {
);
let txs = vec![tx0, tx1];
let results = bank.process_transactions(txs.iter());
// However, an account may not be locked as read-only and writable at the same time.
// Whether an account can be locked as read-only and writable at the same time depends on features.
assert_eq!(results[0], Ok(()));
assert_eq!(results[1], Err(TransactionError::AccountInUse));
assert_eq!(
results[1],
if disable_intrabatch_account_locks {
Ok(())
} else {
Err(TransactionError::AccountInUse)
}
);
}

#[test]
Expand Down Expand Up @@ -9451,8 +9468,9 @@ fn test_vote_epoch_panic() {
);
}

#[test]
fn test_tx_log_order() {
#[test_case(false; "old")]
#[test_case(true; "simd83")]
fn test_tx_log_order(disable_intrabatch_account_locks: bool) {
let GenesisConfigInfo {
genesis_config,
mint_keypair,
Expand All @@ -9462,7 +9480,11 @@ fn test_tx_log_order() {
&Pubkey::new_unique(),
bootstrap_validator_stake_lamports(),
);
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let mut bank = Bank::new_for_tests(&genesis_config);
if !disable_intrabatch_account_locks {
bank.deactivate_feature(&feature_set::disable_intrabatch_account_locks::id());
}
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();
*bank.transaction_log_collector_config.write().unwrap() = TransactionLogCollectorConfig {
mentioned_addresses: HashSet::new(),
filter: TransactionLogCollectorFilter::All,
Expand Down Expand Up @@ -9519,7 +9541,11 @@ fn test_tx_log_order() {
.as_ref()
.unwrap()[2]
.contains(&"failed".to_string()));
assert!(commit_results[2].is_err());
if disable_intrabatch_account_locks {
assert!(commit_results[2].is_ok());
} else {
assert!(commit_results[2].is_err());
}

let stored_logs = &bank.transaction_log_collector.read().unwrap().logs;
let success_log_info = stored_logs
Expand Down

0 comments on commit e3c0b2f

Please sign in to comment.