Skip to content

Commit

Permalink
Test account doesn't need RefCell (solana-labs#7932)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
jackcmay authored and solana-grimes committed Jan 23, 2020
1 parent a197ac0 commit 8f79327
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3081,8 +3081,8 @@ mod tests {

// set up stakes, vote, and storage accounts
bank.store_account(&stake_id, &stake_account);
bank.store_account(&validator_id, &validator_account.borrow());
bank.store_account(&archiver_id, &archiver_account.borrow());
bank.store_account(&validator_id, &validator_account);
bank.store_account(&archiver_id, &archiver_account);

// generate some rewards
let mut vote_state = VoteState::from(&vote_account).unwrap();
Expand Down
40 changes: 20 additions & 20 deletions runtime/src/storage_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(crate) mod tests {
storage_instruction::{self, StorageAccountType},
storage_processor,
};
use std::{cell::RefCell, rc::Rc, sync::Arc};
use std::{rc::Rc, sync::Arc};

#[test]
fn test_store_and_recover() {
Expand Down Expand Up @@ -149,36 +149,33 @@ pub(crate) mod tests {
let ((validator_pubkey, validator_account), (archiver_pubkey, archiver_account)) =
create_storage_accounts_with_credits(credits);

storage_accounts.store(&validator_pubkey, &validator_account.borrow());
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that 2x credits worth of points are available
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);

storage_accounts.store(&validator_pubkey, &validator_account.borrow());
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that 4x credits worth of points are available
assert_eq!(storage_accounts.points(), credits * 2 * 2);

storage_accounts.store(&validator_pubkey, &validator_account.borrow());
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
storage_accounts.store(&validator_pubkey, &validator_account);
storage_accounts.store(&archiver_pubkey, &archiver_account);
// check that storing again has no effect
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 {
credits: account_credits,
..
} = storage_contract
{
account_credits.current_epoch += 1;
}
archiver_account
.borrow_mut()
.set_state(storage_contract)
.unwrap();
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
archiver_account.set_state(storage_contract).unwrap();
storage_accounts.store(&archiver_pubkey, &archiver_account);

// check that incremental store increases credits
assert_eq!(storage_accounts.points(), credits * 2 * 2 + 1);
Expand All @@ -190,10 +187,7 @@ pub(crate) mod tests {

pub fn create_storage_accounts_with_credits(
credits: u64,
) -> (
(Pubkey, Rc<RefCell<Account>>),
(Pubkey, Rc<RefCell<Account>>),
) {
) -> ((Pubkey, Account), (Pubkey, Account)) {
let validator_pubkey = Pubkey::new_rand();
let archiver_pubkey = Pubkey::new_rand();
let validator_account = Account::new_ref(
Expand Down Expand Up @@ -240,8 +234,14 @@ pub(crate) mod tests {
.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(),
),
)
}
}

0 comments on commit 8f79327

Please sign in to comment.