Skip to content

Commit 6715cd1

Browse files
committed
add rust test for create account
1 parent f3e8e8d commit 6715cd1

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
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/create-account/native/program/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ solana-system-interface.workspace = true
1111
crate-type = ["cdylib", "lib"]
1212

1313
[features]
14-
anchor-debug = []
1514
custom-heap = []
1615
custom-panic = []
1716

1817
[lints.rust]
1918
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_create_account() {
10+
let program_id = Pubkey::new_unique();
11+
let program_bytes = include_bytes!("../../../../../target/deploy/create_account_program.so");
12+
13+
let payer = Keypair::new();
14+
let new_keypair = Keypair::new();
15+
16+
let mut svm = LiteSVM::new();
17+
svm.add_program(program_id, program_bytes).unwrap();
18+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
19+
20+
let ix = Instruction {
21+
program_id,
22+
accounts: vec![
23+
AccountMeta::new(payer.pubkey(), true),
24+
AccountMeta::new(new_keypair.pubkey(), true),
25+
AccountMeta::new(solana_system_interface::program::ID, false),
26+
],
27+
data: vec![0],
28+
};
29+
30+
let tx = Transaction::new_signed_with_payer(
31+
&[ix],
32+
Some(&payer.pubkey()),
33+
&[&payer, &new_keypair],
34+
svm.latest_blockhash(),
35+
);
36+
37+
let _ = svm.send_transaction(tx).is_ok();
38+
}

0 commit comments

Comments
 (0)