AccountSharedData.set_data (#15781)
* account.set_data and resize_data * remove data_resize
This commit is contained in:
committed by
GitHub
parent
e1ceb430e3
commit
3419a5446e
@ -6084,10 +6084,10 @@ pub mod tests {
|
||||
|
||||
let mut normal_account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
||||
normal_account.owner = inline_spl_token_v2_0::id();
|
||||
normal_account.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);
|
||||
zero_account.owner = inline_spl_token_v2_0::id();
|
||||
zero_account.data = account_data_with_mint;
|
||||
zero_account.set_data(account_data_with_mint);
|
||||
|
||||
//store an account
|
||||
accounts.store_uncached(0, &[(&pubkey1, &normal_account)]);
|
||||
|
@ -541,7 +541,7 @@ pub mod test_utils {
|
||||
pub fn create_test_account(sample: usize) -> (StoredMeta, AccountSharedData) {
|
||||
let data_len = sample % 256;
|
||||
let mut account = AccountSharedData::new(sample as u64, 0, &Pubkey::default());
|
||||
account.data = (0..data_len).map(|_| data_len as u8).collect();
|
||||
account.set_data((0..data_len).map(|_| data_len as u8).collect());
|
||||
let stored_meta = StoredMeta {
|
||||
write_version: 0,
|
||||
pubkey: Pubkey::default(),
|
||||
|
@ -207,7 +207,7 @@ impl PreAccount {
|
||||
pre.executable = account.executable;
|
||||
if pre.data().len() != account.data().len() {
|
||||
// Only system account can change data size, copy with alloc
|
||||
pre.data = account.data.clone();
|
||||
pre.set_data(account.data().clone());
|
||||
} else {
|
||||
// Copy without allocate
|
||||
pre.data_as_mut_slice().clone_from_slice(&account.data());
|
||||
@ -806,7 +806,9 @@ impl MessageProcessor {
|
||||
);
|
||||
return Err(InstructionError::InvalidRealloc);
|
||||
}
|
||||
account_ref.try_account_ref_mut()?.data = account.data.clone();
|
||||
account_ref
|
||||
.try_account_ref_mut()?
|
||||
.set_data(account.data().clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1319,8 +1321,8 @@ mod tests {
|
||||
self
|
||||
}
|
||||
pub fn data(mut self, pre: Vec<u8>, post: Vec<u8>) -> Self {
|
||||
self.pre.account.borrow_mut().data = pre;
|
||||
self.post.data = post;
|
||||
self.pre.account.borrow_mut().set_data(pre);
|
||||
self.post.set_data(post);
|
||||
self
|
||||
}
|
||||
pub fn rent_epoch(mut self, pre: u64, post: u64) -> Self {
|
||||
@ -1682,7 +1684,7 @@ mod tests {
|
||||
}
|
||||
// Change data in a read-only account
|
||||
MockSystemInstruction::AttemptDataChange { data } => {
|
||||
keyed_accounts[1].account.borrow_mut().data = vec![data];
|
||||
keyed_accounts[1].account.borrow_mut().set_data(vec![data]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -1849,7 +1851,7 @@ mod tests {
|
||||
let mut dup_account = keyed_accounts[2].try_account_ref_mut()?;
|
||||
dup_account.lamports -= lamports;
|
||||
to_account.lamports += lamports;
|
||||
dup_account.data = vec![data];
|
||||
dup_account.set_data(vec![data]);
|
||||
}
|
||||
keyed_accounts[0].try_account_ref_mut()?.lamports -= lamports;
|
||||
keyed_accounts[1].try_account_ref_mut()?.lamports += lamports;
|
||||
|
@ -432,7 +432,7 @@ pub mod tests {
|
||||
assert!(vote_accounts.get(&vote_pubkey).is_none());
|
||||
}
|
||||
|
||||
vote_account.data = cache_data;
|
||||
vote_account.set_data(cache_data);
|
||||
stakes.store(&vote_pubkey, &vote_account, true, true);
|
||||
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ fn allocate(
|
||||
return Err(SystemError::InvalidAccountDataLength.into());
|
||||
}
|
||||
|
||||
account.data = vec![0; space as usize];
|
||||
account.set_data(vec![0; space as usize]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user