Skip to content

Commit

Permalink
Fix proptest (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Aug 30, 2024
1 parent 896ef1b commit 1cefcb7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::setup::{
get_event_attributes_by_ty_and_key, init_test_contract, MAX_SLIPPAGE_HIGH,
PERFORMANCE_FEE_DEFAULT,
get_event_attributes_by_ty_and_key, init_test_contract_with_dex_router_and_swap_pools,
MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT,
};

use cl_vault::{
Expand Down Expand Up @@ -335,8 +335,9 @@ proptest! {
percentages in get_percentage_list(),
account_indexes in get_account_index_list()
) {
let (app, contract_address, _cl_pool_id, admin_account, _) = init_test_contract(
let (app, contract_address, _dex_router_address, _cl_pool_id, _pools, admin_account, _) = init_test_contract_with_dex_router_and_swap_pools(
"./test-tube-build/wasm32-unknown-unknown/release/cl_vault.wasm",
"../dex-router-osmosis/test-tube-build/wasm32-unknown-unknown/release/dex_router_osmosis.wasm",
&[
Coin::new(340282366920938463463374607431768211455, "uosmo"),
Coin::new(340282366920938463463374607431768211455, DENOM_BASE),
Expand All @@ -363,7 +364,8 @@ proptest! {
],
Uint128::zero(),
Uint128::zero(),
PERFORMANCE_FEE_DEFAULT
PERFORMANCE_FEE_DEFAULT,
false
);
let wasm = Wasm::new(&app);
let cl = ConcentratedLiquidity::new(&app);
Expand Down
55 changes: 37 additions & 18 deletions smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
use cl_vault::{helpers::generic::sort_tokens, msg::InstantiateMsg, state::VaultConfig};
use cosmwasm_std::{coin, Addr, Attribute, Coin, Decimal, Uint128};
use dex_router_osmosis::msg::{ExecuteMsg as DexExecuteMsg, InstantiateMsg as DexInstantiate};
use osmosis_std::types::{
cosmos::{bank::v1beta1::QueryBalanceRequest, base::v1beta1},
cosmwasm::wasm::v1::MsgExecuteContractResponse,
osmosis::concentratedliquidity::v1beta1::{
CreateConcentratedLiquidityPoolsProposal, Pool, PoolRecord, PoolsRequest,
use osmosis_std::{
try_proto_to_cosmwasm_coins,
types::{
cosmos::{bank::v1beta1::QueryBalanceRequest, base::v1beta1},
cosmwasm::wasm::v1::MsgExecuteContractResponse,
osmosis::{
concentratedliquidity::v1beta1::{
CreateConcentratedLiquidityPoolsProposal, Pool, PoolRecord, PoolsRequest,
},
poolmanager::v1beta1::SpotPriceRequest,
},
},
osmosis::poolmanager::v1beta1::SpotPriceRequest,
};
use osmosis_test_tube::{
cosmrs::proto::traits::Message,
Expand Down Expand Up @@ -119,6 +124,7 @@ pub fn fixture_dex_router(
Uint128::zero(),
Uint128::zero(),
performance_fee,
true
)
}

Expand Down Expand Up @@ -257,7 +263,7 @@ pub fn init_test_contract(
}

#[allow(clippy::too_many_arguments)]
fn init_test_contract_with_dex_router_and_swap_pools(
pub fn init_test_contract_with_dex_router_and_swap_pools(
filename_cl: &str,
filename_dex: &str,
admin_balance: &[Coin],
Expand All @@ -268,6 +274,7 @@ fn init_test_contract_with_dex_router_and_swap_pools(
token_min_amount0: Uint128,
token_min_amount1: Uint128,
performance_fee: u64,
use_pool_coins: bool,
) -> (
OsmosisTestApp,
Addr,
Expand Down Expand Up @@ -361,9 +368,11 @@ fn init_test_contract_with_dex_router_and_swap_pools(
// Create Balancer pools with previous vec of vec of coins
// TODO: We could be using a mixed set of CL and gAMM pools here
let mut lp_pools = vec![];
for pool_coins in &pools_coins {
let lp_pool = gm.create_basic_pool(pool_coins, &admin).unwrap();
lp_pools.push(lp_pool.data.pool_id);
if use_pool_coins {
for pool_coins in &pools_coins {
let lp_pool = gm.create_basic_pool(pool_coins, &admin).unwrap();
lp_pools.push(lp_pool.data.pool_id);
}
}

// Here we have 4 pools in pools_ids where the index 0 is the cl_pool id
Expand Down Expand Up @@ -399,7 +408,7 @@ fn init_test_contract_with_dex_router_and_swap_pools(

let deposit_ratio_base = calculate_deposit_ratio(
spot_price.spot_price,
tokens_provided,
tokens_provided.clone(),
create_position.data.amount0,
create_position.data.amount1,
DENOM_BASE.to_string(),
Expand All @@ -422,13 +431,23 @@ fn init_test_contract_with_dex_router_and_swap_pools(
.unwrap();

// Here we pass only the 3x swap LP pools, not the Vault CL pool id 1
set_dex_router_paths(
&app,
&contract_dex_router.data.address,
&lp_pools,
&pools_coins,
&admin,
);
if use_pool_coins {
set_dex_router_paths(
&app,
&contract_dex_router.data.address,
&lp_pools,
&pools_coins,
&admin,
);
} else {
set_dex_router_paths(
&app,
&contract_dex_router.data.address,
&[vault_pool.id],
&[try_proto_to_cosmwasm_coins(tokens_provided).unwrap()],
&admin,
);
}

// Instantiate vault
let contract_cl = wasm
Expand Down

0 comments on commit 1cefcb7

Please sign in to comment.