diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index 5192319aec..37e848471a 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -888,7 +888,7 @@ impl ProgramTest { .read() .unwrap() .working_bank() - .register_recent_blockhash(&Hash::new_unique()); + .register_unique_recent_blockhash_for_test(); } }); @@ -1040,7 +1040,7 @@ impl ProgramTestContext { .read() .unwrap() .working_bank() - .register_recent_blockhash(&Hash::new_unique()); + .register_unique_recent_blockhash_for_test(); } }), ); diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 465f9f44a8..97d5c2ceb5 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -4013,7 +4013,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); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 33d7ec6c9b..edc2c26bc4 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4186,6 +4186,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... + 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`. diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 30bf6ceb7b..311b928a29 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -13373,7 +13373,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); } }