diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/error.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/error.rs index 9a67023224..aa61facb18 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/error.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/error.rs @@ -142,12 +142,6 @@ pub enum MixnetContractError { #[error("node {node_id} hasn't been assigned the role of {role} for this epoch")] IncorrectEpochRole { node_id: NodeId, role: Role }, - #[error("Mixnode {mix_id} hasn't been selected to the rewarding set in this epoch ({absolute_epoch_id})")] - MixnodeNotInRewardedSet { - mix_id: NodeId, - absolute_epoch_id: u32, - }, - #[error("Mixnode {mix_id} is currently in the process of unbonding")] MixnodeIsUnbonding { mix_id: NodeId }, diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/events.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/events.rs index e0b7f5f506..4fccb50295 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/events.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/events.rs @@ -157,7 +157,7 @@ pub const PRIOR_UNIT_REWARD_KEY: &str = "prior_unit_reward"; pub const NO_REWARD_REASON_KEY: &str = "no_reward_reason"; pub const BOND_NOT_FOUND_VALUE: &str = "bond_not_found"; -pub const ZERO_PERFORMANCE_VALUE: &str = "zero_performance"; +pub const ZERO_PERFORMANCE_OR_WORK_VALUE: &str = "zero_performance_or_work"; // rewarded set update pub const NUM_MIXNODES_KEY: &str = "num_mixnodes"; @@ -491,7 +491,7 @@ pub fn new_zero_uptime_mix_operator_rewarding_event(interval: Interval, node_id: interval.current_epoch_absolute_id().to_string(), ) .add_attribute(NODE_ID_KEY, node_id.to_string()) - .add_attribute(NO_REWARD_REASON_KEY, ZERO_PERFORMANCE_VALUE) + .add_attribute(NO_REWARD_REASON_KEY, ZERO_PERFORMANCE_OR_WORK_VALUE) } pub fn new_mix_rewarding_event( diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs index 5e7570714d..06caec5376 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs @@ -283,18 +283,8 @@ pub enum ExecuteMsg { TestingResolveAllPendingEvents { limit: Option, }, - - // TO BE REMOVED BEFORE MERGING - TestingUncheckedBondLegacyMixnode { - node: MixNode, - }, - TestingUncheckedBondLegacyGateway { - node: Gateway, - }, } -const bad_const: &str = "clippy will yell so that i'd remember to remove those legacy bonding ops"; - impl ExecuteMsg { pub fn default_memo(&self) -> String { match self { @@ -384,8 +374,6 @@ impl ExecuteMsg { ExecuteMsg::TestingResolveAllPendingEvents { .. } => { "resolving all pending events".into() } - ExecuteMsg::TestingUncheckedBondLegacyMixnode { .. } => "todo!".into(), - ExecuteMsg::TestingUncheckedBondLegacyGateway { .. } => "todo!".into(), } } } diff --git a/contracts/mixnet/schema/nym-mixnet-contract.json b/contracts/mixnet/schema/nym-mixnet-contract.json index 95f69ca095..bf25ebfd76 100644 --- a/contracts/mixnet/schema/nym-mixnet-contract.json +++ b/contracts/mixnet/schema/nym-mixnet-contract.json @@ -1158,48 +1158,6 @@ } }, "additionalProperties": false - }, - { - "type": "object", - "required": [ - "testing_unchecked_bond_legacy_mixnode" - ], - "properties": { - "testing_unchecked_bond_legacy_mixnode": { - "type": "object", - "required": [ - "node" - ], - "properties": { - "node": { - "$ref": "#/definitions/MixNode" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "testing_unchecked_bond_legacy_gateway" - ], - "properties": { - "testing_unchecked_bond_legacy_gateway": { - "type": "object", - "required": [ - "node" - ], - "properties": { - "node": { - "$ref": "#/definitions/Gateway" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false } ], "definitions": { diff --git a/contracts/mixnet/schema/raw/execute.json b/contracts/mixnet/schema/raw/execute.json index a71339ac52..2e220e58a3 100644 --- a/contracts/mixnet/schema/raw/execute.json +++ b/contracts/mixnet/schema/raw/execute.json @@ -955,48 +955,6 @@ } }, "additionalProperties": false - }, - { - "type": "object", - "required": [ - "testing_unchecked_bond_legacy_mixnode" - ], - "properties": { - "testing_unchecked_bond_legacy_mixnode": { - "type": "object", - "required": [ - "node" - ], - "properties": { - "node": { - "$ref": "#/definitions/MixNode" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "testing_unchecked_bond_legacy_gateway" - ], - "properties": { - "testing_unchecked_bond_legacy_gateway": { - "type": "object", - "required": [ - "node" - ], - "properties": { - "node": { - "$ref": "#/definitions/Gateway" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false } ], "definitions": { diff --git a/contracts/mixnet/src/compat/helpers.rs b/contracts/mixnet/src/compat/helpers.rs index 0664bed06b..46b845a05d 100644 --- a/contracts/mixnet/src/compat/helpers.rs +++ b/contracts/mixnet/src/compat/helpers.rs @@ -146,7 +146,6 @@ pub fn may_get_bond( #[cfg(test)] mod tests { use super::*; - use anyhow::bail; #[cfg(test)] mod reward_withdrawing_permission { diff --git a/contracts/mixnet/src/compat/transactions.rs b/contracts/mixnet/src/compat/transactions.rs index 77b20da946..05153d11ec 100644 --- a/contracts/mixnet/src/compat/transactions.rs +++ b/contracts/mixnet/src/compat/transactions.rs @@ -364,7 +364,7 @@ mod tests { MixnetContractError::ProfitMarginOutsideRange { .. } )); - // hundred + // a hundred test.add_dummy_nymnode("owner5", None); let sender = mock_info("owner5", &[]); let env = test.env(); @@ -561,7 +561,6 @@ mod tests { #[cfg(test)] mod withdrawing_operator_reward { use super::*; - use crate::support::tests::test_helpers; use crate::support::tests::test_helpers::{ExtractBankMsg, TestSetup}; use cosmwasm_std::testing::mock_info; use cosmwasm_std::Addr; @@ -586,6 +585,7 @@ mod tests { #[test] fn for_legacy_mixnode() -> anyhow::Result<()> { let mut test = TestSetup::new(); + let active_params = test.active_node_params(100.0); // no rewards test.add_legacy_mixnode("owner1", None); @@ -600,10 +600,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id, - test_helpers::performance(100.), - ); + test.reward_with_distribution(node_id, active_params); let res = try_withdraw_operator_reward(test.deps_mut(), sender)?; let maybe_bank = res.unwrap_bank_msg(); @@ -634,6 +631,7 @@ mod tests { #[test] fn for_nymnode() -> anyhow::Result<()> { let mut test = TestSetup::new(); + let active_params = test.active_node_params(100.0); // no rewards test.add_dummy_nymnode("owner1", None); @@ -648,10 +646,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id, - test_helpers::performance(100.), - ); + test.reward_with_distribution(node_id, active_params); let res = try_withdraw_operator_reward(test.deps_mut(), sender)?; let maybe_bank = res.unwrap_bank_msg(); diff --git a/contracts/mixnet/src/contract.rs b/contracts/mixnet/src/contract.rs index 36ffe22623..b3e3cc5df2 100644 --- a/contracts/mixnet/src/contract.rs +++ b/contracts/mixnet/src/contract.rs @@ -7,17 +7,15 @@ use crate::mixnet_contract_settings::storage as mixnet_params_storage; use crate::nodes::storage as nymnodes_storage; use crate::queued_migrations::migrate_to_nym_nodes_usage; use crate::rewards::storage::RewardingStorage; -use crate::support::tests::legacy; use cosmwasm_std::{ - coin, entry_point, to_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, - Response, + entry_point, to_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, }; use mixnet_contract_common::error::MixnetContractError; use mixnet_contract_common::{ ContractState, ContractStateParams, ExecuteMsg, InstantiateMsg, Interval, MigrateMsg, - NodeCostParams, OperatingCostRange, ProfitMarginRange, QueryMsg, + OperatingCostRange, ProfitMarginRange, QueryMsg, }; -use nym_contracts_common::{set_build_information, Percent}; +use nym_contracts_common::set_build_information; // version info for migration info const CONTRACT_NAME: &str = "crate:nym-mixnet-contract"; @@ -296,24 +294,6 @@ pub fn execute( ExecuteMsg::TestingResolveAllPendingEvents { limit } => { crate::testing::transactions::try_resolve_all_pending_events(deps, env, limit) } - ExecuteMsg::TestingUncheckedBondLegacyMixnode { node } => { - legacy::save_new_mixnode( - deps.storage, - env, - node, - NodeCostParams { - profit_margin_percent: Percent::from_percentage_value(20).unwrap(), - interval_operating_cost: coin(40_000_000, "unym"), - }, - info.sender, - info.funds[0].clone(), - )?; - Ok(Response::default()) - } - ExecuteMsg::TestingUncheckedBondLegacyGateway { node } => { - legacy::save_new_gateway(deps.storage, env, node, info.sender, info.funds[0].clone())?; - Ok(Response::default()) - } } } diff --git a/contracts/mixnet/src/delegations/helpers.rs b/contracts/mixnet/src/delegations/helpers.rs index e82496f1a9..257015d5e2 100644 --- a/contracts/mixnet/src/delegations/helpers.rs +++ b/contracts/mixnet/src/delegations/helpers.rs @@ -24,13 +24,14 @@ pub(crate) fn undelegate( #[cfg(test)] mod tests { use super::*; - use crate::support::tests::test_helpers::{performance, TestSetup}; + use crate::support::tests::test_helpers::TestSetup; use cosmwasm_std::{Addr, Decimal, Uint128}; use mixnet_contract_common::rewarding::helpers::truncate_reward_amount; #[test] fn undelegation_updates_mix_rewarding_storage_and_deletes_delegation() { let mut test = TestSetup::new(); + let active_params = test.active_node_params(100.0); let mix_id = test.add_rewarded_set_nymnode_id("mix-owner", Some(Uint128::new(100_000_000_000))); @@ -40,11 +41,9 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - let dist1 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist1 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist2 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist2 = test.reward_with_distribution_ignore_state(mix_id, active_params); let mix_rewarding = test.mix_rewarding(mix_id); let delegation = test.delegation(mix_id, delegator, &None); diff --git a/contracts/mixnet/src/gateways/queries.rs b/contracts/mixnet/src/gateways/queries.rs index 1cb19655e4..d6eae59487 100644 --- a/contracts/mixnet/src/gateways/queries.rs +++ b/contracts/mixnet/src/gateways/queries.rs @@ -83,11 +83,10 @@ pub(crate) fn query_preassigned_ids_paged( #[cfg(test)] pub(crate) mod tests { use super::*; - use crate::contract::execute; use crate::support::tests; use crate::support::tests::test_helpers; use crate::support::tests::test_helpers::TestSetup; - use cosmwasm_std::testing::{mock_env, mock_info}; + use cosmwasm_std::testing::mock_info; #[test] fn gateways_empty_on_init() { diff --git a/contracts/mixnet/src/interval/pending_events.rs b/contracts/mixnet/src/interval/pending_events.rs index 59e39e434e..ddacc44253 100644 --- a/contracts/mixnet/src/interval/pending_events.rs +++ b/contracts/mixnet/src/interval/pending_events.rs @@ -636,7 +636,6 @@ impl ContractExecutableEvent for PendingIntervalEventData { #[cfg(test)] mod tests { use super::*; - use crate::support::tests::test_helpers; use crate::support::tests::test_helpers::{assert_decimals, TestSetup}; use cosmwasm_std::Decimal; use mixnet_contract_common::Percent; @@ -835,33 +834,24 @@ mod tests { let delegation_og = 120_000_000u128; let delegation_new = 543_000_000u128; let delegation_coin_new = coin(delegation_new, TEST_COIN_DENOM); + let active_params = test.active_node_params(100.0); // perform some rewarding here to advance the unit delegation beyond the initial value test.force_change_rewarded_set(vec![mix_id]); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); + test.skip_to_next_epoch_end(); + test.reward_with_distribution_ignore_state(mix_id, active_params); let owner = "delegator"; test.add_immediate_delegation(owner, delegation_og, mix_id); test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist1 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist2 = test.reward_with_distribution_ignore_state(mix_id, active_params); let storage_key = Delegation::generate_storage_key(mix_id, &Addr::unchecked(owner), None); @@ -918,19 +908,14 @@ mod tests { let delegation = 120_000_000u128; let delegation_coin = coin(120_000_000u128, TEST_COIN_DENOM); + let active_params = test.active_node_params(100.0); // perform some rewarding here to advance the unit delegation beyond the initial value test.force_change_rewarded_set(vec![mix_id]); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let storage_key = Delegation::generate_storage_key(mix_id, &Addr::unchecked(owner), None); @@ -1059,15 +1044,10 @@ mod tests { use crate::compat::transactions::{try_decrease_pledge, try_increase_pledge}; use crate::interval::pending_events::unbond_mixnode; use crate::mixnodes::storage as mixnodes_storage; - use crate::mixnodes::transactions::{ - try_decrease_mixnode_pledge, try_increase_mixnode_pledge, - }; use crate::rewards::storage as rewards_storage; - use crate::support::tests::fixtures::TEST_COIN_DENOM; - use crate::support::tests::test_helpers; use crate::support::tests::test_helpers::{get_bank_send_msg, TestSetup}; use cosmwasm_std::testing::mock_info; - use cosmwasm_std::{coin, to_binary, Addr, CosmosMsg, Uint128, WasmMsg}; + use cosmwasm_std::{Addr, Uint128}; use mixnet_contract_common::error::MixnetContractError; use mixnet_contract_common::mixnode::{PendingMixNodeChanges, UnbondedMixnode}; use mixnet_contract_common::rewarding::helpers::truncate_reward_amount; @@ -1153,18 +1133,13 @@ mod tests { let mix_details = mixnodes_storage::mixnode_bonds() .load(test.deps().storage, mix_id) .unwrap(); + let active_params = test.active_node_params(100.0); test.force_change_rewarded_set(vec![mix_id]); test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist1 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist2 = test.reward_with_distribution_ignore_state(mix_id, active_params); let expected_reward = dist1.operator + dist2.operator; let truncated_reward = truncate_reward_amount(expected_reward); @@ -1271,6 +1246,7 @@ mod tests { let pledge1 = Uint128::new(150_000_000); let pledge2 = Uint128::new(50_000_000); let pledge3 = Uint128::new(200_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1291,14 +1267,9 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id_repledge, mix_id_full_pledge]); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } @@ -1308,6 +1279,7 @@ mod tests { let mut test = TestSetup::new(); let pledge1 = Uint128::new(150_000_000_000); let pledge2 = Uint128::new(50_000_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1319,10 +1291,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id_repledge]); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); let increase = test.coin(pledge2.u128()); increase_mixnode_pledge(test.deps_mut(), 123, mix_id_repledge, increase).unwrap(); @@ -1363,14 +1332,10 @@ mod tests { // go through few epochs of rewarding for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } @@ -1381,6 +1346,7 @@ mod tests { let mut test = TestSetup::new(); let pledge1 = Uint128::new(150_000_000_000); let pledge2 = Uint128::new(50_000_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1398,10 +1364,8 @@ mod tests { // go few epochs of rewarding before adding more pledge for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); + let dist = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); cumulative_op_reward += dist.operator; cumulative_del_reward += dist.delegates; } @@ -1446,14 +1410,10 @@ mod tests { // go through few more epochs of rewarding for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } @@ -1565,6 +1525,7 @@ mod tests { let pledge1 = Uint128::new(200_000_000); let pledge_change = Uint128::new(50_000_000); let pledge3 = Uint128::new(150_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1585,14 +1546,9 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id_repledge, mix_id_full_pledge]); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } @@ -1602,6 +1558,7 @@ mod tests { let mut test = TestSetup::new(); let pledge1 = Uint128::new(200_000_000_000); let pledge_change = Uint128::new(50_000_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1613,10 +1570,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id_repledge]); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); let decrease = test.coin(pledge_change.u128()); decrease_mixnode_pledge(test.deps_mut(), 123, mix_id_repledge, decrease).unwrap(); @@ -1657,14 +1611,10 @@ mod tests { // go through few epochs of rewarding for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } @@ -1675,6 +1625,7 @@ mod tests { let mut test = TestSetup::new(); let pledge1 = Uint128::new(200_000_000_000); let pledge_change = Uint128::new(50_000_000_000); + let active_params = test.active_node_params(100.0); let mix_id_repledge = test.add_rewarded_legacy_mixnode("mix-owner1", Some(pledge1)); test.set_pending_pledge_change(mix_id_repledge, None); @@ -1692,10 +1643,8 @@ mod tests { // go few epochs of rewarding before decreasing pledge for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); + let dist = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); cumulative_op_reward += dist.operator; cumulative_del_reward += dist.delegates; } @@ -1740,14 +1689,10 @@ mod tests { // go through few more epochs of rewarding for _ in 0..500 { test.skip_to_next_epoch_end(); - let dist1 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_repledge, - test_helpers::performance(100.0), - ); - let dist2 = test.legacy_reward_with_distribution_with_state_bypass( - mix_id_full_pledge, - test_helpers::performance(100.0), - ); + let dist1 = + test.reward_with_distribution_ignore_state(mix_id_repledge, active_params); + let dist2 = + test.reward_with_distribution_ignore_state(mix_id_full_pledge, active_params); assert_eq!(dist1, dist2) } diff --git a/contracts/mixnet/src/mixnet_contract_settings/transactions.rs b/contracts/mixnet/src/mixnet_contract_settings/transactions.rs index 7f6ec4b6c7..47199ce605 100644 --- a/contracts/mixnet/src/mixnet_contract_settings/transactions.rs +++ b/contracts/mixnet/src/mixnet_contract_settings/transactions.rs @@ -75,7 +75,6 @@ pub(crate) fn try_update_contract_settings( #[cfg(test)] pub mod tests { use super::*; - use crate::constants::INITIAL_PLEDGE_AMOUNT; use crate::mixnet_contract_settings::queries::query_rewarding_validator_address; use crate::mixnet_contract_settings::storage::rewarding_denom; use crate::support::tests::test_helpers; diff --git a/contracts/mixnet/src/mixnodes/transactions.rs b/contracts/mixnet/src/mixnodes/transactions.rs index 52fe1a45ed..7541de10b4 100644 --- a/contracts/mixnet/src/mixnodes/transactions.rs +++ b/contracts/mixnet/src/mixnodes/transactions.rs @@ -529,8 +529,7 @@ pub mod tests { // prior increase let owner = "mix-owner1"; - let node_id = test.add_legacy_mixnode(owner, None); - let details = test.mixnode_by_id(node_id).unwrap(); + test.add_legacy_mixnode(owner, None); let sender = mock_info(owner, &[test.coin(1000)]); try_increase_pledge(test.deps_mut(), env.clone(), sender.clone()).unwrap(); @@ -777,11 +776,8 @@ pub mod tests { #[cfg(test)] mod increasing_mixnode_pledge { - use crate::mixnodes::helpers::tests::{ - setup_mix_combinations, OWNER_UNBONDED, OWNER_UNBONDED_LEFTOVER, OWNER_UNBONDING, - }; - use super::*; + use crate::mixnodes::helpers::tests::setup_mix_combinations; #[test] fn cant_be_performed_if_epoch_transition_is_in_progress() { @@ -948,11 +944,8 @@ pub mod tests { #[cfg(test)] mod decreasing_mixnode_pledge { - use crate::mixnodes::helpers::tests::{ - setup_mix_combinations, OWNER_UNBONDED, OWNER_UNBONDED_LEFTOVER, OWNER_UNBONDING, - }; - use super::*; + use crate::mixnodes::helpers::tests::setup_mix_combinations; #[test] fn cant_be_performed_if_epoch_transition_is_in_progress() { @@ -1154,7 +1147,6 @@ pub mod tests { let events = test.pending_epoch_events(); assert!(events.is_empty()); - let sender = mock_info(owner, &[]); try_decrease_mixnode_pledge(test.deps_mut(), env, decrease.clone(), details).unwrap(); let events = test.pending_epoch_events(); diff --git a/contracts/mixnet/src/rewards/helpers.rs b/contracts/mixnet/src/rewards/helpers.rs index dfd07956ce..793f8b8f14 100644 --- a/contracts/mixnet/src/rewards/helpers.rs +++ b/contracts/mixnet/src/rewards/helpers.rs @@ -137,7 +137,7 @@ mod tests { use super::*; use crate::mixnodes::helpers::get_mixnode_details_by_id; use crate::rewards::models::RewardPoolChange; - use crate::support::tests::test_helpers::{assert_decimals, performance, TestSetup}; + use crate::support::tests::test_helpers::{assert_decimals, TestSetup}; use cosmwasm_std::Uint128; use mixnet_contract_common::rewarding::helpers::truncate_reward_amount; @@ -259,6 +259,7 @@ mod tests { let pledge = Uint128::new(250_000_000); let pledge_dec = 250_000_000u32.into_base_decimal().unwrap(); let mix_id = test.add_legacy_mixnode("mix-owner", Some(pledge)); + let active_params = test.active_node_params(100.0); // no rewards let mix_details = get_mixnode_details_by_id(test.deps().storage, mix_id) @@ -269,16 +270,13 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - let dist1 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist1 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist2 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist2 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist3 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist3 = test.reward_with_distribution_ignore_state(mix_id, active_params); let mix_details = get_mixnode_details_by_id(test.deps().storage, mix_id) .unwrap() @@ -295,6 +293,7 @@ mod tests { #[test] fn withdrawing_delegator_reward() { let mut test = TestSetup::new(); + let active_params = test.active_node_params(100.0); let delegation_amount = Uint128::new(2_500_000_000); let delegation_dec = 2_500_000_000_u32.into_base_decimal().unwrap(); @@ -311,16 +310,13 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - let dist1 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist1 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist2 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist2 = test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - let dist3 = - test.legacy_reward_with_distribution_with_state_bypass(mix_id, performance(100.0)); + let dist3 = test.reward_with_distribution_ignore_state(mix_id, active_params); let delegation_pre = test.delegation(mix_id, delegator, &None); let mix_rewarding = test.mix_rewarding(mix_id); diff --git a/contracts/mixnet/src/rewards/queries.rs b/contracts/mixnet/src/rewards/queries.rs index 53b7ab9f99..dc296752f1 100644 --- a/contracts/mixnet/src/rewards/queries.rs +++ b/contracts/mixnet/src/rewards/queries.rs @@ -284,7 +284,7 @@ mod tests { assert!(res.amount_earned.is_none()); assert!(res.amount_earned_detailed.is_none()); assert!(res.amount_staked.is_none()); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } #[test] @@ -304,7 +304,7 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), Decimal::zero()); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); } #[test] @@ -313,15 +313,13 @@ mod tests { let owner = "mix-owner"; let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode(owner, Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); let mut total_earned = Decimal::zero(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.operator; let res = query_pending_operator_reward(test.deps(), owner.into()).unwrap(); @@ -333,15 +331,12 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); // reward it few more times for good measure for _ in 0..10 { test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.operator; let res = query_pending_operator_reward(test.deps(), owner.into()).unwrap(); @@ -353,7 +348,7 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); } } @@ -363,15 +358,13 @@ mod tests { let owner = "mix-owner"; let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode(owner, Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); let mut total_earned = Decimal::zero(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.operator; let sender = mock_info(owner, &[]); @@ -386,7 +379,7 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } #[test] @@ -395,14 +388,12 @@ mod tests { let owner = "mix-owner"; let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode(owner, Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let sender = mock_info(owner, &[]); let env = test.env(); @@ -418,7 +409,7 @@ mod tests { assert!(res.amount_earned.is_none()); assert!(res.amount_earned_detailed.is_none()); assert!(res.amount_staked.is_none()); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } } @@ -442,7 +433,7 @@ mod tests { assert!(res.amount_earned.is_none()); assert!(res.amount_earned_detailed.is_none()); assert!(res.amount_staked.is_none()); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } #[test] @@ -463,13 +454,14 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), Decimal::zero()); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); } #[test] fn for_delegator_with_pending_reward() { let mut test = TestSetup::new(); let owner = "delegator"; + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(100_000_000); let mix_id = test @@ -480,10 +472,7 @@ mod tests { test.force_change_rewarded_set(vec![mix_id]); let mut total_earned = Decimal::zero(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.delegates; let res = @@ -494,15 +483,12 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); // reward it few more times for good measure for _ in 0..10 { test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.delegates; let res = query_pending_delegator_reward(test.deps(), owner.into(), mix_id, None) @@ -513,7 +499,7 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(res.mixnode_still_fully_bonded); + assert!(res.node_still_fully_bonded); } } @@ -521,6 +507,7 @@ mod tests { fn for_node_that_is_unbonding() { let mut test = TestSetup::new(); let owner = "delegator"; + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(100_000_000); let mix_id = test @@ -531,10 +518,7 @@ mod tests { test.force_change_rewarded_set(vec![mix_id]); let mut total_earned = Decimal::zero(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.delegates; let sender = mock_info("mix-owner", &[]); @@ -548,13 +532,14 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } #[test] fn for_node_that_has_unbonded() { let mut test = TestSetup::new(); let owner = "delegator"; + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(100_000_000); let mix_id = test @@ -565,10 +550,7 @@ mod tests { test.force_change_rewarded_set(vec![mix_id]); let mut total_earned = Decimal::zero(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + let dist = test.reward_with_distribution_ignore_state(mix_id, active_params); total_earned += dist.delegates; let sender = mock_info("mix-owner", &[]); @@ -583,7 +565,7 @@ mod tests { assert_eq!(res.amount_earned.unwrap(), expected_actual); assert_eq!(res.amount_earned_detailed.unwrap(), total_earned); assert_eq!(res.amount_staked.unwrap().amount, initial_stake); - assert!(!res.mixnode_still_fully_bonded); + assert!(!res.node_still_fully_bonded); } #[test] @@ -595,6 +577,7 @@ mod tests { let del2 = "delegator2"; let del3 = "delegator3"; let del4 = "delegator4"; + let active_params = test.active_node_params(100.); let mix_id = test .add_rewarded_legacy_mixnode("mix-owner", Some(Uint128::new(1_000_000_000_000))); @@ -605,58 +588,35 @@ mod tests { test.force_change_rewarded_set(vec![mix_id]); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.add_immediate_delegation(del3, 500_000_000u32, mix_id); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(85.0), - ); + let params = test.active_node_params(85.0); + test.reward_with_distribution_ignore_state(mix_id, params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(5.0), - ); + let params = test.active_node_params(5.0); + test.reward_with_distribution_ignore_state(mix_id, params); test.add_immediate_delegation(del4, 5_000_000u32, mix_id); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.add_immediate_delegation(del2, 250_000_000u32, mix_id); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(98.0), - ); + let params = test.active_node_params(98.0); + test.reward_with_distribution_ignore_state(mix_id, params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.remove_immediate_delegation(del3, mix_id); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(98.0), - ); + let params = test.active_node_params(98.0); + test.reward_with_distribution_ignore_state(mix_id, params); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let pending1 = query_pending_delegator_reward(test.deps(), del1.into(), mix_id, None).unwrap(); @@ -731,13 +691,11 @@ mod tests { let initial_stake = Uint128::new(1_000_000_000_000); let owner = "mix-owner"; let mix_id = test.add_rewarded_legacy_mixnode(owner, Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let sender = mock_info(owner, &[]); let env = test.env(); @@ -761,13 +719,11 @@ mod tests { let initial_stake = Uint128::new(1_000_000_000_000); let owner = "mix-owner"; let mix_id = test.add_rewarded_legacy_mixnode(owner, Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let sender = mock_info(owner, &[]); let env = test.env(); @@ -789,13 +745,11 @@ mod tests { let mut test = TestSetup::new(); let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.force_change_rewarded_set(vec![]); let res = query_estimated_current_epoch_operator_reward( @@ -815,13 +769,11 @@ mod tests { let mut test = TestSetup::new(); let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let res = query_estimated_current_epoch_operator_reward( test.deps(), @@ -840,13 +792,11 @@ mod tests { let mut test = TestSetup::new(); let initial_stake = Uint128::new(1_000_000_000_000); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", Some(initial_stake)); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let mix_rewarding = test.mix_rewarding(mix_id); let res = query_estimated_current_epoch_operator_reward( @@ -858,10 +808,8 @@ mod tests { .unwrap(); test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(95.0), - ); + let params = test.active_node_params(95.); + let dist = test.reward_with_distribution_ignore_state(mix_id, params); let expected = EstimatedCurrentEpochRewardResponse { original_stake: Some(coin(initial_stake.u128(), TEST_COIN_DENOM)), @@ -910,13 +858,11 @@ mod tests { fn when_delegation_doesnt_exist() { let mut test = TestSetup::new(); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let res = query_estimated_current_epoch_delegator_reward( test.deps(), @@ -934,6 +880,7 @@ mod tests { fn when_node_is_unbonding() { let mut test = TestSetup::new(); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(1_000_000_000); let owner = "delegator"; @@ -941,10 +888,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let sender = mock_info("mix-owner", &[]); let env = test.env(); @@ -967,6 +911,7 @@ mod tests { fn when_node_has_already_unbonded() { let mut test = TestSetup::new(); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(1_000_000_000); let owner = "delegator"; @@ -974,10 +919,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let sender = mock_info("mix-owner", &[]); let env = test.env(); @@ -1001,6 +943,7 @@ mod tests { fn when_node_is_not_in_the_rewarded_set() { let mut test = TestSetup::new(); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(1_000_000_000); let owner = "delegator"; @@ -1008,10 +951,7 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); test.force_change_rewarded_set(vec![]); let res = query_estimated_current_epoch_delegator_reward( @@ -1032,16 +972,14 @@ mod tests { let mut test = TestSetup::new(); let mix_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + let active_params = test.active_node_params(100.); let initial_stake = Uint128::new(1_000_000_000); let owner = "delegator"; test.add_immediate_delegation(owner, initial_stake, mix_id); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution_ignore_state(mix_id, active_params); let res = query_estimated_current_epoch_delegator_reward( test.deps(), @@ -1079,10 +1017,8 @@ mod tests { .unwrap(); test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(95.0), - ); + let params = test.active_node_params(95.); + let dist = test.reward_with_distribution_ignore_state(mix_id, params); let expected = EstimatedCurrentEpochRewardResponse { original_stake: Some(coin(initial_stake.u128(), TEST_COIN_DENOM)), @@ -1118,17 +1054,13 @@ mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![mix_id]); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(95.0), - ); + let params = test.active_node_params(95.0); + test.reward_with_distribution_ignore_state(mix_id, params); test.add_immediate_delegation(del3, initial_stake3, mix_id); test.skip_to_next_epoch_end(); - test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(85.0), - ); + let params = test.active_node_params(85.0); + test.reward_with_distribution_ignore_state(mix_id, params); let mix_rewarding = test.mix_rewarding(mix_id); @@ -1165,10 +1097,8 @@ mod tests { let cur3 = initial_stake3_dec + est3; test.skip_to_next_epoch_end(); - let dist = test.legacy_reward_with_distribution_with_state_bypass( - mix_id, - test_helpers::performance(95.0), - ); + let params = test.active_node_params(95.0); + let dist = test.reward_with_distribution_ignore_state(mix_id, params); let share1 = cur1 / mix_rewarding.delegates * dist.delegates; let share2 = cur2 / mix_rewarding.delegates * dist.delegates; diff --git a/contracts/mixnet/src/rewards/transactions.rs b/contracts/mixnet/src/rewards/transactions.rs index 21ed0e7b33..e3edbcc462 100644 --- a/contracts/mixnet/src/rewards/transactions.rs +++ b/contracts/mixnet/src/rewards/transactions.rs @@ -326,49 +326,29 @@ pub mod tests { use mixnet_contract_common::events::{ MixnetEventType, BOND_NOT_FOUND_VALUE, DELEGATES_REWARD_KEY, NO_REWARD_REASON_KEY, OPERATOR_REWARD_KEY, PRIOR_DELEGATES_KEY, PRIOR_UNIT_REWARD_KEY, - ZERO_PERFORMANCE_VALUE, + ZERO_PERFORMANCE_OR_WORK_VALUE, }; use mixnet_contract_common::helpers::compare_decimals; use mixnet_contract_common::nym_node::Role; - use mixnet_contract_common::reward_params::Performance; + use mixnet_contract_common::reward_params::WorkFactor; use mixnet_contract_common::EpochStatus; // a simple wrapper to streamline checking for rewarding results trait TestRewarding { - #[deprecated] - fn legacy_rewarding( - &mut self, - node_id: NodeId, - performance: Performance, - ) -> Result; - fn execute_rewarding( &mut self, node_id: NodeId, rewarding_params: NodeRewardingParameters, ) -> Result; - fn assert_rewarding(&mut self, node_id: NodeId, performance: Performance) -> Response; + fn assert_rewarding( + &mut self, + node_id: NodeId, + rewarding_params: NodeRewardingParameters, + ) -> Response; } impl TestRewarding for TestSetup { - fn legacy_rewarding( - &mut self, - node_id: NodeId, - performance: Performance, - ) -> Result { - // this is rather temporary (I hope...) - let work_factor = self.get_legacy_rewarding_node_work_factor(node_id); - - self.execute_rewarding( - node_id, - NodeRewardingParameters { - performance, - work_factor, - }, - ) - } - fn execute_rewarding( &mut self, node_id: NodeId, @@ -382,9 +362,13 @@ pub mod tests { } #[track_caller] - fn assert_rewarding(&mut self, node_id: NodeId, performance: Performance) -> Response { + fn assert_rewarding( + &mut self, + node_id: NodeId, + rewarding_params: NodeRewardingParameters, + ) -> Response { let caller = std::panic::Location::caller(); - self.legacy_rewarding(node_id, performance) + self.execute_rewarding(node_id, rewarding_params) .unwrap_or_else(|err| panic!("{caller} failed with: '{err}' ({err:?})")) } } @@ -392,6 +376,7 @@ pub mod tests { #[cfg(test)] mod epoch_state_is_correctly_updated { use super::*; + use mixnet_contract_common::reward_params::WorkFactor; #[test] fn when_target_mixnode_unbonded() { @@ -407,6 +392,7 @@ pub mod tests { node_id_never_existed, ]); test.start_epoch_transition(); + let active_params = test.active_node_params(100.); let env = test.env(); @@ -437,9 +423,7 @@ pub mod tests { ) .unwrap(); - let performance = test_helpers::performance(100.0); - - test.assert_rewarding(node_id_unbonded, performance); + test.assert_rewarding(node_id_unbonded, active_params); assert_eq!( EpochState::Rewarding { last_rewarded: node_id_unbonded, @@ -450,7 +434,7 @@ pub mod tests { .state ); - test.assert_rewarding(node_id_unbonded_leftover, performance); + test.assert_rewarding(node_id_unbonded_leftover, active_params); assert_eq!( EpochState::Rewarding { last_rewarded: node_id_unbonded_leftover, @@ -461,7 +445,7 @@ pub mod tests { .state ); - test.assert_rewarding(node_id_never_existed, performance); + test.assert_rewarding(node_id_never_existed, active_params); assert_eq!( EpochState::ReconcilingEvents, interval_storage::current_epoch_status(test.deps().storage) @@ -479,7 +463,7 @@ pub mod tests { test.force_change_rewarded_set(vec![node_id]); test.start_epoch_transition(); - let zero_performance = test_helpers::performance(0.); + let zero_performance = test.active_node_params(0.); test.assert_rewarding(node_id, zero_performance); assert_eq!( EpochState::ReconcilingEvents, @@ -489,6 +473,69 @@ pub mod tests { ); } + #[test] + fn when_target_mixnode_has_zero_work_factor() { + let mut test = TestSetup::new(); + let node_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + + test.skip_to_next_epoch_end(); + test.force_change_rewarded_set(vec![node_id]); + test.start_epoch_transition(); + + let params = NodeRewardingParameters::new( + test_helpers::performance(100.), + WorkFactor::zero(), + ); + test.assert_rewarding(node_id, params); + assert_eq!( + EpochState::ReconcilingEvents, + interval_storage::current_epoch_status(test.deps().storage) + .unwrap() + .state + ); + } + + #[test] + fn when_target_nymnode_has_zero_performance() { + let mut test = TestSetup::new(); + let node_id = test.add_dummy_nymnode("node-owner", None); + + test.skip_to_next_epoch_end(); + test.force_change_rewarded_set(vec![node_id]); + test.start_epoch_transition(); + + let zero_performance = test.active_node_params(0.); + test.assert_rewarding(node_id, zero_performance); + assert_eq!( + EpochState::ReconcilingEvents, + interval_storage::current_epoch_status(test.deps().storage) + .unwrap() + .state + ); + } + + #[test] + fn when_target_node_has_zero_workfactor() { + let mut test = TestSetup::new(); + let node_id = test.add_dummy_nymnode("mix-owner", None); + + test.skip_to_next_epoch_end(); + test.force_change_rewarded_set(vec![node_id]); + test.start_epoch_transition(); + + let params = NodeRewardingParameters::new( + test_helpers::performance(100.), + WorkFactor::zero(), + ); + test.assert_rewarding(node_id, params); + assert_eq!( + EpochState::ReconcilingEvents, + interval_storage::current_epoch_status(test.deps().storage) + .unwrap() + .state + ); + } + #[test] fn when_theres_only_one_node_to_reward() { let mut test = TestSetup::new(); @@ -497,9 +544,9 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id]); test.start_epoch_transition(); + let active_params = test.active_node_params(100.); - let performance = test_helpers::performance(100.0); - test.assert_rewarding(node_id, performance); + test.assert_rewarding(node_id, active_params); assert_eq!( EpochState::ReconcilingEvents, interval_storage::current_epoch_status(test.deps().storage) @@ -521,10 +568,10 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(ids.clone()); test.start_epoch_transition(); - let performance = test_helpers::performance(100.0); + let active_params = test.active_node_params(100.); for node_id in ids { - test.assert_rewarding(node_id, performance); + test.assert_rewarding(node_id, active_params); let current_state = interval_storage::current_epoch_status(test.deps().storage) .unwrap() @@ -556,6 +603,7 @@ pub mod tests { for bad_state in bad_states { let mut test = TestSetup::new(); + let active_params = test.active_node_params(100.); let mut status = EpochStatus::new(test.rewarding_validator().sender); status.state = bad_state; @@ -565,7 +613,7 @@ pub mod tests { test.skip_to_current_epoch_end(); test.force_change_rewarded_set(vec![1, 2, 3]); - let res = test.legacy_rewarding(1, test_helpers::performance(100.0)); + let res = test.execute_rewarding(1, active_params); assert_eq!( res, @@ -638,14 +686,14 @@ pub mod tests { pending_events::unbond_mixnode(test.deps_mut(), &env, 123, node_id_unbonded_leftover) .unwrap(); - let performance = test_helpers::performance(100.0); + let active_params = test.active_node_params(100.); for &node_id in &[ node_id_unbonded, node_id_unbonded_leftover, node_id_never_existed, ] { - let res = test.assert_rewarding(node_id, performance); + let res = test.assert_rewarding(node_id, active_params); let reason = find_attribute( Some(MixnetEventType::NodeRewarding.to_string()), @@ -666,8 +714,8 @@ pub mod tests { test.skip_to_next_epoch(); test.force_change_rewarded_set(vec![node_id]); - let performance = test_helpers::performance(100.); - let res = test.legacy_rewarding(node_id, performance); + let active_params = test.active_node_params(100.); + let res = test.execute_rewarding(node_id, active_params); assert!(matches!( res, Err(MixnetContractError::EpochInProgress { .. }) @@ -676,74 +724,10 @@ pub mod tests { // epoch is over (sanity check) test.skip_to_current_epoch_end(); test.start_epoch_transition(); - let res = test.legacy_rewarding(node_id, performance); + let res = test.execute_rewarding(node_id, active_params); assert!(res.is_ok()); } - #[test] - fn can_only_be_performed_for_nodes_in_rewarded_set() { - // let mut test = TestSetup::new(); - // - // let active_node_id = test.add_rewarded_legacy_mixnode("mix-owner-active", None); - // let standby_node_id = test.add_rewarded_legacy_mixnode("mix-owner-standby", None); - // let inactive_node_id = test.add_rewarded_legacy_mixnode("mix-owner-inactive", None); - // let sender = test.rewarding_validator(); - // - // test.skip_to_next_epoch_end(); - // - // // manually set the rewarded set so that we'd have 1 active node, 1 standby and 1 inactive - // interval_storage::REWARDED_SET - // .save( - // test.deps_mut().storage, - // active_node_id, - // &RewardedSetNodeStatus::Active, - // ) - // .unwrap(); - // interval_storage::REWARDED_SET - // .save( - // test.deps_mut().storage, - // standby_node_id, - // &RewardedSetNodeStatus::Standby, - // ) - // .unwrap(); - // - // // actually add one more dummy node with high id so we wouldn't go into the next state - // interval_storage::REWARDED_SET - // .save( - // test.deps_mut().storage, - // 9001, - // &RewardedSetNodeStatus::Standby, - // ) - // .unwrap(); - // test.start_epoch_transition(); - // - // let performance = test_helpers::performance(100.); - // let env = test.env(); - // let res_active = try_reward_node( - // test.deps_mut(), - // env.clone(), - // sender.clone(), - // active_node_id, - // performance, - // ); - // let res_standby = try_reward_node( - // test.deps_mut(), - // env.clone(), - // sender.clone(), - // standby_node_id, - // performance, - // ); - // let res_inactive = - // try_reward_node(test.deps_mut(), env, sender, inactive_node_id, performance); - // - // assert!(res_active.is_ok()); - // assert!(res_standby.is_ok()); - // assert!(matches!( - // res_inactive, - // Err(MixnetContractError::MixnodeNotInRewardedSet { node_id, .. }) if node_id == inactive_node_id - // )); - } - #[test] fn can_only_be_performed_once_per_node_per_epoch() { let mut test = TestSetup::new(); @@ -752,13 +736,13 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id, 42]); test.start_epoch_transition(); - let performance = test_helpers::performance(100.); + let active_params = test.active_node_params(100.); // first rewarding - test.assert_rewarding(node_id, performance); + test.assert_rewarding(node_id, active_params); // second rewarding - let res = test.legacy_rewarding(node_id, performance); + let res = test.execute_rewarding(node_id, active_params); assert!(matches!( res, Err(MixnetContractError::NodeAlreadyRewarded { node_id, .. }) if node_id == node_id @@ -768,7 +752,7 @@ pub mod tests { test.skip_to_next_epoch_end(); test.start_epoch_transition(); - let res = test.legacy_rewarding(node_id, performance); + let res = test.execute_rewarding(node_id, active_params); assert!(res.is_ok()); } @@ -780,17 +764,17 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id, 42]); test.start_epoch_transition(); - let zero_performance = test_helpers::performance(0.); - let performance = test_helpers::performance(100.0); + let zero_perf_params = test.active_node_params(0.); + let active_params = test.active_node_params(100.); // first rewarding - let res = test.assert_rewarding(node_id, zero_performance); + let res = test.assert_rewarding(node_id, zero_perf_params); let reason = res.attribute(MixnetEventType::NodeRewarding, NO_REWARD_REASON_KEY); - assert_eq!(ZERO_PERFORMANCE_VALUE, reason); + assert_eq!(ZERO_PERFORMANCE_OR_WORK_VALUE, reason); // sanity check: it's still treated as rewarding, so we can't reward the node again // with different performance for the same epoch - let res = test.legacy_rewarding(node_id, zero_performance); + let res = test.execute_rewarding(node_id, zero_perf_params); assert!(matches!( res, Err(MixnetContractError::NodeAlreadyRewarded { node_id, .. }) if node_id == node_id @@ -800,7 +784,47 @@ pub mod tests { test.skip_to_next_epoch_end(); test.start_epoch_transition(); - let res = test.assert_rewarding(node_id, performance); + let res = test.assert_rewarding(node_id, active_params); + + // rewards got distributed (in this test we don't care what they were exactly, but they must be non-zero) + let operator = res.attribute(MixnetEventType::NodeRewarding, OPERATOR_REWARD_KEY); + assert!(!operator.is_empty()); + assert_ne!("0", operator); + let delegates = res.attribute(MixnetEventType::NodeRewarding, DELEGATES_REWARD_KEY); + assert_eq!("0", delegates); + } + + #[test] + fn requires_nonzero_work_factor() { + let mut test = TestSetup::new(); + let node_id = test.add_rewarded_legacy_mixnode("mix-owner", None); + + test.skip_to_next_epoch_end(); + test.force_change_rewarded_set(vec![node_id, 42]); + test.start_epoch_transition(); + + let zero_work_params = + NodeRewardingParameters::new(test_helpers::performance(100.), WorkFactor::zero()); + let active_params = test.active_node_params(100.); + + // first rewarding + let res = test.assert_rewarding(node_id, zero_work_params); + let reason = res.attribute(MixnetEventType::NodeRewarding, NO_REWARD_REASON_KEY); + assert_eq!(ZERO_PERFORMANCE_OR_WORK_VALUE, reason); + + // sanity check: it's still treated as rewarding, so we can't reward the node again + // with different performance for the same epoch + let res = test.execute_rewarding(node_id, zero_work_params); + assert!(matches!( + res, + Err(MixnetContractError::NodeAlreadyRewarded { node_id, .. }) if node_id == node_id + )); + + // but in the next epoch, as always, we're good again + test.skip_to_next_epoch_end(); + test.start_epoch_transition(); + + let res = test.assert_rewarding(node_id, active_params); // rewards got distributed (in this test we don't care what they were exactly, but they must be non-zero) let operator = res.attribute(MixnetEventType::NodeRewarding, OPERATOR_REWARD_KEY); @@ -820,7 +844,7 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id1, node_id2, node_id3]); test.start_epoch_transition(); - let performance = test_helpers::performance(98.0); + let params = test.active_node_params(98.0); test.add_immediate_delegation("delegator1", Uint128::new(100_000_000), node_id2); @@ -842,7 +866,7 @@ pub mod tests { .load(test.deps().storage, node_id) .unwrap(); - let res = test.assert_rewarding(node_id, performance); + let res = test.assert_rewarding(node_id, params); let operator = res.decimal(MixnetEventType::NodeRewarding, OPERATOR_REWARD_KEY); let delegates = res.decimal(MixnetEventType::NodeRewarding, DELEGATES_REWARD_KEY); @@ -901,14 +925,11 @@ pub mod tests { test.start_epoch_transition(); for &node_id in &[node_id1, node_id2, node_id3] { let mut sim = test.instantiate_simulator(node_id); - let dist = test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id, - performance, - ); let node_params = NodeRewardingParameters::new( performance, global_rewarding_params.active_node_work(), ); + let dist = test.reward_with_distribution(node_id, node_params); let sim_res = sim.simulate_epoch_single_node(node_params).unwrap(); assert_eq!(sim_res, dist); } @@ -934,14 +955,11 @@ pub mod tests { test.start_epoch_transition(); for &node_id in &[node_id1, node_id2, node_id3] { let mut sim = test.instantiate_simulator(node_id); - let dist = test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id, - performance, - ); let node_params = NodeRewardingParameters::new( performance, global_rewarding_params.active_node_work(), ); + let dist = test.reward_with_distribution(node_id, node_params); let sim_res = sim.simulate_epoch_single_node(node_params).unwrap(); assert_eq!(sim_res, dist); } @@ -993,7 +1011,7 @@ pub mod tests { let actual_prior1 = test.mix_rewarding(node_id1); let actual_prior2 = test.mix_rewarding(node_id2); - let res1 = test.assert_rewarding(node_id1, performance); + let res1 = test.assert_rewarding(node_id1, node_params); let prior_delegates1 = res1.decimal(MixnetEventType::NodeRewarding, PRIOR_DELEGATES_KEY); @@ -1034,7 +1052,7 @@ pub mod tests { None, ); - let res2 = test.assert_rewarding(node_id2, performance); + let res2 = test.assert_rewarding(node_id2, node_params); let prior_delegates2 = res2.decimal(MixnetEventType::NodeRewarding, PRIOR_DELEGATES_KEY); @@ -1092,7 +1110,7 @@ pub mod tests { let actual_prior1 = test.mix_rewarding(node_id1); let actual_prior2 = test.mix_rewarding(node_id2); - let res1 = test.assert_rewarding(node_id1, performance); + let res1 = test.assert_rewarding(node_id1, node_params); let prior_delegates1 = res1.decimal(MixnetEventType::NodeRewarding, PRIOR_DELEGATES_KEY); @@ -1141,7 +1159,7 @@ pub mod tests { None, ); - let res2 = test.assert_rewarding(node_id2, performance); + let res2 = test.assert_rewarding(node_id2, node_params); let prior_delegates2 = res2.decimal(MixnetEventType::NodeRewarding, PRIOR_DELEGATES_KEY); @@ -1188,6 +1206,16 @@ pub mod tests { } } + #[cfg(test)] + mod gateway_role_rewarding { + use super::*; + + #[test] + fn unimplemented() { + todo!() + } + } + #[cfg(test)] mod withdrawing_delegator_reward { use crate::interval::pending_events; @@ -1205,6 +1233,7 @@ pub mod tests { .add_rewarded_legacy_mixnode("mix-owner1", Some(Uint128::new(1_000_000_000_000))); let node_id2 = test .add_rewarded_legacy_mixnode("mix-owner2", Some(Uint128::new(1_000_000_000_000))); + let active_params = test.active_node_params(100.); let delegator1 = "delegator1"; let delegator2 = "delegator2"; @@ -1222,14 +1251,8 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id1, node_id2]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id1, - test_helpers::performance(100.0), - ); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id2, - test_helpers::performance(100.0), - ); + test.reward_with_distribution(node_id1, active_params); + test.reward_with_distribution(node_id2, active_params); let res = try_withdraw_delegator_reward(test.deps_mut(), sender1.clone(), node_id1); assert_eq!( @@ -1260,6 +1283,7 @@ pub mod tests { .add_rewarded_legacy_mixnode("mix-owner1", Some(Uint128::new(1_000_000_000_000))); let node_id2 = test .add_rewarded_legacy_mixnode("mix-owner2", Some(Uint128::new(1_000_000_000_000))); + let active_params = test.active_node_params(100.); // very low stake so operating cost would be higher than total reward let low_stake_id = @@ -1276,14 +1300,8 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id1, low_stake_id]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id1, - test_helpers::performance(100.0), - ); - test.legacy_reward_with_distribution_and_legacy_work_factor( - low_stake_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution(node_id1, active_params); + test.reward_with_distribution(low_stake_id, active_params); let res1 = try_withdraw_delegator_reward(test.deps_mut(), sender.clone(), node_id1).unwrap(); @@ -1317,7 +1335,7 @@ pub mod tests { test.add_immediate_delegation(delegator, 100_000_000u128, node_id_unbonding); test.add_immediate_delegation(delegator, 100_000_000u128, node_id_unbonded_leftover); - let performance = test_helpers::performance(100.0); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id_unbonding, node_id_unbonded_leftover]); @@ -1325,14 +1343,8 @@ pub mod tests { for _ in 0..10 { test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_unbonding, - performance, - ); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_unbonded_leftover, - performance, - ); + test.reward_with_distribution(node_id_unbonding, active_params); + test.reward_with_distribution(node_id_unbonded_leftover, active_params); test.skip_to_next_epoch_end(); // bypass proper epoch progression and force change the state @@ -1402,7 +1414,7 @@ pub mod tests { test.add_immediate_delegation(delegator3, amount_quad3, node_id_quad); test.add_immediate_delegation(delegator4, amount_quad4, node_id_quad); - let performance = test_helpers::performance(100.0); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id_single, node_id_quad]); @@ -1411,18 +1423,12 @@ pub mod tests { let mut accumulated_quad = Decimal::zero(); for _ in 0..10 { test.start_epoch_transition(); - let dist = test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_single, - performance, - ); + let dist = test.reward_with_distribution(node_id_single, active_params); // sanity check to make sure test is actually doing what it's supposed to be doing assert!(!dist.delegates.is_zero()); accumulated_single += dist.delegates; - let dist = test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_quad, - performance, - ); + let dist = test.reward_with_distribution(node_id_quad, active_params); accumulated_quad += dist.delegates; test.skip_to_next_epoch_end(); @@ -1487,10 +1493,7 @@ pub mod tests { for _ in 0..10 { test.start_epoch_transition(); - let dist = test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_quad, - performance, - ); + let dist = test.reward_with_distribution(node_id_quad, active_params); accumulated_quad += dist.delegates; test.skip_to_next_epoch_end(); // bypass proper epoch progression and force change the state @@ -1571,14 +1574,12 @@ pub mod tests { let node_id = test.add_rewarded_legacy_mixnode(owner, Some(Uint128::new(1_000_000_000_000))); let sender = mock_info("random-guy", &[]); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id, - test_helpers::performance(100.0), - ); + test.reward_with_distribution(node_id, active_params); let res = try_withdraw_operator_reward(test.deps_mut(), sender.clone()); assert_eq!( @@ -1598,6 +1599,7 @@ pub mod tests { let node_id1 = test.add_rewarded_legacy_mixnode(owner1, Some(Uint128::new(1_000_000_000_000))); test.add_rewarded_legacy_mixnode(owner2, Some(Uint128::new(1_000_000_000_000))); + let active_params = test.active_node_params(100.); let sender1 = mock_info(owner1, &[]); let sender2 = mock_info(owner2, &[]); @@ -1606,10 +1608,7 @@ pub mod tests { test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id1]); test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id1, - test_helpers::performance(100.0), - ); + test.reward_with_distribution(node_id1, active_params); let res1 = try_withdraw_operator_reward(test.deps_mut(), sender1).unwrap(); assert!(matches!( @@ -1638,21 +1637,15 @@ pub mod tests { // add some delegation to the second node so that it wouldn't be cleared upon unbonding test.add_immediate_delegation("delegator", 100_000_000u128, node_id_unbonded_leftover); - let performance = test_helpers::performance(100.0); + let active_params = test.active_node_params(100.); test.skip_to_next_epoch_end(); test.force_change_rewarded_set(vec![node_id_unbonding, node_id_unbonded_leftover]); // go through few rewarding cycles before unbonding nodes (partially or fully) for _ in 0..10 { test.start_epoch_transition(); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_unbonding, - performance, - ); - test.legacy_reward_with_distribution_and_legacy_work_factor( - node_id_unbonded_leftover, - performance, - ); + test.reward_with_distribution(node_id_unbonding, active_params); + test.reward_with_distribution(node_id_unbonded_leftover, active_params); test.skip_to_next_epoch_end(); // bypass proper epoch progression and force change the state diff --git a/contracts/mixnet/src/support/helpers.rs b/contracts/mixnet/src/support/helpers.rs index 8a19de6fa2..586bd5186e 100644 --- a/contracts/mixnet/src/support/helpers.rs +++ b/contracts/mixnet/src/support/helpers.rs @@ -221,10 +221,8 @@ pub(crate) fn ensure_any_node_bonded( // current nym-node match nymnodes_storage::nym_nodes().may_load(storage, node_id)? { - None => return Err(MixnetContractError::NymNodeBondNotFound { node_id }), - Some(bond) if bond.is_unbonding => { - return Err(MixnetContractError::NodeIsUnbonding { node_id }) - } + None => Err(MixnetContractError::NymNodeBondNotFound { node_id }), + Some(bond) if bond.is_unbonding => Err(MixnetContractError::NodeIsUnbonding { node_id }), _ => Ok(()), } } diff --git a/contracts/mixnet/src/support/mod.rs b/contracts/mixnet/src/support/mod.rs index 41cb1691e3..ecef1156f3 100644 --- a/contracts/mixnet/src/support/mod.rs +++ b/contracts/mixnet/src/support/mod.rs @@ -4,6 +4,5 @@ pub(crate) mod helpers; pub(crate) mod legacy; -const foo: &str = "remove that hack"; -// #[cfg(test)] +#[cfg(test)] pub(crate) mod tests; diff --git a/contracts/mixnet/src/support/tests/mod.rs b/contracts/mixnet/src/support/tests/mod.rs index 328c6ef56d..8df5592c17 100644 --- a/contracts/mixnet/src/support/tests/mod.rs +++ b/contracts/mixnet/src/support/tests/mod.rs @@ -73,11 +73,11 @@ pub mod test_helpers { use mixnet_contract_common::rewarding::RewardDistribution; use mixnet_contract_common::{ ContractStateParams, Delegation, EpochEventId, EpochState, EpochStatus, ExecuteMsg, - Gateway, GatewayBondingPayload, IdentityKey, IdentityKeyRef, InitialRewardingParams, - InstantiateMsg, Interval, MixNode, MixNodeBond, MixNodeDetails, MixnodeBondingPayload, - NodeId, NymNode, NymNodeBond, NymNodeBondingPayload, NymNodeDetails, OperatingCostRange, - Percent, ProfitMarginRange, RoleAssignment, SignableGatewayBondingMsg, - SignableMixNodeBondingMsg, SignableNymNodeBondingMsg, + Gateway, GatewayBondingPayload, IdentityKey, InitialRewardingParams, InstantiateMsg, + Interval, MixNode, MixNodeBond, MixNodeDetails, MixnodeBondingPayload, NodeId, NymNode, + NymNodeBond, NymNodeBondingPayload, NymNodeDetails, OperatingCostRange, Percent, + ProfitMarginRange, RoleAssignment, SignableGatewayBondingMsg, SignableMixNodeBondingMsg, + SignableNymNodeBondingMsg, }; use nym_contracts_common::signing::{ ContractMessageContent, MessageSignature, SignableMessage, SigningAlgorithm, SigningPurpose, @@ -109,6 +109,7 @@ pub mod test_helpers { } } + #[allow(clippy::enum_variant_names)] pub enum NodeQueryType { ById(NodeId), ByIdentity(IdentityKey), @@ -997,6 +998,7 @@ pub mod test_helpers { self.rewarding_params().active_node_work() } + #[allow(dead_code)] pub fn standby_node_work(&self) -> WorkFactor { self.rewarding_params().standby_node_work() } @@ -1008,6 +1010,7 @@ pub mod test_helpers { } } + #[allow(dead_code)] pub fn standby_node_params(&self, performance: f32) -> NodeRewardingParameters { NodeRewardingParameters { performance: test_helpers::performance(performance), @@ -1015,6 +1018,7 @@ pub mod test_helpers { } } + #[track_caller] pub fn reward_with_distribution_ignore_state( &mut self, node_id: NodeId, @@ -1027,6 +1031,7 @@ pub mod test_helpers { ) } + #[track_caller] pub fn reward_with_distribution_with_state_bypass( &mut self, node_id: NodeId, @@ -1045,16 +1050,7 @@ pub mod test_helpers { res } - #[deprecated] - pub fn legacy_reward_with_distribution_with_state_bypass( - &mut self, - node_id: NodeId, - performance: Performance, - ) -> RewardDistribution { - let work_factor = self.get_legacy_rewarding_node_work_factor(node_id); - self.reward_with_distribution_with_state_bypass(node_id, performance, work_factor) - } - + #[allow(dead_code)] #[track_caller] pub fn node_role(&self, node_id: NodeId) -> Role { if read_assigned_roles(&self.deps.storage, Role::EntryGateway) @@ -1117,21 +1113,7 @@ pub mod test_helpers { work_factor } - pub fn legacy_reward_with_distribution_and_legacy_work_factor( - &mut self, - node_id: NodeId, - performance: Performance, - ) -> RewardDistribution { - let work_factor = self.get_legacy_rewarding_node_work_factor(node_id); - self.reward_with_distribution( - node_id, - NodeRewardingParameters { - performance, - work_factor, - }, - ) - } - + #[track_caller] pub fn reward_with_distribution( &mut self, node_id: NodeId, diff --git a/contracts/vesting/schema/nym-vesting-contract.json b/contracts/vesting/schema/nym-vesting-contract.json index 1a7b292784..26069a16c4 100644 --- a/contracts/vesting/schema/nym-vesting-contract.json +++ b/contracts/vesting/schema/nym-vesting-contract.json @@ -24,96 +24,6 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", "oneOf": [ - { - "description": "Only owner of the node can crate the family with node as head", - "type": "object", - "required": [ - "create_family" - ], - "properties": { - "create_family": { - "type": "object", - "required": [ - "label" - ], - "properties": { - "label": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Family head needs to sign the joining node IdentityKey, the Node provides its signature signaling consent to join the family", - "type": "object", - "required": [ - "join_family" - ], - "properties": { - "join_family": { - "type": "object", - "required": [ - "family_head", - "join_permit" - ], - "properties": { - "family_head": { - "$ref": "#/definitions/FamilyHead" - }, - "join_permit": { - "$ref": "#/definitions/MessageSignature" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "leave_family" - ], - "properties": { - "leave_family": { - "type": "object", - "required": [ - "family_head" - ], - "properties": { - "family_head": { - "$ref": "#/definitions/FamilyHead" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "kick_family_member" - ], - "properties": { - "kick_family_member": { - "type": "object", - "required": [ - "member" - ], - "properties": { - "member": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, { "type": "object", "required": [ @@ -188,7 +98,7 @@ ], "properties": { "new_costs": { - "$ref": "#/definitions/MixNodeCostParams" + "$ref": "#/definitions/NodeCostParams" } }, "additionalProperties": false @@ -418,7 +328,7 @@ "$ref": "#/definitions/Coin" }, "cost_params": { - "$ref": "#/definitions/MixNodeCostParams" + "$ref": "#/definitions/NodeCostParams" }, "mix_node": { "$ref": "#/definitions/MixNode" @@ -761,10 +671,6 @@ "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" }, - "FamilyHead": { - "description": "Head of particular family as identified by its identity key (i.e. public component of its ed25519 keypair stringified into base58).", - "type": "string" - }, "Gateway": { "description": "Information provided by the node operator during bonding that are used to allow other entities to use the services of this node.", "type": "object", @@ -937,7 +843,7 @@ }, "additionalProperties": false }, - "MixNodeCostParams": { + "NodeCostParams": { "description": "The cost parameters, or the cost function, defined for the particular mixnode that influences how the rewards should be split between the node operator and its delegators.", "type": "object", "required": [ @@ -946,7 +852,7 @@ ], "properties": { "interval_operating_cost": { - "description": "Operating cost of the associated mixnode per the entire interval.", + "description": "Operating cost of the associated node per the entire interval.", "allOf": [ { "$ref": "#/definitions/Coin" @@ -954,7 +860,7 @@ ] }, "profit_margin_percent": { - "description": "The profit margin of the associated mixnode, i.e. the desired percent of the reward to be distributed to the operator.", + "description": "The profit margin of the associated node, i.e. the desired percent of the reward to be distributed to the operator.", "allOf": [ { "$ref": "#/definitions/Percent" diff --git a/contracts/vesting/schema/raw/execute.json b/contracts/vesting/schema/raw/execute.json index 9723294d67..81565897d4 100644 --- a/contracts/vesting/schema/raw/execute.json +++ b/contracts/vesting/schema/raw/execute.json @@ -2,96 +2,6 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", "oneOf": [ - { - "description": "Only owner of the node can crate the family with node as head", - "type": "object", - "required": [ - "create_family" - ], - "properties": { - "create_family": { - "type": "object", - "required": [ - "label" - ], - "properties": { - "label": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Family head needs to sign the joining node IdentityKey, the Node provides its signature signaling consent to join the family", - "type": "object", - "required": [ - "join_family" - ], - "properties": { - "join_family": { - "type": "object", - "required": [ - "family_head", - "join_permit" - ], - "properties": { - "family_head": { - "$ref": "#/definitions/FamilyHead" - }, - "join_permit": { - "$ref": "#/definitions/MessageSignature" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "leave_family" - ], - "properties": { - "leave_family": { - "type": "object", - "required": [ - "family_head" - ], - "properties": { - "family_head": { - "$ref": "#/definitions/FamilyHead" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "kick_family_member" - ], - "properties": { - "kick_family_member": { - "type": "object", - "required": [ - "member" - ], - "properties": { - "member": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, { "type": "object", "required": [ @@ -166,7 +76,7 @@ ], "properties": { "new_costs": { - "$ref": "#/definitions/MixNodeCostParams" + "$ref": "#/definitions/NodeCostParams" } }, "additionalProperties": false @@ -396,7 +306,7 @@ "$ref": "#/definitions/Coin" }, "cost_params": { - "$ref": "#/definitions/MixNodeCostParams" + "$ref": "#/definitions/NodeCostParams" }, "mix_node": { "$ref": "#/definitions/MixNode" @@ -739,10 +649,6 @@ "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" }, - "FamilyHead": { - "description": "Head of particular family as identified by its identity key (i.e. public component of its ed25519 keypair stringified into base58).", - "type": "string" - }, "Gateway": { "description": "Information provided by the node operator during bonding that are used to allow other entities to use the services of this node.", "type": "object", @@ -915,7 +821,7 @@ }, "additionalProperties": false }, - "MixNodeCostParams": { + "NodeCostParams": { "description": "The cost parameters, or the cost function, defined for the particular mixnode that influences how the rewards should be split between the node operator and its delegators.", "type": "object", "required": [ @@ -924,7 +830,7 @@ ], "properties": { "interval_operating_cost": { - "description": "Operating cost of the associated mixnode per the entire interval.", + "description": "Operating cost of the associated node per the entire interval.", "allOf": [ { "$ref": "#/definitions/Coin" @@ -932,7 +838,7 @@ ] }, "profit_margin_percent": { - "description": "The profit margin of the associated mixnode, i.e. the desired percent of the reward to be distributed to the operator.", + "description": "The profit margin of the associated node, i.e. the desired percent of the reward to be distributed to the operator.", "allOf": [ { "$ref": "#/definitions/Percent"