Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test to verify the iteration over owned transactions #1041

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Member

@Voxelot Voxelot Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] forwards vs backwards should probably be separate tests (or use something like testcase)

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