Test account doesn't need RefCell (#7932)

automerge
This commit is contained in:
Jack May
2020-01-22 17:06:11 -08:00
committed by Grimes
parent a197ac092a
commit 8f79327190
2 changed files with 22 additions and 22 deletions

View File

@ -3081,8 +3081,8 @@ mod tests {
// set up stakes, vote, and storage accounts // set up stakes, vote, and storage accounts
bank.store_account(&stake_id, &stake_account); bank.store_account(&stake_id, &stake_account);
bank.store_account(&validator_id, &validator_account.borrow()); bank.store_account(&validator_id, &validator_account);
bank.store_account(&archiver_id, &archiver_account.borrow()); bank.store_account(&archiver_id, &archiver_account);
// generate some rewards // generate some rewards
let mut vote_state = VoteState::from(&vote_account).unwrap(); let mut vote_state = VoteState::from(&vote_account).unwrap();

View File

@ -91,7 +91,7 @@ pub(crate) mod tests {
storage_instruction::{self, StorageAccountType}, storage_instruction::{self, StorageAccountType},
storage_processor, storage_processor,
}; };
use std::{cell::RefCell, rc::Rc, sync::Arc}; use std::{rc::Rc, sync::Arc};
#[test] #[test]
fn test_store_and_recover() { fn test_store_and_recover() {
@ -149,24 +149,24 @@ pub(crate) mod tests {
let ((validator_pubkey, validator_account), (archiver_pubkey, archiver_account)) = let ((validator_pubkey, validator_account), (archiver_pubkey, archiver_account)) =
create_storage_accounts_with_credits(credits); create_storage_accounts_with_credits(credits);
storage_accounts.store(&validator_pubkey, &validator_account.borrow()); storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow()); storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that 2x credits worth of points are available // check that 2x credits worth of points are available
assert_eq!(storage_accounts.points(), credits * 2); assert_eq!(storage_accounts.points(), credits * 2);
let ((validator_pubkey, validator_account), (archiver_pubkey, archiver_account)) = let ((validator_pubkey, validator_account), (archiver_pubkey, mut archiver_account)) =
create_storage_accounts_with_credits(credits); create_storage_accounts_with_credits(credits);
storage_accounts.store(&validator_pubkey, &validator_account.borrow()); storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow()); storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that 4x credits worth of points are available // check that 4x credits worth of points are available
assert_eq!(storage_accounts.points(), credits * 2 * 2); assert_eq!(storage_accounts.points(), credits * 2 * 2);
storage_accounts.store(&validator_pubkey, &validator_account.borrow()); storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow()); storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that storing again has no effect // check that storing again has no effect
assert_eq!(storage_accounts.points(), credits * 2 * 2); assert_eq!(storage_accounts.points(), credits * 2 * 2);
let storage_contract = &mut archiver_account.borrow().state().unwrap(); let storage_contract = &mut archiver_account.state().unwrap();
if let StorageContract::ArchiverStorage { if let StorageContract::ArchiverStorage {
credits: account_credits, credits: account_credits,
.. ..
@ -174,11 +174,8 @@ pub(crate) mod tests {
{ {
account_credits.current_epoch += 1; account_credits.current_epoch += 1;
} }
archiver_account archiver_account.set_state(storage_contract).unwrap();
.borrow_mut() storage_accounts.store(&archiver_pubkey, &archiver_account);
.set_state(storage_contract)
.unwrap();
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
// check that incremental store increases credits // check that incremental store increases credits
assert_eq!(storage_accounts.points(), credits * 2 * 2 + 1); assert_eq!(storage_accounts.points(), credits * 2 * 2 + 1);
@ -190,10 +187,7 @@ pub(crate) mod tests {
pub fn create_storage_accounts_with_credits( pub fn create_storage_accounts_with_credits(
credits: u64, credits: u64,
) -> ( ) -> ((Pubkey, Account), (Pubkey, Account)) {
(Pubkey, Rc<RefCell<Account>>),
(Pubkey, Rc<RefCell<Account>>),
) {
let validator_pubkey = Pubkey::new_rand(); let validator_pubkey = Pubkey::new_rand();
let archiver_pubkey = Pubkey::new_rand(); let archiver_pubkey = Pubkey::new_rand();
let validator_account = Account::new_ref( let validator_account = Account::new_ref(
@ -240,8 +234,14 @@ pub(crate) mod tests {
.unwrap(); .unwrap();
} }
( (
(validator_pubkey, validator_account), (
(archiver_pubkey, archiver_account), validator_pubkey,
Rc::try_unwrap(validator_account).unwrap().into_inner(),
),
(
archiver_pubkey,
Rc::try_unwrap(archiver_account).unwrap().into_inner(),
),
) )
} }
} }