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..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 @@ -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,23 @@ 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}" + ); }