From aaf05dfa89b365b4a8ed63c14afd9edd8be576d3 Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Thu, 20 Nov 2025 04:10:42 +0100 Subject: [PATCH 1/2] add proper assert for rust tests --- basics/account-data/native/program/tests/tests.rs | 2 +- basics/checking-accounts/native/program/tests/test.rs | 4 ++-- basics/close-account/native/program/tests/test.rs | 4 ++-- basics/counter/native/program/tests/test.rs | 2 +- basics/create-account/native/program/tests/test.rs | 2 +- .../native/programs/hand/tests/test.rs | 4 ++-- basics/favorites/native/program/tests/test.rs | 4 ++-- basics/pda-rent-payer/native/program/tests/test.rs | 4 ++-- basics/processing-instructions/native/program/tests/test.rs | 2 +- .../program-derived-addresses/native/program/tests/test.rs | 6 +++--- basics/realloc/native/program/tests/test.rs | 6 +++--- basics/rent/native/program/tests/test.rs | 2 +- basics/repository-layout/native/program/tests/test.rs | 6 +++--- basics/transfer-sol/native/program/tests/test.rs | 6 +++--- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/basics/account-data/native/program/tests/tests.rs b/basics/account-data/native/program/tests/tests.rs index 25fa5beb..515fd5f3 100644 --- a/basics/account-data/native/program/tests/tests.rs +++ b/basics/account-data/native/program/tests/tests.rs @@ -49,7 +49,7 @@ fn test_account_data() { svm.latest_blockhash(), ); - svm.send_transaction(tx).unwrap(); + assert!(svm.send_transaction(tx).is_ok()); let address_info_account_data = &svm .get_account(&address_info_account.pubkey()) diff --git a/basics/checking-accounts/native/program/tests/test.rs b/basics/checking-accounts/native/program/tests/test.rs index a9eb81d5..8fe3ddcf 100644 --- a/basics/checking-accounts/native/program/tests/test.rs +++ b/basics/checking-accounts/native/program/tests/test.rs @@ -36,7 +36,7 @@ fn test_checking_accounts() { ); // verify tx was sent successfully - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let ix = Instruction { program_id, @@ -57,5 +57,5 @@ fn test_checking_accounts() { ); // verify tx was sent successfully - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/close-account/native/program/tests/test.rs b/basics/close-account/native/program/tests/test.rs index 94f15de6..94549910 100644 --- a/basics/close-account/native/program/tests/test.rs +++ b/basics/close-account/native/program/tests/test.rs @@ -46,7 +46,7 @@ fn test_close_account() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); // clsose user ix let data = borsh::to_vec(&MyInstruction::CloseUser).unwrap(); @@ -68,5 +68,5 @@ fn test_close_account() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/counter/native/program/tests/test.rs b/basics/counter/native/program/tests/test.rs index 02fa39fb..05936d44 100644 --- a/basics/counter/native/program/tests/test.rs +++ b/basics/counter/native/program/tests/test.rs @@ -38,7 +38,7 @@ fn test_counter() { &[&payer, &counter_account], svm.latest_blockhash(), ); - svm.send_transaction(tx).unwrap(); + assert!(svm.send_transaction(tx).is_ok()); let ix = Instruction { program_id, diff --git a/basics/create-account/native/program/tests/test.rs b/basics/create-account/native/program/tests/test.rs index 8c29dffb..da70c8d1 100644 --- a/basics/create-account/native/program/tests/test.rs +++ b/basics/create-account/native/program/tests/test.rs @@ -34,5 +34,5 @@ fn test_create_account() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/cross-program-invocation/native/programs/hand/tests/test.rs b/basics/cross-program-invocation/native/programs/hand/tests/test.rs index cd66ed90..9014535a 100644 --- a/basics/cross-program-invocation/native/programs/hand/tests/test.rs +++ b/basics/cross-program-invocation/native/programs/hand/tests/test.rs @@ -46,7 +46,7 @@ fn test_cpi() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&SetPowerStatus { name: "Chris".to_string(), @@ -69,5 +69,5 @@ fn test_cpi() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/favorites/native/program/tests/test.rs b/basics/favorites/native/program/tests/test.rs index 27941865..4b726a6e 100644 --- a/basics/favorites/native/program/tests/test.rs +++ b/basics/favorites/native/program/tests/test.rs @@ -51,7 +51,7 @@ fn test_favorites() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let favorites_account_data = svm.get_account(&favorites_pda).unwrap().data; @@ -79,5 +79,5 @@ fn test_favorites() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/pda-rent-payer/native/program/tests/test.rs b/basics/pda-rent-payer/native/program/tests/test.rs index dfd0c311..337835e5 100644 --- a/basics/pda-rent-payer/native/program/tests/test.rs +++ b/basics/pda-rent-payer/native/program/tests/test.rs @@ -43,7 +43,7 @@ fn test_pda_rent_payer() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let new_account = Keypair::new(); @@ -66,5 +66,5 @@ fn test_pda_rent_payer() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/processing-instructions/native/program/tests/test.rs b/basics/processing-instructions/native/program/tests/test.rs index a2368fe2..ebc20d2d 100644 --- a/basics/processing-instructions/native/program/tests/test.rs +++ b/basics/processing-instructions/native/program/tests/test.rs @@ -47,5 +47,5 @@ fn test_processing_ixs() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/program-derived-addresses/native/program/tests/test.rs b/basics/program-derived-addresses/native/program/tests/test.rs index 6c2a02c3..23e7be93 100644 --- a/basics/program-derived-addresses/native/program/tests/test.rs +++ b/basics/program-derived-addresses/native/program/tests/test.rs @@ -40,7 +40,7 @@ fn test_pda() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let (pda, bump) = Pubkey::find_program_address(&[b"page_visits", test_user.pubkey().as_ref()], &program_id); @@ -69,7 +69,7 @@ fn test_pda() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&IncrementPageVisits {}).unwrap(); @@ -89,7 +89,7 @@ fn test_pda() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); // read page visits let account_info = svm.get_account(&pda).unwrap(); diff --git a/basics/realloc/native/program/tests/test.rs b/basics/realloc/native/program/tests/test.rs index 7fd01d33..0b70fd86 100644 --- a/basics/realloc/native/program/tests/test.rs +++ b/basics/realloc/native/program/tests/test.rs @@ -47,7 +47,7 @@ fn test_realloc() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&ReallocInstruction::ReallocateWithoutZeroInit( EnhancedAddressInfoExtender { @@ -74,7 +74,7 @@ fn test_realloc() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&ReallocInstruction::ReallocateZeroInit(WorkInfo { name: "Pete".to_string(), @@ -97,5 +97,5 @@ fn test_realloc() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/rent/native/program/tests/test.rs b/basics/rent/native/program/tests/test.rs index 86852640..5dbc229e 100644 --- a/basics/rent/native/program/tests/test.rs +++ b/basics/rent/native/program/tests/test.rs @@ -37,7 +37,7 @@ fn test_rent() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); // rent let _rent = svm.get_account(&new_keypair.pubkey()).unwrap().lamports; diff --git a/basics/repository-layout/native/program/tests/test.rs b/basics/repository-layout/native/program/tests/test.rs index 3c551491..e8ad3d03 100644 --- a/basics/repository-layout/native/program/tests/test.rs +++ b/basics/repository-layout/native/program/tests/test.rs @@ -41,7 +41,7 @@ fn test_repo_layout() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&CarnivalInstructionData { name: "Jimmy".to_string(), @@ -65,7 +65,7 @@ fn test_repo_layout() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&CarnivalInstructionData { name: "Jimmy".to_string(), height: 36, @@ -88,5 +88,5 @@ fn test_repo_layout() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } diff --git a/basics/transfer-sol/native/program/tests/test.rs b/basics/transfer-sol/native/program/tests/test.rs index fa7e0a34..09e4abc1 100644 --- a/basics/transfer-sol/native/program/tests/test.rs +++ b/basics/transfer-sol/native/program/tests/test.rs @@ -45,7 +45,7 @@ fn test_transfer_sol() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let payer_balance_after = svm.get_balance(&payer.pubkey()).unwrap(); let recipient_balance_after = svm.get_balance(&test_recipient1.pubkey()).unwrap_or(0); @@ -68,7 +68,7 @@ fn test_transfer_sol() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); let data = borsh::to_vec(&TransferInstruction::ProgramTransfer(LAMPORTS_PER_SOL)).unwrap(); @@ -89,5 +89,5 @@ fn test_transfer_sol() { svm.latest_blockhash(), ); - let _ = svm.send_transaction(tx).is_ok(); + assert!(svm.send_transaction(tx).is_ok()); } From cbd2469cfa2edc89a99eb71b992cbac0166acb98 Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Thu, 20 Nov 2025 04:34:11 +0100 Subject: [PATCH 2/2] Update test.rs --- basics/repository-layout/native/program/tests/test.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basics/repository-layout/native/program/tests/test.rs b/basics/repository-layout/native/program/tests/test.rs index e8ad3d03..2db9c57d 100644 --- a/basics/repository-layout/native/program/tests/test.rs +++ b/basics/repository-layout/native/program/tests/test.rs @@ -48,7 +48,7 @@ fn test_repo_layout() { height: 36, ticket_count: 15, attraction: "game".to_string(), - attraction_name: "I Got it!".to_string(), + attraction_name: "I Got It!".to_string(), }) .unwrap(); @@ -66,6 +66,7 @@ fn test_repo_layout() { ); assert!(svm.send_transaction(tx).is_ok()); + let data = borsh::to_vec(&CarnivalInstructionData { name: "Jimmy".to_string(), height: 36,