Skip to content

Commit

Permalink
tests: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloGie committed Aug 2, 2024
1 parent 9f2503f commit 62a0964
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
apollo-cw-asset = "0.1.1"
osmosis-std = "0.22.0"
cw-it = { git = "https://github.com/apollodao/cw-it.git", rev = "aa46a97c9fb7768842453a045a8eb44d381fc09b"}
cw-it = { git = "https://github.com/apollodao/cw-it.git", rev = "5bcc131991e3d80ba33be71129eab887dfc4c246", features = ["multi-test"]}
apollo-utils = "0.1.0"
astroport = "2.9.0"
astroport_v5 = { package = "astroport", version = "5.1.0" }
test-case = "3.0.0"
proptest = "1.0.0"
cw-multi-test = "=1.2.0"
apollo-cw-multi-test = "0.18.1"
apollo-cw-multi-test = { git = "https://github.com/apollodao/cw-multi-test.git", rev = "7e7bc2b91a8199c47815b45ef23b3ab07390ae3a",features = ["stargate"] }
getrandom = { version = "0.2", features = ["js"] }

# Workspace packages
Expand Down
77 changes: 45 additions & 32 deletions cw-dex-astroport/tests/astroport_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,32 @@ mod tests {
use apollo_utils::coins::coin_from_str;
use apollo_utils::submessages::{find_event, parse_attribute_value};
use astroport::factory::PairType;
use astroport_v5::asset::Asset as AstroportAsset;
use astroport_v5::asset::{Asset as AstroportAsset, PairInfo};
use astroport_v5::pair::QueryMsg as PairQueryMsg;
use cosmwasm_std::testing::{mock_env, MockStorage};

Check failure on line 13 in cw-dex-astroport/tests/astroport_tests.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `MockStorage`, `mock_env`
use cosmwasm_std::{assert_approx_eq, coin, coins, Addr, Coin, SubMsgResponse, Uint128};
use cosmwasm_std::{assert_approx_eq, coin, coins, Addr, Coin, Empty, SubMsgResponse, Uint128};
use cw_dex_astroport::AstroportPool;
use cw_dex_test_contract::msg::{AstroportExecuteMsg, ExecuteMsg, QueryMsg};
use cw_dex_test_helpers::astroport::setup_pool_and_test_contract;
use cw_dex_test_helpers::{cw20_transfer, query_asset_balance};
use cw_it::astroport::utils::AstroportContracts;
use cw_it::cosmrs::proto::cosmos::tx::signing::v1beta1::signature_descriptor::data::Multi;

Check failure on line 20 in cw-dex-astroport/tests/astroport_tests.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `cw_it::cosmrs::proto::cosmos::tx::signing::v1beta1::signature_descriptor::data::Multi`
use cw_it::cw_multi_test::{StargateKeeper, StargateMessageHandler};
use cw_it::helpers::{bank_balance_query, bank_send, Unwrap};
use cw_it::helpers::{bank_all_balances_query, bank_balance_query, bank_send, Unwrap};
use cw_it::multi_test::api::MockApiBech32;
use cw_it::multi_test::modules::TokenFactory;
use cw_it::multi_test::test_addresses::MockAddressGenerator;
use cw_it::multi_test::MultiTestRunner;
use cw_it::osmosis_std::types::cosmos::bank::v1beta1::QueryBalanceRequest;

Check failure on line 27 in cw-dex-astroport/tests/astroport_tests.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `cw_it::osmosis_std::types::cosmos::bank::v1beta1::QueryBalanceRequest`
use cw_it::test_tube::cosmrs::proto::cosmwasm::wasm::v1::MsgExecuteContractResponse;
use cw_it::test_tube::{
Account, ExecuteResponse, Module, Runner, RunnerResult, SigningAccount, Wasm,
};
use cw_it::traits::CwItRunner;
use cw_it::{OwnedTestRunner, TestRunner};
use cw_multi_test::MockApiBech32;
use osmosis_std::types::cosmos::bank::v1beta1::{
QueryAllBalancesRequest, QueryAllBalancesResponse,

Check failure on line 35 in cw-dex-astroport/tests/astroport_tests.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `QueryAllBalancesRequest`, `QueryAllBalancesResponse`
};
use std::str::FromStr;
use test_case::test_case;
// use cw_multi_test::BasicAppBuilder;
Expand All @@ -42,33 +49,21 @@ mod tests {
"multi-test" => {
let mut stargate_keeper = StargateKeeper::new();
TOKEN_FACTORY.register_msgs(&mut stargate_keeper);
// let app = BasicAppBuilder::<Empty, Empty>::new()
// .with_stargate(stargate_keeper)
// .with_api(MockApiBech32::new("osmo"))
// .build(|_, _, _| {});
// BasicAppBuilder::construct(api, block, storage, bank, wasm, custom, staking, distribution, ibc, gov, stargate)
// Construct the App using the AppBuilder
let app = AppBuilder::construct(
MockApiBech32::new("osmo"),
mock_env().block,
MockStorage::new(),
BankKeeper::new(),
WasmKeeper::new(),
FailingModule::new(),
StakeKeeper::new(),
DistributionKeeper::new(),
FailingModule::new(),
FailingModule::new(),
stargate_keeper,
)
.build(|_, _, _| {});

// Instantiate MultiTestRunner with the constructed app
let multi_test_runner = MultiTestRunner::<BankKeeper, MockApiBech32> {
let wasm_keeper: WasmKeeper<Empty, Empty> =
WasmKeeper::new().with_address_generator(MockAddressGenerator);

let app = BasicAppBuilder::<Empty, Empty>::new()
.with_api(MockApiBech32::new("osmo"))
.with_stargate(stargate_keeper)
.with_wasm(wasm_keeper)
.build(|_, _, _| {});

let multi_test_runner = MultiTestRunner {
app,
address_prefix: "osmo",
};

OwnedTestRunner::MultiTest(multi_test_runner)
}
#[cfg(feature = "osmosis-test-tube")]
Expand Down Expand Up @@ -112,14 +107,16 @@ mod tests {
pub fn test_provide_liquidity(pool_type: PairType, initial_liquidity: Vec<(&str, u64)>) {
let owned_runner = get_test_runner();
let runner = owned_runner.as_ref();
let (accs, lp_token_denom, _pair_addr, contract_addr, asset_list, _) =
let (accs, lp_token_denom, pair_addr, contract_addr, asset_list, _) =
setup_pool_and_testing_contract(&runner, pool_type.clone(), initial_liquidity).unwrap();
let admin = &accs[0];
let wasm = Wasm::new(&runner);

let pair_config_res: PairInfo = wasm.query(&pair_addr, &PairQueryMsg::Pair {}).unwrap();
println!("pair_config_res: {:?}", pair_config_res);
// Check contract's LP token balance before providing liquidity
let lp_token_before =
bank_balance_query(&runner, contract_addr.clone(), lp_token_denom.clone()).unwrap();
println!("lp_token_before {:?}", lp_token_before);
assert_eq!(lp_token_before, Uint128::zero());

// Simulate Provide Liquidity. Not supported for concentrated liquidity, so we
Expand All @@ -134,8 +131,13 @@ mod tests {
}
};

println!("expected_out: {:?}", expected_out);

let (funds, cw20s) = separate_natives_and_cw20s(&asset_list);

println!("funds: {:?}", funds);
println!("cw20s: {:?}", cw20s);

// Send cw20 tokens to the contract
for cw20 in cw20s {
cw20_transfer(
Expand All @@ -150,7 +152,8 @@ mod tests {

// Provide liquidity with min_out one more than expected_out. Should fail.
let unwrap = Unwrap::Err("Slippage is more than expected");
let min_out = expected_out + Uint128::one();
let min_out = expected_out + Uint128::new(10);
println!("min_out: {:?}", min_out);
let provide_msg = ExecuteMsg::ProvideLiquidity {
assets: asset_list.clone(),
min_out,
Expand All @@ -159,6 +162,7 @@ mod tests {
&[provide_msg.into_cosmos_msg(contract_addr.clone(), funds.clone())],
admin,
));
println!("after unwrap");

// Provide liquidity with expected_out as min_out. Should succeed.
let provide_msg = ExecuteMsg::ProvideLiquidity {
Expand Down Expand Up @@ -198,7 +202,7 @@ mod tests {
let (accs, lp_token_denom, _pair_addr, contract_addr, asset_list, _) =
setup_pool_and_testing_contract(&runner, pool_type, initial_liquidity).unwrap();
let admin = &accs[0];
let wasm = Wasm::new(&runner);

println!("lp_token_denom: {:?}", lp_token_denom);
let admin_lp_token_balance =
bank_balance_query(&runner, admin.address(), lp_token_denom.clone()).unwrap();
Expand All @@ -207,7 +211,7 @@ mod tests {
bank_balance_query(&runner, contract_addr.clone(), lp_token_denom.clone()).unwrap();
println!("admin_lp_token_balance: {:?}", admin_lp_token_balance);
let amount_to_send = admin_lp_token_balance / Uint128::from(2u128);

let wasm = Wasm::new(&runner);
// Send LP tokens to contract
bank_send(
&runner,
Expand Down Expand Up @@ -324,6 +328,15 @@ mod tests {
let lp_token_balance =
bank_balance_query(&runner, contract_addr.clone(), lp_token_denom.clone()).unwrap();

let all_balances_res =
bank_all_balances_query(&runner, admin.address().clone(), None).unwrap();

println!("all_balances_res : {:?}", all_balances_res);

let all_balances_res =
bank_all_balances_query(&runner, contract_addr.clone(), None).unwrap();

println!("all_balances_res : {:?}", all_balances_res);
// Send LP tokens to the test contract
bank_send(
&runner,
Expand Down
4 changes: 2 additions & 2 deletions test-helpers/src/astroport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub fn setup_pool_and_test_contract<'a>(
amount: Uint128::MAX,
});


let accs = runner.init_accounts(&initial_balances, 10).unwrap();

let admin = &accs[0];
Expand Down Expand Up @@ -256,7 +255,8 @@ pub fn setup_pool_and_test_contract<'a>(
let res = wasm
.execute(&pair_addr, &provide_liq_msg, &native_coins, admin)
.unwrap();

println!("pair_addr: {}", pair_addr);
println!("admin: {}", admin.address());
println!("provide liquidity res: {:?}", res);

// Upload test contract wasm file
Expand Down

0 comments on commit 62a0964

Please sign in to comment.