Skip to content

Commit

Permalink
Added test to verify the iteration over owned transactions (#1041)
Browse files Browse the repository at this point in the history
Added test to cover the iteration over owned transactions.

Ref FuelLabs/fuel-core#1040
  • Loading branch information
crypto523 committed Feb 23, 2023
1 parent b949839 commit 71d0a0d
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions tests/tests/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 71d0a0d

Please sign in to comment.