diff --git a/src/http/activity_log_retrieval.rs b/src/http/activity_log_retrieval.rs index 8b16722..e66dacd 100644 --- a/src/http/activity_log_retrieval.rs +++ b/src/http/activity_log_retrieval.rs @@ -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!( diff --git a/tests/api/activity_log_retrieval.rs b/tests/api/activity_log_retrieval.rs index e20517a..e27426f 100644 --- a/tests/api/activity_log_retrieval.rs +++ b/tests/api/activity_log_retrieval.rs @@ -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; @@ -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(); }