Skip to content

Commit b0cbc68

Browse files
committed
fix: lint and tests
1 parent c1ad4c8 commit b0cbc68

File tree

10 files changed

+68
-85
lines changed

10 files changed

+68
-85
lines changed

contracts/alliance-hub/src/query.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ fn get_pending_rewards(deps: Deps, asset_query: AssetQuery) -> StdResult<Binary>
7878
let key = (addr, AssetInfoKey::from(asset_query.asset.clone()));
7979
let asset_reward_rate =
8080
ASSET_REWARD_RATE.load(deps.storage, AssetInfoKey::from(asset_query.asset.clone()))?;
81-
let user_reward_rate = USER_ASSET_REWARD_RATE.load(deps.storage, key.clone()).unwrap_or(asset_reward_rate);
81+
let user_reward_rate = USER_ASSET_REWARD_RATE
82+
.load(deps.storage, key.clone())
83+
.unwrap_or(asset_reward_rate);
8284
let user_balance = BALANCES.load(deps.storage, key.clone()).unwrap_or_default();
8385
let unclaimed_rewards = UNCLAIMED_REWARDS
8486
.load(deps.storage, key)
@@ -103,9 +105,7 @@ fn get_all_staked_balances(deps: Deps, asset_query: AllStakedBalancesQuery) -> S
103105
let checked_asset_info = asset_key.check(deps.api, None)?;
104106
let asset_info_key = AssetInfoKey::from(checked_asset_info.clone());
105107
let stake_key = (addr.clone(), asset_info_key);
106-
let balance = BALANCES
107-
.load(deps.storage, stake_key)
108-
.unwrap_or_default();
108+
let balance = BALANCES.load(deps.storage, stake_key).unwrap_or_default();
109109

