-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration test for asset group limiter
- Loading branch information
Showing
2 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
contracts/transmuter/src/test/cases/units/swap/swap_with_asset_group_limiters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use cosmwasm_std::{Coin, Decimal, Uint128, Uint64}; | ||
|
||
use crate::{ | ||
asset::AssetConfig, | ||
contract::sv::ExecMsg, | ||
limiter::{LimiterParams, WindowConfig}, | ||
scope::Scope, | ||
ContractError, | ||
}; | ||
|
||
use super::{pool_with_single_lp, test_swap_failed_case, test_swap_success_case, SwapMsg}; | ||
|
||
const REMAINING_DENOM0: u128 = 1_000_000_000_000; | ||
const REMAINING_DENOM1: u128 = 1_000_000_000_000; | ||
const REMAINING_DENOM2: u128 = 1_000_000_000_000; | ||
|
||
#[test] | ||
fn test_swap_with_asset_group_limiters() { | ||
let app = osmosis_test_tube::OsmosisTestApp::new(); | ||
let t = pool_with_single_lp( | ||
&app, | ||
vec![ | ||
Coin::new(REMAINING_DENOM0, "denom0"), | ||
Coin::new(REMAINING_DENOM1, "denom1"), | ||
Coin::new(REMAINING_DENOM2, "denom2"), | ||
], | ||
vec![ | ||
AssetConfig { | ||
denom: "denom0".to_string(), | ||
normalization_factor: Uint128::one(), | ||
}, | ||
AssetConfig { | ||
denom: "denom1".to_string(), | ||
normalization_factor: Uint128::one(), | ||
}, | ||
AssetConfig { | ||
denom: "denom2".to_string(), | ||
normalization_factor: Uint128::one(), | ||
}, | ||
], | ||
); | ||
|
||
// Add asset group and limiters | ||
t.contract | ||
.execute( | ||
&ExecMsg::CreateAssetGroup { | ||
label: "group1".to_string(), | ||
denoms: vec!["denom0".to_string(), "denom1".to_string()], | ||
}, | ||
&[], | ||
&t.accounts["admin"], | ||
) | ||
.unwrap(); | ||
|
||
t.contract | ||
.execute( | ||
&ExecMsg::RegisterLimiter { | ||
scope: Scope::asset_group("group1"), | ||
label: "limiter1".to_string(), | ||
limiter_params: LimiterParams::ChangeLimiter { | ||
window_config: WindowConfig { | ||
window_size: Uint64::from(1000u64), | ||
division_count: Uint64::from(5u64), | ||
}, | ||
boundary_offset: Decimal::percent(10), | ||
}, | ||
}, | ||
&[], | ||
&t.accounts["admin"], | ||
) | ||
.unwrap(); | ||
|
||
// swap within group, even an agressive one wouldn't effect anything | ||
test_swap_success_case( | ||
&t, | ||
SwapMsg::SwapExactAmountOut { | ||
token_in_denom: "denom0".to_string(), | ||
token_in_max_amount: Uint128::from(REMAINING_DENOM1), | ||
token_out: Coin::new(REMAINING_DENOM1, "denom1".to_string()), | ||
}, | ||
Coin::new(REMAINING_DENOM1, "denom1".to_string()), | ||
); | ||
|
||
app.increase_time(5); | ||
|
||
// swap denom0 to denom2 -> increase group1 weight by adding more denom0 | ||
test_swap_failed_case( | ||
&t, | ||
SwapMsg::SwapExactAmountOut { | ||
token_in_denom: "denom0".to_string(), | ||
token_in_max_amount: Uint128::from(REMAINING_DENOM0), | ||
token_out: Coin::new(REMAINING_DENOM0, "denom2".to_string()), | ||
}, | ||
ContractError::UpperLimitExceeded { | ||
scope: Scope::asset_group("group1"), | ||
upper_limit: "0.766666666666666666".parse().unwrap(), | ||
value: Decimal::percent(100), | ||
}, | ||
); | ||
} |