Account->AccountSharedData (#15691)
This commit is contained in:
committed by
GitHub
parent
61c7ce857e
commit
8a3135d17b
@@ -342,7 +342,7 @@ pub fn process_instruction(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::{
|
||||
account::{self, Account},
|
||||
account::{self, AccountSharedData},
|
||||
process_instruction::MockInvokeContext,
|
||||
rent::Rent,
|
||||
};
|
||||
@@ -370,27 +370,27 @@ mod tests {
|
||||
.iter()
|
||||
.map(|meta| {
|
||||
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
|
||||
account::create_account(&Clock::default(), 1)
|
||||
account::create_account_shared_data(&Clock::default(), 1)
|
||||
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
|
||||
account::create_account(&SlotHashes::default(), 1)
|
||||
account::create_account_shared_data(&SlotHashes::default(), 1)
|
||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||
account::create_account(&Rent::free(), 1)
|
||||
account::create_account_shared_data(&Rent::free(), 1)
|
||||
} else if meta.pubkey == invalid_vote_state_pubkey() {
|
||||
Account {
|
||||
AccountSharedData {
|
||||
owner: invalid_vote_state_pubkey(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
}
|
||||
} else {
|
||||
Account {
|
||||
AccountSharedData {
|
||||
owner: id(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
for _ in 0..instruction.accounts.len() {
|
||||
accounts.push(RefCell::new(Account::default()));
|
||||
accounts.push(RefCell::new(AccountSharedData::default()));
|
||||
}
|
||||
{
|
||||
let keyed_accounts: Vec<_> = instruction
|
||||
|
@@ -6,7 +6,7 @@ use bincode::{deserialize, serialize_into, serialized_size, ErrorKind};
|
||||
use log::*;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||
account_utils::State,
|
||||
clock::{Epoch, Slot, UnixTimestamp},
|
||||
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
|
||||
@@ -223,13 +223,13 @@ impl VoteState {
|
||||
}
|
||||
|
||||
// utility function, used by Stakes, tests
|
||||
pub fn from(account: &Account) -> Option<VoteState> {
|
||||
Self::deserialize(&account.data).ok()
|
||||
pub fn from<T: ReadableAccount>(account: &T) -> Option<VoteState> {
|
||||
Self::deserialize(&account.data()).ok()
|
||||
}
|
||||
|
||||
// utility function, used by Stakes, tests
|
||||
pub fn to(versioned: &VoteStateVersions, account: &mut Account) -> Option<()> {
|
||||
Self::serialize(versioned, &mut account.data).ok()
|
||||
pub fn to<T: WritableAccount>(versioned: &VoteStateVersions, account: &mut T) -> Option<()> {
|
||||
Self::serialize(versioned, &mut account.data_as_mut_slice()).ok()
|
||||
}
|
||||
|
||||
pub fn deserialize(input: &[u8]) -> Result<Self, InstructionError> {
|
||||
@@ -248,7 +248,7 @@ impl VoteState {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn credits_from(account: &Account) -> Option<u64> {
|
||||
pub fn credits_from<T: ReadableAccount>(account: &T) -> Option<u64> {
|
||||
Self::from(account).map(|state| state.credits())
|
||||
}
|
||||
|
||||
@@ -747,8 +747,8 @@ pub fn create_account_with_authorized(
|
||||
authorized_withdrawer: &Pubkey,
|
||||
commission: u8,
|
||||
lamports: u64,
|
||||
) -> Account {
|
||||
let mut vote_account = Account::new(lamports, VoteState::size_of(), &id());
|
||||
) -> AccountSharedData {
|
||||
let mut vote_account = AccountSharedData::new(lamports, VoteState::size_of(), &id());
|
||||
|
||||
let vote_state = VoteState::new(
|
||||
&VoteInit {
|
||||
@@ -772,7 +772,7 @@ pub fn create_account(
|
||||
node_pubkey: &Pubkey,
|
||||
commission: u8,
|
||||
lamports: u64,
|
||||
) -> Account {
|
||||
) -> AccountSharedData {
|
||||
create_account_with_authorized(node_pubkey, vote_pubkey, vote_pubkey, commission, lamports)
|
||||
}
|
||||
|
||||
@@ -781,7 +781,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::vote_state;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
account_utils::StateMut,
|
||||
hash::hash,
|
||||
keyed_account::{get_signers, next_keyed_account},
|
||||
@@ -807,11 +807,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_initialize_vote_account() {
|
||||
let vote_account_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let vote_account = Account::new_ref(100, VoteState::size_of(), &id());
|
||||
let vote_account = AccountSharedData::new_ref(100, VoteState::size_of(), &id());
|
||||
let vote_account = KeyedAccount::new(&vote_account_pubkey, false, &vote_account);
|
||||
|
||||
let node_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let node_account = RefCell::new(Account::default());
|
||||
let node_account = RefCell::new(AccountSharedData::default());
|
||||
let keyed_accounts = &[];
|
||||
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
||||
|
||||
@@ -864,7 +864,7 @@ mod tests {
|
||||
assert_eq!(res, Err(InstructionError::AccountAlreadyInitialized));
|
||||
|
||||
//init should fail, account is too big
|
||||
let large_vote_account = Account::new_ref(100, 2 * VoteState::size_of(), &id());
|
||||
let large_vote_account = AccountSharedData::new_ref(100, 2 * VoteState::size_of(), &id());
|
||||
let large_vote_account =
|
||||
KeyedAccount::new(&vote_account_pubkey, false, &large_vote_account);
|
||||
let res = initialize_account(
|
||||
@@ -882,7 +882,7 @@ mod tests {
|
||||
assert_eq!(res, Err(InstructionError::InvalidAccountData));
|
||||
}
|
||||
|
||||
fn create_test_account() -> (Pubkey, RefCell<Account>) {
|
||||
fn create_test_account() -> (Pubkey, RefCell<AccountSharedData>) {
|
||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||
(
|
||||
vote_pubkey,
|
||||
@@ -895,7 +895,8 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn create_test_account_with_authorized() -> (Pubkey, Pubkey, Pubkey, RefCell<Account>) {
|
||||
fn create_test_account_with_authorized() -> (Pubkey, Pubkey, Pubkey, RefCell<AccountSharedData>)
|
||||
{
|
||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let authorized_voter = solana_sdk::pubkey::new_rand();
|
||||
let authorized_withdrawer = solana_sdk::pubkey::new_rand();
|
||||
@@ -916,7 +917,7 @@ mod tests {
|
||||
|
||||
fn simulate_process_vote(
|
||||
vote_pubkey: &Pubkey,
|
||||
vote_account: &RefCell<Account>,
|
||||
vote_account: &RefCell<AccountSharedData>,
|
||||
vote: &Vote,
|
||||
slot_hashes: &[SlotHash],
|
||||
epoch: Epoch,
|
||||
@@ -940,7 +941,7 @@ mod tests {
|
||||
/// exercises all the keyed accounts stuff
|
||||
fn simulate_process_vote_unchecked(
|
||||
vote_pubkey: &Pubkey,
|
||||
vote_account: &RefCell<Account>,
|
||||
vote_account: &RefCell<AccountSharedData>,
|
||||
vote: &Vote,
|
||||
) -> Result<VoteState, InstructionError> {
|
||||
simulate_process_vote(
|
||||
@@ -1035,8 +1036,8 @@ mod tests {
|
||||
create_test_account_with_authorized();
|
||||
|
||||
let node_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let node_account = RefCell::new(Account::default());
|
||||
let authorized_withdrawer_account = RefCell::new(Account::default());
|
||||
let node_account = RefCell::new(AccountSharedData::default());
|
||||
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
||||
@@ -1083,7 +1084,7 @@ mod tests {
|
||||
let (vote_pubkey, _authorized_voter, authorized_withdrawer, vote_account) =
|
||||
create_test_account_with_authorized();
|
||||
|
||||
let authorized_withdrawer_account = RefCell::new(Account::default());
|
||||
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
||||
@@ -1207,7 +1208,7 @@ mod tests {
|
||||
assert_eq!(res, Err(VoteError::TooSoonToReauthorize.into()));
|
||||
|
||||
// verify authorized_voter_pubkey can authorize authorized_voter_pubkey ;)
|
||||
let authorized_voter_account = RefCell::new(Account::default());
|
||||
let authorized_voter_account = RefCell::new(AccountSharedData::default());
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
||||
@@ -1247,7 +1248,7 @@ mod tests {
|
||||
assert_eq!(res, Ok(()));
|
||||
|
||||
// verify authorized_withdrawer can authorize authorized_withdrawer ;)
|
||||
let withdrawer_account = RefCell::new(Account::default());
|
||||
let withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
||||
@@ -1284,7 +1285,7 @@ mod tests {
|
||||
assert_eq!(res, Err(InstructionError::MissingRequiredSignature));
|
||||
|
||||
// signed by authorized voter
|
||||
let authorized_voter_account = RefCell::new(Account::default());
|
||||
let authorized_voter_account = RefCell::new(AccountSharedData::default());
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
||||
@@ -1308,7 +1309,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vote_without_initialization() {
|
||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let vote_account = RefCell::new(Account::new(100, VoteState::size_of(), &id()));
|
||||
let vote_account = RefCell::new(AccountSharedData::new(100, VoteState::size_of(), &id()));
|
||||
|
||||
let res = simulate_process_vote_unchecked(
|
||||
&vote_pubkey,
|
||||
@@ -1646,7 +1647,7 @@ mod tests {
|
||||
&KeyedAccount::new(
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
false,
|
||||
&RefCell::new(Account::default()),
|
||||
&RefCell::new(AccountSharedData::default()),
|
||||
),
|
||||
&signers,
|
||||
);
|
||||
@@ -1661,14 +1662,14 @@ mod tests {
|
||||
&KeyedAccount::new(
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
false,
|
||||
&RefCell::new(Account::default()),
|
||||
&RefCell::new(AccountSharedData::default()),
|
||||
),
|
||||
&signers,
|
||||
);
|
||||
assert_eq!(res, Err(InstructionError::InsufficientFunds));
|
||||
|
||||
// all good
|
||||
let to_account = RefCell::new(Account::default());
|
||||
let to_account = RefCell::new(AccountSharedData::default());
|
||||
let lamports = vote_account.borrow().lamports;
|
||||
let keyed_accounts = &[KeyedAccount::new(&vote_pubkey, true, &vote_account)];
|
||||
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
||||
@@ -1704,7 +1705,7 @@ mod tests {
|
||||
assert_eq!(res, Ok(()));
|
||||
|
||||
// withdraw using authorized_withdrawer to authorized_withdrawer's account
|
||||
let withdrawer_account = RefCell::new(Account::default());
|
||||
let withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||
let keyed_accounts = &[
|
||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
||||
|
Reference in New Issue
Block a user