diff --git a/crates/svm-test/src/svm.rs b/crates/svm-test/src/svm.rs index e0d9621..a894b94 100644 --- a/crates/svm-test/src/svm.rs +++ b/crates/svm-test/src/svm.rs @@ -1,4 +1,5 @@ -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; +use std::hash::{BuildHasherDefault, DefaultHasher}; use litesvm::types::SimulatedTransactionInfo; pub use litesvm::types::{FailedTransactionMetadata, TransactionMetadata, TransactionResult}; @@ -16,10 +17,12 @@ use solana_sdk::{ use crate::spl::SplProgram; use crate::AccountLoader; +pub type DefaultLoader = HashMap>; + const PRE_LOADED: &[Pubkey] = &[ed25519_program::ID, secp256k1_program::ID, sysvar::instructions::ID]; -pub struct Svm { +pub struct Svm { inner: litesvm::LiteSVM, pub loader: L, reserved_account_keys: ReservedAccountKeys, diff --git a/crates/svm-test/src/traits.rs b/crates/svm-test/src/traits.rs index cbe10fd..2f4202b 100644 --- a/crates/svm-test/src/traits.rs +++ b/crates/svm-test/src/traits.rs @@ -42,7 +42,10 @@ pub trait AccountLoader { } } -impl AccountLoader for std::collections::HashMap { +impl AccountLoader for std::collections::HashMap +where + S: std::hash::BuildHasher, +{ fn load(&self, key: &Pubkey) -> Account { self.get(key).cloned().unwrap_or_default() } diff --git a/crates/svm-test/tests/program_unit_test.rs b/crates/svm-test/tests/program_unit_test.rs index 515d5f6..7ad5533 100644 --- a/crates/svm-test/tests/program_unit_test.rs +++ b/crates/svm-test/tests/program_unit_test.rs @@ -1,13 +1,12 @@ //! These examples do not make use of `Harness` and only include local accounts //! & programs. -use std::collections::HashMap; - use expect_test::expect; use litesvm::types::SimulatedTransactionInfo; use solana_sdk::account::Account; use solana_sdk::instruction::Instruction; use solana_sdk::pubkey::Pubkey; use solana_sdk::transaction::Transaction; +use svm_test::svm::DefaultLoader; use svm_test::utils::{test_payer_keypair, TEST_PAYER}; use svm_test::Svm; @@ -16,7 +15,7 @@ const MEMO_ID: Pubkey = Pubkey::new_from_array([1; 32]); #[test] fn memo() { // Load our program & give our test payer some funds. - let mut svm = Svm::new(HashMap::default()); + let mut svm: Svm = Svm::default(); svm.load_program(MEMO_ID, "memo"); svm.set(TEST_PAYER, Account { lamports: 10u64.pow(9), ..Default::default() });