-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
203 additions
and
12 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
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
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
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
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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ mod helpers; | |
mod instantiate; | ||
mod stake_unstake; | ||
mod rewards; | ||
mod modify_assets; |
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,120 @@ | ||
use std::str::FromStr; | ||
|
||
use alliance_protocol::error::ContractError; | ||
use cosmwasm_std::{testing::mock_dependencies, Addr, Decimal, Response}; | ||
use cw_asset::AssetInfo; | ||
|
||
use crate::{tests::helpers::{setup_contract, modify_asset, modify_assets_rewards_rate}, models::{ModifyAsset, ModifyAssetRewardRate}}; | ||
|
||
#[test] | ||
fn test_add_assets() { | ||
let mut deps = mock_dependencies(); | ||
setup_contract(deps.as_mut()); | ||
let res = modify_asset( | ||
deps.as_mut(), | ||
vec![ | ||
ModifyAsset { | ||
asset_info: AssetInfo::native(Addr::unchecked("native_asset")), | ||
delete: false, | ||
}, | ||
ModifyAsset { | ||
asset_info: AssetInfo::Cw20(Addr::unchecked("cw20_asset")), | ||
delete: false, | ||
} | ||
] | ||
); | ||
|
||
assert_eq!( | ||
res, | ||
Response::default() | ||
.add_attributes(vec![ | ||
("action", "modify_assets"), | ||
("asset", "native:native_asset"), | ||
("asset", "cw20:cw20_asset"), | ||
]) | ||
); | ||
} | ||
|
||
|
||
#[test] | ||
fn test_modify_rewards_rate() { | ||
let mut deps = mock_dependencies(); | ||
setup_contract(deps.as_mut()); | ||
modify_asset( | ||
deps.as_mut(), | ||
vec![ | ||
ModifyAsset { | ||
asset_info: AssetInfo::native(Addr::unchecked("native_asset")), | ||
delete: false, | ||
}, | ||
ModifyAsset { | ||
asset_info: AssetInfo::Cw20(Addr::unchecked("cw20_asset")), | ||
delete: false, | ||
} | ||
] | ||
); | ||
|
||
let res = modify_assets_rewards_rate( | ||
deps.as_mut(), | ||
vec![ | ||
ModifyAssetRewardRate { | ||
asset_info: AssetInfo::native(Addr::unchecked("native_asset")), | ||
reward_rate: Decimal::from_str("0.75").unwrap(), | ||
}, | ||
ModifyAssetRewardRate { | ||
asset_info: AssetInfo::Cw20(Addr::unchecked("cw20_asset")), | ||
reward_rate: Decimal::from_str("0.25").unwrap(), | ||
} | ||
] | ||
); | ||
assert_eq!( | ||
res.unwrap(), | ||
Response::default() | ||
.add_attributes(vec![ | ||
("action", "modify_assets_rewards_rate"), | ||
("asset", "native:native_asset"), | ||
("reward_rate", "0.75"), | ||
("asset", "cw20:cw20_asset"), | ||
("reward_rate", "0.25"), | ||
]) | ||
); | ||
} | ||
|
||
|
||
#[test] | ||
fn test_modify_rewards_rate_wrongly() { | ||
let mut deps = mock_dependencies(); | ||
setup_contract(deps.as_mut()); | ||
modify_asset( | ||
deps.as_mut(), | ||
vec![ | ||
ModifyAsset { | ||
asset_info: AssetInfo::native(Addr::unchecked("native_asset")), | ||
delete: false, | ||
}, | ||
ModifyAsset { | ||
asset_info: AssetInfo::Cw20(Addr::unchecked("cw20_asset")), | ||
delete: false, | ||
} | ||
] | ||
); | ||
|
||
let res = modify_assets_rewards_rate( | ||
deps.as_mut(), | ||
vec![ | ||
ModifyAssetRewardRate { | ||
asset_info: AssetInfo::native(Addr::unchecked("native_asset")), | ||
reward_rate: Decimal::from_str("0.85").unwrap(), | ||
}, | ||
ModifyAssetRewardRate { | ||
asset_info: AssetInfo::Cw20(Addr::unchecked("cw20_asset")), | ||
reward_rate: Decimal::from_str("0.25").unwrap(), | ||
} | ||
] | ||
); | ||
|
||
assert_eq!( | ||
res, | ||
Err(ContractError::InvalidTotalDistribution(Decimal::from_str("1.1").unwrap())) | ||
); | ||
} |
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
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