From 7751e858e38ffc65ada3c40ccf9052eb75423330 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 14 Aug 2023 13:31:53 +0530 Subject: [PATCH 1/9] test: remove redis from hedging test --- hedging/tests/hedging.rs | 138 +++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 56 deletions(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 1ece5de3c..6bd355ddf 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -1,17 +1,18 @@ #![allow(clippy::or_fun_call)] -// use futures::{stream::StreamExt, Stream}; -// use galoy_client::GaloyClientConfig; -// use rust_decimal::Decimal; -// use rust_decimal_macros::dec; -// use serial_test::serial; +use futures::{stream::StreamExt, Stream}; +use galoy_client::GaloyClientConfig; +use rust_decimal::Decimal; +use rust_decimal_macros::dec; +use serial_test::serial; -// use std::{env, fs}; +use std::{env, fs}; -// use okex_client::*; -// use shared::{payload::*, pubsub::*}; +use ledger::*; +use okex_client::*; +use shared::pubsub::*; -// use hedging::*; +use hedging::*; // #[derive(serde::Deserialize)] // struct Fixture { @@ -23,32 +24,32 @@ // Ok(serde_json::from_str(&contents)?) // } -// fn okex_config() -> OkexConfig { -// let api_key = env::var("OKEX_API_KEY").expect("OKEX_API_KEY not set"); -// let passphrase = env::var("OKEX_PASSPHRASE").expect("OKEX_PASS_PHRASE not set"); -// let secret_key = env::var("OKEX_SECRET_KEY").expect("OKEX_SECRET_KEY not set"); -// OkexConfig { -// client: OkexClientConfig { -// api_key, -// passphrase, -// secret_key, -// simulated: true, -// }, -// ..Default::default() -// } -// } - -// fn galoy_client_config() -> GaloyClientConfig { -// let api = env::var("GALOY_GRAPHQL_URI").expect("GALOY_GRAPHQL_URI not set"); -// let phone_number = env::var("PHONE_NUMBER").expect("PHONE_NUMBER not set"); -// let code = env::var("AUTH_CODE").expect("AUTH_CODE not set"); - -// GaloyClientConfig { -// api, -// phone_number, -// auth_code: code, -// } -// } +fn okex_config() -> OkexConfig { + let api_key = env::var("OKEX_API_KEY").expect("OKEX_API_KEY not set"); + let passphrase = env::var("OKEX_PASSPHRASE").expect("OKEX_PASS_PHRASE not set"); + let secret_key = env::var("OKEX_SECRET_KEY").expect("OKEX_SECRET_KEY not set"); + OkexConfig { + client: OkexClientConfig { + api_key, + passphrase, + secret_key, + simulated: true, + }, + ..Default::default() + } +} + +fn galoy_client_config() -> GaloyClientConfig { + let api = env::var("GALOY_GRAPHQL_URI").expect("GALOY_GRAPHQL_URI not set"); + let phone_number = env::var("PHONE_NUMBER").expect("PHONE_NUMBER not set"); + let code = env::var("AUTH_CODE").expect("AUTH_CODE not set"); + + GaloyClientConfig { + api, + phone_number, + auth_code: code, + } +} // async fn expect_exposure_between( // mut stream: impl Stream> + Unpin, @@ -109,9 +110,6 @@ // host: Some(redis_host), // ..PubSubConfig::default() // }; -// let pg_host = std::env::var("PG_HOST").unwrap_or("localhost".to_string()); -// let pg_con = format!("postgres://user:password@{pg_host}:5432/pg",); -// let pool = sqlx::PgPool::connect(&pg_con).await?; // let publisher = Publisher::new(pubsub_config.clone()).await?; // let mut subscriber = Subscriber::new(pubsub_config.clone()).await?; @@ -119,24 +117,6 @@ // .subscribe::() // .await?; -// tokio::spawn(async move { -// let (_, recv) = futures::channel::mpsc::unbounded(); -// HedgingApp::run( -// pool.clone(), -// recv, -// HedgingAppConfig { -// ..Default::default() -// }, -// okex_config(), -// galoy_client_config(), -// pubsub_config.clone(), -// tick_recv.resubscribe(), -// ) -// .await -// .expect("HedgingApp failed"); -// }); -// tokio::time::sleep(std::time::Duration::from_secs(5)).await; - // let mut payloads = load_fixture("./tests/fixtures/hedging.json") // .expect("Couldn't load fixtures") // .payloads @@ -168,3 +148,49 @@ // Ok(()) // } + +#[tokio::test] +#[serial] +#[ignore] +async fn hedging() -> anyhow::Result<()> { + let (_, tick_recv) = memory::channel(chrono::Duration::from_std( + std::time::Duration::from_secs(1), + )?); + let pg_host = std::env::var("PG_HOST").unwrap_or("localhost".to_string()); + let pg_con = format!("postgres://user:password@{pg_host}:5432/pg",); + let pool = sqlx::PgPool::connect(&pg_con).await?; + let ledger = ledger::Ledger::init(&pool).await?; + let cloned_pool = pool.clone(); + tokio::spawn(async move { + let (_, recv) = futures::channel::mpsc::unbounded(); + HedgingApp::run( + cloned_pool, + recv, + HedgingAppConfig { + ..Default::default() + }, + okex_config(), + galoy_client_config(), + tick_recv.resubscribe(), + ) + .await + .expect("HedgingApp failed"); + }); + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + ledger + .user_buys_usd( + pool.begin().await?, + LedgerTxId::new(), + UserBuysUsdParams { + satoshi_amount: dec!(1000000), + usd_cents_amount: dec!(50000), + meta: UserBuysUsdMeta { + timestamp: chrono::Utc::now(), + btc_tx_id: "btc_tx_id".to_string(), + usd_tx_id: "usd_tx_id".to_string(), + }, + }, + ) + .await?; + Ok(()) +} From 39affd766bcf4056e8114d82648be229646e7ac6 Mon Sep 17 00:00:00 2001 From: Seb Ver Date: Mon, 14 Aug 2023 19:13:19 +0900 Subject: [PATCH 2/9] fix: spawning of threads --- hedging/tests/hedging.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 6bd355ddf..4879145fd 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -153,6 +153,7 @@ fn galoy_client_config() -> GaloyClientConfig { #[serial] #[ignore] async fn hedging() -> anyhow::Result<()> { + let (send, mut receive) = tokio::sync::mpsc::channel(1); let (_, tick_recv) = memory::channel(chrono::Duration::from_std( std::time::Duration::from_secs(1), )?); @@ -161,21 +162,25 @@ async fn hedging() -> anyhow::Result<()> { let pool = sqlx::PgPool::connect(&pg_con).await?; let ledger = ledger::Ledger::init(&pool).await?; let cloned_pool = pool.clone(); + let hedging_send = send.clone(); tokio::spawn(async move { let (_, recv) = futures::channel::mpsc::unbounded(); - HedgingApp::run( - cloned_pool, - recv, - HedgingAppConfig { - ..Default::default() - }, - okex_config(), - galoy_client_config(), - tick_recv.resubscribe(), - ) - .await - .expect("HedgingApp failed"); + let _ = hedging_send.try_send( + HedgingApp::run( + cloned_pool, + recv, + HedgingAppConfig { + ..Default::default() + }, + okex_config(), + galoy_client_config(), + tick_recv.resubscribe(), + ) + .await + .expect("HedgingApp failed"), + ); }); + let _reason = receive.recv().await.expect("Didn't receive msg"); tokio::time::sleep(std::time::Duration::from_secs(5)).await; ledger .user_buys_usd( @@ -192,5 +197,6 @@ async fn hedging() -> anyhow::Result<()> { }, ) .await?; + tokio::time::sleep(std::time::Duration::from_secs(15)).await; Ok(()) } From e01309946150a002c26bec5ed371cef6d55fef85 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Tue, 15 Aug 2023 01:09:12 +0530 Subject: [PATCH 3/9] fix: can now open and close position on exchange --- hedging/tests/hedging.rs | 180 ++++++++++++--------------------------- 1 file changed, 54 insertions(+), 126 deletions(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 4879145fd..12fdb87a6 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -1,12 +1,10 @@ #![allow(clippy::or_fun_call)] -use futures::{stream::StreamExt, Stream}; use galoy_client::GaloyClientConfig; -use rust_decimal::Decimal; use rust_decimal_macros::dec; use serial_test::serial; -use std::{env, fs}; +use std::env; use ledger::*; use okex_client::*; @@ -14,16 +12,6 @@ use shared::pubsub::*; use hedging::*; -// #[derive(serde::Deserialize)] -// struct Fixture { -// payloads: Vec, -// } - -// fn load_fixture(path: &str) -> anyhow::Result { -// let contents = fs::read_to_string(path).expect("Couldn't load fixtures"); -// Ok(serde_json::from_str(&contents)?) -// } - fn okex_config() -> OkexConfig { let api_key = env::var("OKEX_API_KEY").expect("OKEX_API_KEY not set"); let passphrase = env::var("OKEX_PASSPHRASE").expect("OKEX_PASS_PHRASE not set"); @@ -51,123 +39,41 @@ fn galoy_client_config() -> GaloyClientConfig { } } -// async fn expect_exposure_between( -// mut stream: impl Stream> + Unpin, -// lower: Decimal, -// upper: Decimal, -// ) { -// let mut passed = false; -// for _ in 0..=20 { -// let pos = stream.next().await.unwrap().payload.signed_usd_exposure; -// passed = pos < upper && pos > lower; -// if passed { -// break; -// } -// } -// assert!(passed); -// } - -// async fn expect_exposure_below( -// mut stream: impl Stream> + Unpin, -// expected: Decimal, -// ) { -// let mut passed = false; -// for _ in 0..=10 { -// let pos = stream.next().await.unwrap().payload.signed_usd_exposure; -// passed = pos < expected; -// if passed { -// break; -// } -// tokio::time::sleep(std::time::Duration::from_millis(200)).await; -// } -// assert!(passed); -// } - -// async fn expect_exposure_equal( -// mut stream: impl Stream> + Unpin, -// expected: Decimal, -// ) { -// let mut passed = false; -// for _ in 0..=20 { -// let pos = stream.next().await.unwrap().payload.signed_usd_exposure; -// passed = pos == expected; -// if passed { -// break; -// } -// } -// assert!(passed); -// } - -// #[tokio::test] -// #[serial] -// #[ignore = "okex is very unstable"] -// async fn hedging() -> anyhow::Result<()> { -// let (_, tick_recv) = memory::channel(chrono::Duration::from_std( -// std::time::Duration::from_secs(1), -// )?); -// let redis_host = std::env::var("REDIS_HOST").unwrap_or("localhost".to_string()); -// let pubsub_config = PubSubConfig { -// host: Some(redis_host), -// ..PubSubConfig::default() -// }; - -// let publisher = Publisher::new(pubsub_config.clone()).await?; -// let mut subscriber = Subscriber::new(pubsub_config.clone()).await?; -// let mut stream = subscriber -// .subscribe::() -// .await?; - -// let mut payloads = load_fixture("./tests/fixtures/hedging.json") -// .expect("Couldn't load fixtures") -// .payloads -// .into_iter(); -// publisher.publish(payloads.next().unwrap()).await?; - -// let okex = OkexClient::new(okex_config().client).await?; -// expect_exposure_equal(&mut stream, dec!(0)).await; - -// publisher.publish(payloads.next().unwrap()).await?; - -// for idx in 0..=1 { -// expect_exposure_between(&mut stream, dec!(-21000), dec!(-19000)).await; - -// if idx == 0 { -// okex.place_order( -// ClientOrderId::new(), -// OkexOrderSide::Sell, -// &BtcUsdSwapContracts::from(5), -// ) -// .await?; -// expect_exposure_below(&mut stream, dec!(-50000)).await; -// } -// } - -// publisher.publish(payloads.next().unwrap()).await?; - -// expect_exposure_equal(&mut stream, dec!(0)).await; - -// Ok(()) -// } - #[tokio::test] #[serial] -#[ignore] async fn hedging() -> anyhow::Result<()> { + let pg_host = std::env::var("PG_HOST").unwrap_or_else(|_| "localhost".into()); + let pg_con = format!("postgres://user:password@{}:5432/pg", pg_host); + let pool = sqlx::PgPool::connect(&pg_con).await?; + let ledger = ledger::Ledger::init(&pool).await?; + let (send, mut receive) = tokio::sync::mpsc::channel(1); let (_, tick_recv) = memory::channel(chrono::Duration::from_std( std::time::Duration::from_secs(1), )?); - let pg_host = std::env::var("PG_HOST").unwrap_or("localhost".to_string()); - let pg_con = format!("postgres://user:password@{pg_host}:5432/pg",); - let pool = sqlx::PgPool::connect(&pg_con).await?; - let ledger = ledger::Ledger::init(&pool).await?; - let cloned_pool = pool.clone(); - let hedging_send = send.clone(); + let wait_duration = std::time::Duration::from_secs(30); + + ledger + .user_buys_usd( + pool.begin().await?, + LedgerTxId::new(), + UserBuysUsdParams { + satoshi_amount: dec!(1000000), + usd_cents_amount: dec!(50000), + meta: UserBuysUsdMeta { + timestamp: chrono::Utc::now(), + btc_tx_id: "btc_tx_id".into(), + usd_tx_id: "usd_tx_id".into(), + }, + }, + ) + .await?; + tokio::spawn(async move { let (_, recv) = futures::channel::mpsc::unbounded(); - let _ = hedging_send.try_send( + let _ = send.try_send( HedgingApp::run( - cloned_pool, + pool, recv, HedgingAppConfig { ..Default::default() @@ -182,21 +88,43 @@ async fn hedging() -> anyhow::Result<()> { }); let _reason = receive.recv().await.expect("Didn't receive msg"); tokio::time::sleep(std::time::Duration::from_secs(5)).await; + + let mut event = ledger.usd_okex_position_balance_events().await?; + let user_buy_event = tokio::time::timeout(wait_duration, event.recv()).await??; + // checks if a position of $-500 gets opened on the exchange. + if let ledger::LedgerEventData::BalanceUpdated(data) = user_buy_event.data { + assert_eq!( + (data.settled_cr_balance - data.settled_dr_balance), + dec!(-500) + ) + } else { + return Err(anyhow::anyhow!("Unexpected event data!")); + } + + let pool = sqlx::PgPool::connect(&pg_con).await?; ledger - .user_buys_usd( + .user_sells_usd( pool.begin().await?, LedgerTxId::new(), - UserBuysUsdParams { + UserSellsUsdParams { satoshi_amount: dec!(1000000), usd_cents_amount: dec!(50000), - meta: UserBuysUsdMeta { + meta: UserSellsUsdMeta { timestamp: chrono::Utc::now(), - btc_tx_id: "btc_tx_id".to_string(), - usd_tx_id: "usd_tx_id".to_string(), + btc_tx_id: "btc_tx_id".into(), + usd_tx_id: "usd_tx_id".into(), }, }, ) .await?; - tokio::time::sleep(std::time::Duration::from_secs(15)).await; + + let user_sell_event = tokio::time::timeout(wait_duration, event.recv()).await??; + // checks if the position gets closed on the exchange. + if let ledger::LedgerEventData::BalanceUpdated(data) = user_sell_event.data { + assert_eq!((data.settled_cr_balance - data.settled_dr_balance), dec!(0)) + } else { + return Err(anyhow::anyhow!("Unexpected event data!")); + } + Ok(()) } From 17f72093e7af472a27575b555cca6cf3f26cbd68 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Tue, 15 Aug 2023 03:13:29 +0530 Subject: [PATCH 4/9] fix: add timeout after buy/sell usd --- hedging/tests/hedging.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 12fdb87a6..175a6a530 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -53,22 +53,6 @@ async fn hedging() -> anyhow::Result<()> { )?); let wait_duration = std::time::Duration::from_secs(30); - ledger - .user_buys_usd( - pool.begin().await?, - LedgerTxId::new(), - UserBuysUsdParams { - satoshi_amount: dec!(1000000), - usd_cents_amount: dec!(50000), - meta: UserBuysUsdMeta { - timestamp: chrono::Utc::now(), - btc_tx_id: "btc_tx_id".into(), - usd_tx_id: "usd_tx_id".into(), - }, - }, - ) - .await?; - tokio::spawn(async move { let (_, recv) = futures::channel::mpsc::unbounded(); let _ = send.try_send( @@ -87,8 +71,25 @@ async fn hedging() -> anyhow::Result<()> { ); }); let _reason = receive.recv().await.expect("Didn't receive msg"); - tokio::time::sleep(std::time::Duration::from_secs(5)).await; + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + let pool = sqlx::PgPool::connect(&pg_con).await?; + ledger + .user_buys_usd( + pool.clone().begin().await?, + LedgerTxId::new(), + UserBuysUsdParams { + satoshi_amount: dec!(1000000), + usd_cents_amount: dec!(50000), + meta: UserBuysUsdMeta { + timestamp: chrono::Utc::now(), + btc_tx_id: "btc_tx_id".into(), + usd_tx_id: "usd_tx_id".into(), + }, + }, + ) + .await?; + tokio::time::sleep(std::time::Duration::from_secs(15)).await; let mut event = ledger.usd_okex_position_balance_events().await?; let user_buy_event = tokio::time::timeout(wait_duration, event.recv()).await??; // checks if a position of $-500 gets opened on the exchange. @@ -101,7 +102,6 @@ async fn hedging() -> anyhow::Result<()> { return Err(anyhow::anyhow!("Unexpected event data!")); } - let pool = sqlx::PgPool::connect(&pg_con).await?; ledger .user_sells_usd( pool.begin().await?, @@ -117,7 +117,7 @@ async fn hedging() -> anyhow::Result<()> { }, ) .await?; - + tokio::time::sleep(std::time::Duration::from_secs(15)).await; let user_sell_event = tokio::time::timeout(wait_duration, event.recv()).await??; // checks if the position gets closed on the exchange. if let ledger::LedgerEventData::BalanceUpdated(data) = user_sell_event.data { From 6626e04f2edfea4b77bc31023eb73b8da5df9f27 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Wed, 16 Aug 2023 23:51:37 +0530 Subject: [PATCH 5/9] fix: add try loop to check if position is updated --- hedging/tests/hedging.rs | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 175a6a530..6ab5c89d2 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -51,7 +51,6 @@ async fn hedging() -> anyhow::Result<()> { let (_, tick_recv) = memory::channel(chrono::Duration::from_std( std::time::Duration::from_secs(1), )?); - let wait_duration = std::time::Duration::from_secs(30); tokio::spawn(async move { let (_, recv) = futures::channel::mpsc::unbounded(); @@ -89,17 +88,22 @@ async fn hedging() -> anyhow::Result<()> { }, ) .await?; - tokio::time::sleep(std::time::Duration::from_secs(15)).await; let mut event = ledger.usd_okex_position_balance_events().await?; - let user_buy_event = tokio::time::timeout(wait_duration, event.recv()).await??; - // checks if a position of $-500 gets opened on the exchange. - if let ledger::LedgerEventData::BalanceUpdated(data) = user_buy_event.data { - assert_eq!( - (data.settled_cr_balance - data.settled_dr_balance), - dec!(-500) - ) - } else { - return Err(anyhow::anyhow!("Unexpected event data!")); + let mut passed = false; + for _ in 0..=20 { + let user_buy_event = event.recv().await?; + // checks if a position of $-500 gets opened on the exchange. + if let ledger::LedgerEventData::BalanceUpdated(data) = user_buy_event.data { + if (data.settled_cr_balance - data.settled_dr_balance) == dec!(-500) { + passed = true; + break; + } + } else { + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + } + if !passed { + panic!("Could not open a position on the exchange!"); } ledger @@ -117,13 +121,21 @@ async fn hedging() -> anyhow::Result<()> { }, ) .await?; - tokio::time::sleep(std::time::Duration::from_secs(15)).await; - let user_sell_event = tokio::time::timeout(wait_duration, event.recv()).await??; - // checks if the position gets closed on the exchange. - if let ledger::LedgerEventData::BalanceUpdated(data) = user_sell_event.data { - assert_eq!((data.settled_cr_balance - data.settled_dr_balance), dec!(0)) - } else { - return Err(anyhow::anyhow!("Unexpected event data!")); + let mut passed = false; + for _ in 0..=20 { + let user_sell_event = event.recv().await?; + // checks if the position gets closed on the exchange. + if let ledger::LedgerEventData::BalanceUpdated(data) = user_sell_event.data { + if (data.settled_cr_balance - data.settled_dr_balance) == dec!(0) { + passed = true; + break; + } + } else { + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + } + if !passed { + panic!("Could not close the position on the exchange"); } Ok(()) From 469344f1c5faf2909858a35c017bf313f9461e45 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Wed, 16 Aug 2023 23:52:51 +0530 Subject: [PATCH 6/9] chore: increase runtime for nextest --- .config/nextest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 69ec1b16b..3ca534675 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,2 +1,2 @@ [profile.default] -slow-timeout = { period = "45s", terminate-after = 2 } +slow-timeout = { period = "60s", terminate-after = 2 } From 60339304c2f7fc0cc38c57a576f7fc331f007e6d Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 21 Aug 2023 16:31:03 +0530 Subject: [PATCH 7/9] fix: include buy contracts via okex_client --- hedging/tests/hedging.rs | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/hedging/tests/hedging.rs b/hedging/tests/hedging.rs index 6ab5c89d2..780a69771 100644 --- a/hedging/tests/hedging.rs +++ b/hedging/tests/hedging.rs @@ -106,6 +106,45 @@ async fn hedging() -> anyhow::Result<()> { panic!("Could not open a position on the exchange!"); } + let okex = OkexClient::new(okex_config().client).await?; + okex.place_order( + ClientOrderId::new(), + OkexOrderSide::Buy, + &BtcUsdSwapContracts::from(5), + ) + .await?; + passed = false; + for _ in 0..20 { + let PositionSize { usd_cents, .. } = okex.get_position_in_signed_usd_cents().await?; + // checks if the position gets closed via OkexClient + if usd_cents / dec!(100) == dec!(0) { + passed = true; + break; + } else { + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + } + if !passed { + panic!("Could not close the position via OkexClient!"); + } + + passed = false; + for _ in 0..=20 { + let user_buy_event = event.recv().await?; + // checks if a position of $-500 gets opened on the exchange. + if let ledger::LedgerEventData::BalanceUpdated(data) = user_buy_event.data { + if (data.settled_cr_balance - data.settled_dr_balance) == dec!(-500) { + passed = true; + break; + } + } else { + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + } + if !passed { + panic!("Could not open a position on the exchange after closing it via OkexClient!"); + } + ledger .user_sells_usd( pool.begin().await?, @@ -121,7 +160,7 @@ async fn hedging() -> anyhow::Result<()> { }, ) .await?; - let mut passed = false; + passed = false; for _ in 0..=20 { let user_sell_event = event.recv().await?; // checks if the position gets closed on the exchange. From a52ecc76e7c0682a820436e11e0e72a84c045cbe Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 21 Aug 2023 16:31:30 +0530 Subject: [PATCH 8/9] chore: increase timeout for test --- .config/nextest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 3ca534675..de661f04b 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,2 +1,2 @@ [profile.default] -slow-timeout = { period = "60s", terminate-after = 2 } +slow-timeout = { period = "90s", terminate-after = 2 } From a256804b84506590031e3c9ce688f26b7a591a9a Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 21 Aug 2023 16:31:48 +0530 Subject: [PATCH 9/9] chore: delete fixtures --- hedging/tests/fixtures/hedging.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 hedging/tests/fixtures/hedging.json diff --git a/hedging/tests/fixtures/hedging.json b/hedging/tests/fixtures/hedging.json deleted file mode 100644 index cd165b3bb..000000000 --- a/hedging/tests/fixtures/hedging.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "payloads": [ - { - "liability": "0" - }, - { - "liability": "20000" - }, - { - "liability": "0" - } - ] -}