From c953d4afa9fd8cd59adf4cf9e2d0da48307da8ed Mon Sep 17 00:00:00 2001 From: emidev98 Date: Wed, 24 Jan 2024 12:10:03 +0200 Subject: [PATCH] feat: test claim astro rewards --- .gitignore | 5 +- Makefile.toml | 3 + contracts/alliance-lp-hub/src/contract.rs | 68 ++++---- .../alliance-lp-hub/src/tests/helpers.rs | 19 +- .../alliance-lp-hub/src/tests/mock_querier.rs | 4 +- contracts/alliance-lp-hub/src/tests/mod.rs | 1 + .../alliance-lp-hub/src/tests/modify_asset.rs | 76 ++++++++ .../alliance-lp-hub/src/tests/rewards.rs | 164 ++++++++++++++++-- .../src/tests/stake_unstake.rs | 73 ++++++-- 9 files changed, 332 insertions(+), 81 deletions(-) create mode 100644 contracts/alliance-lp-hub/src/tests/modify_asset.rs diff --git a/.gitignore b/.gitignore index e0005d6..822f14d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ node_modules # Metadata from deployments scripts/.oracle_address.log -scripts/.hub_address.log \ No newline at end of file +scripts/.hub_address.log + +# Code coverage file +lcov.info \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml index 859917a..1333ddf 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -19,6 +19,9 @@ args = ["test", "--locked"] [tasks.test-cover] script = """docker run --security-opt seccomp=unconfined -v "${PWD}:/volume" xd009642/tarpaulin""" +[tasks.test-cover-to-file] +script = "cargo tarpaulin --out Lcov" + [tasks.lint] command = "cargo" args = ["clippy", "--tests", "--", "-D", "warnings"] diff --git a/contracts/alliance-lp-hub/src/contract.rs b/contracts/alliance-lp-hub/src/contract.rs index 5a3d5f5..bf253d5 100644 --- a/contracts/alliance-lp-hub/src/contract.rs +++ b/contracts/alliance-lp-hub/src/contract.rs @@ -94,7 +94,7 @@ pub fn execute( ) -> Result { match msg { // Used to whitelist, modify or delete assets from the allowed list - ExecuteMsg::ModifyAssetPairs(assets) => modify_assets(deps, info, assets), + ExecuteMsg::ModifyAssetPairs(assets) => modify_asset(deps, info, assets), // User interactions Stake, Unstake and ClaimRewards ExecuteMsg::Receive(cw20_msg) => { @@ -131,16 +131,24 @@ pub fn execute( // This method iterate through the list of assets to be modified, // for each asset it checks if it is being listed or delisted, -fn modify_assets( +fn modify_asset( deps: DepsMut, info: MessageInfo, assets: Vec, ) -> Result { let config = CONFIG.load(deps.storage)?; is_governance(&info, &config)?; - let mut attrs = vec![("action".to_string(), "modify_assets".to_string())]; + let mut attrs = vec![("action".to_string(), "modify_asset".to_string())]; for asset in assets { + let reward_asset_info_key = match asset.reward_asset_info { + Some(reward_asset_info) => AssetInfoKey::from(reward_asset_info), + None => { + return Err(ContractError::MissingRewardAsset( + asset.asset_info.to_string(), + )) + } + }; if asset.delete { let asset_key = AssetInfoKey::from(asset.asset_info.clone()); WHITELIST.remove(deps.storage, asset_key.clone()); @@ -150,14 +158,6 @@ fn modify_assets( ]); } else { let asset_key = AssetInfoKey::from(asset.asset_info.clone()); - let reward_asset_info_key = match asset.reward_asset_info { - Some(reward_asset_info) => AssetInfoKey::from(reward_asset_info), - None => { - return Err(ContractError::MissingRewardAsset( - asset.asset_info.to_string(), - )) - } - }; WHITELIST.save(deps.storage, asset_key.clone(), &Decimal::zero())?; ASSET_REWARD_RATE.update( @@ -259,9 +259,7 @@ fn stake( }) } _ => { - return Err(ContractError::AssetNotWhitelisted( - received_asset.info.to_string(), - )); + return Err(ContractError::InvalidDenom(received_asset.info.to_string())); } }; @@ -540,14 +538,20 @@ fn _update_astro_rewards( contract_addr: Addr, astro_incentives: Addr, ) -> Result, ContractError> { - let whitelist = WHITELIST - .range_raw(deps.storage, None, None, Order::Ascending) - .map(|r| r.map(|(a, d)| (AssetInfoKey(a), d))) - .collect::>>()?; + let mut whitelist: Vec = Vec::new(); + + for f in WHITELIST.range(deps.storage, None, None, Order::Ascending) { + let (asset_info, _) = f?; + let asset_info = asset_info.check(deps.api, None)?; + let asset_string = asset_info.to_string(); + let asset_denom = asset_string.split(":").collect::>()[1].to_string(); + + whitelist.push(asset_denom); + } + let mut lp_tokens_list: Vec = vec![]; - for (asset_info, _) in whitelist { - let lp_token = String::from_utf8(asset_info.0)?; + for lp_token in whitelist { let pending_rewards: Vec = deps .querier .query_wasm_smart( @@ -845,23 +849,24 @@ fn reply_claim_astro_rewards( // and group all the **claimed_reward** for each claimed position. let mut astro_claims: Vec = vec![]; let mut astro_claim = AstroClaimRewardsPosition::default(); - let mut add_to_next_claim_position = false; + let mut count_claim_position = true; for attr in event.attributes.iter() { - if attr.key == "claimed_position" { - if add_to_next_claim_position { - astro_claims.push(astro_claim.clone()); - astro_claim = AstroClaimRewardsPosition::default(); - add_to_next_claim_position = false; - } else { - astro_claim.deposited_asset = attr.value.clone(); - } + if attr.key == "claimed_position" && count_claim_position { + astro_claim = AstroClaimRewardsPosition::default(); + astro_claim.deposited_asset = attr.value.clone(); + count_claim_position = false; } if attr.key == "claimed_reward" { let coin = CwCoin::from_str(&attr.value)?; astro_claim.rewards.add(coin)?; - add_to_next_claim_position = true } + + if attr.key == "claimed_reward" && !count_claim_position { + astro_claims.push(astro_claim.clone()); + count_claim_position = true + } + } // Given the claimed rewards account them to the state of the contract @@ -875,12 +880,13 @@ fn reply_claim_astro_rewards( for reward in claim.rewards { let reward_asset_key = from_string_to_asset_info(reward.denom)?; let reward_ammount = Decimal::from_atomics(reward.amount, 0)?; + let mut asset_reward_rate = Decimal::zero(); ASSET_REWARD_RATE.update( deps.storage, (deposit_asset_key.clone(), reward_asset_key), |a| -> StdResult<_> { - let mut asset_reward_rate = a.unwrap_or_default(); + asset_reward_rate = a.unwrap_or_default(); asset_reward_rate = (reward_ammount / total_lp_staked) + asset_reward_rate; Ok(asset_reward_rate) }, diff --git a/contracts/alliance-lp-hub/src/tests/helpers.rs b/contracts/alliance-lp-hub/src/tests/helpers.rs index 6589a1a..42e5e02 100644 --- a/contracts/alliance-lp-hub/src/tests/helpers.rs +++ b/contracts/alliance-lp-hub/src/tests/helpers.rs @@ -9,6 +9,7 @@ use alliance_protocol::alliance_protocol::{ AllianceDelegateMsg, AllianceDelegation, AllianceRedelegateMsg, AllianceRedelegation, AllianceUndelegateMsg, }; +use alliance_protocol::error::ContractError; use alliance_protocol::token_factory::CustomExecuteMsg; use cosmwasm_std::testing::{mock_env, mock_info}; use cosmwasm_std::{coin, from_json, Addr, Binary, Deps, DepsMut, Response, StdResult, Uint128}; @@ -43,22 +44,22 @@ pub fn set_alliance_asset(deps: DepsMut) { .unwrap(); } -pub fn modify_asset(deps: DepsMut, assets: Vec) -> Response { +pub fn modify_asset(deps: DepsMut, assets: Vec) -> Result { let info = mock_info("gov", &[]); let env = mock_env(); let msg = ExecuteMsg::ModifyAssetPairs(assets); - execute(deps, env, info, msg).unwrap() + execute(deps, env, info, msg) } -pub fn stake(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Response { +pub fn stake(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Result { let info = mock_info(user, &[coin(amount, denom)]); let env = mock_env(); let msg = ExecuteMsg::Stake {}; - execute(deps, env, info, msg).unwrap() + execute(deps, env, info, msg) } -pub fn stake_cw20(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Response { +pub fn stake_cw20(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Result { let mut info = mock_info(user, &[]); let env = mock_env(); let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { @@ -67,16 +68,14 @@ pub fn stake_cw20(deps: DepsMut, user: &str, amount: u128, denom: &str) -> Respo msg: Binary::default(), }); info.sender = Addr::unchecked(denom.to_owned()); - execute(deps, env, info, msg).unwrap() + execute(deps, env, info, msg) } -pub fn unstake(deps: DepsMut, user: &str, asset: Asset) -> Response { +pub fn unstake(deps: DepsMut, user: &str, asset: Asset) -> Result { let info = mock_info(user, &[]); let env = mock_env(); let msg = ExecuteMsg::Unstake(asset); - let res = execute(deps, env, info, msg); - - res.unwrap() + execute(deps, env, info, msg) } pub fn alliance_delegate(deps: DepsMut, delegations: Vec<(&str, u128)>) -> Response { diff --git a/contracts/alliance-lp-hub/src/tests/mock_querier.rs b/contracts/alliance-lp-hub/src/tests/mock_querier.rs index 564468e..3b17e81 100644 --- a/contracts/alliance-lp-hub/src/tests/mock_querier.rs +++ b/contracts/alliance-lp-hub/src/tests/mock_querier.rs @@ -66,7 +66,7 @@ impl WasmMockQuerier { panic!("The only mocked tokens are 'astro_existent_cw20' and 'astro_existent_native_coin' you send {}",lp_token) } QueryAstroMsg::PendingRewards { lp_token, user: _ } => { - if lp_token == "astro_native_with_existent_rewards" { + if lp_token == "factory/astro_native_with_existent_rewards" { let msg = vec![Asset { info: AssetInfoBase::native(lp_token.to_string()), amount: Uint128::one(), @@ -79,7 +79,7 @@ impl WasmMockQuerier { }]; return SystemResult::Ok(to_json_binary(&msg).into()); } - panic!("The only mocked token with pending rewards is 'astro_native_with_existent_rewards' {}",lp_token) + panic!("The only mocked token with pending rewards is 'factory/astro_native_with_existent_rewards' {}",lp_token) } }, _ => self.base.handle_query(request), diff --git a/contracts/alliance-lp-hub/src/tests/mod.rs b/contracts/alliance-lp-hub/src/tests/mod.rs index e453f9f..eeddb74 100644 --- a/contracts/alliance-lp-hub/src/tests/mod.rs +++ b/contracts/alliance-lp-hub/src/tests/mod.rs @@ -4,3 +4,4 @@ mod instantiate; mod mock_querier; mod rewards; mod stake_unstake; +mod modify_asset; \ No newline at end of file diff --git a/contracts/alliance-lp-hub/src/tests/modify_asset.rs b/contracts/alliance-lp-hub/src/tests/modify_asset.rs new file mode 100644 index 0000000..f5d9018 --- /dev/null +++ b/contracts/alliance-lp-hub/src/tests/modify_asset.rs @@ -0,0 +1,76 @@ +use crate::models::ModifyAssetPair; +use crate::tests::helpers::{modify_asset, setup_contract, stake}; +use alliance_protocol::error::ContractError; +use cosmwasm_std::{Response, testing::mock_dependencies}; +use cw_asset::AssetInfo; + +#[test] +fn test_stake_non_whitelisted_asset() { + let mut deps = mock_dependencies(); + setup_contract(deps.as_mut()); + + let err = stake(deps.as_mut(), "user1", 100, "native_asset").unwrap_err(); + + assert_eq!( + err, + ContractError::AssetNotWhitelisted("native:native_asset".to_string()) + ); +} + +#[test] +fn test_remove_asset() { + let mut deps = mock_dependencies(); + setup_contract(deps.as_mut()); + + // Whitelist the pair aWHALE-uluna successfully + let res = modify_asset( + deps.as_mut(), + Vec::from([ModifyAssetPair { + asset_info: AssetInfo::Native("aWHALE".to_string()), + reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), + delete: false, + }]), + ) + .unwrap(); + assert_eq!( + res, + Response::default() + .add_attributes(vec![("action", "modify_asset"), ("asset", "native:aWHALE"),]) + ); + + // Try to remove the asset aWHALE, it should error because + // the reward_asset_info is not defined + let err = modify_asset( + deps.as_mut(), + Vec::from([ModifyAssetPair { + asset_info: AssetInfo::Native("aWHALE".to_string()), + reward_asset_info: None, + delete: true, + }]), + ) + .unwrap_err(); + assert_eq!( + err, + ContractError::MissingRewardAsset("native:aWHALE".to_string()) + ); + + // Remove the asset pair aWHALE-uluna successfully because both + // assets are defined + let res = modify_asset( + deps.as_mut(), + Vec::from([ModifyAssetPair { + asset_info: AssetInfo::Native("aWHALE".to_string()), + reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), + delete: true, + }]), + ) + .unwrap(); + assert_eq!( + res, + Response::default().add_attributes(vec![ + ("action", "modify_asset"), + ("asset", "native:aWHALE"), + ("to_remove", "true"), + ]) + ); +} diff --git a/contracts/alliance-lp-hub/src/tests/rewards.rs b/contracts/alliance-lp-hub/src/tests/rewards.rs index 932ba95..af6413d 100644 --- a/contracts/alliance-lp-hub/src/tests/rewards.rs +++ b/contracts/alliance-lp-hub/src/tests/rewards.rs @@ -1,4 +1,5 @@ -use crate::contract::execute; +use crate::astro_models::ExecuteAstroMsg; +use crate::contract::{execute, reply}; use crate::models::{ExecuteMsg, ModifyAssetPair, PendingRewardsRes}; use crate::state::{ ASSET_REWARD_RATE, TEMP_BALANCE, TOTAL_BALANCES, USER_ASSET_REWARD_RATE, VALIDATORS, WHITELIST, @@ -7,10 +8,12 @@ use crate::tests::helpers::{ claim_rewards, modify_asset, query_all_rewards, query_rewards, set_alliance_asset, setup_contract, stake, unstake, DENOM, }; +use crate::tests::mock_querier::mock_dependencies; +use alliance_protocol::error::ContractError; use cosmwasm_std::testing::{mock_dependencies_with_balance, mock_env, mock_info}; use cosmwasm_std::{ - coin, coins, to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Response, SubMsg, - Uint128, WasmMsg, + coin, coins, to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Event, Reply, Response, + SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw_asset::{Asset, AssetInfo, AssetInfoKey}; use std::collections::HashSet; @@ -202,6 +205,23 @@ fn update_alliance_reward_callback() { ); } +#[test] +fn update_alliance_reward_unauthorized_callback() { + let mut deps = mock_dependencies_with_balance(&[coin(2000000, "uluna")]); + setup_contract(deps.as_mut()); + set_alliance_asset(deps.as_mut()); + + let err = execute( + deps.as_mut(), + mock_env(), + mock_info("unauthorized_sender", &[]), + ExecuteMsg::UpdateAllianceRewardsCallback {}, + ) + .unwrap_err(); + + assert_eq!(err, ContractError::Unauthorized {}); +} + #[test] fn update_alliance_rewards_callback_with_unallocated() { let mut deps = mock_dependencies_with_balance(&[coin(2000000, "uluna")]); @@ -303,7 +323,8 @@ fn claim_user_rewards() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }]), - ); + ) + .unwrap(); WHITELIST .save( deps.as_mut().storage, @@ -319,8 +340,8 @@ fn claim_user_rewards() { ) .unwrap(); - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); - stake(deps.as_mut(), "user2", 4000000, "aWHALE"); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); + stake(deps.as_mut(), "user2", 4000000, "aWHALE").unwrap(); TEMP_BALANCE .save( @@ -471,9 +492,10 @@ fn claim_user_rewards_after_staking() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }]), - ); - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); - stake(deps.as_mut(), "user2", 4000000, "aWHALE"); + ) + .unwrap(); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); + stake(deps.as_mut(), "user2", 4000000, "aWHALE").unwrap(); WHITELIST .save( @@ -505,7 +527,7 @@ fn claim_user_rewards_after_staking() { ) .unwrap(); - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); let res = claim_rewards(deps.as_mut(), "user1", "aWHALE"); assert_eq!( @@ -555,10 +577,11 @@ fn claim_rewards_after_staking_and_unstaking() { delete: false, }, ]), - ); - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); - stake(deps.as_mut(), "user2", 4000000, "aWHALE"); - stake(deps.as_mut(), "user2", 1000000, "bWHALE"); + ) + .unwrap(); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); + stake(deps.as_mut(), "user2", 4000000, "aWHALE").unwrap(); + stake(deps.as_mut(), "user2", 1000000, "bWHALE").unwrap(); WHITELIST .save( deps.as_mut().storage, @@ -603,7 +626,7 @@ fn claim_rewards_after_staking_and_unstaking() { // Unstake let asset_info = Asset::native(Addr::unchecked("aWHALE"), 1000000u128); - unstake(deps.as_mut(), "user1", asset_info); + unstake(deps.as_mut(), "user1", asset_info).unwrap(); // Accrue rewards again TEMP_BALANCE @@ -633,7 +656,7 @@ fn claim_rewards_after_staking_and_unstaking() { assert!(curr_rate > prev_rate); // User 1 stakes back - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); // User 1 should not have any rewards let res = query_rewards(deps.as_ref(), "user1", "aWHALE", "uluna"); @@ -686,9 +709,10 @@ fn claim_rewards_after_rebalancing_emissions() { delete: false, }, ]), - ); - stake(deps.as_mut(), "user1", 1000000, "aWHALE"); - stake(deps.as_mut(), "user2", 1000000, "bWHALE"); + ) + .unwrap(); + stake(deps.as_mut(), "user1", 1000000, "aWHALE").unwrap(); + stake(deps.as_mut(), "user2", 1000000, "bWHALE").unwrap(); WHITELIST .save( @@ -756,3 +780,105 @@ fn claim_rewards_after_rebalancing_emissions() { let rewards = query_rewards(deps.as_ref(), "user2", "bWHALE", "uluna"); assert_eq!(rewards.rewards, Uint128::new(500000)); } + +#[test] +fn test_update_rewards_with_astro_rewards() { + let mut deps = mock_dependencies(&[coin(1000000, "uluna")]); + setup_contract(deps.as_mut()); + set_alliance_asset(deps.as_mut()); + + WHITELIST + .save( + deps.as_mut().storage, + AssetInfoKey::from(AssetInfo::Native( + "factory/astro_native_with_existent_rewards".to_string(), + )), + &Decimal::percent(10), + ) + .unwrap(); + VALIDATORS + .save( + deps.as_mut().storage, + &HashSet::from(["validator1".to_string()]), + ) + .unwrap(); + TOTAL_BALANCES + .save( + deps.as_mut().storage, + AssetInfoKey::from(AssetInfo::Native( + "factory/astro_native_with_existent_rewards".to_string(), + )), + &Uint128::new(1000000), + ) + .unwrap(); + + let res = execute( + deps.as_mut(), + mock_env(), + mock_info("user", &[]), + ExecuteMsg::UpdateRewards {}, + ) + .unwrap(); + assert_eq!( + res.messages, + vec![ + SubMsg::reply_always( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: "astro_incentives".to_string(), + msg: to_json_binary(&ExecuteAstroMsg::ClaimRewards { + lp_tokens: vec!["factory/astro_native_with_existent_rewards".to_string()], + }) + .unwrap(), + funds: vec![], + }), + 3 + ), + SubMsg::reply_on_error( + CosmosMsg::Stargate { + type_url: "/alliance.alliance.MsgClaimDelegationRewards".to_string(), + value: Binary::from( + MsgClaimDelegationRewards { + delegator_address: "cosmos2contract".to_string(), + validator_address: "validator1".to_string(), + denom: DENOM.to_string(), + } + .encode_to_vec() + ) + }, + 2 + ), + SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { + funds: vec![], + contract_addr: "cosmos2contract".to_string(), + msg: to_json_binary(&ExecuteMsg::UpdateAllianceRewardsCallback {}).unwrap() + })) + ] + ); + let prev_balance = TEMP_BALANCE + .load( + deps.as_ref().storage, + AssetInfoKey::from(AssetInfo::Native("uluna".to_string())), + ) + .unwrap(); + assert_eq!(prev_balance, Uint128::new(1000000)); + + let reply_msg = Reply { + id: 3, + result: SubMsgResult::Ok(SubMsgResponse { + events: vec![Event::new("wasm") + .add_attribute("_contract_address", "cosmos2contract") + .add_attribute("action", "claim_rewards") + .add_attribute( + "claimed_position", + "factory/astro_native_with_existent_rewards", + ) + .add_attribute("claimed_reward", "1factory/astro")], + data: None, + }), + }; + let res = reply(deps.as_mut(), mock_env(), reply_msg).unwrap(); + assert_eq!( + res, + Response::new().add_attributes(vec![("action", "claim_astro_rewards_success")]) + ); +} diff --git a/contracts/alliance-lp-hub/src/tests/stake_unstake.rs b/contracts/alliance-lp-hub/src/tests/stake_unstake.rs index 6dbf1be..b369272 100644 --- a/contracts/alliance-lp-hub/src/tests/stake_unstake.rs +++ b/contracts/alliance-lp-hub/src/tests/stake_unstake.rs @@ -15,7 +15,7 @@ use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use cw_asset::{Asset, AssetInfo, AssetInfoKey}; #[test] -fn test_stake() { +fn test_stake_multiple_tokens() { let mut deps = mock_dependencies(); setup_contract(deps.as_mut()); modify_asset( @@ -25,9 +25,40 @@ fn test_stake() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], + ) + .unwrap(); + + let info = mock_info( + "user1", + &[coin(100, "native_asset"), coin(100, "native_asset2")], ); + let env = mock_env(); + let msg = ExecuteMsg::Stake {}; + let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); + assert_eq!(err, ContractError::OnlySingleAssetAllowed {}); + + let info = mock_info("user1", &[coin(0, "native_asset")]); + let env = mock_env(); + let msg = ExecuteMsg::Stake {}; + let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); + assert_eq!(err, ContractError::AmountCannotBeZero {}); +} + +#[test] +fn test_stake() { + let mut deps = mock_dependencies(); + setup_contract(deps.as_mut()); + modify_asset( + deps.as_mut(), + vec![ModifyAssetPair { + asset_info: AssetInfo::native(Addr::unchecked("native_asset")), + reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), + delete: false, + }], + ) + .unwrap(); - let res = stake(deps.as_mut(), "user1", 100, "native_asset"); + let res = stake(deps.as_mut(), "user1", 100, "native_asset").unwrap(); assert_eq!( res, Response::default().add_attributes(vec![ @@ -50,7 +81,7 @@ fn test_stake() { assert_eq!(balance, Uint128::new(100)); // Stake more - let res = stake(deps.as_mut(), "user1", 100, "native_asset"); + let res = stake(deps.as_mut(), "user1", 100, "native_asset").unwrap(); assert_eq!( res, Response::default().add_attributes(vec![ @@ -100,9 +131,10 @@ fn test_stake_astro_token() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); + ) + .unwrap(); - let res = stake(deps.as_mut(), "user1", 100, "astro_existent_native_coin"); + let res = stake(deps.as_mut(), "user1", 100, "astro_existent_native_coin").unwrap(); assert_eq!( res, @@ -146,9 +178,10 @@ fn test_stake_cw20() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); + ) + .unwrap(); - let res = stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset"); + let res = stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset").unwrap(); assert_eq!( res, Response::default().add_attributes(vec![ @@ -171,7 +204,7 @@ fn test_stake_cw20() { assert_eq!(balance, Uint128::new(100)); // Stake more - let res = stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset"); + let res = stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset").unwrap(); assert_eq!( res, Response::default().add_attributes(vec![ @@ -221,9 +254,10 @@ fn test_stake_astro_token_cw20() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); + ) + .unwrap(); - let res = stake_cw20(deps.as_mut(), "user1", 100, "astro_existent_cw20"); + let res = stake_cw20(deps.as_mut(), "user1", 100, "astro_existent_cw20").unwrap(); assert_eq!( res, Response::default() @@ -263,11 +297,12 @@ fn test_unstake() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); - stake(deps.as_mut(), "user1", 100, "native_asset"); + ) + .unwrap(); + stake(deps.as_mut(), "user1", 100, "native_asset").unwrap(); let asset_info = Asset::native(Addr::unchecked("native_asset"), 50u128); - let res = unstake(deps.as_mut(), "user1", asset_info); + let res = unstake(deps.as_mut(), "user1", asset_info).unwrap(); assert_eq!( res, Response::default() @@ -295,7 +330,7 @@ fn test_unstake() { assert_eq!(balance, Uint128::new(50)); let asset_info = Asset::native(Addr::unchecked("native_asset"), 50u128); - let res = unstake(deps.as_mut(), "user1", asset_info); + let res = unstake(deps.as_mut(), "user1", asset_info).unwrap(); assert_eq!( res, Response::default() @@ -343,8 +378,9 @@ fn test_unstake_cw20_invalid() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); - stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset"); + ) + .unwrap(); + stake_cw20(deps.as_mut(), "user1", 100, "cw20_asset").unwrap(); // User does not have any staked asset let info = mock_info("user2", &[]); @@ -377,8 +413,9 @@ fn test_unstake_native_invalid() { reward_asset_info: Some(AssetInfo::Native("uluna".to_string())), delete: false, }], - ); - stake(deps.as_mut(), "user1", 100, "native_asset"); + ) + .unwrap(); + stake(deps.as_mut(), "user1", 100, "native_asset").unwrap(); // User does not have any staked asset let info = mock_info("user2", &[]);