Skip to content

Commit f3e8e8d

Browse files
authored
feat: add rust litesvm test for checking account (#434)
1 parent 57d87db commit f3e8e8d

File tree

3 files changed

+207
-1
lines changed

3 files changed

+207
-1
lines changed

Cargo.lock

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

basics/checking-accounts/native/program/Cargo.toml

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

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

1817

1918
[lints.rust]
2019
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
20+
21+
[dev-dependencies]
22+
litesvm = "0.8.1"
23+
solana-keypair = "3.0.1"
24+
solana-native-token = "3.0.0"
25+
solana-pubkey = "3.0.0"
26+
solana-sdk = "3.0.0"
27+
solana-transaction = "3.0.1"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use litesvm::LiteSVM;
2+
use solana_keypair::{Keypair, Signer};
3+
use solana_native_token::LAMPORTS_PER_SOL;
4+
use solana_pubkey::Pubkey;
5+
use solana_system_interface::instruction::create_account;
6+
use solana_transaction::{AccountMeta, Instruction, Transaction};
7+
8+
#[test]
9+
fn test_checking_accounts() {
10+
let mut svm = LiteSVM::new();
11+
12+
let payer = Keypair::new();
13+
let account_to_change = Keypair::new();
14+
let account_to_create = Keypair::new();
15+
16+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
17+
18+
let program_id = Pubkey::new_unique();
19+
let program_bytes =
20+
include_bytes!("../../../../../target/deploy/checking_accounts_native_program.so");
21+
22+
svm.add_program(program_id, program_bytes).unwrap();
23+
24+
let create_account_ix = create_account(
25+
&payer.pubkey(),
26+
&account_to_change.pubkey(),
27+
LAMPORTS_PER_SOL,
28+
0,
29+
&program_id,
30+
);
31+
32+
let tx = Transaction::new_signed_with_payer(
33+
&[create_account_ix],
34+
Some(&payer.pubkey()),
35+
&[&payer, &account_to_change],
36+
svm.latest_blockhash(),
37+
);
38+
39+
// verify tx was sent successfully
40+
let _ = svm.send_transaction(tx).is_ok();
41+
42+
let ix = Instruction {
43+
program_id,
44+
accounts: vec![
45+
AccountMeta::new(payer.pubkey(), true),
46+
AccountMeta::new(account_to_create.pubkey(), true),
47+
AccountMeta::new(account_to_change.pubkey(), true),
48+
AccountMeta::new(solana_system_interface::program::ID, false),
49+
],
50+
data: vec![0],
51+
};
52+
53+
let tx = Transaction::new_signed_with_payer(
54+
&[ix],
55+
Some(&payer.pubkey()),
56+
&[payer, account_to_change, account_to_create],
57+
svm.latest_blockhash(),
58+
);
59+
60+
// verify tx was sent successfully
61+
let _ = svm.send_transaction(tx).is_ok();
62+
}

0 commit comments

Comments
 (0)