From 7138157b310d5968b09b51f0829e2f6b95ffac55 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Jul 2026 18:02:00 +0000 Subject: [PATCH 1/2] test(hello-solana): assert the greeting log, not just tx success hello-solana only logs a message and changes no state, so a test that just checks the transaction landed verifies nothing about the program. Assert each flavor emits 'Hello, Solana!': - anchor: kite's send helper discards transaction metadata, so send through LiteSVM directly (adds a solana-transaction dev-dep) and read the logs. - native: capture the send result and assert the log (was is_ok only). - quasar: assert on result.logs after assert_success. pinocchio already asserted the log. anchor verified with cargo check --tests; native/quasar mirror existing log-asserting tests in the repo. --- Cargo.lock | 1 + .../anchor/programs/hello-solana/Cargo.toml | 1 + .../programs/hello-solana/tests/test_hello.rs | 21 ++++++++++++++++--- .../hello-solana/native/program/tests/test.rs | 6 +++++- basics/hello-solana/quasar/src/tests.rs | 8 +++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4c4461f..54e04145 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1994,6 +1994,7 @@ dependencies = [ "litesvm", "solana-kite", "solana-signer", + "solana-transaction", ] [[package]] diff --git a/basics/hello-solana/anchor/programs/hello-solana/Cargo.toml b/basics/hello-solana/anchor/programs/hello-solana/Cargo.toml index 5595560d..a5c764e3 100644 --- a/basics/hello-solana/anchor/programs/hello-solana/Cargo.toml +++ b/basics/hello-solana/anchor/programs/hello-solana/Cargo.toml @@ -26,6 +26,7 @@ anchor-lang = "1.1.2" litesvm = "0.13.1" solana-signer = "3.0.0" solana-kite = "0.4.0" +solana-transaction = "3.0.1" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } diff --git a/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs b/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs index 095a59e9..46e0d353 100644 --- a/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs +++ b/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs @@ -1,8 +1,9 @@ use { anchor_lang::{solana_program::instruction::Instruction, InstructionData, ToAccountMetas}, litesvm::LiteSVM, - solana_kite::{create_wallet, send_transaction_from_instructions}, + solana_kite::create_wallet, solana_signer::Signer, + solana_transaction::Transaction, }; #[test] @@ -19,6 +20,20 @@ fn test_say_hello() { hello_solana::accounts::HelloAccountConstraints {}.to_account_metas(None), ); - send_transaction_from_instructions(&mut svm, vec![instruction], &[&payer], &payer.pubkey()) - .unwrap(); + // The program only logs; assert it emitted its greeting rather than merely + // that the transaction landed. kite's send helper discards the metadata, so + // send through LiteSVM directly to read the logs. + let transaction = Transaction::new_signed_with_payer( + &[instruction], + Some(&payer.pubkey()), + &[&payer], + svm.latest_blockhash(), + ); + let metadata = svm.send_transaction(transaction).unwrap(); + + assert!( + metadata.logs.iter().any(|log| log.contains("Hello, Solana!")), + "expected the program to log its greeting, got: {:?}", + metadata.logs + ); } diff --git a/basics/hello-solana/native/program/tests/test.rs b/basics/hello-solana/native/program/tests/test.rs index bb9a9ea5..66b73a1e 100644 --- a/basics/hello-solana/native/program/tests/test.rs +++ b/basics/hello-solana/native/program/tests/test.rs @@ -34,5 +34,9 @@ fn test_hello_solana() { svm.latest_blockhash(), ); - assert!(svm.send_transaction(tx).is_ok()); + let result = svm.send_transaction(tx); + assert!(result.is_ok()); + + let logs = result.unwrap().logs; + assert!(logs.iter().any(|log| log.contains("Hello, Solana!"))); } diff --git a/basics/hello-solana/quasar/src/tests.rs b/basics/hello-solana/quasar/src/tests.rs index e20bda85..d831c52d 100644 --- a/basics/hello-solana/quasar/src/tests.rs +++ b/basics/hello-solana/quasar/src/tests.rs @@ -31,4 +31,12 @@ fn test_hello() { ); result.assert_success(); + + // The program only logs; assert it emitted its greeting, not just that the + // transaction succeeded. + let logs = result.logs.join("\n"); + assert!( + logs.contains("Hello, Solana!"), + "expected the program to log its greeting, got:\n{logs}" + ); } From 82ceb38f5d1b3993d66b8f9eaeeaaf84014d58f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Jul 2026 18:09:32 +0000 Subject: [PATCH 2/2] style: rustfmt the hello-solana anchor test assert Wrap the metadata.logs method chain to satisfy cargo fmt --check. --- .../anchor/programs/hello-solana/tests/test_hello.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs b/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs index 46e0d353..6dd3541d 100644 --- a/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs +++ b/basics/hello-solana/anchor/programs/hello-solana/tests/test_hello.rs @@ -32,7 +32,10 @@ fn test_say_hello() { let metadata = svm.send_transaction(transaction).unwrap(); assert!( - metadata.logs.iter().any(|log| log.contains("Hello, Solana!")), + metadata + .logs + .iter() + .any(|log| log.contains("Hello, Solana!")), "expected the program to log its greeting, got: {:?}", metadata.logs );