Allow the same account to be passed multiple times to a single instruction (#7795)
This commit is contained in:
@@ -91,7 +91,7 @@ pub(crate) mod tests {
|
||||
storage_instruction::{self, StorageAccountType},
|
||||
storage_processor,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
|
||||
#[test]
|
||||
fn test_store_and_recover() {
|
||||
@@ -149,25 +149,24 @@ 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);
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account);
|
||||
storage_accounts.store(&validator_pubkey, &validator_account.borrow());
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
|
||||
// check that 2x credits worth of points are available
|
||||
assert_eq!(storage_accounts.points(), credits * 2);
|
||||
|
||||
let ((validator_pubkey, validator_account), (archiver_pubkey, mut archiver_account)) =
|
||||
let ((validator_pubkey, validator_account), (archiver_pubkey, archiver_account)) =
|
||||
create_storage_accounts_with_credits(credits);
|
||||
|
||||
storage_accounts.store(&validator_pubkey, &validator_account);
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account);
|
||||
storage_accounts.store(&validator_pubkey, &validator_account.borrow());
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
|
||||
// check that 4x credits worth of points are available
|
||||
assert_eq!(storage_accounts.points(), credits * 2 * 2);
|
||||
|
||||
storage_accounts.store(&validator_pubkey, &validator_account);
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account);
|
||||
storage_accounts.store(&validator_pubkey, &validator_account.borrow());
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
|
||||
// check that storing again has no effect
|
||||
assert_eq!(storage_accounts.points(), credits * 2 * 2);
|
||||
|
||||
let storage_contract = &mut archiver_account.state().unwrap();
|
||||
let storage_contract = &mut archiver_account.borrow().state().unwrap();
|
||||
if let StorageContract::ArchiverStorage {
|
||||
credits: account_credits,
|
||||
..
|
||||
@@ -175,8 +174,11 @@ pub(crate) mod tests {
|
||||
{
|
||||
account_credits.current_epoch += 1;
|
||||
}
|
||||
archiver_account.set_state(storage_contract).unwrap();
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account);
|
||||
archiver_account
|
||||
.borrow_mut()
|
||||
.set_state(storage_contract)
|
||||
.unwrap();
|
||||
storage_accounts.store(&archiver_pubkey, &archiver_account.borrow());
|
||||
|
||||
// check that incremental store increases credits
|
||||
assert_eq!(storage_accounts.points(), credits * 2 * 2 + 1);
|
||||
@@ -188,48 +190,55 @@ pub(crate) mod tests {
|
||||
|
||||
pub fn create_storage_accounts_with_credits(
|
||||
credits: u64,
|
||||
) -> ((Pubkey, Account), (Pubkey, Account)) {
|
||||
) -> (
|
||||
(Pubkey, Rc<RefCell<Account>>),
|
||||
(Pubkey, Rc<RefCell<Account>>),
|
||||
) {
|
||||
let validator_pubkey = Pubkey::new_rand();
|
||||
let archiver_pubkey = Pubkey::new_rand();
|
||||
|
||||
let mut validator_account = Account::new(
|
||||
let validator_account = Account::new_ref(
|
||||
1,
|
||||
STORAGE_ACCOUNT_SPACE as usize,
|
||||
&solana_storage_program::id(),
|
||||
);
|
||||
let mut validator = StorageAccount::new(validator_pubkey, &mut validator_account);
|
||||
validator
|
||||
.initialize_storage(validator_pubkey, StorageAccountType::Validator)
|
||||
.unwrap();
|
||||
let storage_contract = &mut validator_account.state().unwrap();
|
||||
if let StorageContract::ValidatorStorage {
|
||||
credits: account_credits,
|
||||
..
|
||||
} = storage_contract
|
||||
{
|
||||
account_credits.current_epoch = credits;
|
||||
}
|
||||
validator_account.set_state(storage_contract).unwrap();
|
||||
|
||||
let mut archiver_account = Account::new(
|
||||
let archiver_account = Account::new_ref(
|
||||
1,
|
||||
STORAGE_ACCOUNT_SPACE as usize,
|
||||
&solana_storage_program::id(),
|
||||
);
|
||||
let mut archiver = StorageAccount::new(archiver_pubkey, &mut archiver_account);
|
||||
archiver
|
||||
.initialize_storage(archiver_pubkey, StorageAccountType::Archiver)
|
||||
.unwrap();
|
||||
let storage_contract = &mut archiver_account.state().unwrap();
|
||||
if let StorageContract::ArchiverStorage {
|
||||
credits: account_credits,
|
||||
..
|
||||
} = storage_contract
|
||||
{
|
||||
account_credits.current_epoch = credits;
|
||||
}
|
||||
archiver_account.set_state(storage_contract).unwrap();
|
||||
StorageAccount::new(validator_pubkey, &mut validator_account.borrow_mut())
|
||||
.initialize_storage(validator_pubkey, StorageAccountType::Validator)
|
||||
.unwrap();
|
||||
let storage_contract = &mut validator_account.borrow().state().unwrap();
|
||||
if let StorageContract::ValidatorStorage {
|
||||
credits: account_credits,
|
||||
..
|
||||
} = storage_contract
|
||||
{
|
||||
account_credits.current_epoch = credits;
|
||||
}
|
||||
validator_account
|
||||
.borrow_mut()
|
||||
.set_state(storage_contract)
|
||||
.unwrap();
|
||||
|
||||
StorageAccount::new(archiver_pubkey, &mut archiver_account.borrow_mut())
|
||||
.initialize_storage(archiver_pubkey, StorageAccountType::Archiver)
|
||||
.unwrap();
|
||||
let storage_contract = &mut archiver_account.borrow().state().unwrap();
|
||||
if let StorageContract::ArchiverStorage {
|
||||
credits: account_credits,
|
||||
..
|
||||
} = storage_contract
|
||||
{
|
||||
account_credits.current_epoch = credits;
|
||||
}
|
||||
archiver_account
|
||||
.borrow_mut()
|
||||
.set_state(storage_contract)
|
||||
.unwrap();
|
||||
}
|
||||
(
|
||||
(validator_pubkey, validator_account),
|
||||
(archiver_pubkey, archiver_account),
|
||||
|
Reference in New Issue
Block a user