Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ solana-epoch-rewards = "2.2"
solana-epoch-schedule = "2.2"
solana-hash = "2.2"
solana-instruction = "2.2"
solana-instructions-sysvar = "2.2"
solana-keccak-hasher = "2.2"
solana-loader-v3-interface = "3.0"
solana-loader-v4-interface = "2.2"
Expand Down
1 change: 1 addition & 0 deletions harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ solana-epoch-rewards = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-instructions-sysvar = { workspace = true }
solana-loader-v3-interface = { workspace = true, features = ["serde"] }
solana-loader-v4-interface = { workspace = true }
solana-log-collector = { workspace = true }
Expand Down
40 changes: 40 additions & 0 deletions harness/src/instructions_sysvar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use {
crate::Mollusk,
solana_account::Account,
solana_instruction::{BorrowedAccountMeta, BorrowedInstruction, Instruction},
solana_instructions_sysvar::construct_instructions_data,
solana_pubkey::Pubkey,
};

pub fn keyed_account(mollusk: &Mollusk, instructions: &[Instruction]) -> (Pubkey, Account) {
let data = construct_instructions_data(
instructions
.iter()
.map(|instruction| BorrowedInstruction {
program_id: &instruction.program_id,
accounts: instruction
.accounts
.iter()
.map(|meta| BorrowedAccountMeta {
pubkey: &meta.pubkey,
is_signer: meta.is_signer,
is_writable: meta.is_writable,
})
.collect(),
data: &instruction.data,
})
.collect::<Vec<_>>()
.as_slice(),
);

(
solana_instructions_sysvar::ID,
Account {
lamports: mollusk.sysvars.rent.minimum_balance(data.len()),
data,
owner: solana_sysvar_id::ID,
executable: false,
rent_epoch: Default::default(),
},
)
}
19 changes: 17 additions & 2 deletions harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ pub mod epoch_stake;
pub mod file;
#[cfg(any(feature = "fuzz", feature = "fuzz-fd"))]
pub mod fuzz;
pub mod instructions_sysvar;
pub mod program;
pub mod sysvar;

Expand Down Expand Up @@ -666,6 +667,15 @@ impl Mollusk {
&self,
instruction: &Instruction,
accounts: &[(Pubkey, Account)],
) -> InstructionResult {
self.process_instruction_with_instruction_index(instruction, accounts, 0)
}

pub fn process_instruction_with_instruction_index(
&self,
instruction: &Instruction,
accounts: &[(Pubkey, Account)],
instruction_index: usize,
) -> InstructionResult {
let mut compute_units_consumed = 0;
let mut timings = ExecuteTimings::default();
Expand All @@ -692,6 +702,7 @@ impl Mollusk {
self.compute_budget.max_instruction_stack_depth,
self.compute_budget.max_instruction_trace_length,
);
transaction_context.set_top_level_instruction_index(instruction_index);

let invoke_result = {
let mut program_cache = self.program_cache.cache();
Expand Down Expand Up @@ -803,8 +814,12 @@ impl Mollusk {
..Default::default()
};

for instruction in instructions {
let this_result = self.process_instruction(instruction, &result.resulting_accounts);
for (index, instruction) in instructions.iter().enumerate() {
let this_result = self.process_instruction_with_instruction_index(
instruction,
&result.resulting_accounts,
index,
);

result.absorb(this_result);

Expand Down
Loading