110110
// Append the request
111111
res.push(StakedBalanceRes {
@@ -128,10 +128,12 @@ fn get_all_pending_rewards(deps: Deps, query: AllPendingRewardsQuery) -> StdResu
128128
let asset = asset.check(deps.api, None)?;
129129
let asset_reward_rate =
130130
ASSET_REWARD_RATE.load(deps.storage, AssetInfoKey::from(asset.clone()))?;
131-
let user_balance = BALANCES.load(
132-
deps.storage,
133-
(addr.clone(), AssetInfoKey::from(asset.clone())),
134-
).unwrap_or_default();
131+
let user_balance = BALANCES
132+
.load(
133+
deps.storage,
134+
(addr.clone(), AssetInfoKey::from(asset.clone())),
135+
)
136+
.unwrap_or_default();
135137
let unclaimed_rewards = UNCLAIMED_REWARDS
136138
.load(
137139
deps.storage,

contracts/alliance-hub/src/tests/rewards.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,17 @@ fn claim_user_rewards_without_stake() {
372372
mock_info("cosmos2contract", &[]),
373373
ExecuteMsg::UpdateRewardsCallback {},
374374
)
375-
.unwrap();
375+
.unwrap();
376376

377377
let res = claim_rewards(deps.as_mut(), "user2", "aWHALE");
378378
assert_eq!(
379379
res,
380-
Response::new()
381-
.add_attributes(vec![
382-
("action", "claim_rewards"),
383-
("user", "user2"),
384-
("asset", "native:aWHALE"),
385-
("reward_amount", "0"),
386-
])
380+
Response::new().add_attributes(vec![
381+
("action", "claim_rewards"),
382+
("user", "user2"),
383+
("asset", "native:aWHALE"),
384+
("reward_amount", "0"),
385+
])
387386
);
388387

389388
USER_ASSET_REWARD_RATE
@@ -407,13 +406,9 @@ fn claim_user_rewards_without_stake() {
407406
);
408407

409408
let all_rewards = query_all_rewards(deps.as_ref(), "user2");
410-
assert_eq!(
411-
all_rewards,
412-
vec![]
413-
);
409+
assert_eq!(all_rewards, vec![]);
414410
}
415411

416-
417412
#[test]
418413
fn claim_user_rewards_after_staking() {
419414
let mut deps = mock_dependencies_with_balance(&[coin(2000000, "uluna")]);

contracts/alliance-lp-hub/src/models.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct InstantiateMsg {
2828

2929
pub astro_incentives_addr: String,
3030
pub alliance_reward_denom: AssetInfo,
31-
31+
3232
pub alliance_token_subdenom: String,
3333
}
3434

@@ -124,19 +124,11 @@ pub struct PendingRewards {
124124
}
125125

126126
impl PendingRewards {
127-
pub fn default() -> Self {
128-
PendingRewards {
129-
deposit_asset : None,
130-
reward_asset: None,
131-
rewards: Uint128::zero(),
132-
}
133-
}
134-
135127
pub fn new(deposit_asset: AssetInfo, reward_asset: AssetInfo, rewards: Uint128) -> Self {
136128
PendingRewards {
137-
deposit_asset : Some(deposit_asset),
129+
deposit_asset: Some(deposit_asset),
138130
reward_asset: Some(reward_asset),
139-
rewards: rewards,
131+
rewards,
140132
}
141133
}
142134
}

contracts/alliance-lp-hub/src/query.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use cosmwasm_std::{to_json_binary, Binary, Decimal, Deps, Env, Order, StdResult,
1313
use cw_asset::{AssetInfo, AssetInfoKey, AssetInfoUnchecked};
1414

1515
use crate::state::{
16-
TOTAL_ASSET_REWARD_RATE, USER_BALANCES, CONFIG, TOTAL_BALANCES, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE,
17-
VALIDATORS, WHITELIST,
16+
CONFIG, TOTAL_ASSET_REWARD_RATE, TOTAL_BALANCES, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE,
17+
USER_BALANCES, VALIDATORS, WHITELIST,
1818
};
1919

2020
#[cfg_attr(not(feature = "library"), entry_point)]
@@ -130,7 +130,9 @@ fn get_address_staked_balances(
130130
let asset_info_key = AssetInfoKey::from(checked_asset_info.clone());
131131
let stake_key = (addr.clone(), asset_info_key);
132132

133-
let balance = USER_BALANCES.load(deps.storage, stake_key).unwrap_or_default();
133+
let balance = USER_BALANCES
134+
.load(deps.storage, stake_key)
135+
.unwrap_or_default();
134136

135137
// Append the request
136138
res.push(StakedBalanceRes {
@@ -209,7 +211,7 @@ fn get_address_pending_rewards(deps: Deps, query: AddressPendingRewardsQuery) ->
209211
.unwrap();
210212
let reward_asset_key = AssetInfoKey::from(reward_asset_info.clone());
211213

212-
let user_balance = user_balances.get(&deposit_asset).unwrap().clone();
214+
let user_balance = *user_balances.get(&deposit_asset).unwrap();
213215
let key = (
214216
addr.clone(),
215217
deposit_asset_key.clone(),

contracts/alliance-lp-hub/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub const WHITELIST: Map<AssetInfoKey, Decimal> = Map::new("whitelist");
1414
pub const TOTAL_BALANCES: Map<AssetInfoKey, Uint128> = Map::new("total_balances");
1515
pub const USER_BALANCES: Map<(Addr, AssetInfoKey), Uint128> = Map::new("user_balances");
1616

17-
// Keeps track of the alliance validators where the
18-
// alliance virtual token is being staked that way
17+
// Keeps track of the alliance validators where the
18+
// alliance virtual token is being staked that way
1919
// it can easily operate the operations like unstake.
2020
pub const VALIDATORS: Item<HashSet<String>> = Item::new("validators");
2121

contracts/alliance-lp-hub/src/tests/helpers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::contract::{execute, instantiate};
22
use crate::models::{
3-
AddressPendingRewardsQuery, AssetQuery, Config, ExecuteMsg, InstantiateMsg, ModifyAssetPair, PendingRewardsRes, QueryMsg, StakedBalanceRes
3+
AddressPendingRewardsQuery, AssetQuery, Config, ExecuteMsg, InstantiateMsg, ModifyAssetPair,
4+
PendingRewardsRes, QueryMsg, StakedBalanceRes,
45
};
56
use crate::query::query;
67
use crate::state::CONFIG;

contracts/alliance-lp-hub/src/tests/query_rewards.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::models::{AddressPendingRewardsQuery, AssetQuery, PendingRewardsRes, QueryMsg};
22

33
use crate::query::query;
4-
use crate::state::{TOTAL_ASSET_REWARD_RATE, USER_BALANCES, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE};
4+
use crate::state::{
5+
TOTAL_ASSET_REWARD_RATE, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE, USER_BALANCES,
6+
};
57
use crate::tests::helpers::{set_alliance_asset, setup_contract};
68
use crate::tests::mock_querier::mock_dependencies;
79
use cosmwasm_std::testing::mock_env;

contracts/alliance-lp-hub/src/tests/rewards.rs

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::helpers::from_string_to_asset_info;
44
use crate::models::{AssetQuery, ExecuteMsg, ModifyAssetPair, PendingRewardsRes, QueryMsg};
55
use crate::query::query;
66
use crate::state::{
7-
TOTAL_ASSET_REWARD_RATE, TEMP_BALANCE, TOTAL_BALANCES, USER_ASSET_REWARD_RATE, VALIDATORS, WHITELIST,
7+
TEMP_BALANCE, TOTAL_ASSET_REWARD_RATE, TOTAL_BALANCES, USER_ASSET_REWARD_RATE, VALIDATORS,
8+
WHITELIST,
89
};
910
use crate::tests::helpers::{
1011
claim_rewards, modify_asset, query_all_rewards, query_rewards, set_alliance_asset,
@@ -325,13 +326,13 @@ fn claim_user_rewards() {
325326
Vec::from([
326327
ModifyAssetPair {
327328
asset_info: AssetInfo::Native("aWHALE".to_string()),
328-
asset_distribution: Decimal::percent(50).to_uint_floor(),
329+
asset_distribution: Uint128::new(500000000000000000),
329330
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
330331
delete: false,
331332
},
332333
ModifyAssetPair {
333334
asset_info: AssetInfo::Native("bWHALE".to_string()),
334-
asset_distribution: Decimal::percent(50).to_uint_floor(),
335+
asset_distribution: Uint128::new(500000000000000000),
335336
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
336337
delete: false,
337338
},
@@ -427,29 +428,19 @@ fn claim_user_rewards() {
427428
let all_rewards = query_all_rewards(deps.as_ref(), "user1");
428429
assert_eq!(
429430
all_rewards,
430-
vec![
431-
PendingRewardsRes {
432-
rewards: Uint128::zero(),
433-
deposit_asset: AssetInfo::Native("aWHALE".to_string()),
434-
reward_asset: AssetInfo::Cw20(Addr::unchecked("astro_reward_denom".to_string())),
435-
},
436-
PendingRewardsRes {
437-
rewards: Uint128::zero(),
438-
deposit_asset: AssetInfo::Native("aWHALE".to_string()),
439-
reward_asset: AssetInfo::Native("uluna".to_string()),
440-
}
441-
]
431+
vec![PendingRewardsRes {
432+
rewards: Uint128::zero(),
433+
deposit_asset: AssetInfo::Native("aWHALE".to_string()),
434+
reward_asset: AssetInfo::Native("uluna".to_string()),
435+
}]
442436
);
443437

444438
let res = claim_rewards(deps.as_mut(), "user1", "aWHALE");
445439
assert_eq!(
446440
res,
447441
Response::new().add_attributes(vec![
448442
("action", "claim_alliance_lp_rewards"),
449-
("user", "user1"),
450-
("asset", "native:aWHALE"),
451-
("alliance_reward_amount", "0"),
452-
("astro_reward_amount", "0"),
443+
("sender", "user1")
453444
])
454445
);
455446

@@ -477,10 +468,10 @@ fn claim_user_rewards() {
477468
Response::new()
478469
.add_attributes(vec![
479470
("action", "claim_alliance_lp_rewards"),
480-
("user", "user1"),
481-
("asset", "native:aWHALE"),
482-
("alliance_reward_amount", "10000"),
483-
("astro_reward_amount", "0"),
471+
("sender", "user1"),
472+
("deposit_asset", "native:aWHALE"),
473+
("reward_asset", "native:uluna"),
474+
("rewards_amount", "10000"),
484475
])
485476
.add_message(CosmosMsg::Bank(BankMsg::Send {
486477
to_address: "user1".to_string(),
@@ -495,30 +486,31 @@ fn claim_user_rewards_after_staking() {
495486
setup_contract(deps.as_mut());
496487
set_alliance_asset(deps.as_mut());
497488

498-
// Whitelist two assets with 50% of asset distribution
499-
// from the alliance staking to each asset
500489
let res = modify_asset(
501490
deps.as_mut(),
502491
Vec::from([
503492
ModifyAssetPair {
504493
asset_info: AssetInfo::Native("aWHALE".to_string()),
505-
asset_distribution: Decimal::percent(50).to_uint_floor(),
494+
asset_distribution: Uint128::new(100000000000000000),
506495
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
507496
delete: false,
508497
},
509498
ModifyAssetPair {
510499
asset_info: AssetInfo::Native("bWHALE".to_string()),
511-
asset_distribution: Decimal::percent(50).to_uint_floor(),
500+
asset_distribution: Uint128::new(100000000000000000),
512501
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
513502
delete: false,
514503
},
515504
]),
516505
)
517506
.unwrap();
518-
assert_eq!(res, Response::new()
519-
.add_attribute("action", "modify_asset")
520-
.add_attribute("asset", "native:aWHALE")
521-
.add_attribute("asset", "native:bWHALE"));
507+
assert_eq!(
508+
res,
509+
Response::new()
510+
.add_attribute("action", "modify_asset")
511+
.add_attribute("asset", "native:aWHALE")
512+
.add_attribute("asset", "native:bWHALE")
513+
);
522514

523515
let res = stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap();
524516
assert_eq!(
@@ -562,7 +554,7 @@ fn claim_user_rewards_after_staking() {
562554
.add_attribute("action", "update_alliance_rewards_callback")
563555
.add_message(CosmosMsg::Bank(BankMsg::Send {
564556
to_address: "controller".to_string(),
565-
amount: coins(1000000, "uluna"),
557+
amount: coins(800000, "uluna"),
566558
}))
567559
);
568560

@@ -574,14 +566,14 @@ fn claim_user_rewards_after_staking() {
574566
Response::new()
575567
.add_attributes(vec![
576568
("action", "claim_alliance_lp_rewards"),
577-
("user", "user1"),
569+
("sender", "user1"),
578570
("deposit_asset", "native:aWHALE"),
579-
("reward_asset", "100000"),
580-
("rewards_amount", "0"),
571+
("reward_asset", "native:uluna"),
572+
("rewards_amount", "60000"),
581573
])
582574
.add_message(CosmosMsg::Bank(BankMsg::Send {
583575
to_address: "user1".to_string(),
584-
amount: coins(100000, "uluna"),
576+
amount: coins(60000, "uluna"),
585577
}))
586578
);
587579

@@ -591,10 +583,7 @@ fn claim_user_rewards_after_staking() {
591583
res,
592584
Response::new().add_attributes(vec![
593585
("action", "claim_alliance_lp_rewards"),
594-
("user", "user1"),
595-
("deposit_asset", "native:aWHALE"),
596-
("reward_asset", "0"),
597-
("rewards_amount", "0"),
586+
("sender", "user1")
598587
])
599588
);
600589
}
@@ -609,13 +598,13 @@ fn claim_rewards_after_staking_and_unstaking() {
609598
Vec::from([
610599
ModifyAssetPair {
611600
asset_info: AssetInfo::Native("aWHALE".to_string()),
612-
asset_distribution: Uint128::new(1),
601+
asset_distribution: Uint128::new(500000000000000000),
613602
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
614603
delete: false,
615604
},
616605
ModifyAssetPair {
617606
asset_info: AssetInfo::Native("bWHALE".to_string()),
618-
asset_distribution: Uint128::new(4),
607+
asset_distribution: Uint128::new(400000000000000000),
619608
reward_asset_info: Some(AssetInfo::Native("uluna".to_string())),
620609
delete: false,
621610
},
@@ -712,7 +701,7 @@ fn claim_rewards_after_staking_and_unstaking() {
712701
assert_eq!(
713702
res,
714703
PendingRewardsRes {
715-
rewards: Uint128::new(1000000),
704+
rewards: Uint128::new(800000),
716705
deposit_asset: AssetInfo::Native("bWHALE".to_string()),
717706
reward_asset: AssetInfo::Native("uluna".to_string()),
718707
}

contracts/alliance-lp-hub/src/tests/stake_unstake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::astro_models::{Cw20Msg, ExecuteAstroMsg};
22
use crate::contract::execute;
33
use crate::models::{ExecuteMsg, ModifyAssetPair, StakedBalanceRes};
4-
use crate::state::{USER_BALANCES, TOTAL_BALANCES};
4+
use crate::state::{TOTAL_BALANCES, USER_BALANCES};
55
use crate::tests::helpers::{
66
modify_asset, query_contract_balances, setup_contract, stake, stake_cw20, unstake,
77
unstake_callback,

packages/alliance-protocol/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum ContractError {
5656

5757
#[error("Missing reward asset info for asset {0}")]
5858
MissingRewardAsset(String),
59-
59+
6060
#[error("Asset not staked")]
6161
AssetNotStaked {},
6262
}

0 commit comments

Comments
 (0)