Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Define register_unique_recent_blockhash_for_test #33880

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ impl ProgramTest {
.read()
.unwrap()
.working_bank()
.register_recent_blockhash(&Hash::new_unique());
.register_unique_recent_blockhash_for_test();
}
});

Expand Down Expand Up @@ -1040,7 +1040,7 @@ impl ProgramTestContext {
.read()
.unwrap()
.working_bank()
.register_recent_blockhash(&Hash::new_unique());
.register_unique_recent_blockhash_for_test();
}
}),
);
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4006,7 +4006,7 @@ fn test_cpi_account_ownership_writability() {
TEST_FORBID_WRITE_AFTER_OWNERSHIP_CHANGE_IN_CALLEE,
TEST_FORBID_WRITE_AFTER_OWNERSHIP_CHANGE_IN_CALLER,
] {
bank.register_recent_blockhash(&Hash::new_unique());
bank.register_unique_recent_blockhash_for_test();
let account = AccountSharedData::new(42, account_size, &invoke_program_id);
bank.store_account(&account_keypair.pubkey(), &account);

Expand Down
6 changes: 6 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4185,6 +4185,12 @@ impl Bank {
self.update_recent_blockhashes_locked(&w_blockhash_queue);
}

// gating this under #[cfg(feature = "dev-context-only-utils")] isn't easy due to
// solana-program-test's usage...
Comment on lines +4188 to +4189
Copy link
Contributor Author

Choose a reason for hiding this comment

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

my mind is in firm state not to be derailed for fiddling with my pet subproject (dcou). lol

Copy link
Contributor

Choose a reason for hiding this comment

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

naming and comment make the reasoning clear; all good

pub fn register_unique_recent_blockhash_for_test(&self) {
self.register_recent_blockhash(&Hash::new_unique())
}

/// Tell the bank which Entry IDs exist on the ledger. This function assumes subsequent calls
/// correspond to later entries, and will boot the oldest ones once its internal cache is full.
/// Once boot, the bank will reject transactions using that `hash`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13359,7 +13359,7 @@ fn test_program_execution_restricted_for_stake_account_in_reward_period() {
// Push a dummy blockhash, so that the latest_blockhash() for the transfer transaction in each
// iteration are different. Otherwise, all those transactions will be the same, and will not be
// executed by the bank except the first one.
bank.register_recent_blockhash(&Hash::new_unique());
bank.register_unique_recent_blockhash_for_test();
previous_bank = Arc::new(bank);
}
}
Expand Down