Skip to content

Commit

Permalink
tests: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Jun 10, 2024
1 parent 5ec3829 commit dcc90b2
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 74 deletions.
6 changes: 3 additions & 3 deletions contracts/alliance-hub/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ fn whitelist_assets(
let mut attrs = vec![("action".to_string(), "whitelist_assets".to_string())];
for (chain_id, assets) in &assets_request {
for asset in assets {
WHITELIST.save(deps.storage, &asset, chain_id)?;
ASSET_REWARD_RATE.update(deps.storage, &asset, |rate| -> StdResult<_> {
WHITELIST.save(deps.storage, asset, chain_id)?;
ASSET_REWARD_RATE.update(deps.storage, asset, |rate| -> StdResult<_> {
Ok(rate.unwrap_or(Decimal::zero()))
})?;
}
Expand All @@ -245,7 +245,7 @@ fn remove_assets(
// Only allow the governance address to update whitelisted assets
is_governance(&info, &config)?;
for asset in &assets {
WHITELIST.remove(deps.storage, &asset);
WHITELIST.remove(deps.storage, asset);
}
let assets_str = assets
.iter()
Expand Down
6 changes: 0 additions & 6 deletions contracts/alliance-hub/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn migrate_whitelist_map(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_WHITELIST
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down Expand Up @@ -56,7 +55,6 @@ fn migrate_balances_map(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_BALANCES
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down Expand Up @@ -87,7 +85,6 @@ fn migrate_total_balances_map(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_TOTAL_BALANCES
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down Expand Up @@ -151,7 +148,6 @@ fn migrate_asset_reward_rate(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_ASSET_REWARD_RATE
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down Expand Up @@ -183,7 +179,6 @@ fn migrate_user_asset_reward_rate(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_USER_ASSET_REWARD_RATE
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down Expand Up @@ -215,7 +210,6 @@ fn migrate_unclaimed_rewards(deps: DepsMut) -> Result<(), ContractError> {

let old_map = OLD_UNCLAIMED_REWARDS
.range(deps.storage, None, None, Order::Ascending)
.into_iter()
.map(|item| {
let (key, value) = item.unwrap();
(key, value)
Expand Down
10 changes: 5 additions & 5 deletions contracts/alliance-hub/src/tests/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::state::WHITELIST;
use crate::tests::helpers::{remove_assets, setup_contract, whitelist_assets};
use alliance_protocol::alliance_protocol::{ExecuteMsg, QueryMsg, WhitelistedAssetsResponse};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{from_binary, Response};
use cw_asset_v2::{AssetInfo, AssetInfoKey};
use cosmwasm_std::{from_json, Response};
use cw_asset_v3::AssetInfo;
use std::collections::HashMap;

#[test]
Expand Down Expand Up @@ -51,13 +51,13 @@ fn test_whitelist_assets() {
let chain_id = WHITELIST
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("asset2".to_string())),
&AssetInfo::Native("asset2".to_string()),
)
.unwrap();
assert_eq!(chain_id, "chain-1".to_string());

let res: WhitelistedAssetsResponse =
from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::WhitelistedAssets {}).unwrap())
from_json(&query(deps.as_ref(), mock_env(), QueryMsg::WhitelistedAssets {}).unwrap())
.unwrap();
assert_eq!(
res,
Expand Down Expand Up @@ -116,7 +116,7 @@ fn test_remove_assets() {
WHITELIST
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
)
.unwrap_err();
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/alliance-hub/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::collections::HashMap;

use cosmwasm_std::testing::{mock_env, mock_info};
use cosmwasm_std::{
coin, from_binary, to_binary, Decimal, Deps, DepsMut, Response, StdResult, Uint128,
coin, from_json, to_json_binary, Decimal, Deps, DepsMut, Response, StdResult, Uint128,
};
use cw20::Cw20ReceiveMsg;
use cw_asset_v2::{Asset, AssetInfo};
use cw_asset_v3::{Asset, AssetInfo};

use alliance_protocol::alliance_oracle_types::ChainId;
use alliance_protocol::alliance_protocol::{
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn stake_cw20(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Respo
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
sender: user.to_string(),
amount: amount.into(),
msg: to_binary(&Cw20HookMsg::Stake {}).unwrap(),
msg: to_json_binary(&Cw20HookMsg::Stake {}).unwrap(),
});
execute(deps, env, info, msg).unwrap()
}
Expand Down Expand Up @@ -149,7 +149,7 @@ pub fn claim_rewards(deps: DepsMut, user: &str, denom: &str) -> Response {
}

pub fn query_rewards(deps: Deps, user: &str, denom: &str) -> PendingRewardsRes {
from_binary(
from_json(
&query(
deps,
mock_env(),
Expand All @@ -164,7 +164,7 @@ pub fn query_rewards(deps: Deps, user: &str, denom: &str) -> PendingRewardsRes {
}

pub fn query_all_rewards(deps: Deps, user: &str) -> Vec<PendingRewardsRes> {
from_binary(
from_json(
&query(
deps,
mock_env(),
Expand All @@ -178,11 +178,11 @@ pub fn query_all_rewards(deps: Deps, user: &str) -> Vec<PendingRewardsRes> {
}

pub fn query_all_staked_balances(deps: Deps) -> Vec<StakedBalanceRes> {
from_binary(&query(deps, mock_env(), QueryMsg::TotalStakedBalances {}).unwrap()).unwrap()
from_json(&query(deps, mock_env(), QueryMsg::TotalStakedBalances {}).unwrap()).unwrap()
}

pub fn query_asset_reward_distribution(deps: Deps) -> Vec<AssetDistribution> {
from_binary(&query(deps, mock_env(), QueryMsg::RewardDistribution {}).unwrap()).unwrap()
from_json(&query(deps, mock_env(), QueryMsg::RewardDistribution {}).unwrap()).unwrap()
}

#[inline]
Expand Down
10 changes: 5 additions & 5 deletions contracts/alliance-hub/src/tests/instantiate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{
from_binary, Addr, Binary, CosmosMsg, Reply, Response, SubMsg, SubMsgResponse, SubMsgResult,
from_json, Addr, Binary, CosmosMsg, Reply, Response, SubMsg, SubMsgResponse, SubMsgResult,
Timestamp, Uint128,
};
use terra_proto_rs::traits::MessageExt;
Expand Down Expand Up @@ -34,7 +34,7 @@ fn test_setup_contract() {
// alliance_token_denom and alliance_token_supply
// will be populated on reply.
let query_config = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap();
let config: Config = from_binary(&query_config).unwrap();
let config: Config = from_json(&query_config).unwrap();
assert_eq!(
config,
Config {
Expand Down Expand Up @@ -104,7 +104,7 @@ fn test_reply_create_token() {
);

let query_config = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap();
let config: Config = from_binary(&query_config).unwrap();
let config: Config = from_json(&query_config).unwrap();
assert_eq!(
config,
Config {
Expand Down Expand Up @@ -132,7 +132,7 @@ fn test_update_config() {
oracle,
operator,
..
} = from_binary(&query_config).unwrap();
} = from_json(&query_config).unwrap();

assert_eq!(governance, Addr::unchecked("gov"));
assert_eq!(controller, Addr::unchecked("controller"));
Expand Down Expand Up @@ -192,7 +192,7 @@ fn test_update_config() {
oracle,
operator,
..
} = from_binary(&query_config).unwrap();
} = from_json(&query_config).unwrap();

assert_eq!(governance, Addr::unchecked("new_gov"));
assert_eq!(controller, Addr::unchecked("new_controller"));
Expand Down
26 changes: 13 additions & 13 deletions contracts/alliance-hub/src/tests/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::collections::{HashMap, HashSet};

use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env, mock_info};
use cosmwasm_std::{
coin, coins, to_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Response, SubMsg, Uint128,
WasmMsg,
coin, coins, to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Response, SubMsg,
Uint128, WasmMsg,
};
use cw_asset_v2::{AssetInfo, AssetInfoKey};
use cw_asset_v3::AssetInfo;
use terra_proto_rs::alliance::alliance::MsgClaimDelegationRewards;
use terra_proto_rs::traits::Message;

Expand Down Expand Up @@ -63,7 +63,7 @@ fn test_update_rewards() {
SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute {
funds: vec![],
contract_addr: "cosmos2contract".to_string(),
msg: to_binary(&ExecuteMsg::UpdateRewardsCallback {}).unwrap(),
msg: to_json_binary(&ExecuteMsg::UpdateRewardsCallback {}).unwrap(),
})),
]
);
Expand Down Expand Up @@ -107,14 +107,14 @@ fn update_reward_callback() {
TOTAL_BALANCES
.save(
deps.as_mut().storage,
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
&Uint128::new(1000000),
)
.unwrap();
TOTAL_BALANCES
.save(
deps.as_mut().storage,
AssetInfoKey::from(AssetInfo::Native("bWHALE".to_string())),
&AssetInfo::Native("bWHALE".to_string()),
&Uint128::new(100000),
)
.unwrap();
Expand Down Expand Up @@ -153,7 +153,7 @@ fn update_reward_callback() {
let a_whale_rate = ASSET_REWARD_RATE
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
)
.unwrap();
assert_eq!(
Expand All @@ -163,7 +163,7 @@ fn update_reward_callback() {
let b_whale_rate = ASSET_REWARD_RATE
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("bWHALE".to_string())),
&AssetInfo::Native("bWHALE".to_string()),
)
.unwrap();
assert_eq!(
Expand All @@ -173,7 +173,7 @@ fn update_reward_callback() {
ASSET_REWARD_RATE
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("cMONKEY".to_string())),
&AssetInfo::Native("cMONKEY".to_string()),
)
.unwrap_err();

Expand Down Expand Up @@ -265,14 +265,14 @@ fn claim_user_rewards() {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
),
)
.unwrap();
let asset_reward_rate = ASSET_REWARD_RATE
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
)
.unwrap();
assert_eq!(user_reward_rate, asset_reward_rate);
Expand Down Expand Up @@ -460,7 +460,7 @@ fn claim_rewards_after_staking_and_unstaking() {
let prev_rate = ASSET_REWARD_RATE
.load(
deps.as_mut().storage,
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
)
.unwrap();

Expand All @@ -482,7 +482,7 @@ fn claim_rewards_after_staking_and_unstaking() {
let curr_rate = ASSET_REWARD_RATE
.load(
deps.as_mut().storage,
AssetInfoKey::from(AssetInfo::Native("aWHALE".to_string())),
&AssetInfo::Native("aWHALE".to_string()),
)
.unwrap();
assert!(curr_rate > prev_rate);
Expand Down
Loading

0 comments on commit dcc90b2

Please sign in to comment.