Skip to content

Commit

Permalink
Improve consistency of fake QuasarQuerier (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Aug 27, 2024
1 parent d4b6bbd commit aa4b1a6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
ContractError,
};
use cosmwasm_std::{
coin, Addr, Coin, Decimal, Decimal256, Deps, DepsMut, Env, QuerierWrapper, Storage, Timestamp,
Uint128, Uint256,
coin, Addr, Coin, Decimal, Decimal256, Deps, Env, QuerierWrapper, Storage, Timestamp, Uint128,
Uint256,
};

use super::coinlist::CoinList;
Expand Down
42 changes: 23 additions & 19 deletions smart-contracts/osmosis/contracts/cl-vault/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ use crate::state::{
PoolConfig, Position, VaultConfig, POOL_CONFIG, POSITION, RANGE_ADMIN, VAULT_CONFIG,
};

pub const POOL_ID: u64 = 1;
pub const BASE_DENOM: &str = "base";
pub const QUOTE_DENOM: &str = "quote";

pub struct QuasarQuerier {
position: FullPositionBreakdown,
current_tick: i64,
Expand Down Expand Up @@ -104,10 +108,10 @@ impl Querier for QuasarQuerier {
address: "idc".to_string(),
incentives_address: "not being used".to_string(),
spread_rewards_address: "not being used".to_string(),
id: 1,
id: POOL_ID,
current_tick_liquidity: "100".to_string(),
token0: "uosmo".to_string(),
token1: "uion".to_string(),
token0: BASE_DENOM.to_string(),
token1: QUOTE_DENOM.to_string(),
current_sqrt_price: "not used".to_string(),
current_tick: self.current_tick,
tick_spacing: 100,
Expand Down Expand Up @@ -170,27 +174,27 @@ pub fn mock_deps_with_querier_with_balance(
position: Some(OsmoPosition {
position_id: 1,
address: MOCK_CONTRACT_ADDR.to_string(),
pool_id: 1,
pool_id: POOL_ID,
lower_tick: 100,
upper_tick: 1000,
join_time: None,
liquidity: "1000000.1".to_string(),
}),
asset0: Some(OsmoCoin {
denom: "token0".to_string(),
denom: BASE_DENOM.to_string(),
amount: "1000000".to_string(),
}),
asset1: Some(OsmoCoin {
denom: "token1".to_string(),
denom: QUOTE_DENOM.to_string(),
amount: "1000000".to_string(),
}),
claimable_spread_rewards: vec![
OsmoCoin {
denom: "token0".to_string(),
denom: BASE_DENOM.to_string(),
amount: "100".to_string(),
},
OsmoCoin {
denom: "token1".to_string(),
denom: QUOTE_DENOM.to_string(),
amount: "100".to_string(),
},
],
Expand All @@ -210,9 +214,9 @@ pub fn mock_deps_with_querier_with_balance(
.save(
storage,
&PoolConfig {
pool_id: 1,
token0: "token0".to_string(),
token1: "token1".to_string(),
pool_id: POOL_ID,
token0: BASE_DENOM.to_string(),
token1: QUOTE_DENOM.to_string(),
},
)
.unwrap();
Expand Down Expand Up @@ -256,27 +260,27 @@ pub fn mock_deps_with_querier(
position: Some(OsmoPosition {
position_id,
address: MOCK_CONTRACT_ADDR.to_string(),
pool_id: 1,
pool_id: POOL_ID,
lower_tick: 100,
upper_tick: 1000,
join_time: None,
liquidity: "1000000.1".to_string(),
}),
asset0: Some(OsmoCoin {
denom: "token0".to_string(),
denom: BASE_DENOM.to_string(),
amount: "1000000".to_string(),
}),
asset1: Some(OsmoCoin {
denom: "token1".to_string(),
denom: QUOTE_DENOM.to_string(),
amount: "1000000".to_string(),
}),
claimable_spread_rewards: vec![
OsmoCoin {
denom: "token0".to_string(),
denom: BASE_DENOM.to_string(),
amount: "100".to_string(),
},
OsmoCoin {
denom: "token1".to_string(),
denom: QUOTE_DENOM.to_string(),
amount: "100".to_string(),
},
],
Expand Down Expand Up @@ -306,9 +310,9 @@ pub fn mock_deps_with_querier(
.save(
storage,
&PoolConfig {
pool_id: 1,
token0: "token0".to_string(),
token1: "token1".to_string(),
pool_id: POOL_ID,
token0: BASE_DENOM.to_string(),
token1: QUOTE_DENOM.to_string(),
},
)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ mod tests {
use crate::{
helpers::msgs::refund_bank_msg,
state::{Position, POSITION},
test_helpers::mock_deps_with_querier,
test_helpers::{mock_deps_with_querier, BASE_DENOM, QUOTE_DENOM},
};

use super::*;
Expand Down Expand Up @@ -333,7 +333,7 @@ mod tests {
env,
MessageInfo {
sender: sender.clone(),
funds: vec![coin(100, "token0"), coin(100, "token1")],
funds: vec![coin(100, BASE_DENOM), coin(100, QUOTE_DENOM)],
},
None,
)
Expand Down
8 changes: 5 additions & 3 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ mod tests {
helpers::getters::get_range_admin,
math::tick::build_tick_exp_cache,
state::{MODIFY_RANGE_STATE, RANGE_ADMIN},
test_helpers::{mock_deps_with_querier, mock_deps_with_querier_with_balance},
test_helpers::{
mock_deps_with_querier, mock_deps_with_querier_with_balance, BASE_DENOM, QUOTE_DENOM,
},
vault::range::requires_swap,
};

Expand Down Expand Up @@ -368,7 +370,7 @@ mod tests {
&info,
&[(
MOCK_CONTRACT_ADDR,
&[coin(11000, "token0"), coin(11234, "token1")],
&[coin(11000, BASE_DENOM), coin(11234, QUOTE_DENOM)],
)],
);

Expand Down Expand Up @@ -399,7 +401,7 @@ mod tests {
.find(|a| { a.key == "token1" })
.unwrap()
.value,
"11234token1"
format!("11234{}", QUOTE_DENOM)
); // 10000 withdrawn + 1234 local balance
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ fn withdraw_msg(

#[cfg(test)]
mod tests {
use crate::{state::PoolConfig, test_helpers::mock_deps_with_querier_with_balance};
use crate::{
state::PoolConfig,
test_helpers::{mock_deps_with_querier_with_balance, BASE_DENOM, QUOTE_DENOM},
};
use cosmwasm_std::{
testing::{mock_dependencies, mock_env, mock_info, MOCK_CONTRACT_ADDR},
Addr, CosmosMsg, SubMsgResponse,
Expand All @@ -174,7 +177,7 @@ mod tests {
&info,
&[(
MOCK_CONTRACT_ADDR,
&[coin(2000, "token0"), coin(3000, "token1")],
&[coin(2000, BASE_DENOM), coin(3000, QUOTE_DENOM)],
)],
);
let env = mock_env();
Expand Down

0 comments on commit aa4b1a6

Please sign in to comment.