Skip to content

Commit

Permalink
test: fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Jun 30, 2024
1 parent 4c7b759 commit 225def7
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions contracts/sumtree-orderbook/src/tests/e2e/cases/test_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use rand::{rngs::StdRng, SeedableRng};

use super::utils::{assert, orders};
use crate::constants::MIN_TICK;
use crate::msg::{CalcOutAmtGivenInResponse, QueryMsg, SpotPriceResponse};
use crate::msg::{CalcOutAmtGivenInResponse, QueryMsg};
use crate::tests::e2e::modules::cosmwasm_pool::CosmwasmPool;
use crate::tick_math::{amount_to_value, tick_to_price, RoundingDirection};
use crate::types::Orderbook;
use crate::{
msg::{DenomsResponse, GetTotalPoolLiquidityResponse},
setup,
Expand Down Expand Up @@ -94,16 +95,16 @@ fn test_order_fuzz_linear_single_tick() {
fn test_order_fuzz_mixed() {
let oper_per_iteration = 1000;

run_for_duration(60, oper_per_iteration, |count| {
run_for_duration(10, oper_per_iteration, |count| {
run_fuzz_mixed(count, (-20, 20));
});
}

#[test]
fn test_order_fuzz_mixed_single_tick() {
let oper_per_iteration = 1000;
let oper_per_iteration = 13000;

run_for_duration(60, oper_per_iteration, |count| {
run_for_duration(60 * 60 * 2, oper_per_iteration, |count| {
run_fuzz_mixed(count, (0, 0));
});
}
Expand Down Expand Up @@ -331,8 +332,10 @@ impl MixedFuzzOperation {
}

// Place the order
place_random_market(cp, t, rng, &username, market_direction, max_amount);
Ok(true)
let amount =
place_random_market(cp, t, rng, &username, market_direction, max_amount);

Ok(amount != 0)
}
MixedFuzzOperation::CancelLimit => {
// If there are no active orders skip the operation
Expand Down Expand Up @@ -606,22 +609,28 @@ fn place_random_market(
} else {
("base", "quote")
};
// Get the spot price for the given denoms
let SpotPriceResponse { spot_price } = t
.contract
.query(&QueryMsg::SpotPrice {
base_asset_denom: token_in_denom.to_string(),
quote_asset_denom: token_out_denom.to_string(),
})
.unwrap();

// Get the next tick to determine liquidity
let Orderbook {
next_ask_tick,
next_bid_tick,
..
} = t.contract.query(&QueryMsg::OrderbookState {}).unwrap();
let next_tick = if order_direction == OrderDirection::Bid {
next_ask_tick
} else {
next_bid_tick
};

let price = tick_to_price(next_tick).unwrap();

// Determine how much liquidity is available for token in at the current spot price
// This only provides an estimate as the liquidity may be spread across multiple ticks
// Hence why it can be difficult to fill the ENTIRE liquidity
let liquidity_at_price_u256 = amount_to_value(
order_direction.opposite(),
Uint128::from(max),
Decimal256::from(spot_price),
price,
RoundingDirection::Up,
)
.unwrap();
Expand Down

0 comments on commit 225def7

Please sign in to comment.