Write account path impl ReadableAccount (#16779)
This commit is contained in:
committed by
GitHub
parent
783bd79e9d
commit
f533d3be77
@ -116,6 +116,15 @@ pub trait ReadableAccount: Sized {
|
||||
fn owner(&self) -> &Pubkey;
|
||||
fn executable(&self) -> bool;
|
||||
fn rent_epoch(&self) -> Epoch;
|
||||
fn to_account_shared_data(&self) -> AccountSharedData {
|
||||
AccountSharedData::create(
|
||||
self.lamports(),
|
||||
self.data().to_vec(),
|
||||
*self.owner(),
|
||||
self.executable(),
|
||||
self.rent_epoch(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadableAccount for Account {
|
||||
@ -668,6 +677,17 @@ pub mod tests {
|
||||
account2.serialize_data(&"hello world").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_account_shared_data() {
|
||||
let key = Pubkey::new_unique();
|
||||
let (account1, account2) = make_two_accounts(&key);
|
||||
assert!(accounts_equal(&account1, &account2));
|
||||
let account3 = account1.to_account_shared_data();
|
||||
let account4 = account2.to_account_shared_data();
|
||||
assert!(accounts_equal(&account1, &account3));
|
||||
assert!(accounts_equal(&account1, &account4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_shared_data() {
|
||||
let key = Pubkey::new_unique();
|
||||
|
Reference in New Issue
Block a user