From 9f888d64c4aabbf10628d134d5e3bdf2808660b0 Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Thu, 23 Feb 2023 21:43:53 +0000 Subject: [PATCH] Added test to verify the iteration over owned transactions (#1041) Added test to cover the iteration over owned transactions. Ref https://github.com/FuelLabs/fuel-core/issues/1040 --- tests/tests/tx.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/tests/tests/tx.rs b/tests/tests/tx.rs index 2efb4011b98..90b1b6d055c 100644 --- a/tests/tests/tx.rs +++ b/tests/tests/tx.rs @@ -386,6 +386,101 @@ async fn get_transactions() { assert!(response.has_previous_page); } +#[tokio::test] +async fn get_transactions_by_owner_forward_and_backward_iterations() { + let alice = Address::from([1; 32]); + let bob = Address::from([2; 32]); + + let mut context = TestContext::new(100).await; + let _ = context.transfer(alice, bob, 1).await.unwrap(); + let _ = context.transfer(alice, bob, 2).await.unwrap(); + let _ = context.transfer(alice, bob, 3).await.unwrap(); + let _ = context.transfer(alice, bob, 4).await.unwrap(); + let _ = context.transfer(alice, bob, 5).await.unwrap(); + + let client = context.client; + + let all_transactions_forward = PaginationRequest { + cursor: None, + results: 10, + direction: PageDirection::Forward, + }; + let response = client + .transactions_by_owner(bob.to_string().as_str(), all_transactions_forward) + .await + .unwrap(); + let transactions_forward = response + .results + .into_iter() + .map(|tx| { + assert!(matches!(tx.status, TransactionStatus::Success { .. })); + tx.transaction + }) + .collect_vec(); + assert_eq!(transactions_forward.len(), 5); + + let all_transactions_backward = PaginationRequest { + cursor: None, + results: 10, + direction: PageDirection::Backward, + }; + let response = client + .transactions_by_owner(bob.to_string().as_str(), all_transactions_backward) + .await; + // Backward request is not supported right now. + assert!(response.is_err()); + + ///////////////// Iteration + + let forward_iter_three = PaginationRequest { + cursor: None, + results: 3, + direction: PageDirection::Forward, + }; + let response_after_iter_three = client + .transactions_by_owner(bob.to_string().as_str(), forward_iter_three) + .await + .unwrap(); + let transactions_forward_iter_three = response_after_iter_three + .results + .into_iter() + .map(|tx| { + assert!(matches!(tx.status, TransactionStatus::Success { .. })); + tx.transaction + }) + .collect_vec(); + assert_eq!(transactions_forward_iter_three.len(), 3); + assert_eq!(transactions_forward_iter_three[0], transactions_forward[0]); + assert_eq!(transactions_forward_iter_three[1], transactions_forward[1]); + assert_eq!(transactions_forward_iter_three[2], transactions_forward[2]); + + let forward_iter_next_two = PaginationRequest { + cursor: response_after_iter_three.cursor.clone(), + results: 2, + direction: PageDirection::Forward, + }; + let response = client + .transactions_by_owner(bob.to_string().as_str(), forward_iter_next_two) + .await + .unwrap(); + let transactions_forward_iter_next_two = response + .results + .into_iter() + .map(|tx| { + assert!(matches!(tx.status, TransactionStatus::Success { .. })); + tx.transaction + }) + .collect_vec(); + assert_eq!( + transactions_forward_iter_next_two[0], + transactions_forward[3] + ); + assert_eq!( + transactions_forward_iter_next_two[1], + transactions_forward[4] + ); +} + #[tokio::test] async fn get_transactions_from_manual_blocks() { let (executor, db) = get_executor_and_db();