From 37727fbbc371dd40166fab292b30bfd32d08d3bd Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 16 Dec 2021 13:52:08 -0700 Subject: [PATCH] Revert "Revert "Add set_account to solana-program-test (#21415)"" This reverts commit 480895cc258d7e00f8991b8ff452b01b92c97258. --- program-test/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index adc06d99a1..4cb85a6237 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -1020,6 +1020,18 @@ impl ProgramTestContext { bank.store_account(vote_account_address, &vote_account); } + /// Create or overwrite an account, subverting normal runtime checks. + /// + /// This method exists to make it easier to set up artificial situations + /// that would be difficult to replicate by sending individual transactions. + /// Beware that it can be used to create states that would not be reachable + /// by sending transactions! + pub fn set_account(&mut self, address: &Pubkey, account: &AccountSharedData) { + let bank_forks = self.bank_forks.read().unwrap(); + let bank = bank_forks.working_bank(); + bank.store_account(address, account); + } + /// Force the working bank ahead to a new slot pub fn warp_to_slot(&mut self, warp_slot: Slot) -> Result<(), ProgramTestError> { let mut bank_forks = self.bank_forks.write().unwrap();