Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,32 +2297,40 @@ fn test_verify_snapshot_bank() {

// Test that two bank forks with the same accounts should not hash to the same value.
#[test]
fn test_bank_hash_internal_state_same_account_different_fork() {
fn test_bank_hash_same_account_different_fork() {
Comment on lines 2298 to +2300
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Test that two bank forks with the same accounts should not hash to the same value.
#[test]
fn test_bank_hash_internal_state_same_account_different_fork() {
fn test_bank_hash_same_account_different_fork() {
// Test that two bank forks with the same transactions should not hash to the same value.
#[test]
fn test_bank_hash_same_transactions_different_fork() {

I think this is more accurate considering that the accounts are actually different (because of the clock sysvar)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge the PR as-is, and will address the rename in a follow up. This let's me unblock #7006.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to rename the fn is up here: #7017.

solana_logger::setup();
let (genesis_config, mint_keypair) = create_genesis_config(sol_to_lamports(1.));
let amount = genesis_config.rent.minimum_balance(0);
let (bank0, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let initial_state = bank0.hash_internal_state();
bank0.freeze();

// send the same transfer to both forks
let pubkey = solana_pubkey::new_rand();
let amount = genesis_config.rent.minimum_balance(0);

let bank1 = new_bank_from_parent_with_bank_forks(
bank_forks.as_ref(),
bank0.clone(),
&Pubkey::default(),
1,
);
assert_ne!(bank1.hash_internal_state(), initial_state);

info!("transfer bank1");
let pubkey = solana_pubkey::new_rand();
bank1.transfer(amount, &mint_keypair, &pubkey).unwrap();
assert_ne!(bank1.hash_internal_state(), initial_state);
bank1.freeze();

info!("transfer bank2");
// bank2 should not hash the same as bank1
let bank2 =
new_bank_from_parent_with_bank_forks(bank_forks.as_ref(), bank0, &Pubkey::default(), 2);
let bank2 = new_bank_from_parent_with_bank_forks(
bank_forks.as_ref(),
bank0.clone(),
&Pubkey::default(),
2,
);
bank2.transfer(amount, &mint_keypair, &pubkey).unwrap();
assert_ne!(bank2.hash_internal_state(), initial_state);
assert_ne!(bank1.hash_internal_state(), bank2.hash_internal_state());
bank2.freeze();

let bank0_hash = bank0.hash();
let bank1_hash = bank1.hash();
let bank2_hash = bank2.hash();
assert_ne!(bank0_hash, bank1_hash);
assert_ne!(bank0_hash, bank2_hash);
assert_ne!(bank1_hash, bank2_hash);
}

#[test]
Expand Down
Loading