diff --git a/contracts/distribution/dao-rewards-distributor/src/testing/mod.rs b/contracts/distribution/dao-rewards-distributor/src/testing/mod.rs index f523b7235..836069a0a 100644 --- a/contracts/distribution/dao-rewards-distributor/src/testing/mod.rs +++ b/contracts/distribution/dao-rewards-distributor/src/testing/mod.rs @@ -1,287 +1,2 @@ pub mod suite; pub mod tests; - -pub const DENOM: &str = "ujuno"; -pub const ALT_DENOM: &str = "unotjuno"; -pub const OWNER: &str = "owner"; -pub const ADDR1: &str = "addr1"; -pub const ADDR2: &str = "addr2"; -pub const ADDR3: &str = "addr3"; -pub const ADDR4: &str = "addr4"; - -mod cw4_setup { - use cosmwasm_std::Addr; - use cw4::Member; - use cw_multi_test::{App, Executor}; - use dao_testing::contracts::{cw4_group_contract, dao_voting_cw4_contract}; - - use super::OWNER; - - pub fn setup_cw4_test(app: &mut App, initial_members: Vec) -> (Addr, Addr) { - let cw4_group_code_id = app.store_code(cw4_group_contract()); - let vp_code_id = app.store_code(dao_voting_cw4_contract()); - - let msg = dao_voting_cw4::msg::InstantiateMsg { - group_contract: dao_voting_cw4::msg::GroupContract::New { - cw4_group_code_id, - initial_members, - }, - }; - - let vp_addr = app - .instantiate_contract( - vp_code_id, - Addr::unchecked(OWNER), - &msg, - &[], - "cw4-vp", - None, - ) - .unwrap(); - - let cw4_addr: Addr = app - .wrap() - .query_wasm_smart( - vp_addr.clone(), - &dao_voting_cw4::msg::QueryMsg::GroupContract {}, - ) - .unwrap(); - - (vp_addr, cw4_addr) - } -} - -mod native_setup { - use cosmwasm_std::{coins, Addr}; - use cw_multi_test::{App, Executor}; - use dao_testing::contracts::dao_voting_token_staked_contract; - - use super::{DENOM, OWNER}; - - pub fn stake_tokenfactory_tokens( - app: &mut App, - staking_addr: &Addr, - address: &str, - amount: u128, - ) { - let msg = dao_voting_token_staked::msg::ExecuteMsg::Stake {}; - app.execute_contract( - Addr::unchecked(address), - staking_addr.clone(), - &msg, - &coins(amount, DENOM), - ) - .unwrap(); - } - - pub fn unstake_tokenfactory_tokens( - app: &mut App, - staking_addr: &Addr, - address: &str, - amount: u128, - ) { - let msg = dao_voting_token_staked::msg::ExecuteMsg::Unstake { - amount: amount.into(), - }; - app.execute_contract(Addr::unchecked(address), staking_addr.clone(), &msg, &[]) - .unwrap(); - } - - pub fn setup_native_token_test(app: &mut App) -> Addr { - let vp_code_id = app.store_code(dao_voting_token_staked_contract()); - - let msg = dao_voting_token_staked::msg::InstantiateMsg { - active_threshold: None, - unstaking_duration: None, - token_info: dao_voting_token_staked::msg::TokenInfo::Existing { - denom: DENOM.to_string(), - }, - }; - - app.instantiate_contract( - vp_code_id, - Addr::unchecked(OWNER), - &msg, - &[], - "native-vp", - None, - ) - .unwrap() - } -} - -mod cw20_setup { - use cosmwasm_std::{to_json_binary, Addr, Uint128}; - use cw20::Cw20Coin; - use cw_multi_test::{App, Executor}; - use cw_utils::Duration; - use dao_testing::contracts::{ - cw20_base_contract, cw20_stake_contract, dao_voting_cw20_staked_contract, - }; - - use super::OWNER; - - pub fn instantiate_cw20(app: &mut App, name: &str, initial_balances: Vec) -> Addr { - let cw20_id = app.store_code(cw20_base_contract()); - let msg = cw20_base::msg::InstantiateMsg { - name: name.to_string(), - symbol: name.to_string(), - decimals: 6, - initial_balances, - mint: None, - marketing: None, - }; - - app.instantiate_contract(cw20_id, Addr::unchecked(OWNER), &msg, &[], "cw20", None) - .unwrap() - } - - pub fn instantiate_cw20_staking( - app: &mut App, - cw20: Addr, - unstaking_duration: Option, - ) -> Addr { - let staking_code_id = app.store_code(cw20_stake_contract()); - let msg = cw20_stake::msg::InstantiateMsg { - owner: Some(OWNER.to_string()), - token_address: cw20.to_string(), - unstaking_duration, - }; - app.instantiate_contract( - staking_code_id, - Addr::unchecked(OWNER), - &msg, - &[], - "staking", - None, - ) - .unwrap() - } - - pub fn instantiate_cw20_vp_contract(app: &mut App, cw20: Addr, staking_contract: Addr) -> Addr { - let vp_code_id = app.store_code(dao_voting_cw20_staked_contract()); - let msg = dao_voting_cw20_staked::msg::InstantiateMsg { - token_info: dao_voting_cw20_staked::msg::TokenInfo::Existing { - address: cw20.to_string(), - staking_contract: dao_voting_cw20_staked::msg::StakingInfo::Existing { - staking_contract_address: staking_contract.to_string(), - }, - }, - active_threshold: None, - }; - app.instantiate_contract(vp_code_id, Addr::unchecked(OWNER), &msg, &[], "vp", None) - .unwrap() - } - - pub fn setup_cw20_test(app: &mut App, initial_balances: Vec) -> (Addr, Addr, Addr) { - // Instantiate cw20 contract - let cw20_addr = instantiate_cw20(app, "test", initial_balances.clone()); - - // Instantiate staking contract - let staking_addr = instantiate_cw20_staking(app, cw20_addr.clone(), None); - - // Instantiate vp contract - let vp_addr = instantiate_cw20_vp_contract(app, cw20_addr.clone(), staking_addr.clone()); - - (staking_addr, cw20_addr, vp_addr) - } - - #[allow(dead_code)] - pub fn stake_cw20_tokens>( - app: &mut App, - staking_addr: &Addr, - cw20_addr: &Addr, - sender: T, - amount: u128, - ) { - let msg = cw20::Cw20ExecuteMsg::Send { - contract: staking_addr.to_string(), - amount: Uint128::new(amount), - msg: to_json_binary(&cw20_stake::msg::ReceiveMsg::Stake {}).unwrap(), - }; - app.execute_contract(Addr::unchecked(sender), cw20_addr.clone(), &msg, &[]) - .unwrap(); - } -} - -mod cw721_setup { - - use cosmwasm_std::{to_json_binary, Addr, Binary, Empty}; - use cw_multi_test::{App, Executor}; - use dao_testing::contracts::{cw721_base_contract, dao_voting_cw721_staked_contract}; - use dao_voting_cw721_staked::state::Config; - - use super::OWNER; - - pub fn stake_cw721( - app: &mut App, - vp_addr: &Addr, - cw721_addr: &Addr, - address: &str, - token_id: &str, - ) { - let msg = cw721_base::msg::ExecuteMsg::::SendNft { - contract: vp_addr.to_string(), - token_id: token_id.to_string(), - msg: Binary::default(), - }; - - app.execute_contract(Addr::unchecked(address), cw721_addr.clone(), &msg, &[]) - .unwrap(); - } - - pub fn unstake_cw721(app: &mut App, vp_addr: &Addr, address: &str, token_id: &str) { - app.execute_contract( - Addr::unchecked(address), - vp_addr.clone(), - &dao_voting_cw721_staked::msg::ExecuteMsg::Unstake { - token_ids: vec![token_id.to_string()], - }, - &[], - ) - .unwrap(); - } - - pub fn setup_cw721_test(app: &mut App, initial_nfts: Vec) -> (Addr, Addr) { - let cw721_code_id = app.store_code(cw721_base_contract()); - let vp_code_id = app.store_code(dao_voting_cw721_staked_contract()); - - let msg = dao_voting_cw721_staked::msg::InstantiateMsg { - nft_contract: dao_voting_cw721_staked::msg::NftContract::New { - code_id: cw721_code_id, - label: "Test NFT contract".to_string(), - msg: to_json_binary(&cw721_base::msg::InstantiateMsg { - name: "Test NFT".to_string(), - symbol: "TEST".to_string(), - minter: OWNER.to_string(), - }) - .unwrap(), - initial_nfts, - }, - active_threshold: None, - unstaking_duration: None, - }; - - let vp_addr = app - .instantiate_contract( - vp_code_id, - Addr::unchecked(OWNER), - &msg, - &[], - "cw721-vp", - None, - ) - .unwrap(); - - let cw721_addr = app - .wrap() - .query_wasm_smart::( - vp_addr.clone(), - &dao_voting_cw721_staked::msg::QueryMsg::Config {}, - ) - .unwrap() - .nft_address; - - (vp_addr, cw721_addr) - } -} diff --git a/contracts/distribution/dao-rewards-distributor/src/testing/suite.rs b/contracts/distribution/dao-rewards-distributor/src/testing/suite.rs index a5df4fb76..94278ebc8 100644 --- a/contracts/distribution/dao-rewards-distributor/src/testing/suite.rs +++ b/contracts/distribution/dao-rewards-distributor/src/testing/suite.rs @@ -1,14 +1,15 @@ -use std::borrow::BorrowMut; - use cosmwasm_schema::cw_serde; -use cosmwasm_std::{coin, coins, to_json_binary, Addr, Coin, Empty, Timestamp, Uint128}; +use cosmwasm_std::{coin, to_json_binary, Addr, Coin, Timestamp, Uint128}; use cw20::{Cw20Coin, Expiration, UncheckedDenom}; use cw4::{Member, MemberListResponse}; -use cw_multi_test::{App, BankSudo, Executor, SudoMsg}; +use cw_multi_test::{BankSudo, Executor, SudoMsg}; use cw_ownable::Action; use cw_utils::Duration; -use dao_interface::voting::InfoResponse; -use dao_testing::contracts::dao_rewards_distributor_contract; +use dao_interface::{token::InitialBalance, voting::InfoResponse}; +use dao_testing::{ + Cw20TestDao, Cw4TestDao, Cw721TestDao, DaoTestingSuite, DaoTestingSuiteBase, InitialNft, + TokenTestDao, GOV_DENOM, MEMBER1, MEMBER2, MEMBER3, OWNER, +}; use crate::{ msg::{ @@ -16,25 +17,13 @@ use crate::{ PendingRewardsResponse, QueryMsg, ReceiveCw20Msg, }, state::{DistributionState, EmissionRate}, - testing::cw20_setup::instantiate_cw20, }; use dao_rewards_distributor::ContractError; - -use super::{ - cw20_setup::{self, setup_cw20_test}, - cw4_setup::setup_cw4_test, - cw721_setup::{setup_cw721_test, stake_cw721, unstake_cw721}, - native_setup::{ - setup_native_token_test, stake_tokenfactory_tokens, unstake_tokenfactory_tokens, - }, - ADDR1, ADDR2, ADDR3, DENOM, OWNER, -}; - pub enum DaoType { CW20, + CW4, CW721, Native, - CW4, } #[cw_serde] @@ -47,7 +36,6 @@ pub struct RewardsConfig { } pub struct SuiteBuilder { - pub _instantiate: InstantiateMsg, pub dao_type: DaoType, pub rewards_config: RewardsConfig, pub cw4_members: Vec, @@ -56,28 +44,25 @@ pub struct SuiteBuilder { impl SuiteBuilder { pub fn base(dao_type: DaoType) -> Self { Self { - _instantiate: InstantiateMsg { - owner: Some(OWNER.to_string()), - }, dao_type, rewards_config: RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Height(10), destination: None, continuous: true, }, cw4_members: vec![ Member { - addr: ADDR1.to_string(), + addr: MEMBER1.to_string(), weight: 2, }, Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 1, }, Member { - addr: ADDR3.to_string(), + addr: MEMBER3.to_string(), weight: 1, }, ], @@ -102,153 +87,133 @@ impl SuiteBuilder { impl SuiteBuilder { pub fn build(mut self) -> Suite { - let owner = Addr::unchecked(OWNER); - let mut suite_built = Suite { - app: App::default(), - owner: Some(owner.clone()), + base: DaoTestingSuiteBase::new(), + core_addr: Addr::unchecked(""), staking_addr: Addr::unchecked(""), voting_power_addr: Addr::unchecked(""), reward_code_id: 0, distribution_contract: Addr::unchecked(""), cw20_addr: Addr::unchecked(""), - reward_denom: DENOM.to_string(), + reward_denom: GOV_DENOM.to_string(), + cw20_dao: None, + cw4_dao: None, + cw721_dao: None, + token_dao: None, }; - // start at 0 height and time - suite_built.app.borrow_mut().update_block(|b| b.height = 0); - suite_built - .app - .borrow_mut() - .update_block(|b| b.time = Timestamp::from_seconds(0)); - match self.dao_type { DaoType::CW4 => { - let (voting_power_addr, dao_voting_addr) = - setup_cw4_test(suite_built.app.borrow_mut(), self.cw4_members); - suite_built.voting_power_addr = voting_power_addr.clone(); - suite_built.staking_addr = dao_voting_addr.clone(); + let dao = suite_built.base.cw4().with_members(self.cw4_members).dao(); + suite_built.core_addr = dao.core_addr.clone(); + suite_built.voting_power_addr = dao.voting_module_addr.clone(); + suite_built.staking_addr = dao.x.group_addr.clone(); + suite_built.cw4_dao = Some(dao); } DaoType::CW20 => { - let initial_balances = vec![ - Cw20Coin { - address: ADDR1.to_string(), - amount: Uint128::new(100), - }, - Cw20Coin { - address: ADDR2.to_string(), - amount: Uint128::new(50), - }, - Cw20Coin { - address: ADDR3.to_string(), - amount: Uint128::new(50), - }, - ]; - - let (staking_addr, cw20_addr, vp_addr) = - setup_cw20_test(suite_built.app.borrow_mut(), initial_balances.clone()); - - suite_built.voting_power_addr = vp_addr.clone(); - suite_built.cw20_addr = cw20_addr.clone(); - suite_built.staking_addr = staking_addr.clone(); - - for coin in initial_balances.clone() { - suite_built.stake_cw20_tokens(coin.amount.u128(), coin.address.as_str()); - } + let dao = suite_built + .base + .cw20() + .with_initial_balances(vec![ + Cw20Coin { + address: MEMBER1.to_string(), + amount: Uint128::new(100), + }, + Cw20Coin { + address: MEMBER2.to_string(), + amount: Uint128::new(50), + }, + Cw20Coin { + address: MEMBER3.to_string(), + amount: Uint128::new(50), + }, + ]) + .dao(); + + suite_built.core_addr = dao.core_addr.clone(); + suite_built.voting_power_addr = dao.voting_module_addr.clone(); + suite_built.cw20_addr = dao.x.cw20_addr.clone(); + suite_built.staking_addr = dao.x.staking_addr.clone(); + suite_built.cw20_dao = Some(dao); } DaoType::CW721 => { - let initial_nfts = vec![ - to_json_binary(&cw721_base::msg::ExecuteMsg::::Mint { - token_id: "1".to_string(), - owner: ADDR1.to_string(), - token_uri: Some("https://jpegs.com".to_string()), - extension: Empty {}, - }) - .unwrap(), - to_json_binary(&cw721_base::msg::ExecuteMsg::::Mint { - token_id: "2".to_string(), - owner: ADDR1.to_string(), - token_uri: Some("https://jpegs.com".to_string()), - extension: Empty {}, - }) - .unwrap(), - to_json_binary(&cw721_base::msg::ExecuteMsg::::Mint { - token_id: "3".to_string(), - owner: ADDR2.to_string(), - token_uri: Some("https://jpegs.com".to_string()), - extension: Empty {}, - }) - .unwrap(), - to_json_binary(&cw721_base::msg::ExecuteMsg::::Mint { - token_id: "4".to_string(), - owner: ADDR3.to_string(), - token_uri: Some("https://jpegs.com".to_string()), - extension: Empty {}, - }) - .unwrap(), - ]; - - let (vp_addr, cw721) = setup_cw721_test(suite_built.app.borrow_mut(), initial_nfts); - - suite_built.voting_power_addr = vp_addr.clone(); - suite_built.staking_addr = cw721.clone(); - - suite_built.stake_nft(ADDR1, 1); - suite_built.stake_nft(ADDR1, 2); - suite_built.stake_nft(ADDR2, 3); - suite_built.stake_nft(ADDR3, 4); + let dao = suite_built + .base + .cw721() + .with_initial_nfts(vec![ + InitialNft { + token_id: "1".to_string(), + owner: MEMBER1.to_string(), + }, + InitialNft { + token_id: "2".to_string(), + owner: MEMBER1.to_string(), + }, + InitialNft { + token_id: "3".to_string(), + owner: MEMBER2.to_string(), + }, + InitialNft { + token_id: "4".to_string(), + owner: MEMBER3.to_string(), + }, + ]) + .dao(); + + suite_built.core_addr = dao.core_addr.clone(); + suite_built.voting_power_addr = dao.voting_module_addr.clone(); + suite_built.staking_addr = dao.x.cw721_addr.clone(); + suite_built.cw721_dao = Some(dao); } DaoType::Native => { - let initial_balances = vec![ - (ADDR1, coins(100, DENOM)), - (ADDR2, coins(50, DENOM)), - (ADDR3, coins(50, DENOM)), - ]; - - // Mint tokens for initial balances - for init_bal in initial_balances { - suite_built - .app - .borrow_mut() - .sudo(SudoMsg::Bank({ - BankSudo::Mint { - to_address: init_bal.0.to_string(), - amount: init_bal.1, - } - })) - .unwrap(); - } - - // Create Native token staking contract - let vp_addr = setup_native_token_test(suite_built.app.borrow_mut()); - suite_built.voting_power_addr = vp_addr.clone(); - suite_built.staking_addr = vp_addr.clone(); - suite_built.stake_native_tokens(ADDR1, 100); - suite_built.stake_native_tokens(ADDR2, 50); - suite_built.stake_native_tokens(ADDR3, 50); + let dao = suite_built + .base + .token() + .with_initial_balances(vec![ + InitialBalance { + address: MEMBER1.to_string(), + amount: Uint128::new(100), + }, + InitialBalance { + address: MEMBER2.to_string(), + amount: Uint128::new(50), + }, + InitialBalance { + address: MEMBER3.to_string(), + amount: Uint128::new(50), + }, + ]) + .dao(); + + suite_built.core_addr = dao.core_addr.clone(); + suite_built.voting_power_addr = dao.voting_module_addr.clone(); + suite_built.staking_addr = dao.voting_module_addr.clone(); + suite_built.token_dao = Some(dao); } }; + // start at 0 height and time + suite_built.base.app.update_block(|b| { + b.height = 0; + b.time = Timestamp::from_seconds(0); + }); + // initialize the rewards distributor - suite_built.reward_code_id = suite_built - .app - .borrow_mut() - .store_code(dao_rewards_distributor_contract()); - let reward_addr = suite_built + suite_built.reward_code_id = suite_built.base.rewards_distributor_id; + suite_built.distribution_contract = suite_built + .base .app - .borrow_mut() .instantiate_contract( suite_built.reward_code_id, - owner.clone(), + Addr::unchecked(OWNER), &InstantiateMsg { - owner: Some(owner.clone().into_string()), + owner: Some(OWNER.to_string()), }, &[], "reward", None, ) .unwrap(); - suite_built.distribution_contract = reward_addr.clone(); // depending on the dao type we register rewards differently match self.dao_type { @@ -261,7 +226,7 @@ impl SuiteBuilder { ); match self.rewards_config.denom { UncheckedDenom::Native(_) => { - suite_built.fund_native(1, coin(100_000_000, DENOM.to_string())); + suite_built.fund_native(1, coin(100_000_000, GOV_DENOM.to_string())); } UncheckedDenom::Cw20(_) => { suite_built.fund_cw20( @@ -278,15 +243,16 @@ impl SuiteBuilder { self.rewards_config.denom = match self.rewards_config.denom { UncheckedDenom::Native(denom) => UncheckedDenom::Native(denom), UncheckedDenom::Cw20(_) => UncheckedDenom::Cw20( - instantiate_cw20( - suite_built.app.borrow_mut(), - "rewardcw", - vec![Cw20Coin { - address: OWNER.to_string(), - amount: Uint128::new(1_000_000_000), - }], - ) - .to_string(), + suite_built + .base + .instantiate_cw20( + "rewardcw", + vec![Cw20Coin { + address: OWNER.to_string(), + amount: Uint128::new(1_000_000_000), + }], + ) + .to_string(), ), }; suite_built.reward_denom = match self.rewards_config.denom.clone() { @@ -302,7 +268,7 @@ impl SuiteBuilder { ); match &self.rewards_config.denom { UncheckedDenom::Native(_) => { - suite_built.fund_native(1, coin(100_000_000, DENOM.to_string())); + suite_built.fund_native(1, coin(100_000_000, GOV_DENOM.to_string())); } UncheckedDenom::Cw20(addr) => { suite_built.fund_cw20( @@ -324,9 +290,9 @@ impl SuiteBuilder { } pub struct Suite { - pub app: App, - pub owner: Option, + pub base: DaoTestingSuiteBase, + pub core_addr: Addr, pub staking_addr: Addr, pub voting_power_addr: Addr, pub reward_denom: String, @@ -336,13 +302,19 @@ pub struct Suite { // cw20 type fields pub cw20_addr: Addr, + + // DAO types + pub cw20_dao: Option, + pub cw4_dao: Option, + pub cw721_dao: Option, + pub token_dao: Option, } // SUITE QUERIES impl Suite { pub fn get_time_until_rewards_expiration(&mut self) -> u64 { let distribution = &self.get_distributions().distributions[0]; - let current_block = self.app.block_info(); + let current_block = self.base.app.block_info(); let (expiration_unit, current_unit) = match distribution.active_epoch.ends_at { cw20::Expiration::AtHeight(h) => (h, current_block.height), cw20::Expiration::AtTime(t) => (t.seconds(), current_block.time.seconds()), @@ -361,7 +333,8 @@ impl Suite { address: T, denom: U, ) -> u128 { - self.app + self.base + .app .wrap() .query_balance(address, denom) .unwrap() @@ -378,6 +351,7 @@ impl Suite { address: address.into(), }; let result: cw20::BalanceResponse = self + .base .app .wrap() .query_wasm_smart(contract_addr, &msg) @@ -386,7 +360,8 @@ impl Suite { } pub fn get_distributions(&mut self) -> DistributionsResponse { - self.app + self.base + .app .wrap() .query_wasm_smart( self.distribution_contract.clone(), @@ -400,6 +375,7 @@ impl Suite { pub fn get_distribution(&mut self, id: u64) -> DistributionState { let resp: DistributionState = self + .base .app .wrap() .query_wasm_smart( @@ -412,8 +388,8 @@ impl Suite { pub fn get_undistributed_rewards(&mut self, id: u64) -> Uint128 { let undistributed_rewards: Uint128 = self + .base .app - .borrow_mut() .wrap() .query_wasm_smart( self.distribution_contract.clone(), @@ -425,8 +401,8 @@ impl Suite { pub fn get_owner(&mut self) -> Addr { let ownable_response: cw_ownable::Ownership = self + .base .app - .borrow_mut() .wrap() .query_wasm_smart(self.distribution_contract.clone(), &QueryMsg::Ownership {}) .unwrap(); @@ -434,8 +410,8 @@ impl Suite { } pub fn get_info(&mut self) -> InfoResponse { - self.app - .borrow_mut() + self.base + .app .wrap() .query_wasm_smart(self.distribution_contract.clone(), &QueryMsg::Info {}) .unwrap() @@ -480,8 +456,8 @@ impl Suite { pub fn assert_pending_rewards(&mut self, address: &str, id: u64, expected: u128) { let res: PendingRewardsResponse = self + .base .app - .borrow_mut() .wrap() .query_wasm_smart( self.distribution_contract.clone(), @@ -535,7 +511,8 @@ impl Suite { impl Suite { pub fn withdraw(&mut self, id: u64) { let msg = ExecuteMsg::Withdraw { id }; - self.app + self.base + .app .execute_contract( Addr::unchecked(OWNER), self.distribution_contract.clone(), @@ -547,7 +524,8 @@ impl Suite { pub fn withdraw_error(&mut self, id: u64) -> ContractError { let msg = ExecuteMsg::Withdraw { id }; - self.app + self.base + .app .execute_contract( Addr::unchecked(OWNER), self.distribution_contract.clone(), @@ -563,8 +541,9 @@ impl Suite { let msg = cw4_group::msg::ExecuteMsg::AddHook { addr: self.distribution_contract.to_string(), }; - self.app - .execute_contract(Addr::unchecked(OWNER), addr, &msg, &[]) + self.base + .app + .execute_contract(self.core_addr.clone(), addr, &msg, &[]) .unwrap(); } @@ -597,10 +576,10 @@ impl Suite { vec![] }; - self.app - .borrow_mut() + self.base + .app .execute_contract( - self.owner.clone().unwrap(), + Addr::unchecked(OWNER), self.distribution_contract.clone(), &execute_create_msg, &send_funds, @@ -610,8 +589,8 @@ impl Suite { pub fn mint_native(&mut self, coin: Coin, dest: &str) { // mint the tokens to be funded - self.app - .borrow_mut() + self.base + .app .sudo(SudoMsg::Bank({ BankSudo::Mint { to_address: dest.to_string(), @@ -622,13 +601,13 @@ impl Suite { } pub fn mint_cw20(&mut self, coin: Cw20Coin, name: &str) -> Addr { - cw20_setup::instantiate_cw20(self.app.borrow_mut(), name, vec![coin]) + self.base.instantiate_cw20(name, vec![coin]) } pub fn fund_native(&mut self, id: u64, coin: Coin) { self.mint_native(coin.clone(), OWNER); - self.app - .borrow_mut() + self.base + .app .execute_contract( Addr::unchecked(OWNER), self.distribution_contract.clone(), @@ -640,8 +619,8 @@ impl Suite { pub fn fund_latest_native(&mut self, coin: Coin) { self.mint_native(coin.clone(), OWNER); - self.app - .borrow_mut() + self.base + .app .execute_contract( Addr::unchecked(OWNER), self.distribution_contract.clone(), @@ -653,7 +632,8 @@ impl Suite { pub fn fund_cw20(&mut self, id: u64, coin: Cw20Coin) { let fund_sub_msg = to_json_binary(&ReceiveCw20Msg::Fund(FundMsg { id })).unwrap(); - self.app + self.base + .app .execute_contract( Addr::unchecked(OWNER), Addr::unchecked(coin.address), @@ -669,7 +649,8 @@ impl Suite { pub fn fund_latest_cw20(&mut self, coin: Cw20Coin) { let fund_sub_msg = to_json_binary(&ReceiveCw20Msg::FundLatest {}).unwrap(); - self.app + self.base + .app .execute_contract( Addr::unchecked(OWNER), Addr::unchecked(coin.address), @@ -684,14 +665,14 @@ impl Suite { } pub fn skip_blocks(&mut self, blocks: u64) { - self.app.borrow_mut().update_block(|b| { + self.base.app.update_block(|b| { println!("skipping blocks {:?} -> {:?}", b.height, b.height + blocks); b.height += blocks }); } pub fn skip_seconds(&mut self, seconds: u64) { - self.app.borrow_mut().update_block(|b| { + self.base.app.update_block(|b| { let new_block_time = b.time.plus_seconds(seconds); println!( "skipping seconds {:?} -> {:?}", @@ -710,7 +691,8 @@ impl Suite { pub fn claim_rewards(&mut self, address: &str, id: u64) { let msg = ExecuteMsg::Claim { id }; - self.app + self.base + .app .execute_contract( Addr::unchecked(address), self.distribution_contract.clone(), @@ -727,7 +709,8 @@ impl Suite { amount: Uint128::new(amount), msg: to_json_binary(&cw20_stake::msg::ReceiveMsg::Stake {}).unwrap(), }; - self.app + self.base + .app .execute_contract(Addr::unchecked(sender), self.cw20_addr.clone(), &msg, &[]) .unwrap(); } @@ -736,7 +719,8 @@ impl Suite { let msg = cw20_stake::msg::ExecuteMsg::Unstake { amount: Uint128::new(amount), }; - self.app + self.base + .app .execute_contract( Addr::unchecked(sender), self.staking_addr.clone(), @@ -747,30 +731,31 @@ impl Suite { } pub fn stake_nft(&mut self, sender: &str, token_id: u64) { - stake_cw721( - self.app.borrow_mut(), - &self.voting_power_addr, - &self.staking_addr, + self.base.cw721().stake( + &self.cw721_dao.clone().unwrap(), sender, - &token_id.to_string(), + token_id.to_string(), ) } pub fn unstake_nft(&mut self, sender: &str, token_id: u64) { - unstake_cw721( - self.app.borrow_mut(), - &self.voting_power_addr, + self.base.cw721().unstake( + &self.cw721_dao.clone().unwrap(), sender, - &token_id.to_string(), + token_id.to_string(), ) } pub fn stake_native_tokens(&mut self, address: &str, amount: u128) { - stake_tokenfactory_tokens(self.app.borrow_mut(), &self.staking_addr, address, amount) + self.base + .token() + .stake(&self.token_dao.clone().unwrap(), address, amount) } pub fn unstake_native_tokens(&mut self, address: &str, amount: u128) { - unstake_tokenfactory_tokens(self.app.borrow_mut(), &self.staking_addr, address, amount) + self.base + .token() + .unstake(&self.token_dao.clone().unwrap(), address, amount) } pub fn update_emission_rate( @@ -794,6 +779,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -815,6 +801,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -836,6 +823,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -857,6 +845,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -878,6 +867,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -899,6 +889,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -920,6 +911,7 @@ impl Suite { }; let _resp = self + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -933,13 +925,15 @@ impl Suite { pub fn update_members(&mut self, add: Vec, remove: Vec) { let msg = cw4_group::msg::ExecuteMsg::UpdateMembers { remove, add }; - self.app - .execute_contract(Addr::unchecked(OWNER), self.staking_addr.clone(), &msg, &[]) + self.base + .app + .execute_contract(self.core_addr.clone(), self.staking_addr.clone(), &msg, &[]) .unwrap(); } pub fn query_members(&mut self) -> Vec { let members: MemberListResponse = self + .base .app .wrap() .query_wasm_smart( @@ -960,7 +954,8 @@ impl Suite { expiry: None, }); - self.app + self.base + .app .execute_contract( Addr::unchecked(OWNER), self.distribution_contract.clone(), @@ -969,7 +964,8 @@ impl Suite { ) .unwrap(); - self.app + self.base + .app .execute_contract( Addr::unchecked(new_owner), self.distribution_contract.clone(), diff --git a/contracts/distribution/dao-rewards-distributor/src/testing/tests.rs b/contracts/distribution/dao-rewards-distributor/src/testing/tests.rs index ec619e6ce..b40752e97 100644 --- a/contracts/distribution/dao-rewards-distributor/src/testing/tests.rs +++ b/contracts/distribution/dao-rewards-distributor/src/testing/tests.rs @@ -1,5 +1,3 @@ -use std::borrow::BorrowMut; - use cosmwasm_std::testing::{mock_dependencies, mock_env}; use cosmwasm_std::{coin, coins, to_json_binary, Addr, Timestamp}; use cosmwasm_std::{Uint128, Uint256}; @@ -10,21 +8,17 @@ use cw_multi_test::Executor; use cw_ownable::OwnershipError; use cw_utils::Duration; use dao_interface::voting::InfoResponse; +use dao_testing::{DaoTestingSuite, GOV_DENOM, MEMBER1, MEMBER2, MEMBER3, MEMBER4, OWNER}; use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; +use crate::msg::ExecuteMsg; use crate::msg::{CreateMsg, FundMsg, InstantiateMsg, MigrateMsg}; use crate::state::{EmissionRate, Epoch}; -use crate::testing::native_setup::setup_native_token_test; -use crate::{ - msg::ExecuteMsg, - testing::{ADDR1, ADDR2, ADDR3, ADDR4, DENOM}, -}; use dao_rewards_distributor::ContractError; -use super::{ - suite::{RewardsConfig, SuiteBuilder}, - ALT_DENOM, OWNER, -}; +use super::suite::{RewardsConfig, SuiteBuilder}; + +const ALT_DENOM: &str = "ualtgovtoken"; // By default, the tests are set up to distribute rewards over 1_000_000 units of time. // Over that time, 100_000_000 token rewards will be distributed. @@ -34,7 +28,7 @@ use super::{ fn test_fund_native_404() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); - let mint_coin = coin(100, DENOM); + let mint_coin = coin(100, GOV_DENOM); suite.mint_native(mint_coin.clone(), OWNER); suite.fund_native(3, mint_coin); @@ -80,24 +74,24 @@ fn test_native_dao_rewards_update_reward_rate() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); suite.assert_undistributed_rewards(1, 90_000_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); suite.assert_undistributed_rewards(1, 80_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_pending_rewards(MEMBER1, 1, 0); // set the rewards rate to half of the current one // now there will be 5_000_000 tokens distributed over 100_000 blocks @@ -106,9 +100,9 @@ fn test_native_dao_rewards_update_reward_rate() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 2_500_000); - suite.assert_pending_rewards(ADDR2, 1, 6_250_000); - suite.assert_pending_rewards(ADDR3, 1, 6_250_000); + suite.assert_pending_rewards(MEMBER1, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 6_250_000); + suite.assert_pending_rewards(MEMBER3, 1, 6_250_000); suite.assert_undistributed_rewards(1, 75_000_000); @@ -119,18 +113,18 @@ fn test_native_dao_rewards_update_reward_rate() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 7_500_000); - suite.assert_pending_rewards(ADDR2, 1, 8_750_000); - suite.assert_pending_rewards(ADDR3, 1, 8_750_000); + suite.assert_pending_rewards(MEMBER1, 1, 7_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 8_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 8_750_000); suite.assert_undistributed_rewards(1, 65_000_000); // skip 2/10ths of the time suite.skip_blocks(200_000); - suite.assert_pending_rewards(ADDR1, 1, 17_500_000); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER1, 1, 17_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); suite.assert_undistributed_rewards(1, 45_000_000); @@ -141,44 +135,44 @@ fn test_native_dao_rewards_update_reward_rate() { suite.skip_blocks(100_000); // assert no pending rewards changed - suite.assert_pending_rewards(ADDR1, 1, 17_500_000); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER1, 1, 17_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); suite.assert_undistributed_rewards(1, 45_000_000); - // assert ADDR1 pre-claim balance - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - // ADDR1 claims their rewards - suite.claim_rewards(ADDR1, 1); - // assert ADDR1 post-claim balance to be pre-claim + pending - suite.assert_native_balance(ADDR1, DENOM, 10_000_000 + 17_500_000); - // assert ADDR1 is now entitled to 0 pending rewards - suite.assert_pending_rewards(ADDR1, 1, 0); + // assert MEMBER1 pre-claim balance + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + // MEMBER1 claims their rewards + suite.claim_rewards(MEMBER1, 1); + // assert MEMBER1 post-claim balance to be pre-claim + pending + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000 + 17_500_000); + // assert MEMBER1 is now entitled to 0 pending rewards + suite.assert_pending_rewards(MEMBER1, 1, 0); // user 2 unstakes their stake - suite.unstake_native_tokens(ADDR2, 50); + suite.unstake_native_tokens(MEMBER2, 50); // skip 1/10th of the time suite.skip_blocks(100_000); - // only the ADDR1 pending rewards should have changed - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); + // only the MEMBER1 pending rewards should have changed + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); suite.assert_undistributed_rewards(1, 45_000_000); - // ADDR2 claims their rewards (has 50 to begin with as they unstaked) - suite.assert_native_balance(ADDR2, DENOM, 50); - suite.claim_rewards(ADDR2, 1); - // assert ADDR2 post-claim balance to be pre-claim + pending and has 0 pending rewards - suite.assert_native_balance(ADDR2, DENOM, 13_750_000 + 50); - suite.assert_pending_rewards(ADDR2, 1, 0); + // MEMBER2 claims their rewards (has 50 to begin with as they unstaked) + suite.assert_native_balance(MEMBER2, GOV_DENOM, 50); + suite.claim_rewards(MEMBER2, 1); + // assert MEMBER2 post-claim balance to be pre-claim + pending and has 0 pending rewards + suite.assert_native_balance(MEMBER2, GOV_DENOM, 13_750_000 + 50); + suite.assert_pending_rewards(MEMBER2, 1, 0); // update the reward rate back to 1_000 / 10blocks // this should now distribute 10_000_000 tokens over 100_000 blocks - // between ADDR1 (2/3rds) and ADDR3 (1/3rd) + // between MEMBER1 (2/3rds) and MEMBER3 (1/3rd) suite.update_emission_rate(1, Duration::Height(10), 1000, true); // update with the same rate does nothing @@ -188,37 +182,37 @@ fn test_native_dao_rewards_update_reward_rate() { suite.skip_blocks(100_000); // assert that rewards are being distributed at the expected rate - suite.assert_pending_rewards(ADDR1, 1, 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000 + 3_333_333); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000 + 3_333_333); suite.assert_undistributed_rewards(1, 35_000_000); - // ADDR3 claims their rewards - suite.assert_native_balance(ADDR3, DENOM, 0); - suite.claim_rewards(ADDR3, 1); - suite.assert_pending_rewards(ADDR3, 1, 0); - suite.assert_native_balance(ADDR3, DENOM, 13_750_000 + 3_333_333); + // MEMBER3 claims their rewards + suite.assert_native_balance(MEMBER3, GOV_DENOM, 0); + suite.claim_rewards(MEMBER3, 1); + suite.assert_pending_rewards(MEMBER3, 1, 0); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 13_750_000 + 3_333_333); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 6_666_666 + 6_666_666 + 1); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666 + 6_666_666 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333); suite.assert_undistributed_rewards(1, 25_000_000); // claim everything so that there are 0 pending rewards - suite.claim_rewards(ADDR3, 1); - suite.claim_rewards(ADDR1, 1); + suite.claim_rewards(MEMBER3, 1); + suite.claim_rewards(MEMBER1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); // update the rewards rate to 40_000_000 per 100_000 blocks. - // split is still 2/3rds to ADDR1 and 1/3rd to ADDR3 + // split is still 2/3rds to MEMBER1 and 1/3rd to MEMBER3 suite.update_emission_rate(1, Duration::Height(10), 4000, true); suite.assert_ends_at(Expiration::AtHeight(1_062_500)); @@ -226,40 +220,41 @@ fn test_native_dao_rewards_update_reward_rate() { let addr1_pending = 20_000_000 * 2 / 3; let addr3_pending = 20_000_000 / 3; - suite.assert_pending_rewards(ADDR1, 1, addr1_pending); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending); suite.assert_undistributed_rewards(1, 5_000_000); - // ADDR2 wakes up to the increased staking rate and stakes 50 tokens - // this brings new split to: [ADDR1: 50%, ADDR2: 25%, ADDR3: 25%] - suite.stake_native_tokens(ADDR2, 50); + // MEMBER2 wakes up to the increased staking rate and stakes 50 tokens + // this brings new split to: [MEMBER1: 50%, MEMBER2: 25%, MEMBER3: 25%] + suite.stake_native_tokens(MEMBER2, 50); suite.skip_blocks(10_000); // allocates 4_000_000 tokens - suite.assert_pending_rewards(ADDR1, 1, addr1_pending + 4_000_000 * 2 / 4); - suite.assert_pending_rewards(ADDR2, 1, 4_000_000 / 4); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending + 4_000_000 / 4); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending + 4_000_000 * 2 / 4); + suite.assert_pending_rewards(MEMBER2, 1, 4_000_000 / 4); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending + 4_000_000 / 4); suite.assert_undistributed_rewards(1, 1_000_000); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER3, 1); let addr1_pending = 0; let addr3_pending = 0; suite.skip_blocks(10_000); // skips from 1,060,000 to 1,070,000, and the end is 1,062,500, so this allocates only 1_000_000 tokens instead of 4_000_000 - suite.assert_pending_rewards(ADDR1, 1, addr1_pending + 1_000_000 * 2 / 4); - suite.assert_pending_rewards(ADDR2, 1, 4_000_000 / 4 + 1_000_000 / 4); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending + 1_000_000 / 4); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending + 1_000_000 * 2 / 4); + suite.assert_pending_rewards(MEMBER2, 1, 4_000_000 / 4 + 1_000_000 / 4); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending + 1_000_000 / 4); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER2, 1); suite.assert_undistributed_rewards(1, 0); // TODO: there's a few denoms remaining here, ensure such cases are handled properly - let remaining_rewards = suite.get_balance_native(suite.distribution_contract.clone(), DENOM); + let remaining_rewards = + suite.get_balance_native(suite.distribution_contract.clone(), GOV_DENOM); println!("Remaining rewards: {}", remaining_rewards); } @@ -268,7 +263,7 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Height(10), destination: None, continuous: true, @@ -282,20 +277,20 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_pending_rewards(MEMBER1, 1, 0); // set the rewards rate to time-based rewards suite.update_emission_rate(1, Duration::Time(10), 500, true); @@ -303,9 +298,9 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 2_500_000); - suite.assert_pending_rewards(ADDR2, 1, 6_250_000); - suite.assert_pending_rewards(ADDR3, 1, 6_250_000); + suite.assert_pending_rewards(MEMBER1, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 6_250_000); + suite.assert_pending_rewards(MEMBER3, 1, 6_250_000); // double the rewards rate // now there will be 10_000_000 tokens distributed over 100_000 seconds @@ -314,16 +309,16 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 7_500_000); - suite.assert_pending_rewards(ADDR2, 1, 8_750_000); - suite.assert_pending_rewards(ADDR3, 1, 8_750_000); + suite.assert_pending_rewards(MEMBER1, 1, 7_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 8_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 8_750_000); // skip 2/10ths of the time suite.skip_seconds(200_000); - suite.assert_pending_rewards(ADDR1, 1, 17_500_000); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER1, 1, 17_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); // pause the rewards distribution suite.pause_emission(1); @@ -332,73 +327,73 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { suite.skip_blocks(100_000); // assert no pending rewards changed - suite.assert_pending_rewards(ADDR1, 1, 17_500_000); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); - - // assert ADDR1 pre-claim balance - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - // ADDR1 claims their rewards - suite.claim_rewards(ADDR1, 1); - // assert ADDR1 post-claim balance to be pre-claim + pending - suite.assert_native_balance(ADDR1, DENOM, 10_000_000 + 17_500_000); - // assert ADDR1 is now entitled to 0 pending rewards - suite.assert_pending_rewards(ADDR1, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 17_500_000); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); + + // assert MEMBER1 pre-claim balance + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + // MEMBER1 claims their rewards + suite.claim_rewards(MEMBER1, 1); + // assert MEMBER1 post-claim balance to be pre-claim + pending + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000 + 17_500_000); + // assert MEMBER1 is now entitled to 0 pending rewards + suite.assert_pending_rewards(MEMBER1, 1, 0); // user 2 unstakes their stake - suite.unstake_native_tokens(ADDR2, 50); + suite.unstake_native_tokens(MEMBER2, 50); // skip 1/10th of the time suite.skip_blocks(100_000); - // only the ADDR1 pending rewards should have changed - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 13_750_000); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000); + // only the MEMBER1 pending rewards should have changed + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 13_750_000); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000); - // ADDR2 claims their rewards (has 50 to begin with as they unstaked) - suite.assert_native_balance(ADDR2, DENOM, 50); - suite.claim_rewards(ADDR2, 1); - // assert ADDR2 post-claim balance to be pre-claim + pending and has 0 pending rewards - suite.assert_native_balance(ADDR2, DENOM, 13_750_000 + 50); - suite.assert_pending_rewards(ADDR2, 1, 0); + // MEMBER2 claims their rewards (has 50 to begin with as they unstaked) + suite.assert_native_balance(MEMBER2, GOV_DENOM, 50); + suite.claim_rewards(MEMBER2, 1); + // assert MEMBER2 post-claim balance to be pre-claim + pending and has 0 pending rewards + suite.assert_native_balance(MEMBER2, GOV_DENOM, 13_750_000 + 50); + suite.assert_pending_rewards(MEMBER2, 1, 0); // update the reward rate back to 1_000 / 10blocks // this should now distribute 10_000_000 tokens over 100_000 blocks - // between ADDR1 (2/3rds) and ADDR3 (1/3rd) + // between MEMBER1 (2/3rds) and MEMBER3 (1/3rd) suite.update_emission_rate(1, Duration::Height(10), 1000, true); // skip 1/10th of the time suite.skip_blocks(100_000); // assert that rewards are being distributed at the expected rate - suite.assert_pending_rewards(ADDR1, 1, 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 13_750_000 + 3_333_333); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 13_750_000 + 3_333_333); - // ADDR3 claims their rewards - suite.assert_native_balance(ADDR3, DENOM, 0); - suite.claim_rewards(ADDR3, 1); - suite.assert_pending_rewards(ADDR3, 1, 0); - suite.assert_native_balance(ADDR3, DENOM, 13_750_000 + 3_333_333); + // MEMBER3 claims their rewards + suite.assert_native_balance(MEMBER3, GOV_DENOM, 0); + suite.claim_rewards(MEMBER3, 1); + suite.assert_pending_rewards(MEMBER3, 1, 0); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 13_750_000 + 3_333_333); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 6_666_666 + 6_666_666 + 1); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666 + 6_666_666 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333); // claim everything so that there are 0 pending rewards - suite.claim_rewards(ADDR3, 1); - suite.claim_rewards(ADDR1, 1); + suite.claim_rewards(MEMBER3, 1); + suite.claim_rewards(MEMBER1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); // update the rewards rate to 40_000_000 per 100_000 seconds. - // split is still 2/3rds to ADDR1 and 1/3rd to ADDR3 + // split is still 2/3rds to MEMBER1 and 1/3rd to MEMBER3 suite.update_emission_rate(1, Duration::Time(10), 4000, true); suite.assert_ends_at(Expiration::AtTime(Timestamp::from_seconds(462_500))); @@ -406,34 +401,35 @@ fn test_native_dao_rewards_reward_rate_switch_unit() { let addr1_pending = 20_000_000 * 2 / 3; let addr3_pending = 20_000_000 / 3; - suite.assert_pending_rewards(ADDR1, 1, addr1_pending); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending); - // ADDR2 wakes up to the increased staking rate and stakes 50 tokens - // this brings new split to: [ADDR1: 50%, ADDR2: 25%, ADDR3: 25%] - suite.stake_native_tokens(ADDR2, 50); + // MEMBER2 wakes up to the increased staking rate and stakes 50 tokens + // this brings new split to: [MEMBER1: 50%, MEMBER2: 25%, MEMBER3: 25%] + suite.stake_native_tokens(MEMBER2, 50); suite.skip_seconds(10_000); // allocates 4_000_000 tokens - suite.assert_pending_rewards(ADDR1, 1, addr1_pending + 4_000_000 * 2 / 4); - suite.assert_pending_rewards(ADDR2, 1, 4_000_000 / 4); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending + 4_000_000 / 4); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending + 4_000_000 * 2 / 4); + suite.assert_pending_rewards(MEMBER2, 1, 4_000_000 / 4); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending + 4_000_000 / 4); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER3, 1); let addr1_pending = 0; let addr3_pending = 0; suite.skip_seconds(10_000); // skips from 460,000 to 470,000, and the end is 462,500, so this allocates only 1_000_000 tokens instead of 4_000_000 - suite.assert_pending_rewards(ADDR1, 1, addr1_pending + 1_000_000 * 2 / 4); - suite.assert_pending_rewards(ADDR2, 1, 4_000_000 / 4 + 1_000_000 / 4); - suite.assert_pending_rewards(ADDR3, 1, addr3_pending + 1_000_000 / 4); + suite.assert_pending_rewards(MEMBER1, 1, addr1_pending + 1_000_000 * 2 / 4); + suite.assert_pending_rewards(MEMBER2, 1, 4_000_000 / 4 + 1_000_000 / 4); + suite.assert_pending_rewards(MEMBER3, 1, addr3_pending + 1_000_000 / 4); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER2, 1); // TODO: there's a few denoms remaining here, ensure such cases are handled properly - let remaining_rewards = suite.get_balance_native(suite.distribution_contract.clone(), DENOM); + let remaining_rewards = + suite.get_balance_native(suite.distribution_contract.clone(), GOV_DENOM); println!("Remaining rewards: {}", remaining_rewards); } @@ -448,80 +444,80 @@ fn test_cw20_dao_native_rewards_block_height_based() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their rewards - suite.unstake_cw20_tokens(50, ADDR2); - suite.unstake_cw20_tokens(50, ADDR3); + // MEMBER2 and MEMBER3 unstake their rewards + suite.unstake_cw20_tokens(50, MEMBER2); + suite.unstake_cw20_tokens(50, MEMBER3); // skip 1/10th of the time suite.skip_blocks(100_000); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR2 and ADDR3 wake up, claim and restake their rewards - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up, claim and restake their rewards + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - suite.stake_cw20_tokens(50, ADDR2); + suite.stake_cw20_tokens(50, MEMBER2); // skip 3/10th of the time suite.skip_blocks(300_000); - suite.stake_cw20_tokens(50, ADDR3); + suite.stake_cw20_tokens(50, MEMBER3); - suite.assert_pending_rewards(ADDR1, 1, 30_000_000); - suite.assert_pending_rewards(ADDR2, 1, 10_000_000); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 30_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 0); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); let remaining_time = suite.get_time_until_rewards_expiration(); suite.skip_blocks(remaining_time - 100_000); - suite.claim_rewards(ADDR1, 1); - suite.unstake_cw20_tokens(100, ADDR1); - suite.assert_pending_rewards(ADDR1, 1, 0); + suite.claim_rewards(MEMBER1, 1); + suite.unstake_cw20_tokens(100, MEMBER1); + suite.assert_pending_rewards(MEMBER1, 1, 0); suite.skip_blocks(100_000); - suite.unstake_cw20_tokens(50, ADDR2); + suite.unstake_cw20_tokens(50, MEMBER2); suite.skip_blocks(100_000); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); - let addr1_bal = suite.get_balance_native(ADDR1, DENOM); - let addr2_bal = suite.get_balance_native(ADDR2, DENOM); - let addr3_bal = suite.get_balance_native(ADDR3, DENOM); + let addr1_bal = suite.get_balance_native(MEMBER1, GOV_DENOM); + let addr2_bal = suite.get_balance_native(MEMBER2, GOV_DENOM); + let addr3_bal = suite.get_balance_native(MEMBER3, GOV_DENOM); println!("Balances: {}, {}, {}", addr1_bal, addr2_bal, addr3_bal); } @@ -537,41 +533,41 @@ fn test_cw721_dao_rewards() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their nfts - suite.unstake_nft(ADDR2, 3); - suite.unstake_nft(ADDR3, 4); + // MEMBER2 and MEMBER3 unstake their nfts + suite.unstake_nft(MEMBER2, 3); + suite.unstake_nft(MEMBER3, 4); // skip 1/10th of the time suite.skip_blocks(100_000); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR2 and ADDR3 wake up, claim and restake their nfts - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up, claim and restake their nfts + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - suite.stake_nft(ADDR2, 3); - suite.stake_nft(ADDR3, 4); + suite.stake_nft(MEMBER2, 3); + suite.stake_nft(MEMBER3, 4); } #[test] @@ -582,13 +578,13 @@ fn test_claim_zero_rewards() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); - // ADDR1 attempts to claim again - suite.claim_rewards(ADDR1, 1); + // MEMBER1 attempts to claim again + suite.claim_rewards(MEMBER1, 1); } #[test] @@ -598,7 +594,7 @@ fn test_native_dao_cw20_rewards_time_based() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Cw20(DENOM.to_string()), + denom: UncheckedDenom::Cw20(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: true, @@ -614,41 +610,41 @@ fn test_native_dao_cw20_rewards_time_based() { // skip 1/10th of the time suite.skip_seconds(100_000); - // suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + // suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_cw20_balance(cw20_denom, ADDR1, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_cw20_balance(cw20_denom, MEMBER1, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their stake - suite.unstake_cw20_tokens(50, ADDR2); - suite.unstake_cw20_tokens(50, ADDR3); + // MEMBER2 and MEMBER3 unstake their stake + suite.unstake_cw20_tokens(50, MEMBER2); + suite.unstake_cw20_tokens(50, MEMBER3); // skip 1/10th of the time suite.skip_seconds(100_000); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR2 and ADDR3 wake up and claim their rewards - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up and claim their rewards + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - suite.assert_cw20_balance(cw20_denom, ADDR1, 10_000_000); - suite.assert_cw20_balance(cw20_denom, ADDR2, 5_000_000); + suite.assert_cw20_balance(cw20_denom, MEMBER1, 10_000_000); + suite.assert_cw20_balance(cw20_denom, MEMBER2, 5_000_000); } #[test] @@ -658,7 +654,7 @@ fn test_native_dao_rewards_time_based() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: true, @@ -672,44 +668,44 @@ fn test_native_dao_rewards_time_based() { // skip 1/10th of the time suite.skip_seconds(100_000); - // suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + // suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their stake - suite.unstake_native_tokens(ADDR2, 50); - suite.unstake_native_tokens(ADDR3, 50); + // MEMBER2 and MEMBER3 unstake their stake + suite.unstake_native_tokens(MEMBER2, 50); + suite.unstake_native_tokens(MEMBER3, 50); // skip 1/10th of the time suite.skip_seconds(100_000); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR2 and ADDR3 wake up, claim and restake their rewards - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up, claim and restake their rewards + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - let addr1_balance = suite.get_balance_native(ADDR1, DENOM); - let addr2_balance = suite.get_balance_native(ADDR2, DENOM); + let addr1_balance = suite.get_balance_native(MEMBER1, GOV_DENOM); + let addr2_balance = suite.get_balance_native(MEMBER2, GOV_DENOM); - suite.stake_native_tokens(ADDR1, addr1_balance); - suite.stake_native_tokens(ADDR2, addr2_balance); + suite.stake_native_tokens(MEMBER1, addr1_balance); + suite.stake_native_tokens(MEMBER2, addr2_balance); } // all of the `+1` corrections highlight rounding @@ -720,22 +716,22 @@ fn test_native_dao_rewards_time_based_with_rounding() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW4) .with_rewards_config(RewardsConfig { amount: 100, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Time(100), destination: None, continuous: true, }) .with_cw4_members(vec![ Member { - addr: ADDR1.to_string(), + addr: MEMBER1.to_string(), weight: 140, }, Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 40, }, Member { - addr: ADDR3.to_string(), + addr: MEMBER3.to_string(), weight: 20, }, ]) @@ -748,99 +744,99 @@ fn test_native_dao_rewards_time_based_with_rounding() { // skip 1 interval suite.skip_seconds(100); - suite.assert_pending_rewards(ADDR1, 1, 70); - suite.assert_pending_rewards(ADDR2, 1, 20); - suite.assert_pending_rewards(ADDR3, 1, 10); + suite.assert_pending_rewards(MEMBER1, 1, 70); + suite.assert_pending_rewards(MEMBER2, 1, 20); + suite.assert_pending_rewards(MEMBER3, 1, 10); // change voting power of one of the members and claim suite.update_members( vec![Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 60, }], vec![], ); - suite.claim_rewards(ADDR2, 1); - suite.assert_native_balance(ADDR2, DENOM, 20); - suite.assert_pending_rewards(ADDR2, 1, 0); + suite.claim_rewards(MEMBER2, 1); + suite.assert_native_balance(MEMBER2, GOV_DENOM, 20); + suite.assert_pending_rewards(MEMBER2, 1, 0); // skip 1 interval suite.skip_seconds(100); - suite.assert_pending_rewards(ADDR1, 1, 70 + 63); - suite.assert_pending_rewards(ADDR2, 1, 27); - suite.assert_pending_rewards(ADDR3, 1, 10 + 9); + suite.assert_pending_rewards(MEMBER1, 1, 70 + 63); + suite.assert_pending_rewards(MEMBER2, 1, 27); + suite.assert_pending_rewards(MEMBER3, 1, 10 + 9); // increase reward rate and claim suite.update_emission_rate(1, Duration::Time(100), 150, true); - suite.claim_rewards(ADDR3, 1); - suite.assert_native_balance(ADDR3, DENOM, 10 + 9); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.claim_rewards(MEMBER3, 1); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 10 + 9); + suite.assert_pending_rewards(MEMBER3, 1, 0); // skip 1 interval suite.skip_seconds(100); - suite.assert_pending_rewards(ADDR1, 1, 70 + 63 + 95 + 1); - suite.assert_pending_rewards(ADDR2, 1, 27 + 40 + 1); - suite.assert_pending_rewards(ADDR3, 1, 13); + suite.assert_pending_rewards(MEMBER1, 1, 70 + 63 + 95 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 27 + 40 + 1); + suite.assert_pending_rewards(MEMBER3, 1, 13); // claim rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 70 + 63 + 95 + 1); - suite.assert_pending_rewards(ADDR1, 1, 0); + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 70 + 63 + 95 + 1); + suite.assert_pending_rewards(MEMBER1, 1, 0); // skip 3 intervals suite.skip_seconds(300); - suite.assert_pending_rewards(ADDR1, 1, 3 * 95 + 1); - suite.assert_pending_rewards(ADDR2, 1, 27 + 4 * 40 + 1 + 1 + 1); - suite.assert_pending_rewards(ADDR3, 1, 4 * 13 + 1 + 1); + suite.assert_pending_rewards(MEMBER1, 1, 3 * 95 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 27 + 4 * 40 + 1 + 1 + 1); + suite.assert_pending_rewards(MEMBER3, 1, 4 * 13 + 1 + 1); // change voting power for all suite.update_members( vec![ Member { - addr: ADDR1.to_string(), + addr: MEMBER1.to_string(), weight: 100, }, Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 80, }, Member { - addr: ADDR3.to_string(), + addr: MEMBER3.to_string(), weight: 40, }, ], vec![], ); - suite.claim_rewards(ADDR2, 1); - suite.assert_native_balance(ADDR2, DENOM, 20 + 27 + 4 * 40 + 1 + 1 + 1); - suite.assert_pending_rewards(ADDR2, 1, 0); + suite.claim_rewards(MEMBER2, 1); + suite.assert_native_balance(MEMBER2, GOV_DENOM, 20 + 27 + 4 * 40 + 1 + 1 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); // skip 1 interval suite.skip_seconds(100); - suite.assert_pending_rewards(ADDR1, 1, 3 * 95 + 1 + 68); - suite.assert_pending_rewards(ADDR2, 1, 54); - suite.assert_pending_rewards(ADDR3, 1, 4 * 13 + 1 + 1 + 27); + suite.assert_pending_rewards(MEMBER1, 1, 3 * 95 + 1 + 68); + suite.assert_pending_rewards(MEMBER2, 1, 54); + suite.assert_pending_rewards(MEMBER3, 1, 4 * 13 + 1 + 1 + 27); // claim all - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); - suite.assert_native_balance(ADDR1, DENOM, 70 + 63 + 95 + 1 + 3 * 95 + 1 + 68); - suite.assert_native_balance(ADDR2, DENOM, 20 + 27 + 4 * 40 + 1 + 1 + 1 + 54); - suite.assert_native_balance(ADDR3, DENOM, 10 + 9 + 4 * 13 + 1 + 1 + 27); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 70 + 63 + 95 + 1 + 3 * 95 + 1 + 68); + suite.assert_native_balance(MEMBER2, GOV_DENOM, 20 + 27 + 4 * 40 + 1 + 1 + 1 + 54); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 10 + 9 + 4 * 13 + 1 + 1 + 27); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); // TODO: fix this rug of 3 udenom by the distribution contract suite.assert_native_balance( suite.distribution_contract.as_str(), - DENOM, + GOV_DENOM, 100_000_000 - (100 * 2 + 150 * 5) + 3, ); } @@ -868,6 +864,7 @@ fn test_immediate_emission() { // create distribution suite + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -878,9 +875,9 @@ fn test_immediate_emission() { .unwrap(); // users immediately have access to rewards - suite.assert_pending_rewards(ADDR1, 2, 50_000_000); - suite.assert_pending_rewards(ADDR2, 2, 25_000_000); - suite.assert_pending_rewards(ADDR3, 2, 25_000_000); + suite.assert_pending_rewards(MEMBER1, 2, 50_000_000); + suite.assert_pending_rewards(MEMBER2, 2, 25_000_000); + suite.assert_pending_rewards(MEMBER3, 2, 25_000_000); // ensure undistributed rewards are immediately 0 suite.assert_undistributed_rewards(2, 0); @@ -889,16 +886,16 @@ fn test_immediate_emission() { suite.fund_native(2, coin(100_000_000, ALT_DENOM)); // users immediately have access to new rewards - suite.assert_pending_rewards(ADDR1, 2, 2 * 50_000_000); - suite.assert_pending_rewards(ADDR2, 2, 2 * 25_000_000); - suite.assert_pending_rewards(ADDR3, 2, 2 * 25_000_000); + suite.assert_pending_rewards(MEMBER1, 2, 2 * 50_000_000); + suite.assert_pending_rewards(MEMBER2, 2, 2 * 25_000_000); + suite.assert_pending_rewards(MEMBER3, 2, 2 * 25_000_000); // ensure undistributed rewards are immediately 0 suite.assert_undistributed_rewards(2, 0); // a new user stakes tokens - suite.mint_native(coin(200, DENOM), ADDR4); - suite.stake_native_tokens(ADDR4, 200); + suite.mint_native(coin(200, GOV_DENOM), MEMBER4); + suite.stake_native_tokens(MEMBER4, 200); // skip 2 blocks so stake takes effect suite.skip_blocks(2); @@ -906,22 +903,22 @@ fn test_immediate_emission() { // another fund takes into account new voting power suite.fund_native(2, coin(100_000_000, ALT_DENOM)); - suite.assert_pending_rewards(ADDR1, 2, 2 * 50_000_000 + 25_000_000); - suite.assert_pending_rewards(ADDR2, 2, 2 * 25_000_000 + 12_500_000); - suite.assert_pending_rewards(ADDR3, 2, 2 * 25_000_000 + 12_500_000); - suite.assert_pending_rewards(ADDR4, 2, 50_000_000); + suite.assert_pending_rewards(MEMBER1, 2, 2 * 50_000_000 + 25_000_000); + suite.assert_pending_rewards(MEMBER2, 2, 2 * 25_000_000 + 12_500_000); + suite.assert_pending_rewards(MEMBER3, 2, 2 * 25_000_000 + 12_500_000); + suite.assert_pending_rewards(MEMBER4, 2, 50_000_000); // ensure undistributed rewards are immediately 0 suite.assert_undistributed_rewards(2, 0); - suite.claim_rewards(ADDR1, 2); - suite.claim_rewards(ADDR2, 2); - suite.claim_rewards(ADDR3, 2); - suite.claim_rewards(ADDR4, 2); + suite.claim_rewards(MEMBER1, 2); + suite.claim_rewards(MEMBER2, 2); + suite.claim_rewards(MEMBER3, 2); + suite.claim_rewards(MEMBER4, 2); - suite.unstake_native_tokens(ADDR1, 100); - suite.unstake_native_tokens(ADDR2, 50); - suite.unstake_native_tokens(ADDR3, 50); + suite.unstake_native_tokens(MEMBER1, 100); + suite.unstake_native_tokens(MEMBER2, 50); + suite.unstake_native_tokens(MEMBER3, 50); // skip 2 blocks so stake takes effect suite.skip_blocks(2); @@ -929,10 +926,10 @@ fn test_immediate_emission() { // another fund takes into account new voting power suite.fund_native(2, coin(100_000_000, ALT_DENOM)); - suite.assert_pending_rewards(ADDR1, 2, 0); - suite.assert_pending_rewards(ADDR2, 2, 0); - suite.assert_pending_rewards(ADDR3, 2, 0); - suite.assert_pending_rewards(ADDR4, 2, 100_000_000); + suite.assert_pending_rewards(MEMBER1, 2, 0); + suite.assert_pending_rewards(MEMBER2, 2, 0); + suite.assert_pending_rewards(MEMBER3, 2, 0); + suite.assert_pending_rewards(MEMBER4, 2, 100_000_000); // ensure undistributed rewards are immediately 0 suite.assert_undistributed_rewards(2, 0); @@ -946,9 +943,9 @@ fn test_immediate_emission_fails_if_no_voting_power() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); // all users unstake - suite.unstake_native_tokens(ADDR1, 100); - suite.unstake_native_tokens(ADDR2, 50); - suite.unstake_native_tokens(ADDR3, 50); + suite.unstake_native_tokens(MEMBER1, 100); + suite.unstake_native_tokens(MEMBER2, 50); + suite.unstake_native_tokens(MEMBER3, 50); // skip 2 blocks since the contract depends on the previous block's total // voting power, and voting power takes 1 block to take effect. so if voting @@ -969,6 +966,7 @@ fn test_immediate_emission_fails_if_no_voting_power() { // create and fund distribution suite + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -990,78 +988,78 @@ fn test_transition_to_immediate() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 unstakes their stake - suite.unstake_native_tokens(ADDR2, 50); + // MEMBER2 unstakes their stake + suite.unstake_native_tokens(MEMBER2, 50); // skip 1/10th of the time suite.skip_blocks(100_000); - // because ADDR2 is not staking, ADDR1 and ADDR3 receive the rewards. ADDR2 + // because MEMBER2 is not staking, MEMBER1 and MEMBER3 receive the rewards. MEMBER2 // should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000 + 3_333_333); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000 + 3_333_333); - // ADDR2 claims their rewards - suite.claim_rewards(ADDR2, 1); - suite.assert_pending_rewards(ADDR2, 1, 0); + // MEMBER2 claims their rewards + suite.claim_rewards(MEMBER2, 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); // switching to immediate emission instantly distributes the remaining 70M suite.set_immediate_emission(1); - // ADDR1 and ADDR3 split the rewards, and ADDR2 gets none - suite.assert_pending_rewards(ADDR1, 1, 6_666_666 + 46_666_666 + 1); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000 + 3_333_333 + 23_333_333); + // MEMBER1 and MEMBER3 split the rewards, and MEMBER2 gets none + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666 + 46_666_666 + 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000 + 3_333_333 + 23_333_333); // claim all rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER3, 1); - // ADDR3 unstakes their stake, leaving only ADDR1 staked - suite.unstake_native_tokens(ADDR3, 50); + // MEMBER3 unstakes their stake, leaving only MEMBER1 staked + suite.unstake_native_tokens(MEMBER3, 50); // skip 2 blocks so unstake takes effect suite.skip_blocks(2); // another fund immediately adds to the pending rewards - suite.mint_native(coin(100_000_000, DENOM), OWNER); - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.mint_native(coin(100_000_000, GOV_DENOM), OWNER); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); - // ADDR1 gets all - suite.assert_pending_rewards(ADDR1, 1, 100_000_000); + // MEMBER1 gets all + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000); // change back to linear emission suite.update_emission_rate(1, Duration::Height(10), 1000, true); // fund with 100M again - suite.mint_native(coin(100_000_000, DENOM), OWNER); - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.mint_native(coin(100_000_000, GOV_DENOM), OWNER); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); - // ADDR1 has same pending as before - suite.assert_pending_rewards(ADDR1, 1, 100_000_000); + // MEMBER1 has same pending as before + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000); // skip 1/10th of the time suite.skip_blocks(100_000); - // ADDR1 has new linearly distributed rewards - suite.assert_pending_rewards(ADDR1, 1, 100_000_000 + 10_000_000); + // MEMBER1 has new linearly distributed rewards + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000 + 10_000_000); } #[test] @@ -1075,44 +1073,44 @@ fn test_native_dao_rewards() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 10_000_000); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 10_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their stake - suite.unstake_native_tokens(ADDR2, 50); - suite.unstake_native_tokens(ADDR3, 50); + // MEMBER2 and MEMBER3 unstake their stake + suite.unstake_native_tokens(MEMBER2, 50); + suite.unstake_native_tokens(MEMBER3, 50); // skip 1/10th of the time suite.skip_blocks(100_000); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 5_000_000); - suite.assert_pending_rewards(ADDR3, 1, 5_000_000); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 5_000_000); - // ADDR2 and ADDR3 wake up, claim and restake their rewards - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up, claim and restake their rewards + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - let addr1_balance = suite.get_balance_native(ADDR1, DENOM); - let addr2_balance = suite.get_balance_native(ADDR2, DENOM); + let addr1_balance = suite.get_balance_native(MEMBER1, GOV_DENOM); + let addr2_balance = suite.get_balance_native(MEMBER2, GOV_DENOM); - suite.stake_native_tokens(ADDR1, addr1_balance); - suite.stake_native_tokens(ADDR2, addr2_balance); + suite.stake_native_tokens(MEMBER1, addr1_balance); + suite.stake_native_tokens(MEMBER2, addr2_balance); } #[test] @@ -1126,39 +1124,39 @@ fn test_continuous_backfill_latest_voting_power() { // skip all of the time suite.skip_blocks(1_000_000); - suite.assert_pending_rewards(ADDR1, 1, 50_000_000); - suite.assert_pending_rewards(ADDR2, 1, 25_000_000); - suite.assert_pending_rewards(ADDR3, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 25_000_000); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); // skip 1/10th of the time suite.skip_blocks(100_000); // change voting powers (1 = 200, 2 = 50, 3 = 50) - suite.stake_native_tokens(ADDR1, 100); + suite.stake_native_tokens(MEMBER1, 100); // skip 1/10th of the time suite.skip_blocks(100_000); // change voting powers again (1 = 50, 2 = 100, 3 = 100) - suite.unstake_native_tokens(ADDR1, 150); - suite.stake_native_tokens(ADDR2, 50); - suite.stake_native_tokens(ADDR3, 50); + suite.unstake_native_tokens(MEMBER1, 150); + suite.stake_native_tokens(MEMBER2, 50); + suite.stake_native_tokens(MEMBER3, 50); // skip 1/10th of the time suite.skip_blocks(100_000); // fund with 100M - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // since this is continuous, rewards should backfill based on the latest // voting powers. we skipped 30% of the time, so 30M should be distributed - suite.assert_pending_rewards(ADDR1, 1, 6_000_000); - suite.assert_pending_rewards(ADDR2, 1, 12_000_000); - suite.assert_pending_rewards(ADDR3, 1, 12_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 6_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 12_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 12_000_000); } #[test] @@ -1172,124 +1170,128 @@ fn test_cw4_dao_rewards() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // remove the second member - suite.update_members(vec![], vec![ADDR2.to_string()]); + suite.update_members(vec![], vec![MEMBER2.to_string()]); suite.query_members(); // skip 1/10th of the time suite.skip_blocks(100_000); - // now that ADDR2 is no longer a member, ADDR1 and ADDR3 will split the rewards - suite.assert_pending_rewards(ADDR1, 1, 5_000_000 + 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333 + 2_500_000); + // now that MEMBER2 is no longer a member, MEMBER1 and MEMBER3 will split the rewards + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000 + 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333 + 2_500_000); // reintroduce the 2nd member with double the vp let add_member_2 = Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 2, }; suite.update_members(vec![add_member_2], vec![]); suite.query_members(); - // now the vp split is [ADDR1: 40%, ADDR2: 40%, ADDR3: 20%] + // now the vp split is [MEMBER1: 40%, MEMBER2: 40%, MEMBER3: 20%] // meaning the token reward per 100k blocks is 4mil, 4mil, 2mil - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 5_000_000 + 6_666_666); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 5_000_000 + 6_666_666); - // assert pending rewards are still the same (other than ADDR1) - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333 + 2_500_000); + // assert pending rewards are still the same (other than MEMBER1) + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333 + 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 4_000_000); - suite.assert_pending_rewards(ADDR2, 1, 6_500_000); - suite.assert_pending_rewards(ADDR3, 1, 7_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 4_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 6_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 7_833_333); // skip 1/2 of time, leaving 200k blocks left suite.skip_blocks(500_000); - suite.assert_pending_rewards(ADDR1, 1, 24_000_000); - suite.assert_pending_rewards(ADDR2, 1, 26_500_000); - suite.assert_pending_rewards(ADDR3, 1, 17_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 24_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 26_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 17_833_333); // remove all members suite.update_members( vec![], - vec![ADDR1.to_string(), ADDR2.to_string(), ADDR3.to_string()], + vec![ + MEMBER1.to_string(), + MEMBER2.to_string(), + MEMBER3.to_string(), + ], ); - suite.assert_pending_rewards(ADDR1, 1, 24_000_000); - suite.assert_pending_rewards(ADDR2, 1, 26_500_000); - suite.assert_pending_rewards(ADDR3, 1, 17_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 24_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 26_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 17_833_333); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 24_000_000); - suite.assert_pending_rewards(ADDR2, 1, 26_500_000); - suite.assert_pending_rewards(ADDR3, 1, 17_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 24_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 26_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 17_833_333); suite.update_members( vec![ Member { - addr: ADDR1.to_string(), + addr: MEMBER1.to_string(), weight: 2, }, Member { - addr: ADDR2.to_string(), + addr: MEMBER2.to_string(), weight: 2, }, Member { - addr: ADDR3.to_string(), + addr: MEMBER3.to_string(), weight: 1, }, ], vec![], ); - suite.assert_pending_rewards(ADDR1, 1, 24_000_000); - suite.assert_pending_rewards(ADDR2, 1, 26_500_000); - suite.assert_pending_rewards(ADDR3, 1, 17_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 24_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 26_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 17_833_333); - suite.claim_rewards(ADDR1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_native_balance(ADDR1, DENOM, 35_666_666); + suite.claim_rewards(MEMBER1, 1); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 35_666_666); // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 4_000_000); - suite.assert_pending_rewards(ADDR2, 1, 30_500_000); - suite.assert_pending_rewards(ADDR3, 1, 19_833_333); + suite.assert_pending_rewards(MEMBER1, 1, 4_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 30_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 19_833_333); // at the very expiration block, claim rewards - suite.claim_rewards(ADDR2, 1); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_native_balance(ADDR2, DENOM, 30_500_000); + suite.claim_rewards(MEMBER2, 1); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_native_balance(MEMBER2, GOV_DENOM, 30_500_000); suite.skip_blocks(100_000); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER3, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 0); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 0); let contract = suite.distribution_contract.clone(); // for 100k blocks there were no members so some rewards are remaining in the contract. - let contract_token_balance = suite.get_balance_native(contract.clone(), DENOM); + let contract_token_balance = suite.get_balance_native(contract.clone(), GOV_DENOM); assert!(contract_token_balance > 0); } @@ -1299,7 +1301,7 @@ fn test_fund_multiple_denoms() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); let alt_coin = coin(100_000_000, ALT_DENOM); - let coin = coin(100_000_000, DENOM); + let coin = coin(100_000_000, GOV_DENOM); suite.mint_native(alt_coin.clone(), OWNER); suite.mint_native(coin.clone(), OWNER); let hook_caller = suite.staking_addr.to_string(); @@ -1316,8 +1318,8 @@ fn test_fund_multiple_denoms() { ); suite + .base .app - .borrow_mut() .execute_contract( Addr::unchecked(OWNER), suite.distribution_contract.clone(), @@ -1363,7 +1365,7 @@ fn test_fund_cw20_with_invalid_cw20_receive_msg() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20).build(); let unregistered_cw20_coin = Cw20Coin { - address: ADDR1.to_string(), + address: MEMBER1.to_string(), amount: Uint128::new(1_000_000), }; @@ -1371,9 +1373,10 @@ fn test_fund_cw20_with_invalid_cw20_receive_msg() { let fund_sub_msg = to_json_binary(&"not_the_fund: {}").unwrap(); suite + .base .app .execute_contract( - Addr::unchecked(ADDR1), + Addr::unchecked(MEMBER1), new_cw20_mint.clone(), &cw20::Cw20ExecuteMsg::Send { contract: suite.distribution_contract.to_string(), @@ -1392,7 +1395,7 @@ fn test_fund_invalid_cw20_denom() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20).build(); let unregistered_cw20_coin = Cw20Coin { - address: ADDR1.to_string(), + address: MEMBER1.to_string(), amount: Uint128::new(1_000_000), }; @@ -1420,30 +1423,30 @@ fn test_withdraw_alternative_destination_address() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // user 1 and 2 claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); // user 2 unstakes - suite.unstake_native_tokens(ADDR2, 50); + suite.unstake_native_tokens(MEMBER2, 50); suite.skip_blocks(100_000); let distribution_contract = suite.distribution_contract.to_string(); - suite.assert_native_balance(subdao_addr.as_str(), DENOM, 0); + suite.assert_native_balance(subdao_addr.as_str(), GOV_DENOM, 0); let pre_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); suite.withdraw(1); let post_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); - let post_withdraw_subdao_balance = suite.get_balance_native(subdao_addr.to_string(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); + let post_withdraw_subdao_balance = suite.get_balance_native(subdao_addr.to_string(), GOV_DENOM); // after withdraw the balance of the subdao should be the same // as pre-withdraw-distributor-bal minus post-withdraw-distributor-bal @@ -1460,30 +1463,30 @@ fn test_withdraw_block_based() { // skip 1/10th of the time suite.skip_blocks(100_000); - // suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - // suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - // suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + // suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + // suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + // suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // user 1 and 2 claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); // user 2 unstakes - suite.unstake_native_tokens(ADDR2, 50); + suite.unstake_native_tokens(MEMBER2, 50); suite.skip_blocks(100_000); let distribution_contract = suite.distribution_contract.to_string(); let pre_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); - suite.assert_native_balance(suite.owner.clone().unwrap().as_str(), DENOM, 0); + suite.assert_native_balance(OWNER, GOV_DENOM, 0); suite.withdraw(1); let post_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); - let post_withdraw_owner_balance = suite.get_balance_native(suite.owner.clone().unwrap(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); + let post_withdraw_owner_balance = suite.get_balance_native(OWNER, GOV_DENOM); // after withdraw the balance of the owner should be the same // as pre-withdraw-distributor-bal minus post-withdraw-distributor-bal @@ -1505,25 +1508,25 @@ fn test_withdraw_block_based() { ); // we assert that pending rewards did not change - suite.assert_pending_rewards(ADDR1, 1, 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333 + 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333 + 2_500_000); // user 1 can claim their rewards - suite.claim_rewards(ADDR1, 1); - // suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_native_balance(ADDR1, DENOM, 11_666_666); + suite.claim_rewards(MEMBER1, 1); + // suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 11_666_666); // user 3 can unstake and claim their rewards - suite.unstake_native_tokens(ADDR3, 50); + suite.unstake_native_tokens(MEMBER3, 50); suite.skip_blocks(100_000); - suite.assert_native_balance(ADDR3, DENOM, 50); - suite.claim_rewards(ADDR3, 1); - // suite.assert_pending_rewards(ADDR3, 1, 0); - suite.assert_native_balance(ADDR3, DENOM, 3_333_333 + 2_500_000 + 50); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 50); + suite.claim_rewards(MEMBER3, 1); + // suite.assert_pending_rewards(MEMBER3, 1, 0); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 3_333_333 + 2_500_000 + 50); // TODO: fix this rug of 1 udenom by the distribution contract - suite.assert_native_balance(&distribution_contract, DENOM, 1); + suite.assert_native_balance(&distribution_contract, GOV_DENOM, 1); } #[test] @@ -1531,7 +1534,7 @@ fn test_withdraw_time_based() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: true, @@ -1541,30 +1544,30 @@ fn test_withdraw_time_based() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // user 1 and 2 claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); // user 2 unstakes - suite.unstake_native_tokens(ADDR2, 50); + suite.unstake_native_tokens(MEMBER2, 50); suite.skip_seconds(100_000); let distribution_contract = suite.distribution_contract.to_string(); let pre_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); - suite.assert_native_balance(suite.owner.clone().unwrap().as_str(), DENOM, 0); + suite.assert_native_balance(OWNER, GOV_DENOM, 0); suite.withdraw(1); let post_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); - let post_withdraw_owner_balance = suite.get_balance_native(suite.owner.clone().unwrap(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); + let post_withdraw_owner_balance = suite.get_balance_native(OWNER, GOV_DENOM); // after withdraw the balance of the owner should be the same // as pre-withdraw-distributor-bal minus post-withdraw-distributor-bal @@ -1586,25 +1589,25 @@ fn test_withdraw_time_based() { ); // we assert that pending rewards did not change - suite.assert_pending_rewards(ADDR1, 1, 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 0); - suite.assert_pending_rewards(ADDR3, 1, 3_333_333 + 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 0); + suite.assert_pending_rewards(MEMBER3, 1, 3_333_333 + 2_500_000); // user 1 can claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_pending_rewards(ADDR1, 1, 0); - suite.assert_native_balance(ADDR1, DENOM, 11_666_666); + suite.claim_rewards(MEMBER1, 1); + suite.assert_pending_rewards(MEMBER1, 1, 0); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 11_666_666); // user 3 can unstake and claim their rewards - suite.unstake_native_tokens(ADDR3, 50); + suite.unstake_native_tokens(MEMBER3, 50); suite.skip_seconds(100_000); - suite.assert_native_balance(ADDR3, DENOM, 50); - suite.claim_rewards(ADDR3, 1); - suite.assert_pending_rewards(ADDR3, 1, 0); - suite.assert_native_balance(ADDR3, DENOM, 3_333_333 + 2_500_000 + 50); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 50); + suite.claim_rewards(MEMBER3, 1); + suite.assert_pending_rewards(MEMBER3, 1, 0); + suite.assert_native_balance(MEMBER3, GOV_DENOM, 3_333_333 + 2_500_000 + 50); // TODO: fix this rug of 1 udenom by the distribution contract - suite.assert_native_balance(&distribution_contract, DENOM, 1); + suite.assert_native_balance(&distribution_contract, GOV_DENOM, 1); } #[test] @@ -1612,7 +1615,7 @@ fn test_withdraw_and_restart_with_continuous() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: true, @@ -1622,14 +1625,14 @@ fn test_withdraw_and_restart_with_continuous() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // users claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); // skip 1/10th of the time suite.skip_seconds(100_000); @@ -1637,14 +1640,14 @@ fn test_withdraw_and_restart_with_continuous() { let distribution_contract = suite.distribution_contract.to_string(); let pre_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); - suite.assert_native_balance(suite.owner.clone().unwrap().as_str(), DENOM, 0); + suite.assert_native_balance(OWNER, GOV_DENOM, 0); suite.withdraw(1); let post_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); - let post_withdraw_owner_balance = suite.get_balance_native(suite.owner.clone().unwrap(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); + let post_withdraw_owner_balance = suite.get_balance_native(OWNER, GOV_DENOM); // after withdraw the balance of the owner should be the same // as pre-withdraw-distributor-bal minus post-withdraw-distributor-bal @@ -1667,22 +1670,22 @@ fn test_withdraw_and_restart_with_continuous() { ); // we assert that pending rewards did not change - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); // fund again - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // check that pending rewards did not restart. since we skipped 1/10th the // time after the withdraw occurred, everyone should already have 10% of the // new amount pending. - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); } #[test] @@ -1690,7 +1693,7 @@ fn test_withdraw_and_restart_not_continuous() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: false, @@ -1700,14 +1703,14 @@ fn test_withdraw_and_restart_not_continuous() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // users claim their rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); // skip 1/10th of the time suite.skip_seconds(100_000); @@ -1715,14 +1718,14 @@ fn test_withdraw_and_restart_not_continuous() { let distribution_contract = suite.distribution_contract.to_string(); let pre_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); - suite.assert_native_balance(suite.owner.clone().unwrap().as_str(), DENOM, 0); + suite.assert_native_balance(OWNER, GOV_DENOM, 0); suite.withdraw(1); let post_withdraw_distributor_balance = - suite.get_balance_native(distribution_contract.clone(), DENOM); - let post_withdraw_owner_balance = suite.get_balance_native(suite.owner.clone().unwrap(), DENOM); + suite.get_balance_native(distribution_contract.clone(), GOV_DENOM); + let post_withdraw_owner_balance = suite.get_balance_native(OWNER, GOV_DENOM); // after withdraw the balance of the owner should be the same // as pre-withdraw-distributor-bal minus post-withdraw-distributor-bal @@ -1745,15 +1748,15 @@ fn test_withdraw_and_restart_not_continuous() { ); // we assert that pending rewards did not change - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); // fund again - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // skip 1/10th of the time suite.skip_seconds(100_000); @@ -1761,9 +1764,9 @@ fn test_withdraw_and_restart_not_continuous() { // check that pending rewards restarted from the funding date. since we // skipped 1/10th the time after the funding occurred, everyone should // have 10% of the new amount pending - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); } #[test] @@ -1775,10 +1778,10 @@ fn test_withdraw_unauthorized() { suite.skip_blocks(100_000); suite + .base .app - .borrow_mut() .execute_contract( - Addr::unchecked(ADDR1), + Addr::unchecked(MEMBER1), suite.distribution_contract.clone(), &ExecuteMsg::Withdraw { id: 1 }, &[], @@ -1803,7 +1806,7 @@ fn test_claim_404() { suite.skip_blocks(100_000); - suite.claim_rewards(ADDR1, 3); + suite.claim_rewards(MEMBER1, 3); } #[test] @@ -1813,8 +1816,8 @@ fn test_fund_latest_404() { // make new rewards contract let reward_addr = suite + .base .app - .borrow_mut() .instantiate_contract( suite.reward_code_id, Addr::unchecked(OWNER), @@ -1828,15 +1831,15 @@ fn test_fund_latest_404() { .unwrap(); // try to fund latest before creating a distribution - suite.mint_native(coin(100_000_000, DENOM), OWNER); + suite.mint_native(coin(100_000_000, GOV_DENOM), OWNER); suite + .base .app - .borrow_mut() .execute_contract( Addr::unchecked(OWNER), reward_addr, &ExecuteMsg::FundLatest {}, - &[coin(100_000_000, DENOM)], + &[coin(100_000_000, GOV_DENOM)], ) .unwrap(); } @@ -1867,8 +1870,8 @@ fn test_fund_invalid_native_denom() { suite.mint_native(coin(100_000_000, ALT_DENOM), OWNER); suite + .base .app - .borrow_mut() .execute_contract( Addr::unchecked(OWNER), suite.distribution_contract.clone(), @@ -1883,7 +1886,7 @@ fn test_fund_native_block_based_post_expiration_not_continuous() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Height(10), destination: None, continuous: false, @@ -1901,22 +1904,22 @@ fn test_fund_native_block_based_post_expiration_not_continuous() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); - // ADDR2 unstake their stake - suite.unstake_native_tokens(ADDR2, 50); + // MEMBER2 unstake their stake + suite.unstake_native_tokens(MEMBER2, 50); // addr3 claims their rewards - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER3, 1); // skip to 100_000 blocks past the expiration suite.skip_blocks(1_000_000); - suite.assert_pending_rewards(ADDR1, 1, 65_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 30_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 65_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 30_000_000); suite.assert_ends_at(expiration_date); suite.assert_started_at(started_at); @@ -1924,9 +1927,9 @@ fn test_fund_native_block_based_post_expiration_not_continuous() { // we fund the distributor with the same amount of coins as // during setup, meaning that the rewards distribution duration // should be the same. - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); - let current_block = suite.app.block_info(); + let current_block = suite.base.app.block_info(); // funding after the reward period had expired should // reset the start date to that of the funding. @@ -1943,7 +1946,7 @@ fn test_fund_cw20_time_based_post_expiration_not_continuous() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Cw20(DENOM.to_string()), + denom: UncheckedDenom::Cw20(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: false, @@ -1963,23 +1966,23 @@ fn test_fund_cw20_time_based_post_expiration_not_continuous() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); - // ADDR2 unstake their stake - suite.unstake_cw20_tokens(50, ADDR2); + // MEMBER2 unstake their stake + suite.unstake_cw20_tokens(50, MEMBER2); // addr3 claims their rewards - suite.claim_rewards(ADDR3, 1); - suite.assert_cw20_balance(cw20_denom, ADDR3, 2_500_000); + suite.claim_rewards(MEMBER3, 1); + suite.assert_cw20_balance(cw20_denom, MEMBER3, 2_500_000); // skip to 100_000 blocks past the expiration suite.skip_seconds(1_000_000); - suite.assert_pending_rewards(ADDR1, 1, 65_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 30_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 65_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 30_000_000); suite.assert_ends_at(expiration_date); suite.assert_started_at(started_at); @@ -1994,7 +1997,7 @@ fn test_fund_cw20_time_based_post_expiration_not_continuous() { suite.fund_cw20(1, funding_denom.clone()); - let current_block = suite.app.block_info(); + let current_block = suite.base.app.block_info(); // funding after the reward period had expired should // reset the start date to that of the funding. @@ -2013,7 +2016,7 @@ fn test_fund_cw20_time_based_pre_expiration() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Cw20(DENOM.to_string()), + denom: UncheckedDenom::Cw20(GOV_DENOM.to_string()), duration: Duration::Time(10), destination: None, continuous: true, @@ -2031,22 +2034,22 @@ fn test_fund_cw20_time_based_pre_expiration() { // skip 1/10th of the time suite.skip_seconds(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); - // ADDR2 unstake their stake - suite.unstake_cw20_tokens(50, ADDR2); + // MEMBER2 unstake their stake + suite.unstake_cw20_tokens(50, MEMBER2); // addr3 claims their rewards - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER3, 1); // skip to 100_000 blocks before the expiration suite.skip_seconds(800_000); - suite.assert_pending_rewards(ADDR1, 1, 58_333_333); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 26_666_666); + suite.assert_pending_rewards(MEMBER1, 1, 58_333_333); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 26_666_666); suite.assert_ends_at(expiration_date); suite.assert_started_at(started_at); @@ -2087,22 +2090,22 @@ fn test_fund_native_height_based_pre_expiration() { // skip 1/10th of the time suite.skip_blocks(100_000); - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); - // ADDR2 unstake their stake - suite.unstake_native_tokens(ADDR2, 50); + // MEMBER2 unstake their stake + suite.unstake_native_tokens(MEMBER2, 50); // addr3 claims their rewards - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER3, 1); // skip to 100_000 blocks before the expiration suite.skip_blocks(800_000); - suite.assert_pending_rewards(ADDR1, 1, 58_333_333); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 26_666_666); + suite.assert_pending_rewards(MEMBER1, 1, 58_333_333); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 26_666_666); suite.assert_ends_at(expiration_date); suite.assert_started_at(started_at); @@ -2110,7 +2113,7 @@ fn test_fund_native_height_based_pre_expiration() { // we fund the distributor with the same amount of coins as // during setup, meaning that the rewards distribution duration // should be the same. - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // funding before the reward period expires should // not reset the existing rewards cycle @@ -2127,7 +2130,7 @@ fn test_native_dao_rewards_entry_edge_case() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); // we start with the following staking power split: - // [ADDR1: 100, ADDR2: 50, ADDR3: 50], or [ADDR1: 50%, ADDR2: 25%, ADDR3: 25% + // [MEMBER1: 100, MEMBER2: 50, MEMBER3: 50], or [MEMBER1: 50%, MEMBER2: 25%, MEMBER3: 25% suite.assert_amount(1_000); suite.assert_ends_at(Expiration::AtHeight(1_000_000)); suite.assert_duration(10); @@ -2135,63 +2138,63 @@ fn test_native_dao_rewards_entry_edge_case() { // skip 1/10th of the time suite.skip_blocks(100_000); - // ADDR1 stakes additional 100 tokens, bringing the new staking power split to - // [ADDR1: 200, ADDR2: 50, ADDR3: 50], or [ADDR1: 66.6%, ADDR2: 16.6%, ADDR3: 16.6%] - // this means that per 100_000 blocks, ADDR1 should receive 6_666_666, while - // ADDR2 and ADDR3 should receive 1_666_666 each. - suite.mint_native(coin(100, DENOM), ADDR1); - suite.stake_native_tokens(ADDR1, 100); + // MEMBER1 stakes additional 100 tokens, bringing the new staking power split to + // [MEMBER1: 200, MEMBER2: 50, MEMBER3: 50], or [MEMBER1: 66.6%, MEMBER2: 16.6%, MEMBER3: 16.6%] + // this means that per 100_000 blocks, MEMBER1 should receive 6_666_666, while + // MEMBER2 and MEMBER3 should receive 1_666_666 each. + suite.mint_native(coin(100, GOV_DENOM), MEMBER1); + suite.stake_native_tokens(MEMBER1, 100); // rewards here should not be affected by the new stake, - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip 1/10th of the time suite.skip_blocks(100_000); // here we should see the new stake affecting the rewards split. - suite.assert_pending_rewards(ADDR1, 1, 5_000_000 + 6_666_666); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000 + 1_666_666); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000 + 6_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000 + 1_666_666); - // ADDR1 claims rewards - suite.claim_rewards(ADDR1, 1); - suite.assert_native_balance(ADDR1, DENOM, 5_000_000 + 6_666_666); - suite.assert_pending_rewards(ADDR1, 1, 0); + // MEMBER1 claims rewards + suite.claim_rewards(MEMBER1, 1); + suite.assert_native_balance(MEMBER1, GOV_DENOM, 5_000_000 + 6_666_666); + suite.assert_pending_rewards(MEMBER1, 1, 0); - // ADDR2 and ADDR3 unstake their stake - // new voting power split is [ADDR1: 100%, ADDR2: 0%, ADDR3: 0%] - suite.unstake_native_tokens(ADDR2, 50); - suite.unstake_native_tokens(ADDR3, 50); + // MEMBER2 and MEMBER3 unstake their stake + // new voting power split is [MEMBER1: 100%, MEMBER2: 0%, MEMBER3: 0%] + suite.unstake_native_tokens(MEMBER2, 50); + suite.unstake_native_tokens(MEMBER3, 50); - // we assert that by unstaking, ADDR2 and ADDR3 do not forfeit their earned but unclaimed rewards - suite.assert_pending_rewards(ADDR2, 1, 2_500_000 + 1_666_666); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000 + 1_666_666); + // we assert that by unstaking, MEMBER2 and MEMBER3 do not forfeit their earned but unclaimed rewards + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000 + 1_666_666); // skip a block and assert that nothing changes suite.skip_blocks(1); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000 + 1_666_666); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000 + 1_666_666); // skip the remaining blocks to reach 1/10th of the time suite.skip_blocks(99_999); - // because ADDR2 and ADDR3 are not staking, ADDR1 receives all the rewards. - // ADDR2 and ADDR3 should have the same amount of pending rewards as before. - suite.assert_pending_rewards(ADDR1, 1, 10_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000 + 1_666_666); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000 + 1_666_666); + // because MEMBER2 and MEMBER3 are not staking, MEMBER1 receives all the rewards. + // MEMBER2 and MEMBER3 should have the same amount of pending rewards as before. + suite.assert_pending_rewards(MEMBER1, 1, 10_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000 + 1_666_666); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000 + 1_666_666); - // ADDR2 and ADDR3 wake up, claim and restake their rewards - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + // MEMBER2 and MEMBER3 wake up, claim and restake their rewards + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); - let addr1_balance = suite.get_balance_native(ADDR1, DENOM); - let addr2_balance = suite.get_balance_native(ADDR2, DENOM); + let addr1_balance = suite.get_balance_native(MEMBER1, GOV_DENOM); + let addr2_balance = suite.get_balance_native(MEMBER2, GOV_DENOM); - suite.stake_native_tokens(ADDR1, addr1_balance); - suite.stake_native_tokens(ADDR2, addr2_balance); + suite.stake_native_tokens(MEMBER1, addr1_balance); + suite.stake_native_tokens(MEMBER2, addr2_balance); } #[test] @@ -2233,20 +2236,20 @@ fn test_fund_native_on_create() { suite.skip_blocks(1_000_000); // skip 1/10th of the time - suite.assert_pending_rewards(ADDR1, 2, 5_000_000); - suite.assert_pending_rewards(ADDR2, 2, 2_500_000); - suite.assert_pending_rewards(ADDR3, 2, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 2, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 2, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 2, 2_500_000); } #[test] -#[should_panic(expected = "Must send reserve token 'ujuno'")] +#[should_panic(expected = "Must send reserve token 'ugovtoken'")] fn test_fund_native_with_other_denom() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); suite.mint_native(coin(100, ALT_DENOM), OWNER); let execute_create_msg = ExecuteMsg::Create(CreateMsg { - denom: cw20::UncheckedDenom::Native(DENOM.to_string()), + denom: cw20::UncheckedDenom::Native(GOV_DENOM.to_string()), emission_rate: EmissionRate::Linear { amount: Uint128::new(1000), duration: Duration::Height(100), @@ -2260,6 +2263,7 @@ fn test_fund_native_with_other_denom() { // create distribution with other denom provided suite + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -2275,11 +2279,11 @@ fn test_fund_native_with_other_denom() { fn test_fund_native_multiple_denoms() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); - suite.mint_native(coin(100, DENOM), OWNER); + suite.mint_native(coin(100, GOV_DENOM), OWNER); suite.mint_native(coin(100, ALT_DENOM), OWNER); let execute_create_msg = ExecuteMsg::Create(CreateMsg { - denom: cw20::UncheckedDenom::Native(DENOM.to_string()), + denom: cw20::UncheckedDenom::Native(GOV_DENOM.to_string()), emission_rate: EmissionRate::Linear { amount: Uint128::new(1000), duration: Duration::Height(100), @@ -2293,12 +2297,13 @@ fn test_fund_native_multiple_denoms() { // create distribution with 0 amount suite + .base .app .execute_contract( Addr::unchecked(OWNER), suite.distribution_contract.clone(), &execute_create_msg, - &[coin(100, DENOM), coin(100, ALT_DENOM)], + &[coin(100, GOV_DENOM), coin(100, ALT_DENOM)], ) .unwrap(); } @@ -2308,7 +2313,7 @@ fn test_fund_native_multiple_denoms() { fn test_fund_native_on_create_cw20() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); - suite.mint_native(coin(100, DENOM), OWNER); + suite.mint_native(coin(100, GOV_DENOM), OWNER); let cw20_denom = suite .mint_cw20( @@ -2335,12 +2340,13 @@ fn test_fund_native_on_create_cw20() { // create cw20 distribution with native funds provided suite + .base .app .execute_contract( Addr::unchecked(OWNER), suite.distribution_contract.clone(), &execute_create_msg, - &coins(100, DENOM), + &coins(100, GOV_DENOM), ) .unwrap(); } @@ -2381,7 +2387,7 @@ fn test_update_owner() { fn test_update_vp_contract() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native).build(); - let new_vp_contract = setup_native_token_test(suite.app.borrow_mut()); + let new_vp_contract = suite.base.cw4().dao().voting_module_addr; suite.update_vp_contract(1, new_vp_contract.as_str()); @@ -2462,7 +2468,7 @@ fn test_rewards_not_lost_after_discontinuous_restart() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 3_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Height(1), destination: None, continuous: false, @@ -2477,17 +2483,17 @@ fn test_rewards_not_lost_after_discontinuous_restart() { suite.skip_blocks(33_333); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 49999500); - suite.assert_pending_rewards(ADDR2, 1, 24999750); - suite.assert_pending_rewards(ADDR3, 1, 24999750); + suite.assert_pending_rewards(MEMBER1, 1, 49999500); + suite.assert_pending_rewards(MEMBER2, 1, 24999750); + suite.assert_pending_rewards(MEMBER3, 1, 24999750); // before user claim rewards, someone funded - suite.fund_native(1, coin(1u128, DENOM)); + suite.fund_native(1, coin(1u128, GOV_DENOM)); // pending rewards should still exist - suite.assert_pending_rewards(ADDR1, 1, 49999500); - suite.assert_pending_rewards(ADDR2, 1, 24999750); - suite.assert_pending_rewards(ADDR3, 1, 24999750); + suite.assert_pending_rewards(MEMBER1, 1, 49999500); + suite.assert_pending_rewards(MEMBER2, 1, 24999750); + suite.assert_pending_rewards(MEMBER3, 1, 24999750); } #[test] @@ -2502,20 +2508,20 @@ fn test_fund_while_paused() { suite.skip_blocks(100_000); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // pause suite.pause_emission(1); // pending rewards should still exist - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // fund during pause the amount that's already been distributed - suite.fund_native(1, coin(10_000_000, DENOM)); + suite.fund_native(1, coin(10_000_000, GOV_DENOM)); // restart suite.update_emission_rate(1, Duration::Height(10), 1_000, true); @@ -2527,13 +2533,13 @@ fn test_fund_while_paused() { suite.skip_blocks(100_000); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 2 * 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2 * 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2 * 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 2 * 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2 * 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2 * 2_500_000); // pause and fund more suite.pause_emission(1); - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // restart suite.update_emission_rate(1, Duration::Height(10), 1_000, true); @@ -2555,9 +2561,9 @@ fn test_pause_expired() { suite.skip_blocks(100_000); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // check undistributed rewards suite.assert_undistributed_rewards(1, 90_000_000); @@ -2572,9 +2578,9 @@ fn test_pause_expired() { suite.update_emission_rate(1, Duration::Height(10), 1_000, false); // check pending rewards are the same - suite.assert_pending_rewards(ADDR1, 1, 5_000_000); - suite.assert_pending_rewards(ADDR2, 1, 2_500_000); - suite.assert_pending_rewards(ADDR3, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER1, 1, 5_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 2_500_000); + suite.assert_pending_rewards(MEMBER3, 1, 2_500_000); // skip all and more, expiring suite.skip_blocks(1_100_000); @@ -2583,9 +2589,9 @@ fn test_pause_expired() { suite.assert_undistributed_rewards(1, 0); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 50_000_000); - suite.assert_pending_rewards(ADDR2, 1, 25_000_000); - suite.assert_pending_rewards(ADDR3, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 25_000_000); // pause suite.pause_emission(1); @@ -2594,12 +2600,12 @@ fn test_pause_expired() { suite.assert_undistributed_rewards(1, 0); // pending rewards should still exist - suite.assert_pending_rewards(ADDR1, 1, 50_000_000); - suite.assert_pending_rewards(ADDR2, 1, 25_000_000); - suite.assert_pending_rewards(ADDR3, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 25_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 25_000_000); // fund - suite.fund_native(1, coin(100_000_000, DENOM)); + suite.fund_native(1, coin(100_000_000, GOV_DENOM)); // resume suite.update_emission_rate(1, Duration::Height(10), 1_000, false); @@ -2614,9 +2620,9 @@ fn test_pause_expired() { suite.assert_undistributed_rewards(1, 0); // check pending rewards - suite.assert_pending_rewards(ADDR1, 1, 100_000_000); - suite.assert_pending_rewards(ADDR2, 1, 50_000_000); - suite.assert_pending_rewards(ADDR3, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 50_000_000); } #[test] @@ -2624,7 +2630,7 @@ fn test_large_stake_before_claim() { let mut suite = SuiteBuilder::base(super::suite::DaoType::Native) .with_rewards_config(RewardsConfig { amount: 3_000, - denom: UncheckedDenom::Native(DENOM.to_string()), + denom: UncheckedDenom::Native(GOV_DENOM.to_string()), duration: Duration::Height(1), destination: None, continuous: true, @@ -2635,22 +2641,22 @@ fn test_large_stake_before_claim() { suite.assert_ends_at(Expiration::AtHeight(33_333)); suite.assert_duration(1); - // ADDR1 stake big amount of tokens + // MEMBER1 stake big amount of tokens suite.skip_blocks(33_000); - suite.mint_native(coin(10_000, &suite.reward_denom), ADDR1); - suite.stake_native_tokens(ADDR1, 10_000); + suite.mint_native(coin(10_000, &suite.reward_denom), MEMBER1); + suite.stake_native_tokens(MEMBER1, 10_000); // ADD1 claims rewards in the next block suite.skip_blocks(1); - suite.claim_rewards(ADDR1, 1); + suite.claim_rewards(MEMBER1, 1); // skip to end suite.skip_blocks(100_000_000); // all users should be able to claim rewards - suite.claim_rewards(ADDR1, 1); - suite.claim_rewards(ADDR2, 1); - suite.claim_rewards(ADDR3, 1); + suite.claim_rewards(MEMBER1, 1); + suite.claim_rewards(MEMBER2, 1); + suite.claim_rewards(MEMBER3, 1); } #[test] @@ -2662,14 +2668,14 @@ fn test_fund_latest_native() { suite.assert_duration(10); // double duration by 1_000_000 blocks - suite.fund_latest_native(coin(100_000_000, DENOM)); + suite.fund_latest_native(coin(100_000_000, GOV_DENOM)); // skip all of the time suite.skip_blocks(2_000_000); - suite.assert_pending_rewards(ADDR1, 1, 100_000_000); - suite.assert_pending_rewards(ADDR2, 1, 50_000_000); - suite.assert_pending_rewards(ADDR3, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 50_000_000); } #[test] @@ -2677,7 +2683,7 @@ fn test_fund_latest_cw20() { let mut suite = SuiteBuilder::base(super::suite::DaoType::CW20) .with_rewards_config(RewardsConfig { amount: 1_000, - denom: UncheckedDenom::Cw20(DENOM.to_string()), + denom: UncheckedDenom::Cw20(GOV_DENOM.to_string()), duration: Duration::Height(10), destination: None, continuous: true, @@ -2697,9 +2703,9 @@ fn test_fund_latest_cw20() { // skip all of the time suite.skip_blocks(2_000_000); - suite.assert_pending_rewards(ADDR1, 1, 100_000_000); - suite.assert_pending_rewards(ADDR2, 1, 50_000_000); - suite.assert_pending_rewards(ADDR3, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER1, 1, 100_000_000); + suite.assert_pending_rewards(MEMBER2, 1, 50_000_000); + suite.assert_pending_rewards(MEMBER3, 1, 50_000_000); } #[test] @@ -2715,7 +2721,7 @@ fn test_fund_latest_cw20_invalid_native() { }) .build(); - suite.fund_latest_native(coin(100, DENOM)); + suite.fund_latest_native(coin(100, GOV_DENOM)); } #[test] @@ -2761,6 +2767,7 @@ fn test_closed_funding() { // create distribution suite + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -2778,12 +2785,12 @@ fn test_closed_funding() { ); // test fund from non-owner - suite.mint_native(coin(100, ALT_DENOM), ADDR1); + suite.mint_native(coin(100, ALT_DENOM), MEMBER1); let err: ContractError = suite + .base .app - .borrow_mut() .execute_contract( - Addr::unchecked(ADDR1), + Addr::unchecked(MEMBER1), suite.distribution_contract.clone(), &ExecuteMsg::Fund(FundMsg { id: 2 }), &[coin(100, ALT_DENOM)], @@ -2798,9 +2805,10 @@ fn test_closed_funding() { // test fund from non-owner suite + .base .app .execute_contract( - Addr::unchecked(ADDR1), + Addr::unchecked(MEMBER1), suite.distribution_contract.clone(), &ExecuteMsg::Fund(FundMsg { id: 2 }), &[coin(100, ALT_DENOM)], @@ -2837,6 +2845,7 @@ fn test_queries_before_funded() { // create distribution with no funds suite + .base .app .execute_contract( Addr::unchecked(OWNER), @@ -2847,9 +2856,9 @@ fn test_queries_before_funded() { .unwrap(); // users have no rewards - suite.assert_pending_rewards(ADDR1, 2, 0); - suite.assert_pending_rewards(ADDR2, 2, 0); - suite.assert_pending_rewards(ADDR3, 2, 0); + suite.assert_pending_rewards(MEMBER1, 2, 0); + suite.assert_pending_rewards(MEMBER2, 2, 0); + suite.assert_pending_rewards(MEMBER3, 2, 0); // ensure undistributed rewards are immediately 0 suite.assert_undistributed_rewards(2, 0); diff --git a/packages/dao-testing/src/suite/base.rs b/packages/dao-testing/src/suite/base.rs index 174c2b9a8..60256b430 100644 --- a/packages/dao-testing/src/suite/base.rs +++ b/packages/dao-testing/src/suite/base.rs @@ -1,10 +1,12 @@ -use cosmwasm_std::{to_json_binary, Addr, Empty, QuerierWrapper}; +use cosmwasm_std::{to_json_binary, Addr, Empty, QuerierWrapper, Timestamp}; +use cw20::Cw20Coin; use cw_multi_test::{App, Executor}; use cw_utils::Duration; use super::*; use crate::contracts::*; +#[derive(Clone, Debug)] pub struct TestDao { pub core_addr: Addr, pub voting_module_addr: Addr, @@ -171,6 +173,12 @@ impl DaoTestingSuiteBase { pub fn new() -> Self { let mut app = App::default(); + // start at 0 height and time + app.update_block(|b| { + b.height = 0; + b.time = Timestamp::from_seconds(0); + }); + let core_id = app.store_code(dao_dao_core_contract()); let admin_factory_id = app.store_code(cw_admin_factory_contract()); let proposal_single_id = app.store_code(dao_proposal_single_contract()); @@ -196,7 +204,7 @@ impl DaoTestingSuiteBase { let admin_factory_addr = app .instantiate_contract( admin_factory_id, - Addr::unchecked(CREATOR), + Addr::unchecked(OWNER), &cw_admin_factory::msg::InstantiateMsg { admin: None }, &[], "admin factory", @@ -230,6 +238,26 @@ impl DaoTestingSuiteBase { admin_factory_addr, } } + + pub fn instantiate_cw20(&mut self, name: &str, initial_balances: Vec) -> Addr { + self.app + .instantiate_contract( + self.cw20_base_id, + Addr::unchecked(OWNER), + &cw20_base::msg::InstantiateMsg { + name: name.to_string(), + symbol: name.to_string(), + decimals: 6, + initial_balances, + mint: None, + marketing: None, + }, + &[], + "cw20", + None, + ) + .unwrap() + } } // DAO CREATION @@ -255,7 +283,7 @@ impl DaoTestingSuiteBase { let res = self .app .execute_contract( - Addr::unchecked(CREATOR), + Addr::unchecked(OWNER), self.admin_factory_addr.clone(), &cw_admin_factory::msg::ExecuteMsg::InstantiateContractWithSelfAdmin { instantiate_msg: to_json_binary(&init).unwrap(), diff --git a/packages/dao-testing/src/suite/cw20_suite.rs b/packages/dao-testing/src/suite/cw20_suite.rs index f5d65762e..705cd0ac8 100644 --- a/packages/dao-testing/src/suite/cw20_suite.rs +++ b/packages/dao-testing/src/suite/cw20_suite.rs @@ -13,6 +13,7 @@ pub struct DaoTestingSuiteCw20<'a> { pub active_threshold: Option, } +#[derive(Clone, Debug)] pub struct Cw20DaoExtra { pub cw20_addr: Addr, pub staking_addr: Addr, @@ -48,7 +49,7 @@ impl<'a> DaoTestingSuiteCw20<'a> { }, ], initial_dao_balance: Uint128::new(10000), - unstaking_duration: Some(Duration::Height(10)), + unstaking_duration: None, active_threshold: None, } } diff --git a/packages/dao-testing/src/suite/cw4_suite.rs b/packages/dao-testing/src/suite/cw4_suite.rs index 3bd955593..aa3a55afd 100644 --- a/packages/dao-testing/src/suite/cw4_suite.rs +++ b/packages/dao-testing/src/suite/cw4_suite.rs @@ -8,6 +8,7 @@ pub struct DaoTestingSuiteCw4<'a> { pub members: Vec, } +#[derive(Clone, Debug)] pub struct Cw4DaoExtra { pub group_addr: Addr, } diff --git a/packages/dao-testing/src/suite/cw721_suite.rs b/packages/dao-testing/src/suite/cw721_suite.rs index fa8ce286b..06b52b125 100644 --- a/packages/dao-testing/src/suite/cw721_suite.rs +++ b/packages/dao-testing/src/suite/cw721_suite.rs @@ -18,6 +18,7 @@ pub struct DaoTestingSuiteCw721<'a> { pub active_threshold: Option, } +#[derive(Clone, Debug)] pub struct Cw721DaoExtra { pub cw721_addr: Addr, } @@ -51,7 +52,7 @@ impl<'a> DaoTestingSuiteCw721<'a> { owner: MEMBER5.to_string(), }, ], - unstaking_duration: Some(Duration::Height(10)), + unstaking_duration: None, active_threshold: None, } } @@ -136,7 +137,7 @@ impl<'a> DaoTestingSuite for DaoTestingSuiteCw721<'a> { msg: to_json_binary(&cw721_base::msg::InstantiateMsg { name: "Voting NFT".to_string(), symbol: "VOTE".to_string(), - minter: CREATOR.to_string(), + minter: OWNER.to_string(), }) .unwrap(), initial_nfts: self diff --git a/packages/dao-testing/src/suite/mod.rs b/packages/dao-testing/src/suite/mod.rs index 1f09c5d4b..312380ede 100644 --- a/packages/dao-testing/src/suite/mod.rs +++ b/packages/dao-testing/src/suite/mod.rs @@ -4,7 +4,7 @@ mod cw4_suite; mod cw721_suite; mod token_suite; -pub const CREATOR: &str = "creator"; +pub const OWNER: &str = "owner"; pub const MEMBER1: &str = "member1"; pub const MEMBER2: &str = "member2"; @@ -12,7 +12,7 @@ pub const MEMBER3: &str = "member3"; pub const MEMBER4: &str = "member4"; pub const MEMBER5: &str = "member5"; -pub const GOVTOKEN1: &str = "govtoken1"; +pub const GOV_DENOM: &str = "ugovtoken"; pub use cw_multi_test::Executor; diff --git a/packages/dao-testing/src/suite/token_suite.rs b/packages/dao-testing/src/suite/token_suite.rs index e5f9441c4..0053f2ea5 100644 --- a/packages/dao-testing/src/suite/token_suite.rs +++ b/packages/dao-testing/src/suite/token_suite.rs @@ -13,6 +13,7 @@ pub struct DaoTestingSuiteToken<'a> { pub active_threshold: Option, } +#[derive(Clone, Debug)] pub struct TokenDaoExtra { pub denom: String, } @@ -46,7 +47,7 @@ impl<'a> DaoTestingSuiteToken<'a> { amount: Uint128::new(100), }, ], - unstaking_duration: Some(Duration::Height(10)), + unstaking_duration: None, active_threshold: None, } } @@ -140,7 +141,7 @@ impl<'a> DaoTestingSuite for DaoTestingSuiteToken<'a> { code_id: self.base.voting_token_staked_id, msg: to_json_binary(&dao_voting_token_staked::msg::InstantiateMsg { token_info: dao_voting_token_staked::msg::TokenInfo::Existing { - denom: GOVTOKEN1.to_string(), + denom: GOV_DENOM.to_string(), }, unstaking_duration: self.unstaking_duration, active_threshold: self.active_threshold.clone(),