Skip to content

Commit

Permalink
Define register_unique_recent_blockhash_for_test (#33880)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun authored Oct 27, 2023
1 parent 080285c commit 0873705
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
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 @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
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 @@ -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);
}
}
Expand Down

0 comments on commit 0873705

Please sign in to comment.