Skip to content

Commit

Permalink
fix: bump cw-it, use create_astroport_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloGie committed Jul 3, 2024
1 parent f15b1bc commit cdd2383
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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 = "0.4.0-rc.1"
cw-it = { git = "https://github.com/apollodao/cw-it.git", branch = "dev/astroport-native-lp-tokens"}
apollo-utils = "0.1.0"
astroport = "2.9.0"
astroport_v5 = { package = "astroport", version = "5.1.0" }
Expand All @@ -50,3 +50,4 @@ lto = true
opt-level = 3
overflow-checks = true
rpath = false

72 changes: 38 additions & 34 deletions cw-dex-astroport/tests/astroport_tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
mod tests {
use std::str::FromStr;

use apollo_cw_asset::{Asset, AssetInfo, AssetInfoBase, AssetList};
use apollo_utils::assets::separate_natives_and_cw20s;
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 cosmwasm_std::{assert_approx_eq, coin, coins, Addr, Coin, SubMsgResponse, Uint128};
use cw_it::cw_multi_test::{StargateKeeper, StargateMessageHandler};
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_balance_query, cw20_transfer, query_asset_balance};
use cw_dex_test_helpers::{cw20_transfer, query_asset_balance};
use cw_it::astroport::utils::AstroportContracts;
use cw_it::helpers::Unwrap;
use cw_it::cw_multi_test::{StargateKeeper, StargateMessageHandler};
use cw_it::helpers::{bank_balance_query, bank_send, Unwrap};
use cw_it::multi_test::modules::TokenFactory;
use cw_it::multi_test::MultiTestRunner;
use cw_it::test_tube::cosmrs::proto::cosmwasm::wasm::v1::MsgExecuteContractResponse;
Expand All @@ -27,7 +29,7 @@ mod tests {
#[cfg(feature = "osmosis-test-tube")]
use cw_it::osmosis_test_tube::OsmosisTestApp;

pub const DENOM_CREATION_FEE: &str = "0uosmo";
pub const DENOM_CREATION_FEE: &str = "10000000uosmo";
const TOKEN_FACTORY: &TokenFactory =
&TokenFactory::new("factory", 32, 16, 59 + 16, DENOM_CREATION_FEE);
pub fn get_test_runner<'a>() -> OwnedTestRunner<'a> {
Expand Down Expand Up @@ -66,6 +68,7 @@ mod tests {
initial_liquidity,
2,
TEST_CONTRACT_WASM_FILE_PATH,
&[Coin::from_str(DENOM_CREATION_FEE).unwrap()],
)
}

Expand All @@ -80,14 +83,14 @@ 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_addr, _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);

