Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 committed Jul 31, 2024
1 parent 7747475 commit 7e75c23
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 33 deletions.
4 changes: 2 additions & 2 deletions contracts/carrot-app/examples/install_savings_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use cw_orch::{
prelude::Stargate,
tokio::runtime::Runtime,
};
use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::cosmos::authz::v1beta1::MsgGrantResponse;
use dotenv::dotenv;

use carrot_app::{
msg::{AppInstantiateMsg, CreatePositionMessage},
state::AutocompoundRewardsConfig,
};
use osmosis_std::types::cosmos::authz::v1beta1::MsgGrantResponse;

pub struct CarrotAppInitData {
pub pool_id: u64,
Expand Down Expand Up @@ -179,7 +179,7 @@ mod utils {
use carrot_app::contract::{APP_ID, APP_VERSION};
use cosmwasm_std::{to_json_binary, to_json_vec};
use cw_orch::{environment::CwEnv, prelude::*};
use osmosis_std::types::{
use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::{
cosmos::{
authz::v1beta1::{GenericAuthorization, Grant, MsgGrant},
bank::v1beta1::SendAuthorization,
Expand Down
55 changes: 39 additions & 16 deletions contracts/carrot-app/tests/autocompound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,45 @@ use carrot_app::state::AutocompoundRewardsConfig;
use cosmwasm_std::{coin, coins, Uint128, Uint64};
use cw_asset::AssetBase;
use cw_orch::{anyhow, prelude::*};
use cw_orch_osmosis_test_tube::osmosis_test_tube::{Account, Module};
use osmosis_std::shim::Timestamp;
use osmosis_std::types::cosmos::base::v1beta1;
use osmosis_std::types::osmosis::incentives::MsgCreateGauge;
use osmosis_std::types::osmosis::lockup::{LockQueryType, QueryCondition};
use cw_orch_osmosis_test_tube::osmosis_test_tube::{
osmosis_std::{
shim::Timestamp,
types::{
cosmos::base::v1beta1,
osmosis::{
incentives::{MsgCreateGauge, QueryLockableDurationsRequest},
lockup::{LockQueryType, QueryCondition},
},
},
},
Account, Module,
};

#[test]
fn check_autocompound() -> anyhow::Result<()> {
let (pool_id, carrot_app) = setup_test_tube(false)?;

let chain = carrot_app.environment().clone();
let mut chain = carrot_app.environment().clone();
chain.add_balance(
chain.sender_addr(),
coins(5_000_000, format!("gamm/pool/{pool_id}")),
)?;

// Add incentive
{
let test_tube = chain.app.borrow();
let time = test_tube.get_block_timestamp().plus_seconds(5);
let incentives = Incentives::new(&*test_tube);
let lockable_durations =
incentives.query_lockable_durations(&QueryLockableDurationsRequest {})?;
let _ = incentives.create_gauge(
MsgCreateGauge {
is_perpetual: false,
owner: chain.sender.address(),
distribute_to: Some(QueryCondition {
lock_query_type: LockQueryType::NoLock.into(),
denom: "".to_owned(),
duration: None,
lock_query_type: LockQueryType::ByDuration.into(),
denom: format!("gamm/pool/{pool_id}"),
duration: Some(lockable_durations.lockable_durations[0].clone()),
timestamp: None,
}),
coins: vec![v1beta1::Coin {
Expand All @@ -49,10 +63,11 @@ fn check_autocompound() -> anyhow::Result<()> {
nanos: time.subsec_nanos() as i32,
}),
num_epochs_paid_over: 10,
pool_id,
pool_id: 0, // Can't set it with LockQueryType::ByDuration
},
&chain.sender,
)?;
chain.wait_seconds(lockable_durations.lockable_durations[0].seconds as u64)?;
}
// Create position
create_position(
Expand Down Expand Up @@ -85,7 +100,8 @@ fn check_autocompound() -> anyhow::Result<()> {
// Check it has some rewards to autocompound first
let status = carrot_app.compound_status()?;
assert!(!status.spread_rewards.is_empty());
assert!(status.incentives.iter().any(|c| c.denom == GAS_DENOM));
// TODO: broken for a while https://github.com/osmosis-labs/test-tube/pull/53
// assert!(status.incentives.iter().any(|c| c.denom == GAS_DENOM));

// Save balances
let balance_before_autocompound: AssetsBalanceResponse = carrot_app.balance()?;
Expand Down Expand Up @@ -135,6 +151,10 @@ fn stranger_autocompound() -> anyhow::Result<()> {
let (pool_id, carrot_app) = setup_test_tube(false)?;

let mut chain = carrot_app.environment().clone();
chain.add_balance(
chain.sender_addr(),
coins(5_000_000, format!("gamm/pool/{pool_id}")),
)?;
let stranger = chain.init_account(coins(LOTS, GAS_DENOM))?;

// Create position
Expand All @@ -150,14 +170,16 @@ fn stranger_autocompound() -> anyhow::Result<()> {
let test_tube = chain.app.borrow();
let time = test_tube.get_block_timestamp().plus_seconds(5);
let incentives = Incentives::new(&*test_tube);
let lockable_durations =
incentives.query_lockable_durations(&QueryLockableDurationsRequest {})?;
let _ = incentives.create_gauge(
MsgCreateGauge {
is_perpetual: false,
owner: chain.sender.address(),
distribute_to: Some(QueryCondition {
lock_query_type: LockQueryType::NoLock.into(),
denom: "".to_owned(),
duration: None,
lock_query_type: LockQueryType::ByDuration.into(),
denom: format!("gamm/pool/{pool_id}"),
duration: Some(lockable_durations.lockable_durations[0].clone()),
timestamp: None,
}),
coins: vec![v1beta1::Coin {
Expand All @@ -169,7 +191,7 @@ fn stranger_autocompound() -> anyhow::Result<()> {
nanos: time.subsec_nanos() as i32,
}),
num_epochs_paid_over: 10,
pool_id,
pool_id: 0, // Can't set it with LockQueryType::ByDuration
},
&chain.sender,
)?;
Expand Down Expand Up @@ -197,7 +219,8 @@ fn stranger_autocompound() -> anyhow::Result<()> {
// Check it has some rewards to autocompound first
let status = carrot_app.compound_status()?;
assert!(!status.spread_rewards.is_empty());
assert!(status.incentives.iter().any(|c| c.denom == GAS_DENOM));
// TODO: broken for a while https://github.com/osmosis-labs/test-tube/pull/53
// assert!(status.incentives.iter().any(|c| c.denom == GAS_DENOM));
let CompoundStatus::Cooldown(cooldown) = status.status else {
panic!("Contract should be still on cooldown")
};
Expand Down
28 changes: 20 additions & 8 deletions contracts/carrot-app/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ use cosmwasm_std::{coin, coins, to_json_binary, to_json_vec, Decimal, Uint128, U
use cw_asset::AssetInfoUnchecked;
use cw_orch::anyhow;
use cw_orch::prelude::*;
use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::{
cosmos::bank::v1beta1::SendAuthorization,
cosmwasm::wasm::v1::MsgExecuteContract,
osmosis::concentratedliquidity::v1beta1::{
CreateConcentratedLiquidityPoolsProposal, MsgAddToPosition, MsgCollectIncentives,
MsgCollectSpreadRewards, PoolRecord,
},
};
use cw_orch_osmosis_test_tube::osmosis_test_tube::{
osmosis_std::types::{
cosmos::{
Expand All @@ -30,12 +38,6 @@ use cw_orch_osmosis_test_tube::osmosis_test_tube::{
ConcentratedLiquidity, Gamm, GovWithAppAccess, Module,
};
use cw_orch_osmosis_test_tube::OsmosisTestTube;
use osmosis_std::types::cosmos::bank::v1beta1::SendAuthorization;
use osmosis_std::types::cosmwasm::wasm::v1::MsgExecuteContract;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::{
CreateConcentratedLiquidityPoolsProposal, MsgAddToPosition, MsgCollectIncentives,
MsgCollectSpreadRewards, PoolRecord,
};
use prost::Message;
use prost_types::Any;

Expand Down Expand Up @@ -422,8 +424,14 @@ pub fn give_authorizations<Chain: CwEnv + Stargate>(
}

pub mod incentives {
use cw_orch_osmosis_test_tube::osmosis_test_tube::{fn_execute, Module, Runner};
use osmosis_std::types::osmosis::incentives::{MsgCreateGauge, MsgCreateGaugeResponse};
use cw_orch_osmosis_test_tube::osmosis_test_tube::{
fn_execute, fn_query,
osmosis_std::types::osmosis::incentives::{
MsgCreateGauge, MsgCreateGaugeResponse, QueryLockableDurationsRequest,
QueryLockableDurationsResponse,
},
Module, Runner,
};

#[allow(unused)]
pub struct Incentives<'a, R: Runner<'a>> {
Expand All @@ -445,5 +453,9 @@ pub mod incentives {
// (pub)? <fn_name>: <request_type> => <response_type>
pub create_gauge: MsgCreateGauge => MsgCreateGaugeResponse
}

fn_query! {
pub query_lockable_durations ["/osmosis.incentives.Query/LockableDurations"]: QueryLockableDurationsRequest => QueryLockableDurationsResponse
}
}
}
2 changes: 1 addition & 1 deletion contracts/carrot-app/tests/deposit_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use common::{DEX_NAME, GAS_DENOM};
use cosmwasm_std::{coin, coins, Decimal, Uint128, Uint256};
use cw_orch::anyhow;
use cw_orch::prelude::*;
use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::osmosis::concentratedliquidity::v1beta1::PositionByIdRequest;
use cw_orch_osmosis_test_tube::osmosis_test_tube::{
osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgWithdrawPosition,
ConcentratedLiquidity, Module,
};
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::PositionByIdRequest;

#[test]
fn deposit_lands() -> anyhow::Result<()> {
Expand Down
12 changes: 7 additions & 5 deletions contracts/carrot-app/tests/recreate_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ use carrot_app::state::AutocompoundRewardsConfig;
use common::REWARD_ASSET;
use cosmwasm_std::{coin, coins, Uint128, Uint256, Uint64};
use cw_orch::{anyhow, prelude::*};
use cw_orch_osmosis_test_tube::osmosis_test_tube::{
osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgWithdrawPosition,
ConcentratedLiquidity, Module,
use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::osmosis::concentratedliquidity::v1beta1::PositionByIdRequest;
use cw_orch_osmosis_test_tube::{
osmosis_test_tube::{
osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgWithdrawPosition,
ConcentratedLiquidity, Module,
},
OsmosisTestTube,
};
use cw_orch_osmosis_test_tube::OsmosisTestTube;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::PositionByIdRequest;

#[test]
fn create_multiple_positions() -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ wasm:
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
${image}:0.15.0
${image}:0.16.0

# wasm fast
wasm-f:
Expand Down

0 comments on commit 7e75c23

Please sign in to comment.