1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! # TestSVM
//!
//! A comprehensive testing framework for Solana SVM (Solana Virtual Machine) programs.
//!
//! This crate provides a developer-friendly wrapper around LiteSVM, offering enhanced debugging,
//! transaction management, and testing utilities for Solana program development.
//!
//! ## Features
//!
//! - **Enhanced LiteSVM Interface**: Simplified API for common testing operations
//! - **Transaction Result Management**: Detailed error reporting and transaction analysis
//! - **Address Book Integration**: Built-in address tracking and labeling
//! - **Account References**: Type-safe account management with automatic tracking
//! - **Colored Output**: Enhanced debugging with color-coded transaction logs
//! - **Helper Functions**: Utilities for airdrop, account creation, and more
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use testsvm::prelude::*;
//! # fn main() -> Result<()> {
//!
//! // Create a new test environment
//! let mut env = TestSVM::init()?;
//!
//! // Add a program to test
//! let program_id = Pubkey::new_unique();
//! env.add_program_from_path(
//! "my_program",
//! program_id,
//! "path/to/program.so"
//! )?;
//!
//! // Create and fund test accounts
//! let user = env.new_wallet("alice")?;
//!
//! // Build and execute transactions
//! let instructions = vec![
//! // Your instructions here
//! ];
//! let transaction = Transaction::new_signed_with_payer(
//! &instructions,
//! Some(&env.default_fee_payer()),
//! &[&env.default_fee_payer],
//! env.svm.latest_blockhash(),
//! );
//! let result = env.execute_transaction(transaction)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Working with Programs
//!
//! ```rust,no_run
//! use testsvm::prelude::*;
//! use solana_sdk::pubkey::Pubkey;
//! # use anyhow::Result;
//! # fn main() -> Result<()> {
//!
//! let mut env = TestSVM::init()?;
//!
//! // Load program from file
//! let program_id = Pubkey::new_unique();
//! env.add_program_from_path(
//! "token_program",
//! program_id,
//! "./fixtures/programs/token.so"
//! )?;
//!
//! // Add program fixture from fixtures directory
//! let fixture_program_id = Pubkey::new_unique();
//! env.add_program_fixture("my_program", fixture_program_id)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Account Management
//!
//! ```rust
//! use testsvm::prelude::*;
//! # fn main() -> Result<()> {
//!
//! let mut env = TestSVM::init()?;
//!
//! // Create wallets with automatic tracking
//! let alice = env.new_wallet("alice")?;
//! let bob = env.new_wallet("bob")?;
//!
//! // Create token mint
//! let mint = env.create_mint("usdc_mint", 6, &alice.pubkey())?;
//!
//! // Create Associated Token Accounts
//! let (alice_ata_ix, alice_ata) = env.create_ata_ix("alice_usdc", &alice.pubkey(), &mint.key)?;
//! let (bob_ata_ix, bob_ata) = env.create_ata_ix("bob_usdc", &bob.pubkey(), &mint.key)?;
//!
//! // Execute the instructions to create the ATAs
//! env.execute_ixs(&[alice_ata_ix, bob_ata_ix])?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Transaction Building and Execution
//!
//! ```rust
//! use testsvm::prelude::*;
//! # fn main() -> Result<()> {
//!
//! let mut env = TestSVM::init()?;
//! let payer = env.new_wallet("payer")?;
//!
//! // Build transaction
//! let instructions = vec![
//! // Your instructions here
//! ];
//!
//! let tx = Transaction::new_signed_with_payer(
//! &instructions,
//! Some(&payer.pubkey()),
//! &[&payer],
//! env.svm.latest_blockhash(),
//! );
//!
//! // Execute and verify
//! let result = env.execute_transaction(tx)?;
//!
//! // Access detailed results
//! println!("Compute units used: {}", result.compute_units_consumed);
//! println!("Logs: {:?}", result.logs);
//! # Ok(())
//! # }
//! ```
//!
//! ## Debugging and Analysis
//!
//! ```rust
//! use testsvm::prelude::*;
//! # fn main() -> Result<()> {
//!
//! let mut env = TestSVM::init()?;
//!
//! // Execute transaction (example transaction)
//! let instructions = vec![];
//! let tx = Transaction::new_signed_with_payer(
//! &instructions,
//! Some(&env.default_fee_payer()),
//! &[&env.default_fee_payer],
//! env.svm.latest_blockhash(),
//! );
//! let result = env.execute_transaction(tx)?;
//!
//! // Print formatted output
//! println!("Transaction logs: {:?}", result.logs);
//!
//! // Access address book for debugging
//! env.address_book.print_all();
//!
//! // Get account balance
//! let account = env.default_fee_payer();
//! let account_info = env.svm.get_account(&account);
//! if let Some(info) = account_info {
//! println!("Account balance: {} lamports", info.lamports);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Integration with Anchor
//!
//! ```rust,no_run
//! use testsvm::prelude::*;
//!
//! // Example program module (would be generated by Anchor)
//! // declare_program!(my_program) would generate something similar to:
//! # pub mod my_program {
//! # use solana_sdk::pubkey::Pubkey;
//! # pub const ID: Pubkey = Pubkey::new_from_array([0; 32]);
//! # pub mod accounts {
//! # use anchor_lang::prelude::*;
//! # pub struct Initialize {}
//! # impl anchor_lang::ToAccountMetas for Initialize {
//! # fn to_account_metas(&self, _: Option<bool>) -> Vec<solana_sdk::instruction::AccountMeta> { vec![] }
//! # }
//! # }
//! # pub mod instruction {
//! # use anchor_lang::prelude::*;
//! # #[derive(AnchorSerialize, AnchorDeserialize)]
//! # pub struct Initialize {}
//! # impl anchor_lang::Discriminator for Initialize {
//! # const DISCRIMINATOR: &'static [u8] = &[0; 8];
//! # }
//! # impl anchor_lang::InstructionData for Initialize {
//! # fn data(&self) -> Vec<u8> {
//! # let mut data = Vec::with_capacity(8);
//! # data.extend_from_slice(&Self::DISCRIMINATOR);
//! # data.extend_from_slice(&AnchorSerialize::try_to_vec(self).unwrap_or_default());
//! # data
//! # }
//! # }
//! # }
//! # }
//!
//! # fn main() -> Result<()> {
//! let mut env = TestSVM::init()?;
//! let payer = env.new_wallet("payer")?;
//!
//! // Create instruction using Anchor's generated types
//! let ix = anchor_instruction(
//! my_program::ID,
//! my_program::accounts::Initialize {},
//! my_program::instruction::Initialize {},
//! );
//!
//! // Execute in test environment
//! let result = env.execute_ixs_with_signers(&[ix], &[&payer])?;
//! # Ok(())
//! # }
//! ```
// Re-export from other crates
pub use *;
pub use *;
pub use testsvm_assertions;
pub use testsvm_core;
pub use testsvm_spl;