From 7c62ff62fbe78173b2dabf3747b2cbe61106d1e4 Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 16 Dec 2023 15:25:29 -0800 Subject: [PATCH] clippy --- cli/src/main.rs | 4 ++-- lean/src/add.rs | 4 ++-- lean/src/buy.rs | 28 +++++++++++------------ lean/src/sell/cancel_sell.rs | 4 ++-- lean/src/sell/commit_sell.rs | 8 +++---- lean/src/sell/init_sell.rs | 12 +++++----- lean/src/trigger.rs | 2 +- lean/src/trigger/buy/cancel_set_buy.rs | 4 ++-- lean/src/trigger/buy/set_buy_amount.rs | 4 ++-- lean/src/trigger/buy/set_buy_trigger.rs | 5 ++-- lean/src/trigger/sell/cancel_set_sell.rs | 4 ++-- lean/src/trigger/sell/set_sell_amount.rs | 8 +++---- lean/src/trigger/sell/set_sell_trigger.rs | 8 +++---- 13 files changed, 47 insertions(+), 48 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 24bf872..35115b7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -221,9 +221,9 @@ fn spawn_commands( let start = SystemTime::now(); let mut join_set = JoinSet::new(); let commands_by_user = commands.into_iter().map(|it| (it.user(), it)).fold( - BTreeMap::new(), + BTreeMap::<_, Vec<_>>::new(), |mut acc, (user, cmd)| { - acc.entry(user).or_insert_with(Vec::new).push(cmd); + acc.entry(user).or_default().push(cmd); acc }, ); diff --git a/lean/src/add.rs b/lean/src/add.rs index 0efacc1..d6c2fed 100644 --- a/lean/src/add.rs +++ b/lean/src/add.rs @@ -26,7 +26,7 @@ mod tests { #[sqlx::test] async fn test_add_new_user(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 100_f64).await?; + let _log = add(&pool, "marcus", 100_f64).await?; struct Trader { user_id: String, @@ -48,7 +48,7 @@ mod tests { async fn test_add_old_user(pool: PgPool) -> anyhow::Result<()> { let add1 = add(&pool, "marcus", 100_f64); let add2 = add(&pool, "marcus", 100_f64); - tokio::try_join!(add1, add2)?; + let (_log1, _log2) = tokio::try_join!(add1, add2)?; struct Trader { user_id: String, diff --git a/lean/src/buy.rs b/lean/src/buy.rs index 094b4c3..cd06a4a 100644 --- a/lean/src/buy.rs +++ b/lean/src/buy.rs @@ -39,7 +39,7 @@ mod tests { #[sqlx::test] async fn test_sufficient_funds(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 100_f64).await?; + let _log = crate::add::add(&pool, "marcus", 100_f64).await?; let buy = init_buy(&pool, "marcus", "APPL", 50_f64, 100_f64).await; assert!(buy.is_ok(), "expected ok but was {buy:?}"); @@ -75,7 +75,7 @@ mod tests { #[sqlx::test] async fn test_insufficient_funds(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 100_f64).await?; + let _log = crate::add::add(&pool, "marcus", 100_f64).await?; let buy = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await; assert!(buy.is_err(), "expected error but was {buy:?}"); Ok(()) @@ -83,8 +83,8 @@ mod tests { #[sqlx::test] async fn test_override_queued_buy(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; let buy = init_buy(&pool, "marcus", "TSLA", 50_f64, 100_f64).await; @@ -124,8 +124,8 @@ mod tests { #[sqlx::test] async fn init_buy_removes_funds(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; let Balance { balance } = sqlx::query_as!( Balance, @@ -167,8 +167,8 @@ mod tests { #[sqlx::test] async fn commit_buy_with_buy(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; let buy = commit_buy(&pool, "marcus").await; assert!(buy.is_ok(), "expected error but was {buy:?}"); @@ -202,9 +202,9 @@ mod tests { #[sqlx::test] async fn commit_timed_out_buy(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; sqlx::query!("UPDATE queued_buy SET time_created = time_created - interval '6 minutes' WHERE user_id = 'marcus'") .execute(&pool) @@ -244,8 +244,8 @@ mod tests { #[sqlx::test] async fn test_cancel_buy_with_pending_buy(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; let cancel = cancel_buy(&pool, "marcus").await; assert!(cancel.is_ok(), "expected ok but was {cancel:?}"); @@ -275,8 +275,8 @@ mod tests { #[sqlx::test] async fn test_cancel_buy_with_expired_queued_buy(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 200_f64).await?; sqlx::query!("UPDATE queued_buy SET time_created = now() - interval '6 minutes' WHERE user_id = 'marcus'") .execute(&pool) diff --git a/lean/src/sell/cancel_sell.rs b/lean/src/sell/cancel_sell.rs index 273c9bc..e482919 100644 --- a/lean/src/sell/cancel_sell.rs +++ b/lean/src/sell/cancel_sell.rs @@ -76,8 +76,8 @@ mod tests { #[sqlx::test] async fn test_cancel_sell_with_pending_sell(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 200_f64).await?; - init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; + let _log = add(&pool, "marcus", 200_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; commit_buy(&pool, "marcus").await?; init_sell(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; diff --git a/lean/src/sell/commit_sell.rs b/lean/src/sell/commit_sell.rs index 5f36552..c4618f2 100644 --- a/lean/src/sell/commit_sell.rs +++ b/lean/src/sell/commit_sell.rs @@ -104,8 +104,8 @@ mod tests { #[sqlx::test] async fn test_commit_sell_with_pending_sell(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 200_f64).await?; - init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; + let _log = add(&pool, "marcus", 200_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; commit_buy(&pool, "marcus").await?; init_sell::init_sell(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; @@ -145,8 +145,8 @@ mod tests { #[sqlx::test] async fn test_commit_sell_with_expired_queued_sell(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 200_f64).await?; - init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; + let _log = add(&pool, "marcus", 200_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; commit_buy(&pool, "marcus").await?; init_sell::init_sell(&pool, "marcus", "AAPL", 100_f64, 100_f64).await?; diff --git a/lean/src/sell/init_sell.rs b/lean/src/sell/init_sell.rs index 03f378c..9c2fc58 100644 --- a/lean/src/sell/init_sell.rs +++ b/lean/src/sell/init_sell.rs @@ -147,8 +147,8 @@ mod tests { #[sqlx::test] async fn test_init_sell_with_stocks_to_sell(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 100_f64).await?; - crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 100_f64).await?; + let _log = crate::add::add(&pool, "marcus", 100_f64).await?; + let _log = crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 100_f64).await?; crate::buy::commit_buy(&pool, "marcus").await?; let sell = init_sell(&pool, "marcus", "APPL", 50_f64, 100_f64).await; @@ -197,8 +197,8 @@ mod tests { #[sqlx::test] async fn test_init_buy_with_insufficient_stocks_to_sell(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 100_f64).await?; - crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 100_f64).await?; + let _log = crate::add::add(&pool, "marcus", 100_f64).await?; + let _log = crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 100_f64).await?; crate::buy::commit_buy(&pool, "marcus").await?; let sell = init_sell(&pool, "marcus", "APPL", 50_f64, 200_f64).await; @@ -231,8 +231,8 @@ mod tests { #[sqlx::test] async fn test_override_queued_sell(pool: PgPool) -> anyhow::Result<()> { - crate::add::add(&pool, "marcus", 400_f64).await?; - crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 200_f64).await?; + let _log = crate::add::add(&pool, "marcus", 400_f64).await?; + let _log = crate::buy::init_buy(&pool, "marcus", "APPL", 50_f64, 200_f64).await?; crate::buy::commit_buy(&pool, "marcus").await?; init_sell(&pool, "marcus", "APPL", 50_f64, 200_f64).await?; diff --git a/lean/src/trigger.rs b/lean/src/trigger.rs index 310ce8f..20ce5f4 100644 --- a/lean/src/trigger.rs +++ b/lean/src/trigger.rs @@ -165,7 +165,7 @@ mod tests { amount_dollars: 100.0, }; - add(&pool, "test", 100_f64).await?; + let _log = add(&pool, "test", 100_f64).await?; execute_buy_triggers(&pool, vec![trigger], "APPL", 1_f64).await?; diff --git a/lean/src/trigger/buy/cancel_set_buy.rs b/lean/src/trigger/buy/cancel_set_buy.rs index 3344f2a..4b44ad7 100644 --- a/lean/src/trigger/buy/cancel_set_buy.rs +++ b/lean/src/trigger/buy/cancel_set_buy.rs @@ -73,8 +73,8 @@ mod tests { #[sqlx::test] async fn test_cancel_set_buy_with_buy(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 100_f64).await?; - set_buy_amount(&pool, "marcus", "APPL", 100_f64).await?; + let _log = add(&pool, "marcus", 100_f64).await?; + let _log = set_buy_amount(&pool, "marcus", "APPL", 100_f64).await?; let cancel = cancel_set_buy(&pool, "marcus", "APPL").await; assert!(cancel.is_ok(), "expected ok but was {cancel:?}"); diff --git a/lean/src/trigger/buy/set_buy_amount.rs b/lean/src/trigger/buy/set_buy_amount.rs index 1b94564..a89f83f 100644 --- a/lean/src/trigger/buy/set_buy_amount.rs +++ b/lean/src/trigger/buy/set_buy_amount.rs @@ -105,7 +105,7 @@ mod tests { #[sqlx::test] async fn test_set_buy_amount_sufficient_funds(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 200_f64).await?; + let _log = add(&pool, "marcus", 200_f64).await?; let set = set_buy_amount(&pool, "marcus", "AAPL", 100_f64).await; assert!(set.is_ok(), "expected ok but was {set:?}"); @@ -131,7 +131,7 @@ mod tests { #[sqlx::test] async fn test_set_buy_with_already_existing_buy(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 200_f64).await?; + let _log = add(&pool, "marcus", 200_f64).await?; let set = set_buy_amount(&pool, "marcus", "AAPL", 100_f64).await; assert!(set.is_ok(), "expected ok but was {set:?}"); diff --git a/lean/src/trigger/buy/set_buy_trigger.rs b/lean/src/trigger/buy/set_buy_trigger.rs index 4ee3744..50a1be8 100644 --- a/lean/src/trigger/buy/set_buy_trigger.rs +++ b/lean/src/trigger/buy/set_buy_trigger.rs @@ -40,9 +40,8 @@ mod tests { #[sqlx::test] async fn test_set_buy_trigger_with_set_buy(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 1000_f64).await?; - - set_buy_amount(&pool, "marcus", "AAPL", 100_f64).await?; + let _log = add(&pool, "marcus", 1000_f64).await?; + let _log = set_buy_amount(&pool, "marcus", "AAPL", 100_f64).await?; let set = set_buy_trigger(&pool, "marcus", "AAPL", 100_f64).await; assert!(set.is_ok(), "expected error but was {set:?}"); diff --git a/lean/src/trigger/sell/cancel_set_sell.rs b/lean/src/trigger/sell/cancel_set_sell.rs index fc6e6a8..98ec584 100644 --- a/lean/src/trigger/sell/cancel_set_sell.rs +++ b/lean/src/trigger/sell/cancel_set_sell.rs @@ -76,8 +76,8 @@ mod tests { #[sqlx::test] async fn test_cancel_set_sell_with_set_sell(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 100.0).await?; - init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; + let _log = add(&pool, "marcus", 100.0).await?; + let _log = init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; commit_buy(&pool, "marcus").await?; set_sell_amount(&pool, "marcus", "TEST", 1.0).await?; set_sell_trigger(&pool, "marcus", "TEST", 40_f64).await?; diff --git a/lean/src/trigger/sell/set_sell_amount.rs b/lean/src/trigger/sell/set_sell_amount.rs index d8f4b6e..62812e1 100644 --- a/lean/src/trigger/sell/set_sell_amount.rs +++ b/lean/src/trigger/sell/set_sell_amount.rs @@ -109,8 +109,8 @@ mod tests { #[sqlx::test] async fn test_set_sell_amount_with_stock(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 1000_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 100_f64).await?; + let _log = add(&pool, "marcus", 1000_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 100_f64).await?; commit_buy(&pool, "marcus").await?; let stock = sqlx::query!( @@ -153,8 +153,8 @@ mod tests { #[sqlx::test] async fn test_set_sell_amount_with_prev_sell_trigger(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 1000_f64).await?; - init_buy(&pool, "marcus", "AAPL", 50_f64, 100_f64).await?; + let _log = add(&pool, "marcus", 1000_f64).await?; + let _log = init_buy(&pool, "marcus", "AAPL", 50_f64, 100_f64).await?; commit_buy(&pool, "marcus").await?; set_sell_amount(&pool, "marcus", "AAPL", 2_f64).await?; diff --git a/lean/src/trigger/sell/set_sell_trigger.rs b/lean/src/trigger/sell/set_sell_trigger.rs index 83321c8..7181897 100644 --- a/lean/src/trigger/sell/set_sell_trigger.rs +++ b/lean/src/trigger/sell/set_sell_trigger.rs @@ -33,8 +33,8 @@ mod tests { #[sqlx::test] async fn test_set_sell_trigger_no_set_amount(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 100.0).await?; - init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; + let _log = add(&pool, "marcus", 100.0).await?; + let _log = init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; commit_buy(&pool, "marcus").await?; let result = set_sell_trigger(&pool, "marcus", "TEST", 1.0).await; @@ -55,8 +55,8 @@ mod tests { #[sqlx::test] async fn test_set_sell_trigger_with_set_amount(pool: PgPool) -> anyhow::Result<()> { - add(&pool, "marcus", 100.0).await?; - init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; + let _log = add(&pool, "marcus", 100.0).await?; + let _log = init_buy(&pool, "marcus", "TEST", 50_f64, 100.0).await?; commit_buy(&pool, "marcus").await?; set_sell_amount(&pool, "marcus", "TEST", 1_f64).await?;