Skip to content

Commit

Permalink
add tests for zero amounts deposit and withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKuczma committed Aug 16, 2024
1 parent e7262d6 commit fa92b14
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions amm/drink-tests/src/stable_swap_tests/tests_add_remove_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,147 @@ fn test_lp_withdraw_all_but_no_more() {
)
.expect_err("Should not successfully remove liquidity");
}

#[drink::test]
fn test_for_zero_deposit(mut session: Session) {
seed_account(&mut session, CHARLIE);
seed_account(&mut session, DAVE);
seed_account(&mut session, EVA);

let initial_reserves = vec![100000 * ONE_DAI, 100000 * ONE_USDT, 100000 * ONE_USDC];
let initial_supply = initial_reserves
.iter()
.map(|amount| amount * 100_000_000_000)
.collect::<Vec<u128>>();
let (stable_swap, tokens) = setup_stable_swap_with_tokens(
&mut session,
vec![18, 6, 6],
initial_supply.clone(),
10_000,
2_500_000,
200_000_000,
BOB,
vec![],
);

_ = stable_swap::add_liquidity(
&mut session,
stable_swap,
BOB,
1,
initial_reserves.clone(),
bob(),
)
.expect("Should successfully add liquidity");

// setup max allowance for stable swap contract on both tokens
transfer_and_increase_allowance(
&mut session,
stable_swap,
tokens.clone(),
CHARLIE,
vec![500 * ONE_DAI, 500 * ONE_USDT, 500 * ONE_USDC],
BOB,
);

let err = stable_swap::add_liquidity(
&mut session,
stable_swap,
CHARLIE,
0,
vec![0, 0, 0],
charlie(),
)
.expect_err("Should return an error");

assert_eq!(
err,
StablePoolError::InsufficientAmounts(),
"Should return appropriate error"
);

_ = stable_swap::add_liquidity(
&mut session,
stable_swap,
CHARLIE,
0,
vec![1, 0, 0],
charlie(),
)
.expect("Should min liqudity");
}

#[drink::test]
fn test_for_zero_withdrawal(mut session: Session) {
seed_account(&mut session, CHARLIE);
seed_account(&mut session, DAVE);
seed_account(&mut session, EVA);

let initial_reserves = vec![100000 * ONE_DAI, 100000 * ONE_USDT, 100000 * ONE_USDC];
let initial_supply = initial_reserves
.iter()
.map(|amount| amount * 100_000_000_000)
.collect::<Vec<u128>>();
let (stable_swap, _) = setup_stable_swap_with_tokens(
&mut session,
vec![18, 6, 6],
initial_supply.clone(),
10_000,
2_500_000,
200_000_000,
BOB,
vec![],
);

_ = stable_swap::add_liquidity(
&mut session,
stable_swap,
BOB,
1,
initial_reserves.clone(),
bob(),
)
.expect("Should successfully add liquidity");

let err = stable_swap::remove_liquidity_by_shares(
&mut session,
stable_swap,
BOB,
1,
vec![0, 0, 0],
bob(),
)
.expect_err("Should return an error");

assert_eq!(
err,
StablePoolError::InsufficientAmounts(),
"Should return appropriate error"
);

let err = stable_swap::remove_liquidity_by_amounts(
&mut session,
stable_swap,
BOB,
0,
vec![0, 0, 0],
bob(),
)
.expect_err("Should return an error");

assert_eq!(
err,
StablePoolError::InsufficientAmounts(),
"Should return appropriate error"
);

_ = stable_swap::remove_liquidity_by_amounts(
&mut session,
stable_swap,
BOB,
1,
vec![1, 0, 0],
bob(),
)
.expect("Should burn liquidity");
}

0 comments on commit fa92b14

Please sign in to comment.