Skip to content

Commit

Permalink
chore: use reserved_account_keys instead of BUILTIN_PROGRAMS_KEYS
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk committed Oct 9, 2024
1 parent 0b359ee commit 0c88ecb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions crates/svm-test/src/svm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashSet;

pub use litesvm::types::{FailedTransactionMetadata, TransactionMetadata, TransactionResult};
use solana_sdk::account::{Account, AccountSharedData};
use solana_sdk::message::legacy::BUILTIN_PROGRAMS_KEYS;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::reserved_account_keys::ReservedAccountKeys;
use solana_sdk::sysvar::{Sysvar, SysvarId};
use solana_sdk::transaction::{SanitizedTransaction, VersionedTransaction};
use solana_sdk::{
Expand All @@ -20,14 +20,19 @@ const PRE_LOADED: &[Pubkey] =
pub struct Svm<L> {
inner: litesvm::LiteSVM,
pub loader: L,
reserved_account_keys: ReservedAccountKeys,
}

impl<L> Default for Svm<L>
where
L: AccountLoader + Default,
{
fn default() -> Self {
Svm { inner: Self::inner(), loader: Default::default() }
Svm {
inner: Self::inner(),
loader: Default::default(),
reserved_account_keys: ReservedAccountKeys::new_all_activated(),
}
}
}

Expand All @@ -49,7 +54,11 @@ where
}

pub fn new(loader: L) -> Self {
Svm { inner: Self::inner(), loader }
Svm {
inner: Self::inner(),
loader,
reserved_account_keys: ReservedAccountKeys::new_all_activated(),
}
}

/* /////////////////////////////////////////////////////////////////////////////
Expand All @@ -71,9 +80,16 @@ where

#[cfg(feature = "spl")]
pub fn load_spl_program(&mut self, program: SplProgram) {
let elf = match program {
SplProgram::Token => litesvm::spl,
let (program_id, program_bytes) = match program {
SplProgram::Token => (spl_token::ID, litesvm::spl::TOKEN_ELF),
SplProgram::Token2022 => (spl_token_2022::ID, litesvm::spl::TOKEN_2022_ELF),
SplProgram::AssociatedTokenAccount => {
(spl_associated_token_account::ID, litesvm::spl::ASSOCIATED_TOKEN_ACCOUNT_ELF)
}
};

self.inner
.add_program(&bpf_loader::ID, program_id, program_bytes);
}

pub fn get(&self, key: &Pubkey) -> Option<Account> {
Expand Down Expand Up @@ -151,7 +167,7 @@ where
// Load any missing accounts.
for key in sanitized.message().account_keys().iter().filter(|key| {
!PRE_LOADED.contains(key)
&& !BUILTIN_PROGRAMS_KEYS.contains(key)
&& !self.reserved_account_keys.is_reserved(key)
&& key != &&compute_budget::ID
}) {
// We only go to the loader the first time an account is touched.
Expand Down

0 comments on commit 0c88ecb

Please sign in to comment.