Skip to content

Commit 745d90c

Browse files
committed
add rust test for repo layout example
1 parent f3e8e8d commit 745d90c

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-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/repository-layout/native/program/Cargo.toml

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

1919
[lints.rust]
2020
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-transaction = "3.0.1"
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use litesvm::LiteSVM;
2+
3+
use repository_layout_program::processor::CarnivalInstructionData;
4+
use solana_instruction::{AccountMeta, Instruction};
5+
use solana_keypair::{Keypair, Signer};
6+
use solana_program::native_token::LAMPORTS_PER_SOL;
7+
use solana_pubkey::Pubkey;
8+
use solana_transaction::Transaction;
9+
10+
#[test]
11+
fn test_repo_layout() {
12+
let mut svm = LiteSVM::new();
13+
14+
let program_id = Pubkey::new_unique();
15+
let program_bytes = include_bytes!("../../../../../target/deploy/repository_layout_program.so");
16+
17+
svm.add_program(program_id, program_bytes).unwrap();
18+
19+
let payer = Keypair::new();
20+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
21+
22+
let data = borsh::to_vec(&CarnivalInstructionData {
23+
name: "Jimmy".to_string(),
24+
height: 36,
25+
ticket_count: 15,
26+
attraction: "ride".to_string(),
27+
attraction_name: "Scrambler".to_string(),
28+
})
29+
.unwrap();
30+
31+
let ix = Instruction {
32+
program_id,
33+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
34+
data,
35+
};
36+
37+
let tx = Transaction::new_signed_with_payer(
38+
&[ix],
39+
Some(&payer.pubkey()),
40+
&[&payer],
41+
svm.latest_blockhash(),
42+
);
43+
44+
let _ = svm.send_transaction(tx).is_ok();
45+
46+
let data = borsh::to_vec(&CarnivalInstructionData {
47+
name: "Jimmy".to_string(),
48+
height: 36,
49+
ticket_count: 15,
50+
attraction: "game".to_string(),
51+
attraction_name: "I Got it!".to_string(),
52+
})
53+
.unwrap();
54+
55+
let ix = Instruction {
56+
program_id,
57+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
58+
data,
59+
};
60+
61+
let tx = Transaction::new_signed_with_payer(
62+
&[ix],
63+
Some(&payer.pubkey()),
64+
&[&payer],
65+
svm.latest_blockhash(),
66+
);
67+
68+
let _ = svm.send_transaction(tx).is_ok();
69+
let data = borsh::to_vec(&CarnivalInstructionData {
70+
name: "Jimmy".to_string(),
71+
height: 36,
72+
ticket_count: 15,
73+
attraction: "food".to_string(),
74+
attraction_name: "Taco Shack".to_string(),
75+
})
76+
.unwrap();
77+
78+
let ix = Instruction {
79+
program_id,
80+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
81+
data,
82+
};
83+
84+
let tx = Transaction::new_signed_with_payer(
85+
&[ix],
86+
Some(&payer.pubkey()),
87+
&[&payer],
88+
svm.latest_blockhash(),
89+
);
90+
91+
let _ = svm.send_transaction(tx).is_ok();
92+
}

0 commit comments

Comments
 (0)