Skip to content

Commit 7f885c2

Browse files
committed
docs(README): update installation instructions and add usage examples
1 parent 12b91ca commit 7f885c2

1 file changed

Lines changed: 80 additions & 12 deletions

File tree

README.md

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,35 @@
1111

1212
`hpsvm` is a fast and lightweight library for testing Solana programs. It works by creating an in-process Solana VM optimized for program developers. This makes it much faster to run and compile than alternatives like `solana-program-test` and `solana-test-validator`. In a further break from tradition, it has an ergonomic API with sane defaults and extensive configurability for those who want it.
1313

14-
This is a pure Rust library with no Node.js dependencies.
14+
This is a pure Rust library, making it ideal for Rust-native Solana development workflows.
15+
16+
## ✨ Features
17+
18+
- 🚀 **High Performance**: In-process VM runs tests significantly faster than external validators
19+
- 🛠️ **Easy to Use**: Simple API with sensible defaults and comprehensive configuration options
20+
- 🔧 **Pure Rust**: No external dependencies or runtime requirements beyond Rust
21+
- 📊 **Comprehensive Testing**: Supports transactions, account management, and program execution
22+
- 🔄 **Configurable**: Extensive options for customizing the test environment
23+
- 📚 **Well Documented**: Full API documentation and examples
1524

1625
## 🚀 Getting Started
1726

27+
### Prerequisites
28+
29+
- Rust
30+
- Solana CLI (for building test programs)
31+
1832
### 🔧 Installation
1933

34+
Add `hpsvm` as a development dependency to your Solana program project:
35+
2036
```sh
2137
cargo add --dev hpsvm
2238
```
2339

24-
### 🤖 Minimal Example
40+
### 🤖 Quick Example
41+
42+
Here's a minimal example that demonstrates creating a test environment, airdropping SOL, and executing a transfer transaction:
2543

2644
```rust
2745
use hpsvm::HPSVM;
@@ -32,33 +50,83 @@ use solana_signer::Signer;
3250
use solana_system_interface::instruction::transfer;
3351
use solana_transaction::Transaction;
3452

53+
// Create keypairs for testing
3554
let from_keypair = Keypair::new();
3655
let from = from_keypair.pubkey();
3756
let to = Address::new_unique();
3857

58+
// Initialize the SVM with default configuration
3959
let mut svm = HPSVM::new();
60+
61+
// Airdrop SOL to the sender account
4062
svm.airdrop(&from, 10_000).unwrap();
4163

64+
// Create a transfer instruction
4265
let instruction = transfer(&from, &to, 64);
66+
67+
// Build and sign the transaction
4368
let tx = Transaction::new(
4469
&[&from_keypair],
4570
Message::new(&[instruction], Some(&from)),
4671
svm.latest_blockhash(),
4772
);
48-
let tx_res = svm.send_transaction(tx).unwrap();
4973

50-
let from_account = svm.get_account(&from);
51-
let to_account = svm.get_account(&to);
52-
assert_eq!(from_account.unwrap().lamports, 4936);
53-
assert_eq!(to_account.unwrap().lamports, 64);
74+
// Execute the transaction
75+
let tx_result = svm.send_transaction(tx).unwrap();
76+
77+
// Verify the results
78+
let from_account = svm.get_account(&from).unwrap();
79+
let to_account = svm.get_account(&to).unwrap();
80+
assert_eq!(from_account.lamports, 4936); // 10000 - 64 - fee
81+
assert_eq!(to_account.lamports, 64);
5482
```
5583

56-
### 🛠️ Developing hpsvm
84+
### 📖 Usage
85+
86+
For more advanced usage, including custom configurations, program deployment, and complex transaction scenarios, see the [full documentation](https://docs.rs/hpsvm).
87+
88+
## 🛠️ Developing hpsvm
5789

58-
#### Run the tests
90+
### Building Test Programs
91+
92+
The test suite uses Solana programs that need to be built first:
93+
94+
```bash
95+
cd crates/hpsvm/test_programs
96+
cargo build-sbf
97+
```
5998

60-
The tests in this repo use some test programs you need to build first (Solana CLI >= 1.18.8 required):
99+
### Running Tests
100+
101+
Run the full test suite:
102+
103+
```bash
104+
cargo test
105+
```
106+
107+
### Running Benchmarks
108+
109+
```bash
110+
cargo bench
111+
```
112+
113+
### Code Quality
114+
115+
Format code:
116+
117+
```bash
118+
cargo fmt
119+
```
120+
121+
Lint code:
122+
123+
```bash
124+
cargo clippy
125+
```
61126

62-
```cd crates/hpsvm/test_programs && cargo build-sbf```
127+
## 🙏 Acknowledgments
63128

64-
Then just run `cargo test`.
129+
- Initially forked from [litesvm](https://github.com/LiteSVM/litesvm)
130+
- Built for the Solana ecosystem
131+
- Inspired by the need for faster, more ergonomic testing tools
132+
- Thanks to the Solana community for their contributions and feedback

0 commit comments

Comments
 (0)