Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Aug 28, 2024
1 parent 96bb42b commit c939db1
Show file tree
Hide file tree
Showing 17 changed files with 1,122 additions and 947 deletions.
14 changes: 0 additions & 14 deletions contracts/oraiswap-v3/src/tests/get_tickmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn test_get_tickmap() {
approve!(app, token_y, dex, initial_amount, alice).unwrap();

let fee_tier = FeeTier::new(Percentage::from_scale(5, 1), 1).unwrap();
let fee_tier_1 = FeeTier::new(Percentage::from_scale(1, 2), 2).unwrap();
let pool_key = PoolKey::new(token_x.to_string(), token_y.to_string(), fee_tier).unwrap();
let init_tick = 0;
let init_sqrt_price = calculate_sqrt_price(init_tick).unwrap();
Expand All @@ -46,21 +45,8 @@ fn test_get_tickmap() {
alice
);
assert!(result.is_ok());
add_fee_tier!(app, dex, fee_tier_1, alice).unwrap();
let result = create_pool!(
app,
dex,
token_x,
token_y,
fee_tier_1,
init_sqrt_price,
init_tick,
alice
)
.unwrap();

let pool = get_pool!(app, dex, token_x, token_y, fee_tier).unwrap();

let liquidity_delta = Liquidity::new(1000);

create_position!(
Expand Down
23 changes: 20 additions & 3 deletions contracts/oraiswap-v3/src/tests/helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Binary, Coin, Event, StdResult, Timestamp};
use cosmwasm_std::{Addr, Binary, Coin, Event, StdResult};
use cosmwasm_testing_util::{ExecuteResponse, MockResult};

use crate::{
Expand Down Expand Up @@ -476,6 +476,23 @@ pub fn extract_amount(events: &[Event], key: &str) -> Option<TokenAmount> {
None
}

pub fn subtract_assets(old_assets: &[Asset], new_assets: &[Asset]) -> Vec<Asset> {
let mut assets = vec![];
for asset in new_assets {
let amount = asset.amount
- old_assets
.iter()
.find(|a| a.info.eq(&asset.info))
.map(|a| a.amount)
.unwrap_or_default();
assets.push(Asset {
info: asset.info.clone(),
amount,
})
}
assets
}

pub mod macros {
macro_rules! create_dex {
($app:ident, $protocol_fee:expr,$owner: tt) => {{
Expand Down Expand Up @@ -1282,7 +1299,7 @@ pub mod macros {
macro_rules! multiple_swap {
($app:ident, $x_to_y:expr,$owner:tt,$bob:tt) => {{
use decimal::*;
let (dex, token_x, token_y) = init_dex_and_tokens!($app);
let (dex, token_x, token_y) = init_dex_and_tokens!($app, $owner);

let fee_tier = crate::FeeTier {
fee: crate::percentage::Percentage::from_scale(1, 3),
Expand Down Expand Up @@ -1433,7 +1450,7 @@ pub mod macros {
macro_rules! big_deposit_and_swap {
($app:ident, $x_to_y:expr,$owner:tt) => {{
let (dex, token_x, token_y) =
init_dex_and_tokens!($app, u128::MAX, Percentage::from_scale(1, 2));
init_dex_and_tokens!($app, u128::MAX, Percentage::from_scale(1, 2), $owner);

let mint_amount = 2u128.pow(75) - 1;

Expand Down
Loading

0 comments on commit c939db1

Please sign in to comment.