Browse Source

feat: add proper assert for rust tests (#459)

* add proper assert for rust tests

* Update test.rs
Perelyn 2 ngày trước cách đây
mục cha
commit
a11dcf9234

+ 1 - 1
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())

+ 2 - 2
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());
 }

+ 2 - 2
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());
 }

+ 1 - 1
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,

+ 1 - 1
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());
 }

+ 2 - 2
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());
 }

+ 2 - 2
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());
 }

+ 2 - 2
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());
 }

+ 1 - 1
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());
 }

+ 3 - 3
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();

+ 3 - 3
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());
 }

+ 1 - 1
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;

+ 5 - 4
basics/repository-layout/native/program/tests/test.rs

@@ -41,14 +41,14 @@ 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,
         ticket_count: 15,
         attraction: "game".to_string(),
-        attraction_name: "I Got it!".to_string(),
+        attraction_name: "I Got It!".to_string(),
     })
     .unwrap();
 
@@ -65,7 +65,8 @@ 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 +89,5 @@ fn test_repo_layout() {
         svm.latest_blockhash(),
     );
 
-    let _ = svm.send_transaction(tx).is_ok();
+    assert!(svm.send_transaction(tx).is_ok());
 }

+ 3 - 3
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());
 }