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

(Fix) Fix failing tests #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/http/activity_log_retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn log_retrieval(
}

if let Some(amount_to) = query_params.amount_to {
conditions.push(format!("AND amount_to = '{}'", amount_to));
conditions.push(format!("AND amount_to = {}", amount_to));
}

let query_build = format!(
Expand Down
72 changes: 0 additions & 72 deletions tests/api/activity_log_retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,6 @@ async fn populate_db(pool: &PgPool) -> bool {
true
}

async fn populate_db_alt(pool: &PgPool) -> bool {
sqlx::query(
"INSERT INTO transactions_log (
wallet_address,
from_token,
to_token,
percentage,
amount_from,
amount_to,
created_at,
updated_at
) VALUES
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:42.728841+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:42.316783+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:41.917281+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:41.514413+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:41.08329+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:40.562681+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:40.053961+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:39.507289+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:38.464406+00', NULL),
('0x1234567890abcdef8234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111111', 70, 1870000000, 500600000, '2024-11-29 10:49:36.202316+00', NULL),
('0x1234567890abcdef1234567890abcdef12345678', '0x9876543210fedcba9812345670fedcba98765432', '0x1111111111111111111111111111111111111234', 50, 100000000, 50000000, '2024-11-28 12:02:49.898622+00', NULL),
('0x1234567890abcdef1234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111234', 50, 100000000, 50000000, '2024-11-28 12:02:47.453754+00', NULL),
('0x1234567890abcdef1234567890abcdef12345678', '0x9876543210fedcba9876543210fedcba98765432', '0x1111111111111111111111111111111111111234', 50, 100000000, 50000000, '2024-11-28 12:02:42.457038+00', NULL);

",).execute(pool).await.unwrap();
true
}

#[tokio::test]
async fn test_log_retrieval_pagination() {
let app = TestApp::new().await;
Expand Down Expand Up @@ -168,76 +138,34 @@ async fn test_log_retrieval_invalid_cursor() {
async fn test_log_retrieval_filter_with_wallet_address() {
let app = TestApp::new().await;

sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();

populate_db_alt(&app.db.pool).await;

let sample_address = "0x1234567890abcdef1234567890abcdef12345678";
let req = Request::get(format!("/log_retrieval?wallet_address={}", sample_address))
.body(Body::empty())
.unwrap();
let resp = app.request(req).await;
assert_eq!(resp.status(), StatusCode::OK);
let body_bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let response_body: ActivityLogGetResponse = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(response_body.transactions.len(), 3);
sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();
}

#[tokio::test]
async fn test_log_retrieval_filter_with_from_token() {
let app = TestApp::new().await;

sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();

populate_db_alt(&app.db.pool).await;

let sample_token = "0x9876543210fedcba9876543210fedcba98765432";
let req = Request::get(format!("/log_retrieval?from_token={}", sample_token))
.body(Body::empty())
.unwrap();
let resp = app.request(req).await;
assert_eq!(resp.status(), StatusCode::OK);
let body_bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let response_body: ActivityLogGetResponse = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(response_body.transactions.len(), 7);
sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();
}

#[tokio::test]
async fn test_log_retrieval_filter_with_amount_to() {
let app = TestApp::new().await;

sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();

populate_db_alt(&app.db.pool).await;

let sample_amount = "50000000";
let req = Request::get(format!("/log_retrieval?amount_to={}", sample_amount))
.body(Body::empty())
.unwrap();
let resp = app.request(req).await;
assert_eq!(resp.status(), StatusCode::OK);
let body_bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let response_body: ActivityLogGetResponse = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(response_body.transactions.len(), 3);
sqlx::query!("DELETE FROM transactions_log")
.execute(&app.db.pool)
.await
.unwrap();
}
Loading