Skip to content

Commit 3ed4420

Browse files
committed
add rust test for rent example
1 parent f3e8e8d commit 3ed4420

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

Cargo.lock

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

basics/rent/native/program/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ solana-system-interface .workspace = true
1313
crate-type = ["cdylib", "lib"]
1414

1515
[features]
16-
anchor-debug = []
1716
custom-heap = []
1817
custom-panic = []
1918

2019
[lints.rust]
2120
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
21+
22+
[dev-dependencies]
23+
litesvm = "0.8.1"
24+
solana-instruction = "3.0.0"
25+
solana-keypair = "3.0.1"
26+
solana-native-token = "3.0.0"
27+
solana-pubkey = "3.0.0"
28+
solana-rent = "3.0.0"
29+
solana-transaction = "3.0.1"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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_rent() {
10+
let mut svm = LiteSVM::new();
11+
12+
let program_id = Pubkey::new_unique();
13+
let program_bytes = include_bytes!("../../../../../target/deploy/program.so");
14+
15+
svm.add_program(program_id, program_bytes).unwrap();
16+
17+
let payer = Keypair::new();
18+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
19+
20+
let new_keypair = Keypair::new();
21+
22+
let ix = Instruction {
23+
program_id,
24+
accounts: vec![
25+
AccountMeta::new(payer.pubkey(), true),
26+
AccountMeta::new(new_keypair.pubkey(), true),
27+
AccountMeta::new(payer.pubkey(), true),
28+
AccountMeta::new(solana_system_interface::program::ID, false),
29+
],
30+
data: [0_u8; 1000].to_vec(),
31+
};
32+
33+
let tx = Transaction::new_signed_with_payer(
34+
&[ix],
35+
Some(&payer.pubkey()),
36+
&[&payer, &new_keypair],
37+
svm.latest_blockhash(),
38+
);
39+
40+
let _ = svm.send_transaction(tx).is_ok();
41+
42+
// rent
43+
let _rent = svm.get_account(&new_keypair.pubkey()).unwrap().lamports;
44+
}

0 commit comments

Comments
 (0)