Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Account #78

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let instruction = Instruction::new_with_bytes(
);

let accounts = vec![
(key1, AccountSharedData::default()),
(key2, AccountSharedData::default()),
(key1, Account::default()),
(key2, Account::default()),
];

let mollusk = Mollusk::new(program_id, "my_program");
Expand All @@ -48,11 +48,11 @@ let instruction = system_instruction::transfer(&sender, &recipient, transfer_amo
let accounts = [
(
sender,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
Account::new(base_lamports, 0, &system_program::id()),
),
(
recipient,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
Account::new(base_lamports, 0, &system_program::id()),
),
];
let checks = vec![
Expand Down
4 changes: 2 additions & 2 deletions bencher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ mod result;
use {
mollusk_svm::{result::ProgramResult, Mollusk},
result::{write_results, MolluskComputeUnitBenchResult},
solana_sdk::{account::AccountSharedData, instruction::Instruction, pubkey::Pubkey},
solana_sdk::{account::Account, instruction::Instruction, pubkey::Pubkey},
std::path::PathBuf,
};

/// A bench is a tuple of a name, an instruction, and a list of accounts.
pub type Bench<'a> = (&'a str, &'a Instruction, &'a [(Pubkey, AccountSharedData)]);
pub type Bench<'a> = (&'a str, &'a Instruction, &'a [(Pubkey, Account)]);

/// Mollusk's compute unit bencher.
///
Expand Down
26 changes: 11 additions & 15 deletions fuzz/fixture-fd/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! An account with an address: `(Pubkey, AccountSharedData)`.
//! An account with an address: `(Pubkey, Account)`.

use {
super::proto::{AcctState as ProtoAccount, SeedAddress as ProtoSeedAddress},
solana_sdk::{
account::{Account, AccountSharedData},
keccak::Hasher,
pubkey::Pubkey,
},
solana_sdk::{account::Account, keccak::Hasher, pubkey::Pubkey},
};

#[derive(Clone, Debug, Default, PartialEq)]
Expand All @@ -33,7 +29,7 @@ impl From<SeedAddress> for ProtoSeedAddress {
}
}

