Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusDunn committed Dec 16, 2023
1 parent 9171524 commit 7c62ff6
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 48 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
);
Expand Down
4 changes: 2 additions & 2 deletions lean/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions lean/src/buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down Expand Up @@ -75,16 +75,16 @@ 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(())
}

#[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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:?}");

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:?}");

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lean/src/sell/cancel_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
8 changes: 4 additions & 4 deletions lean/src/sell/commit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
12 changes: 6 additions & 6 deletions lean/src/sell/init_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion lean/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
4 changes: 2 additions & 2 deletions lean/src/trigger/buy/cancel_set_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down
4 changes: 2 additions & 2 deletions lean/src/trigger/buy/set_buy_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand All @@ -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:?}");
Expand Down
5 changes: 2 additions & 3 deletions lean/src/trigger/buy/set_buy_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");

Expand Down
4 changes: 2 additions & 2 deletions lean/src/trigger/sell/cancel_set_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
8 changes: 4 additions & 4 deletions lean/src/trigger/sell/set_sell_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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?;
Expand Down
8 changes: 4 additions & 4 deletions lean/src/trigger/sell/set_sell_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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?;
Expand Down

0 comments on commit 7c62ff6

Please sign in to comment.