Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move integration tests out of unit-tests for dex-router-osmosis #664

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --bin schema"
test-tube = "test -- --include-ignored --test-threads=1"
test-tube = "test --features test-tube -- --include-ignored --test-threads=1"
test-tube-build = "build --release --lib --target wasm32-unknown-unknown --target-dir ./test-tube-build"
5 changes: 2 additions & 3 deletions smart-contracts/contracts/dex-router-osmosis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ name = "schema"
[features]
default = []
library = []
test-tube = ["osmosis-test-tube"]

[dependencies]
cosmwasm-std = { workspace = true }
Expand All @@ -36,6 +37,4 @@ mars-owner = { workspace = true }
osmosis-std = { workspace = true }
quasar-types = { workspace = true }
prost = { workspace = true }

[dev-dependencies]
osmosis-test-tube = { workspace = true }
osmosis-test-tube = { workspace = true, optional = true }
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod initialize;
mod remove_path;
mod set_path;
mod swap;
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use crate::contract::{execute, instantiate};
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::msg::{ExecuteMsg, InstantiateMsg};
use crate::state::PATHS;
use crate::tests::initialize::{
init_test_contract, setup_paths, single_gamm_pool_fixture, PoolWithDenoms,
ADMIN_BALANCE_AMOUNT, DENOM_BASE, DENOM_QUOTE, FEE_DENOM, TESTUBE_BINARY,
};
use crate::ContractError;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::Coin;
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use osmosis_test_tube::{Module, OsmosisTestApp, Wasm};

#[test]
fn test_if_not_owner_then_remove_path_fails() {
Expand Down Expand Up @@ -228,61 +222,3 @@ fn test_remove_one_of_two_paths() {
Some(vec![path2])
);
}

#[test]
#[ignore]
fn test_set_and_remove_path() {
let app = OsmosisTestApp::new();

// Create new account with initial funds
let admin = app
.init_account(&[
Coin::new(ADMIN_BALANCE_AMOUNT, FEE_DENOM),
Coin::new(ADMIN_BALANCE_AMOUNT, DENOM_BASE),
Coin::new(ADMIN_BALANCE_AMOUNT, DENOM_QUOTE),
])
.unwrap();
let wasm = Wasm::new(&app);

let mut pools: Vec<PoolWithDenoms> = vec![];
pools = single_gamm_pool_fixture(
&app,
&admin,
vec![DENOM_BASE.to_string(), DENOM_QUOTE.to_string()],
pools,
);

let contract_address = init_test_contract(&app, &admin, TESTUBE_BINARY);

setup_paths(
&wasm,
&contract_address,
vec![pools[0].pool],
pools[0].denom0.clone(),
pools[0].denom1.clone(),
&admin,
);
let _ = wasm
.execute(
&contract_address.to_string(),
&ExecuteMsg::RemovePath {
path: vec![pools.first().unwrap().pool],
bidirectional: true,
offer_denom: pools.first().unwrap().denom0.clone(),
ask_denom: pools.first().unwrap().denom1.clone(),
},
&[],
&admin,
)
.unwrap();

let resp: Result<Vec<Vec<SwapAmountInRoute>>, osmosis_test_tube::RunnerError> = wasm.query(
contract_address.as_str(),
&QueryMsg::PathsForPair {
offer_denom: pools.first().unwrap().denom0.clone(),
ask_denom: pools.first().unwrap().denom1.clone(),
},
);

assert!(resp.is_err(), "Path not found");
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
use crate::contract::{execute, instantiate};
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::tests::initialize::{
init_test_contract, setup_paths, PoolWithDenoms, ADMIN_BALANCE_AMOUNT, DENOM_BASE, DENOM_QUOTE,
FEE_DENOM, TESTUBE_BINARY,
};
use crate::msg::{ExecuteMsg, InstantiateMsg};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::Coin;
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use osmosis_test_tube::{Module, OsmosisTestApp, Wasm};

use super::initialize::single_cl_pool_fixture;

#[test]
fn test_if_not_owner_then_set_path_fails() {
Expand Down Expand Up @@ -52,61 +43,3 @@ fn test_if_path_is_empty_then_set_path_fails() {
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::EmptyPath {});
}

#[test]
#[ignore]
fn test_set_path_works() {
let app = OsmosisTestApp::new();

// Create new account with initial funds
let admin = app
.init_account(&[
Coin::new(ADMIN_BALANCE_AMOUNT, FEE_DENOM),
Coin::new(ADMIN_BALANCE_AMOUNT, DENOM_BASE),
Coin::new(ADMIN_BALANCE_AMOUNT, DENOM_QUOTE),
])
.unwrap();
let wasm = Wasm::new(&app);

let mut pools: Vec<PoolWithDenoms> = vec![];
pools = single_cl_pool_fixture(
&app,
&admin,
vec![DENOM_BASE.to_string(), DENOM_QUOTE.to_string()],
pools,
);

let contract_address = init_test_contract(&app, &admin, TESTUBE_BINARY);

setup_paths(
&wasm,
&contract_address,
vec![pools[0].pool],
pools[0].denom0.clone(),
pools[0].denom1.clone(),
&admin,
);

let resp: Vec<Vec<SwapAmountInRoute>> = wasm
.query(
contract_address.as_str(),
&QueryMsg::PathsForPair {
offer_denom: pools.first().unwrap().denom0.clone(),
ask_denom: pools.first().unwrap().denom1.clone(),
},
)
.unwrap();

// Assert that the set path is included in the response
let expected_path = SwapAmountInRoute {
pool_id: pools.first().unwrap().pool,
token_out_denom: pools.first().unwrap().denom1.clone(),
};

let paths_contain_expected = resp.iter().any(|path| path.contains(&expected_path));

assert!(
paths_contain_expected,
"Expected path was not found in the response"
);
}
Loading
Loading