Skip to content

Commit

Permalink
Merge pull request #36 from Levana-Protocol/tests-deposit
Browse files Browse the repository at this point in the history
tests: Fix deposit fee check
  • Loading branch information
lvn-rusty-dragon authored Sep 20, 2024
2 parents f3f9e2c + 5abbb8f commit 50edb73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions contract/src/cpmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct Buy {
}

#[must_use]
#[derive(Debug)]
pub struct Sell {
/// Funds the user will receive for the sale
pub funds: Collateral,
Expand Down
29 changes: 14 additions & 15 deletions contract/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cell::RefCell;
use std::{cell::RefCell, str::FromStr};

use cosmwasm_std::{Addr, Uint256};
use cw_multi_test::{error::AnyResult, App, AppResponse, ContractWrapper, Executor};
Expand Down Expand Up @@ -417,27 +417,26 @@ fn winning_bet() {
fn deposit_fees_check() {
let app = Predict::new();

let house_yes_tokens = app.query_tokens(&app.house, 0).unwrap();
let house_no_tokens = app.query_tokens(&app.house, 1).unwrap();
let before_market = app.query_latest_market().unwrap();
let before_lp_shares = before_market.lp_shares;
let lp_share_value = before_lp_shares.0 / (house_yes_tokens.0 + house_no_tokens.0);

let bet_amount = 1000u64;
app.place_bet(&app.better, 0, bet_amount).unwrap();

let deposit_fee = before_market.deposit_fee * Decimal256::from_ratio(bet_amount, 1u64);
let deposit_fee: Uint256 = deposit_fee.to_uint_ceil();

// TODO come back to this later
// let tokens = app.query_tokens(&app.better, 0).unwrap();

// let tokens_in_collateral = {
// let mut market = app.query_latest_market().unwrap();
// market.sell(0.into(), tokens).unwrap()
// };

// let calculated_deposit_fees = Collateral(Uint256::from(bet_amount))
// .checked_sub(tokens_in_collateral.funds)
// .unwrap()
// .0;
// assert_eq!(deposit_fee, calculated_deposit_fees);
let after_market = app.query_latest_market().unwrap();
let after_lp_shares = after_market.lp_shares;
let diff_lp_shares = after_lp_shares - before_lp_shares;
let lp_share_to_collateral = diff_lp_shares.0 / lp_share_value;
// Because half lp shares was burnt
let calculated_deposit_fee = lp_share_to_collateral
.checked_mul(Uint256::from_str("2").unwrap())
.unwrap();
assert_eq!(deposit_fee, calculated_deposit_fee);
assert_eq!(deposit_fee, Uint256::from(10u8));
}

Expand Down

0 comments on commit 50edb73

Please sign in to comment.