From 2359da970e474c2284bf3c7ba2fbcdad84d0f32e Mon Sep 17 00:00:00 2001 From: aaravm Date: Tue, 2 Jul 2024 19:36:15 +0530 Subject: [PATCH] added unit test for fetch_maker_request --- .../coordinator/src/communication/api.rs | 2 +- .../coordinator/src/database/mod.rs | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/taptrade-cli-demo/coordinator/src/communication/api.rs b/taptrade-cli-demo/coordinator/src/communication/api.rs index bc158c1..891bcff 100644 --- a/taptrade-cli-demo/coordinator/src/communication/api.rs +++ b/taptrade-cli-demo/coordinator/src/communication/api.rs @@ -11,7 +11,7 @@ pub struct OrderRequest { } // Define a struct representing your response data -#[derive(Serialize)] +#[derive(Serialize, PartialEq, Debug)] pub struct BondRequirementResponse { pub bond_address: String, pub locking_amount_sat: u64, // min amount of the bond output in sat diff --git a/taptrade-cli-demo/coordinator/src/database/mod.rs b/taptrade-cli-demo/coordinator/src/database/mod.rs index 310e1a3..1677233 100644 --- a/taptrade-cli-demo/coordinator/src/database/mod.rs +++ b/taptrade-cli-demo/coordinator/src/database/mod.rs @@ -441,6 +441,50 @@ mod tests { Ok(()) } + + #[tokio::test] + async fn test_fetch_maker_request() -> Result<()> { + let database = create_coordinator().await?; + + // Create a sample order request and insert it into the database + let robohash_hex = "a3f1f1f0e2f3f4f5"; + let order_request = ( + hex::decode(robohash_hex).unwrap(), + true, // is_buy_order + 1000, // amount_satoshi + 50, // bond_ratio + 1234567890, // offer_duration_ts + "1BitcoinAddress".to_string(), // bond_address + 500, // bond_amount_sat + ); + + sqlx::query( + "INSERT INTO maker_requests (robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat) + VALUES (?, ?, ?, ?, ?, ?, ?)", + ) + .bind(order_request.0.clone()) + .bind(order_request.1) + .bind(order_request.2) + .bind(order_request.3) + .bind(order_request.4) + .bind(order_request.5.clone()) + .bind(order_request.6) + .execute(&*database.db_pool) + .await?; + + // Fetch and delete the order request + let fetched_offer = database.fetch_maker_request(&robohash_hex.to_string()).await?; + + // Verify the result + let expected = BondRequirementResponse { + bond_address: "1BitcoinAddress".to_string(), + locking_amount_sat: 500_u64, + }; + assert_eq!(fetched_offer, expected); + + Ok(()) + } + #[tokio::test] async fn test_fetch_and_delete_offer_from_bond_table() -> Result<()> { // Set up the in-memory database