impl From<ProtoAccount> for (Pubkey, AccountSharedData, Option<SeedAddress>) {
impl From<ProtoAccount> for (Pubkey, Account, Option<SeedAddress>) {
fn from(value: ProtoAccount) -> Self {
let ProtoAccount {
address,
Expand All @@ -53,27 +49,27 @@ impl From<ProtoAccount> for (Pubkey, AccountSharedData, Option<SeedAddress>) {

(
pubkey,
AccountSharedData::from(Account {
Account {
data,
executable,
lamports,
owner,
rent_epoch,
}),
},
seed_addr.map(Into::into),
)
}
}

impl From<(Pubkey, AccountSharedData, Option<SeedAddress>)> for ProtoAccount {
fn from(value: (Pubkey, AccountSharedData, Option<SeedAddress>)) -> Self {
impl From<(Pubkey, Account, Option<SeedAddress>)> for ProtoAccount {
fn from(value: (Pubkey, Account, Option<SeedAddress>)) -> Self {
let Account {
lamports,
data,
owner,
executable,
rent_epoch,
} = value.1.into();
} = value.1;

ProtoAccount {
address: value.0.to_bytes().to_vec(),
Expand All @@ -87,15 +83,15 @@ impl From<(Pubkey, AccountSharedData, Option<SeedAddress>)> for ProtoAccount {
}
}

impl From<(Pubkey, AccountSharedData)> for ProtoAccount {
fn from(value: (Pubkey, AccountSharedData)) -> Self {
impl From<(Pubkey, Account)> for ProtoAccount {
fn from(value: (Pubkey, Account)) -> Self {
let Account {
lamports,
data,
owner,
executable,
rent_epoch,
} = value.1.into();
} = value.1;

ProtoAccount {
address: value.0.to_bytes().to_vec(),
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fixture-fd/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
},
crate::account::SeedAddress,
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, keccak::Hasher, pubkey::Pubkey,
account::Account, feature_set::FeatureSet, keccak::Hasher, pubkey::Pubkey,
transaction_context::InstructionAccount,
},
};
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct Context {
/// The program ID of the program being invoked.
pub program_id: Pubkey,
/// Input accounts with state.
pub accounts: Vec<(Pubkey, AccountSharedData, Option<SeedAddress>)>,
pub accounts: Vec<(Pubkey, Account, Option<SeedAddress>)>,
/// Accounts to pass to the instruction.
pub instruction_accounts: Vec<InstructionAccount>,
/// The instruction data.
Expand All @@ -79,7 +79,7 @@ impl From<ProtoContext> for Context {
.expect("Invalid bytes for program ID");
let program_id = Pubkey::new_from_array(program_id_bytes);

let accounts: Vec<(Pubkey, AccountSharedData, Option<SeedAddress>)> =
let accounts: Vec<(Pubkey, Account, Option<SeedAddress>)> =
value.accounts.into_iter().map(Into::into).collect();

let instruction_accounts: Vec<InstructionAccount> =
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fixture-fd/src/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use {
super::proto::InstrEffects as ProtoEffects,
crate::account::SeedAddress,
solana_sdk::{account::AccountSharedData, keccak::Hasher, pubkey::Pubkey},
solana_sdk::{account::Account, keccak::Hasher, pubkey::Pubkey},
};

/// Represents the effects of a single instruction.
Expand All @@ -14,7 +14,7 @@ pub struct Effects {
// Custom error code, also non-zero if any.
pub program_custom_code: u32,
/// Copies of accounts that were changed.
pub modified_accounts: Vec<(Pubkey, AccountSharedData, Option<SeedAddress>)>,
pub modified_accounts: Vec<(Pubkey, Account, Option<SeedAddress>)>,
/// Compute units available after executing the instruction.
pub compute_units_available: u64,
/// Instruction return data.
Expand All @@ -31,7 +31,7 @@ impl From<ProtoEffects> for Effects {
return_data,
} = value;

let modified_accounts: Vec<(Pubkey, AccountSharedData, Option<SeedAddress>)> =
let modified_accounts: Vec<(Pubkey, Account, Option<SeedAddress>)> =
modified_accounts.into_iter().map(Into::into).collect();

Self {
Expand Down
10 changes: 5 additions & 5 deletions fuzz/fixture-fd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod tests {
},
mollusk_svm_fuzz_fs::SerializableFixture,
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, keccak::Hash, pubkey::Pubkey,
account::Account, feature_set::FeatureSet, keccak::Hash, pubkey::Pubkey,
transaction_context::InstructionAccount,
},
};
Expand All @@ -131,22 +131,22 @@ mod tests {
let accounts = vec![
(
Pubkey::new_unique(),
AccountSharedData::new(42, 42, &Pubkey::default()),
Account::new(42, 42, &Pubkey::default()),
None,
),
(
Pubkey::new_unique(),
AccountSharedData::new(42, 42, &Pubkey::default()),
Account::new(42, 42, &Pubkey::default()),
None,
),
(
Pubkey::new_unique(),
AccountSharedData::new(42, 42, &Pubkey::default()),
Account::new(42, 42, &Pubkey::default()),
None,
),
(
Pubkey::new_unique(),
AccountSharedData::new(42, 42, &Pubkey::default()),
Account::new(42, 42, &Pubkey::default()),
None,
),
];
Expand Down
20 changes: 8 additions & 12 deletions fuzz/fixture/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//! An account with an address: `(Pubkey, AccountSharedData)`.
//! An account with an address: `(Pubkey, Account)`.

use {
super::proto::AcctState as ProtoAccount,
solana_sdk::{
account::{Account, AccountSharedData},
keccak::Hasher,
pubkey::Pubkey,
},
solana_sdk::{account::Account, keccak::Hasher, pubkey::Pubkey},
};

impl From<ProtoAccount> for (Pubkey, AccountSharedData) {
impl From<ProtoAccount> for (Pubkey, Account) {
fn from(value: ProtoAccount) -> Self {
let ProtoAccount {
address,
Expand All @@ -28,26 +24,26 @@ impl From<ProtoAccount> for (Pubkey, AccountSharedData) {

(
pubkey,
AccountSharedData::from(Account {
Account {
data,
executable,
lamports,
owner,
rent_epoch,
}),
},
)
}
}

impl From<(Pubkey, AccountSharedData)> for ProtoAccount {
fn from(value: (Pubkey, AccountSharedData)) -> Self {
impl From<(Pubkey, Account)> for ProtoAccount {
fn from(value: (Pubkey, Account)) -> Self {
let Account {
lamports,
data,
owner,
executable,
rent_epoch,
} = value.1.into();
} = value.1;

ProtoAccount {
address: value.0.to_bytes().to_vec(),
Expand Down
9 changes: 4 additions & 5 deletions fuzz/fixture/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use {
},
solana_compute_budget::compute_budget::ComputeBudget,
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, instruction::AccountMeta,
keccak::Hasher, pubkey::Pubkey,
account::Account, feature_set::FeatureSet, instruction::AccountMeta, keccak::Hasher,
pubkey::Pubkey,
},
};

Expand All @@ -28,7 +28,7 @@ pub struct Context {
/// The instruction data.
pub instruction_data: Vec<u8>,
/// Input accounts with state.
pub accounts: Vec<(Pubkey, AccountSharedData)>,
pub accounts: Vec<(Pubkey, Account)>,
}

impl From<ProtoContext> for Context {
Expand All @@ -39,8 +39,7 @@ impl From<ProtoContext> for Context {
.expect("Invalid bytes for program ID");
let program_id = Pubkey::new_from_array(program_id_bytes);

let accounts: Vec<(Pubkey, AccountSharedData)> =
value.accounts.into_iter().map(Into::into).collect();
let accounts: Vec<(Pubkey, Account)> = value.accounts.into_iter().map(Into::into).collect();

let instruction_accounts: Vec<AccountMeta> = value
.instr_accounts
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fixture/src/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use {
super::proto::{AcctState as ProtoAccount, InstrEffects as ProtoEffects},
solana_sdk::{account::AccountSharedData, keccak::Hasher, pubkey::Pubkey},
solana_sdk::{account::Account, keccak::Hasher, pubkey::Pubkey},
};

/// Represents the effects of a single instruction.
Expand All @@ -16,7 +16,7 @@ pub struct Effects {
pub program_result: u64,
pub return_data: Vec<u8>,
/// Resulting accounts with state, to be checked post-simulation.
pub resulting_accounts: Vec<(Pubkey, AccountSharedData)>,
pub resulting_accounts: Vec<(Pubkey, Account)>,
}

impl From<ProtoEffects> for Effects {
Expand All @@ -29,7 +29,7 @@ impl From<ProtoEffects> for Effects {
resulting_accounts,
} = value;

let resulting_accounts: Vec<(Pubkey, AccountSharedData)> =
let resulting_accounts: Vec<(Pubkey, Account)> =
resulting_accounts.into_iter().map(Into::into).collect();

Self {
Expand Down
11 changes: 3 additions & 8 deletions fuzz/fixture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ mod tests {
mollusk_svm_fuzz_fs::SerializableFixture,
solana_compute_budget::compute_budget::ComputeBudget,
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, instruction::AccountMeta,
keccak::Hash, pubkey::Pubkey,
account::Account, feature_set::FeatureSet, instruction::AccountMeta, keccak::Hash,
pubkey::Pubkey,
},
};

Expand All @@ -124,12 +124,7 @@ mod tests {
let instruction_data = vec![4; 24];
let accounts = instruction_accounts
.iter()
.map(|meta| {
(
meta.pubkey,
AccountSharedData::new(42, 42, &Pubkey::default()),
)
})
.map(|meta| (meta.pubkey, Account::new(42, 42, &Pubkey::default())))
.collect::<Vec<_>>();

let context = Context {
Expand Down
8 changes: 4 additions & 4 deletions harness/benches/ips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use {
criterion::{criterion_group, criterion_main, Criterion, Throughput},
mollusk_svm::{result::Check, Mollusk},
solana_sdk::{
account::AccountSharedData, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey,
system_instruction, system_program,
account::Account, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, system_instruction,
system_program,
},
solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS,
};
Expand All @@ -20,11 +20,11 @@ fn transfer_checked_unchecked(c: &mut Criterion) {
let accounts = vec![
(
sender,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
Account::new(base_lamports, 0, &system_program::id()),
),
(
recipient,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
Account::new(base_lamports, 0, &system_program::id()),
),
];
let checks = vec![
Expand Down
6 changes: 3 additions & 3 deletions harness/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
keys::KeyMap,
},
solana_sdk::{
account::{AccountSharedData, WritableAccount},
account::{Account, WritableAccount},
instruction::Instruction,
pubkey::Pubkey,
transaction_context::{InstructionAccount, TransactionAccount},
Expand All @@ -25,11 +25,11 @@ pub struct CompiledAccounts {

pub fn compile_accounts(
instruction: &Instruction,
accounts: &[(Pubkey, AccountSharedData)],
accounts: &[(Pubkey, Account)],
loader_key: Pubkey,
) -> CompiledAccounts {
let stub_out_program_account = move || {
let mut program_account = AccountSharedData::default();
let mut program_account = Account::default();
program_account.set_owner(loader_key);
program_account.set_executable(true);
program_account
Expand Down
Loading
Loading