Skip to content

Commit 786fd5c

Browse files
committed
add rust test for processing ix
1 parent f3e8e8d commit 786fd5c

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
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/processing-instructions/native/program/Cargo.toml

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

1414
[features]
15-
anchor-debug = []
1615
custom-heap = []
1716
custom-panic = []
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-instruction = "3.0.0"
24+
solana-keypair = "3.0.1"
25+
solana-pubkey = "3.0.0"
26+
solana-transaction = "3.0.1"
27+
solana-native-token = "3.0.0"

basics/processing-instructions/native/program/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fn process_instruction(
2727

2828
#[derive(BorshSerialize, BorshDeserialize, Debug)]
2929
pub struct InstructionData {
30-
name: String,
31-
height: u32,
30+
pub name: String,
31+
pub height: u32,
3232
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use litesvm::LiteSVM;
2+
use processing_instructions_program::InstructionData;
3+
use solana_instruction::{AccountMeta, Instruction};
4+
use solana_keypair::{Keypair, Signer};
5+
use solana_native_token::LAMPORTS_PER_SOL;
6+
use solana_pubkey::Pubkey;
7+
use solana_transaction::Transaction;
8+
9+
#[test]
10+
fn test_processing_ixs() {
11+
let mut svm = LiteSVM::new();
12+
13+
let program_id = Pubkey::new_unique();
14+
let program_bytes =
15+
include_bytes!("../../../../../target/deploy/processing_instructions_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 jimmy = InstructionData {
23+
name: "Jimmy".to_string(),
24+
height: 3,
25+
};
26+
27+
let mary = InstructionData {
28+
name: "Mary".to_string(),
29+
height: 3,
30+
};
31+
32+
let ix1 = Instruction {
33+
program_id,
34+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
35+
data: borsh::to_vec(&jimmy).unwrap(),
36+
};
37+
38+
let ix2 = Instruction {
39+
program_id,
40+
accounts: vec![AccountMeta::new(payer.pubkey(), true)],
41+
data: borsh::to_vec(&mary).unwrap(),
42+
};
43+
44+
let tx = Transaction::new_signed_with_payer(
45+
&[ix1, ix2],
46+
Some(&payer.pubkey()),
47+
&[&payer],
48+
svm.latest_blockhash(),
49+
);
50+
51+
let _ = svm.send_transaction(tx).is_ok();
52+
}

0 commit comments

Comments
 (0)