Skip to content

Commit 8c0bd14

Browse files
committed
add rust test for hello solana
1 parent f3e8e8d commit 8c0bd14

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

basics/hello-solana/native/program/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ custom-panic = []
1616

1717
[lints.rust]
1818
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
19+
20+
[dev-dependencies]
21+
litesvm = "0.8.1"
22+
solana-instruction = "3.0.0"
23+
solana-keypair = "3.0.1"
24+
solana-native-token = "3.0.0"
25+
solana-pubkey = "3.0.0"
26+
solana-transaction = "3.0.1"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use litesvm::LiteSVM;
2+
use solana_instruction::{AccountMeta, Instruction};
3+
use solana_keypair::{Keypair, Signer};
4+
use solana_native_token::LAMPORTS_PER_SOL;
5+
use solana_pubkey::Pubkey;
6+
use solana_transaction::Transaction;
7+
8+
#[test]
9+
fn test_hello_solana() {
10+
let program_id = Pubkey::new_unique();
11+
let program_bytes = include_bytes!("../../../../../target/deploy/hello_solana_program.so");
12+
13+
let mut svm = LiteSVM::new();
14+
svm.add_program(program_id, program_bytes).unwrap();
15+
16+
let payer = Keypair::new();
17+
18+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
19+
20+
let ix = Instruction {
21+
program_id,
22+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
23+
data: vec![0],
24+
};
25+
26+
let tx = Transaction::new_signed_with_payer(
27+
&[ix],
28+
Some(&payer.pubkey()),
29+
&[&payer],
30+
svm.latest_blockhash(),
31+
);
32+
33+
let _ = svm.send_transaction(tx).is_err();
34+
}

0 commit comments

Comments
 (0)