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

Commit 0873705

Browse files
authored
Define register_unique_recent_blockhash_for_test (#33880)
1 parent 080285c commit 0873705

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

program-test/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl ProgramTest {
888888
.read()
889889
.unwrap()
890890
.working_bank()
891-
.register_recent_blockhash(&Hash::new_unique());
891+
.register_unique_recent_blockhash_for_test();
892892
}
893893
});
894894

@@ -1040,7 +1040,7 @@ impl ProgramTestContext {
10401040
.read()
10411041
.unwrap()
10421042
.working_bank()
1043-
.register_recent_blockhash(&Hash::new_unique());
1043+
.register_unique_recent_blockhash_for_test();
10441044
}
10451045
}),
10461046
);

programs/sbf/tests/programs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4013,7 +4013,7 @@ fn test_cpi_account_ownership_writability() {
40134013
TEST_FORBID_WRITE_AFTER_OWNERSHIP_CHANGE_IN_CALLEE,
40144014
TEST_FORBID_WRITE_AFTER_OWNERSHIP_CHANGE_IN_CALLER,
40154015
] {
4016-
bank.register_recent_blockhash(&Hash::new_unique());
4016+
bank.register_unique_recent_blockhash_for_test();
40174017
let account = AccountSharedData::new(42, account_size, &invoke_program_id);
40184018
bank.store_account(&account_keypair.pubkey(), &account);
40194019

runtime/src/bank.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,6 +4186,12 @@ impl Bank {
41864186
self.update_recent_blockhashes_locked(&w_blockhash_queue);
41874187
}
41884188

4189+
// gating this under #[cfg(feature = "dev-context-only-utils")] isn't easy due to
4190+
// solana-program-test's usage...
4191+
pub fn register_unique_recent_blockhash_for_test(&self) {
4192+
self.register_recent_blockhash(&Hash::new_unique())
4193+
}
4194+
41894195
/// Tell the bank which Entry IDs exist on the ledger. This function assumes subsequent calls
41904196
/// correspond to later entries, and will boot the oldest ones once its internal cache is full.
41914197
/// Once boot, the bank will reject transactions using that `hash`.

runtime/src/bank/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13373,7 +13373,7 @@ fn test_program_execution_restricted_for_stake_account_in_reward_period() {
1337313373
// Push a dummy blockhash, so that the latest_blockhash() for the transfer transaction in each
1337413374
// iteration are different. Otherwise, all those transactions will be the same, and will not be
1337513375
// executed by the bank except the first one.
13376-
bank.register_recent_blockhash(&Hash::new_unique());
13376+
bank.register_unique_recent_blockhash_for_test();
1337713377
previous_bank = Arc::new(bank);
1337813378
}
1337913379
}

0 commit comments

Comments
 (0)