account.owner = X -> account.set_owner(X) (#16754)

This commit is contained in:
Jeff Washington (jwash) 2021-04-23 12:34:22 -05:00 committed by GitHub
parent 63436cc2bf
commit fb0b76c1f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 14 deletions

View File

@ -2455,7 +2455,7 @@ mod tests {
min_program_balance, min_program_balance,
min_programdata_balance, min_programdata_balance,
); );
program_account.borrow_mut().owner = Pubkey::new_unique(); program_account.borrow_mut().set_owner(Pubkey::new_unique());
let keyed_accounts = vec![ let keyed_accounts = vec![
KeyedAccount::new(&programdata_address, false, &programdata_account), KeyedAccount::new(&programdata_address, false, &programdata_account),
KeyedAccount::new(&program_address, false, &program_account), KeyedAccount::new(&program_address, false, &program_account),

View File

@ -626,7 +626,7 @@ mod tests {
use super::*; use super::*;
use bincode::serialize; use bincode::serialize;
use solana_sdk::{ use solana_sdk::{
account::{self, Account, AccountSharedData}, account::{self, Account, AccountSharedData, WritableAccount},
keyed_account::KeyedAccount, keyed_account::KeyedAccount,
process_instruction::MockInvokeContext, process_instruction::MockInvokeContext,
rent::Rent, rent::Rent,
@ -1026,7 +1026,9 @@ mod tests {
let stake_account = create_default_stake_account(); let stake_account = create_default_stake_account();
let vote_address = Pubkey::default(); let vote_address = Pubkey::default();
let mut bad_vote_account = create_default_account(); let mut bad_vote_account = create_default_account();
bad_vote_account.get_mut().owner = solana_vote_program::id(); bad_vote_account
.get_mut()
.set_owner(solana_vote_program::id());
let clock_address = sysvar::clock::id(); let clock_address = sysvar::clock::id();
let clock_account = RefCell::new(account::create_account_shared_data_for_test( let clock_account = RefCell::new(account::create_account_shared_data_for_test(
&sysvar::clock::Clock::default(), &sysvar::clock::Clock::default(),

View File

@ -1708,8 +1708,11 @@ mod tests {
use super::*; use super::*;
use crate::id; use crate::id;
use solana_sdk::{ use solana_sdk::{
account::AccountSharedData, native_token, process_instruction::MockInvokeContext, account::{AccountSharedData, WritableAccount},
pubkey::Pubkey, system_program, native_token,
process_instruction::MockInvokeContext,
pubkey::Pubkey,
system_program,
}; };
use solana_vote_program::vote_state; use solana_vote_program::vote_state;
use std::{cell::RefCell, iter::FromIterator}; use std::{cell::RefCell, iter::FromIterator};
@ -2010,7 +2013,9 @@ mod tests {
// signed but faked vote account // signed but faked vote account
let faked_vote_account = vote_account.clone(); let faked_vote_account = vote_account.clone();
faked_vote_account.borrow_mut().owner = solana_sdk::pubkey::new_rand(); faked_vote_account
.borrow_mut()
.set_owner(solana_sdk::pubkey::new_rand());
let faked_vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &faked_vote_account); let faked_vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &faked_vote_account);
assert_eq!( assert_eq!(
stake_keyed_account.delegate( stake_keyed_account.delegate(

View File

@ -6687,10 +6687,10 @@ pub mod tests {
account_data_with_mint[..PUBKEY_BYTES].clone_from_slice(&(mint_key.to_bytes())); account_data_with_mint[..PUBKEY_BYTES].clone_from_slice(&(mint_key.to_bytes()));
let mut normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); let mut normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
normal_account.owner = inline_spl_token_v2_0::id(); normal_account.set_owner(inline_spl_token_v2_0::id());
normal_account.set_data(account_data_with_mint.clone()); normal_account.set_data(account_data_with_mint.clone());
let mut zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner()); let mut zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
zero_account.owner = inline_spl_token_v2_0::id(); zero_account.set_owner(inline_spl_token_v2_0::id());
zero_account.set_data(account_data_with_mint); zero_account.set_data(account_data_with_mint);
//store an account //store an account

View File

@ -12121,7 +12121,7 @@ pub(crate) mod tests {
// freely modified with malicious data // freely modified with malicious data
let bogus_vote_program = Pubkey::new_unique(); let bogus_vote_program = Pubkey::new_unique();
vote_account.lamports = original_lamports; vote_account.lamports = original_lamports;
vote_account.owner = bogus_vote_program; vote_account.set_owner(bogus_vote_program);
bank.store_account( bank.store_account(
&validator_vote_keypairs0.vote_keypair.pubkey(), &validator_vote_keypairs0.vote_keypair.pubkey(),
&vote_account, &vote_account,
@ -12135,7 +12135,7 @@ pub(crate) mod tests {
let mut stake_account = bank let mut stake_account = bank
.get_account(&validator_vote_keypairs1.stake_keypair.pubkey()) .get_account(&validator_vote_keypairs1.stake_keypair.pubkey())
.unwrap_or_default(); .unwrap_or_default();
stake_account.owner = bogus_stake_program; stake_account.set_owner(bogus_stake_program);
bank.store_account( bank.store_account(
&validator_vote_keypairs1.stake_keypair.pubkey(), &validator_vote_keypairs1.stake_keypair.pubkey(),
&stake_account, &stake_account,

View File

@ -916,7 +916,9 @@ impl MessageProcessor {
return Err(InstructionError::InvalidRealloc); return Err(InstructionError::InvalidRealloc);
} }
dst_keyed_account.try_account_ref_mut()?.lamports = src_keyed_account.lamports; dst_keyed_account.try_account_ref_mut()?.lamports = src_keyed_account.lamports;
dst_keyed_account.try_account_ref_mut()?.owner = src_keyed_account.owner; dst_keyed_account
.try_account_ref_mut()?
.set_owner(src_keyed_account.owner);
dst_keyed_account dst_keyed_account
.try_account_ref_mut()? .try_account_ref_mut()?
.set_data(src_keyed_account.data().to_vec()); .set_data(src_keyed_account.data().to_vec());
@ -1463,7 +1465,7 @@ mod tests {
self self
} }
pub fn owner(mut self, post: &Pubkey) -> Self { pub fn owner(mut self, post: &Pubkey) -> Self {
self.post.owner = *post; self.post.set_owner(*post);
self self
} }
pub fn data(mut self, pre: Vec<u8>, post: Vec<u8>) -> Self { pub fn data(mut self, pre: Vec<u8>, post: Vec<u8>) -> Self {

View File

@ -1,6 +1,6 @@
use log::*; use log::*;
use solana_sdk::{ use solana_sdk::{
account::{AccountSharedData, ReadableAccount}, account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut, account_utils::StateMut,
ic_msg, ic_msg,
instruction::InstructionError, instruction::InstructionError,
@ -126,7 +126,7 @@ fn assign(
return Err(SystemError::InvalidProgramId.into()); return Err(SystemError::InvalidProgramId.into());
} }
account.owner = *owner; account.set_owner(*owner);
Ok(()) Ok(())
} }