From 8c0bd14e188d55b01f7cf6a3302a209bbd9c62e9 Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Thu, 30 Oct 2025 01:02:56 +0100 Subject: [PATCH 1/3] add rust test for hello solana --- Cargo.lock | 6 ++++ basics/hello-solana/native/program/Cargo.toml | 8 +++++ .../hello-solana/native/program/tests/test.rs | 34 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 basics/hello-solana/native/program/tests/test.rs diff --git a/Cargo.lock b/Cargo.lock index 1275e977e..df2289938 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1486,7 +1486,13 @@ dependencies = [ name = "hello-solana-program" version = "0.1.0" dependencies = [ + "litesvm", + "solana-instruction 3.0.0", + "solana-keypair", + "solana-native-token 3.0.0", "solana-program 3.0.0", + "solana-pubkey 3.0.0", + "solana-transaction", ] [[package]] diff --git a/basics/hello-solana/native/program/Cargo.toml b/basics/hello-solana/native/program/Cargo.toml index 5aa41edbd..9d43c4459 100644 --- a/basics/hello-solana/native/program/Cargo.toml +++ b/basics/hello-solana/native/program/Cargo.toml @@ -16,3 +16,11 @@ custom-panic = [] [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } + +[dev-dependencies] +litesvm = "0.8.1" +solana-instruction = "3.0.0" +solana-keypair = "3.0.1" +solana-native-token = "3.0.0" +solana-pubkey = "3.0.0" +solana-transaction = "3.0.1" diff --git a/basics/hello-solana/native/program/tests/test.rs b/basics/hello-solana/native/program/tests/test.rs new file mode 100644 index 000000000..1bb288edc --- /dev/null +++ b/basics/hello-solana/native/program/tests/test.rs @@ -0,0 +1,34 @@ +use litesvm::LiteSVM; +use solana_instruction::{AccountMeta, Instruction}; +use solana_keypair::{Keypair, Signer}; +use solana_native_token::LAMPORTS_PER_SOL; +use solana_pubkey::Pubkey; +use solana_transaction::Transaction; + +#[test] +fn test_hello_solana() { + let program_id = Pubkey::new_unique(); + let program_bytes = include_bytes!("../../../../../target/deploy/hello_solana_program.so"); + + let mut svm = LiteSVM::new(); + svm.add_program(program_id, program_bytes).unwrap(); + + let payer = Keypair::new(); + + svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap(); + + let ix = Instruction { + program_id, + accounts: vec![AccountMeta::new(payer.pubkey(), true)], + data: vec![0], + }; + + let tx = Transaction::new_signed_with_payer( + &[ix], + Some(&payer.pubkey()), + &[&payer], + svm.latest_blockhash(), + ); + + let _ = svm.send_transaction(tx).is_err(); +} From c80fbc25c6efc80a1d8b69229adcc0f58739c025 Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Wed, 19 Nov 2025 06:04:14 +0100 Subject: [PATCH 2/3] Update test.rs --- basics/hello-solana/native/program/tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/hello-solana/native/program/tests/test.rs b/basics/hello-solana/native/program/tests/test.rs index 1bb288edc..643cbb62a 100644 --- a/basics/hello-solana/native/program/tests/test.rs +++ b/basics/hello-solana/native/program/tests/test.rs @@ -8,7 +8,7 @@ use solana_transaction::Transaction; #[test] fn test_hello_solana() { let program_id = Pubkey::new_unique(); - let program_bytes = include_bytes!("../../../../../target/deploy/hello_solana_program.so"); + let program_bytes = include_bytes!("../../tests/fixtures/hello_solana_program.so"); let mut svm = LiteSVM::new(); svm.add_program(program_id, program_bytes).unwrap(); From 2ec90f043783bc84cb4f14aaa1ee5e36e73152e3 Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Wed, 19 Nov 2025 06:23:56 +0100 Subject: [PATCH 3/3] Update test.rs --- basics/hello-solana/native/program/tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/hello-solana/native/program/tests/test.rs b/basics/hello-solana/native/program/tests/test.rs index 643cbb62a..aa0527203 100644 --- a/basics/hello-solana/native/program/tests/test.rs +++ b/basics/hello-solana/native/program/tests/test.rs @@ -30,5 +30,5 @@ fn test_hello_solana() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_err(); + assert!(svm.send_transaction(tx).is_ok()); }