Skip to content

Commit

Permalink
program: add test for get_token_amount for bonk
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 2, 2024
1 parent 3170473 commit 446ecf6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions programs/drift/src/math/spot_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::state::oracle::{OraclePriceData, StrictOraclePrice};
use crate::state::spot_market::{SpotBalanceType, SpotMarket};
use crate::state::user::SpotPosition;


#[cfg(test)]
mod tests;

pub fn get_spot_balance(
token_amount: u128,
spot_market: &SpotMarket,
Expand Down
22 changes: 22 additions & 0 deletions programs/drift/src/math/spot_balance/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#[cfg(test)]
mod test {
use crate::math::spot_balance::{get_spot_balance, get_token_amount};
use crate::state::spot_market::{SpotBalanceType, SpotMarket};
use crate::SPOT_CUMULATIVE_INTEREST_PRECISION;

#[test]
fn bonk() {
let spot_market = SpotMarket {
cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION,
decimals: 5,
..SpotMarket::default_quote_market()
};

let one_bonk = 10_u128.pow(spot_market.decimals);

let balance = get_spot_balance(one_bonk, &spot_market, &SpotBalanceType::Deposit, false).unwrap();

let token_amount = get_token_amount(balance, &spot_market, &SpotBalanceType::Deposit).unwrap();
assert_eq!(token_amount, one_bonk);
}
}

0 comments on commit 446ecf6

Please sign in to comment.