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 e976975
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
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
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
32 changes: 16 additions & 16 deletions contracts/alliance-hub/src/tests/stake_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::tests::helpers::{
};
use alliance_protocol::alliance_protocol::{ExecuteMsg, StakedBalanceRes};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coin, to_binary, Addr, BankMsg, CosmosMsg, Response, Uint128, WasmMsg};
use cw_asset_v2::{Asset, AssetInfo, AssetInfoKey};
use cosmwasm_std::{coin, to_json_binary, Addr, BankMsg, CosmosMsg, Response, Uint128, WasmMsg};
use cw_asset_v3::{Asset, AssetInfo};
use std::collections::HashMap;

mod cw20_support {
Expand Down Expand Up @@ -42,7 +42,7 @@ mod cw20_support {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1"))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
),
)
.unwrap();
Expand All @@ -64,7 +64,7 @@ mod cw20_support {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1"))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
),
)
.unwrap();
Expand All @@ -73,7 +73,7 @@ mod cw20_support {
let total_balance = TOTAL_BALANCES
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1"))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
)
.unwrap();
assert_eq!(total_balance, Uint128::new(200));
Expand Down Expand Up @@ -123,7 +123,7 @@ mod cw20_support {
])
.add_message(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "asset1".into(),
msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer {
msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer {
recipient: "user1".into(),
amount: Uint128::new(50),
})
Expand All @@ -137,7 +137,7 @@ mod cw20_support {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1".to_string()))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
),
)
.unwrap();
Expand All @@ -155,7 +155,7 @@ mod cw20_support {
])
.add_message(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: "asset1".into(),
msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer {
msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer {
recipient: "user1".into(),
amount: Uint128::new(50),
})
Expand All @@ -169,7 +169,7 @@ mod cw20_support {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1".to_string()))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
),
)
.unwrap();
Expand All @@ -178,7 +178,7 @@ mod cw20_support {
let total_balance = TOTAL_BALANCES
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Cw20(Addr::unchecked("asset1".to_string()))),
&AssetInfo::Cw20(Addr::unchecked("asset1")),
)
.unwrap();
assert_eq!(total_balance, Uint128::new(0));
Expand Down Expand Up @@ -212,7 +212,7 @@ fn test_stake() {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
),
)
.unwrap();
Expand All @@ -234,7 +234,7 @@ fn test_stake() {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
),
)
.unwrap();
Expand All @@ -243,7 +243,7 @@ fn test_stake() {
let total_balance = TOTAL_BALANCES
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
)
.unwrap();
assert_eq!(total_balance, Uint128::new(200));
Expand Down Expand Up @@ -329,7 +329,7 @@ fn test_unstake() {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
),
)
.unwrap();
Expand All @@ -356,7 +356,7 @@ fn test_unstake() {
deps.as_ref().storage,
(
Addr::unchecked("user1"),
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
),
)
.unwrap();
Expand All @@ -365,7 +365,7 @@ fn test_unstake() {
let total_balance = TOTAL_BALANCES
.load(
deps.as_ref().storage,
AssetInfoKey::from(AssetInfo::Native("asset1".to_string())),
&AssetInfo::Native("asset1".to_string()),
)
.unwrap();
assert_eq!(total_balance, Uint128::new(0));
Expand Down

0 comments on commit e976975

Please sign in to comment.