// Check contract's LP token balance before providing liquidity
let lp_token_before =
cw20_balance_query(&runner, lp_token_addr.clone(), contract_addr.clone()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types
assert_eq!(lp_token_before, Uint128::zero());

// Simulate Provide Liquidity. Not supported for concentrated liquidity, so we
Expand Down Expand Up @@ -142,7 +145,7 @@ mod tests {

// Query LP token balance after
let lp_token_after =
cw20_balance_query(&runner, lp_token_addr, contract_addr.clone()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types
assert_eq!(lp_token_after, expected_out);

// Query asset balances in contract, assert that all were used
Expand All @@ -163,27 +166,27 @@ mod tests {
fn test_withdraw_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_addr, _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, initial_liquidity).unwrap();
let admin = &accs[0];
let wasm = Wasm::new(&runner);

//Query admin LP token balance
let admin_lp_token_balance =
cw20_balance_query(&runner, lp_token_addr.clone(), admin.address()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types
let amount_to_send = admin_lp_token_balance / Uint128::from(2u128);

// Send LP tokens to contract
cw20_transfer(
bank_send(
&runner,
lp_token_addr.clone(),
contract_addr.clone(),
amount_to_send,
admin,
&contract_addr.clone(),
coins(amount_to_send.u128(), lp_token_denom),
)
.unwrap();

let contract_lp_token_balance =
cw20_balance_query(&runner, lp_token_addr.clone(), contract_addr.clone()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types
assert_eq!(contract_lp_token_balance, amount_to_send);

// Simulate withdraw liquidity to get expected out assets
Expand Down Expand Up @@ -226,7 +229,7 @@ mod tests {

// Query LP token balance after
let lp_token_balance_after =
cw20_balance_query(&runner, lp_token_addr, contract_addr.clone()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

// Assert that LP token balance is zero after withdrawing all liquidity
assert_eq!(lp_token_balance_after, Uint128::zero());
Expand All @@ -242,12 +245,12 @@ mod tests {
fn stake_all_lp_tokens<'a, R: Runner<'a>>(
runner: &'a R,
contract_addr: String,
lp_token_addr: String,
lp_token_denom: String,
signer: &SigningAccount,
) -> ExecuteResponse<MsgExecuteContractResponse> {
// Query LP token balance
let lp_token_balance =
cw20_balance_query(runner, lp_token_addr, contract_addr.clone()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

// Stake LP tokens
let stake_msg = ExecuteMsg::Stake {
Expand All @@ -256,7 +259,10 @@ mod tests {

runner
.execute_cosmos_msgs::<MsgExecuteContractResponse>(
&[stake_msg.into_cosmos_msg(contract_addr, vec![])],
&[stake_msg.into_cosmos_msg(
contract_addr,
coins(lp_token_balance.u128(), lp_token_denom),
)],
signer,
)
.unwrap()
Expand All @@ -277,22 +283,21 @@ mod tests {
) -> RunnerResult<()> {
let owned_runner = get_test_runner();
let runner = owned_runner.as_ref();
let (accs, lp_token_addr, _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, initial_liquidity).unwrap();

let admin = &accs[0];

// Query LP token balance
let lp_token_balance =
cw20_balance_query(&runner, lp_token_addr.clone(), admin.address()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

// Send LP tokens to the test contract
cw20_transfer(
bank_send(
&runner,
lp_token_addr.clone(),
contract_addr.clone(),
lp_token_balance,
admin,
&contract_addr.clone(),
coins(lp_token_balance.u128(), lp_token_denom),
)
.unwrap();

Expand All @@ -312,7 +317,7 @@ mod tests {

// Query LP token balance after
let lp_token_balance_after =
cw20_balance_query(&runner, lp_token_addr.clone(), contract_addr.to_string()).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

// Assert that LP token balance is 0
assert_eq!(lp_token_balance_after, Uint128::zero());
Expand All @@ -330,7 +335,7 @@ mod tests {

// Query LP token balance
let lp_token_balance_after_unstake =
cw20_balance_query(&runner, lp_token_addr, contract_addr).unwrap();
bank_balance_query(runner, contract_addr.clone(), lp_token_denom).unwrap();

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

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

// Assert that LP tokens have been unstakeed
assert_eq!(lp_token_balance_after_unstake, lp_token_balance);
Expand Down Expand Up @@ -442,7 +447,7 @@ mod tests {
let runner = owned_runner.as_ref();
let (
accs,
lp_token_addr,
lp_token_denom,
_pair_addr,
testing_contract_addr,
_asset_list,
Expand Down Expand Up @@ -546,7 +551,7 @@ mod tests {
wasm.execute(
&astroport_contracts.incentives.address,
&astroport_v5::incentives::ExecuteMsg::Incentivize {
lp_token: lp_token_addr.clone(),
lp_token: lp_token_denom.clone(),
schedule: astroport_v5::incentives::InputSchedule {
reward: incentive,
duration_periods: periods,
Expand All @@ -560,15 +565,14 @@ mod tests {

// Query LP token balance
let lp_token_balance =
cw20_balance_query(&runner, lp_token_addr.clone(), admin.address()).unwrap();
bank_balance_query(runner, admin.address().clone(), lp_token_denom).unwrap();

// Send LP tokens to the test contract
cw20_transfer(
bank_send(
&runner,
lp_token_addr.clone(),
testing_contract_addr.clone(),
lp_token_balance,
admin,
&testing_contract_addr.clone(),
coins(lp_token_balance.u128(), lp_token_denom),
)
.unwrap();

Expand All @@ -589,7 +593,7 @@ mod tests {
.query(
&astroport_contracts.incentives.address,
&astroport_v5::incentives::QueryMsg::PendingRewards {
lp_token: lp_token_addr.clone(),
lp_token: lp_token_denom.clone(),
user: testing_contract_addr.clone(),
},
)
Expand Down
3 changes: 3 additions & 0 deletions test-helpers/src/astroport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn setup_pool_and_test_contract<'a>(
initial_liquidity: Vec<(&str, u64)>,
native_denom_count: usize,
wasm_file_path: &str,
denom_creation_fee: &[Coin],
) -> RunnerResult<(
Vec<SigningAccount>,
String,
Expand Down Expand Up @@ -226,6 +227,7 @@ pub fn setup_pool_and_test_contract<'a>(
init_params,
admin,
None,
denom_creation_fee,
);

// Increase allowance of CW20's for Pair contract
Expand Down Expand Up @@ -318,3 +320,4 @@ pub fn instantiate_test_astroport_contract<'a, R: Runner<'a>>(
.data
.address)
}

0 comments on commit cdd2383

Please sign in to comment.