From 46e804f06b9bdca37bc3c0c550682e61a2deaac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Fri, 12 Jul 2024 13:01:37 +0200 Subject: [PATCH] kairos-server/tests: move posgres into individual test case to avoid dropping --- kairos-server/tests/transactions.rs | 41 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/kairos-server/tests/transactions.rs b/kairos-server/tests/transactions.rs index 5b429c61..934d7787 100644 --- a/kairos-server/tests/transactions.rs +++ b/kairos-server/tests/transactions.rs @@ -35,16 +35,14 @@ use kairos_tx::asn::{SigningPayload, Transfer, Withdrawal}; static TEST_ENVIRONMENT: OnceLock<()> = OnceLock::new(); #[cfg(feature = "deposit-mock")] -async fn new_test_app() -> TestServer { +async fn new_test_app(#[cfg(feature = "database")] postgres_url: &Url) -> TestServer { let dummy_url = Url::parse("http://0.0.0.0:0").unwrap(); - #[cfg(feature = "database")] - let postgres = PostgresDB::run(None).unwrap(); new_test_app_with_casper_node( &dummy_url, &dummy_url, #[cfg(feature = "database")] - &postgres.connection.clone().into(), + postgres_url, ) .await } @@ -160,7 +158,14 @@ async fn test_signed_deploy_is_forwarded_if_sender_in_approvals() { async fn test_deposit_withdraw() { use kairos_circuit_logic::transactions::L1Deposit; - let server = new_test_app().await; + #[cfg(feature = "database")] + let postgres = PostgresDB::run(None).unwrap(); + + let server = new_test_app( + #[cfg(feature = "database")] + &postgres.connection.clone().into(), + ) + .await; let deposit = L1Deposit { recipient: "alice_key".into(), @@ -174,11 +179,13 @@ async fn test_deposit_withdraw() { .assert_status_failure(); // deposit - server + let response = server .post(MockDepositPath.to_uri().path()) .json(&deposit) - .await - .assert_status_success(); + .await; + + println!("{}", &response.text()); + response.assert_status_success(); // wrong arguments server @@ -244,7 +251,14 @@ async fn test_deposit_withdraw() { async fn test_deposit_transfer_withdraw() { use kairos_circuit_logic::transactions::L1Deposit; - let server = new_test_app().await; + #[cfg(feature = "database")] + let postgres = PostgresDB::run(None).unwrap(); + + let server = new_test_app( + #[cfg(feature = "database")] + &postgres.connection.clone().into(), + ) + .await; // deposit server @@ -288,7 +302,14 @@ async fn test_deposit_transfer_withdraw() { async fn test_deposit_transfer_to_self_withdraw() { use kairos_circuit_logic::transactions::L1Deposit; - let server = new_test_app().await; + #[cfg(feature = "database")] + let postgres = PostgresDB::run(None).unwrap(); + + let server = new_test_app( + #[cfg(feature = "database")] + &postgres.connection.clone().into(), + ) + .await; // deposit server