diff --git a/pallets/parachain-staking/src/mock.rs b/pallets/parachain-staking/src/mock.rs index e3d9e7e323..4079b56f54 100644 --- a/pallets/parachain-staking/src/mock.rs +++ b/pallets/parachain-staking/src/mock.rs @@ -116,6 +116,10 @@ const GENESIS_BLOCKS_PER_ROUND: BlockNumber = 5; const GENESIS_COLLATOR_COMMISSION: Perbill = Perbill::from_percent(20); const GENESIS_PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(30); const GENESIS_NUM_SELECTED_CANDIDATES: u32 = 5; + +pub const POINTS_PER_BLOCK: u32 = 20; +pub const POINTS_PER_ROUND: u32 = GENESIS_BLOCKS_PER_ROUND * POINTS_PER_BLOCK; + parameter_types! { pub const MinBlocksPerRound: u32 = 3; pub const MaxOfflineRounds: u32 = 2; @@ -277,10 +281,8 @@ impl ExtBuilder { } /// Rolls forward one block. Returns the new block number. -fn roll_one_block(finalize_parachain_staking: bool) -> BlockNumber { - if finalize_parachain_staking { - ParachainStaking::on_finalize(System::block_number()); - } +fn roll_one_block() -> BlockNumber { + ParachainStaking::on_finalize(System::block_number()); Balances::on_finalize(System::block_number()); System::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); @@ -292,27 +294,21 @@ fn roll_one_block(finalize_parachain_staking: bool) -> BlockNumber { } /// Rolls to the desired block. Returns the number of blocks played. -/// Allows to decide whther to finalize blocks with ParachainStaking::on_finalize or not. -fn roll_to_block(n: BlockNumber, finalize_parachain_staking: bool) -> BlockNumber { +pub(crate) fn roll_to(n: BlockNumber) -> BlockNumber { let mut num_blocks = 0; let mut block = System::block_number(); while block < n { - block = roll_one_block(finalize_parachain_staking); + block = roll_one_block(); num_blocks += 1; } num_blocks } -/// Rolls to the desired block. Returns the number of blocks played. -pub(crate) fn roll_to(n: BlockNumber) -> BlockNumber { - roll_to_block(n, false) -} - /// Rolls desired number of blocks. Returns the final block. pub(crate) fn roll_blocks(num_blocks: u32) -> BlockNumber { let mut block = System::block_number(); for _ in 0..num_blocks { - block = roll_one_block(false); + block = roll_one_block(); } block } @@ -320,8 +316,6 @@ pub(crate) fn roll_blocks(num_blocks: u32) -> BlockNumber { /// Rolls block-by-block to the beginning of the specified round. /// This will complete the block in which the round change occurs. /// Returns the number of blocks played. -/// -/// NOTE: this function is aware of changes to [`ParachainStaking::round()`]. pub(crate) fn roll_to_round_begin(round: BlockNumber) -> BlockNumber { let r = ParachainStaking::round(); @@ -337,8 +331,6 @@ pub(crate) fn roll_to_round_begin(round: BlockNumber) -> BlockNumber { /// Rolls block-by-block to the end of the specified round. /// The block following will be the one in which the specified round change occurs. -/// -/// NOTE: this function is aware of changes to [`ParachainStaking::round()`]. pub(crate) fn roll_to_round_end(round: BlockNumber) -> BlockNumber { let r = ParachainStaking::round(); @@ -352,25 +344,6 @@ pub(crate) fn roll_to_round_end(round: BlockNumber) -> BlockNumber { roll_to(target) } -/// Rolls block-by-block to the beginning of the next round. -/// This will complete the block in which the round change occurs. -/// Returns the number of blocks played. -/// -/// NOTE: this function is aware of changes to [`ParachainStaking::round()`]. -pub(crate) fn roll_to_next_round_begin() -> BlockNumber { - let block = ParachainStaking::round().first + ParachainStaking::round().length; - roll_to_block(block, true) -} - -/// Rolls block-by-block to the end of the current round. -/// The block following will be the one in which the specified round change occurs. -/// -/// NOTE: this function is aware of changes to [`ParachainStaking::round()`]. -pub(crate) fn roll_to_current_round_end() -> BlockNumber { - let block = ParachainStaking::round().first + ParachainStaking::round().length - 1; - roll_to_block(block, true) -} - pub(crate) fn inflation_configs( pbr: AccountId, pbr_percent: u8, diff --git a/pallets/parachain-staking/src/tests.rs b/pallets/parachain-staking/src/tests.rs index 1b94aff16f..f40339fea2 100644 --- a/pallets/parachain-staking/src/tests.rs +++ b/pallets/parachain-staking/src/tests.rs @@ -25,9 +25,9 @@ use crate::auto_compound::{AutoCompoundConfig, AutoCompoundDelegations}; use crate::delegation_requests::{CancelledScheduledRequest, DelegationAction, ScheduledRequest}; use crate::mock::{ - inflation_configs, roll_blocks, roll_to, roll_to_current_round_end, roll_to_next_round_begin, - roll_to_round_begin, roll_to_round_end, set_author, set_block_author, AccountId, Balances, - BlockNumber, ExtBuilder, ParachainStaking, RuntimeEvent, RuntimeOrigin, Test, + inflation_configs, roll_blocks, roll_to, roll_to_round_begin, roll_to_round_end, set_author, + set_block_author, AccountId, Balances, BlockNumber, ExtBuilder, ParachainStaking, RuntimeEvent, + RuntimeOrigin, Test, POINTS_PER_BLOCK, POINTS_PER_ROUND, }; use crate::{ assert_events_emitted, assert_events_emitted_match, assert_events_eq, assert_no_events, @@ -36,7 +36,7 @@ use crate::{ DELEGATOR_LOCK_ID, }; use frame_support::traits::{Currency, ExistenceRequirement, WithdrawReasons}; -use frame_support::{assert_err, assert_noop, assert_ok, pallet_prelude::*, BoundedVec}; +use frame_support::{assert_err, assert_noop, assert_ok, BoundedVec}; use pallet_balances::{Event as BalancesEvent, PositiveImbalance}; use sp_runtime::{traits::Zero, DispatchError, ModuleError, Perbill, Percent}; // ~~ ROOT ~~ @@ -1190,30 +1190,33 @@ fn hadstake_is_cleaned_up_after_max_offline_rounds() { set_block_author(ACTIVE_COLLATOR); // Round 2 - roll_to_next_round_begin(); + roll_to_round_begin(2); // ACTIVE_COLLATOR has a stake in round 1 assert!(>::contains_key(1, ACTIVE_COLLATOR)); assert!(>::contains_key(1, ACTIVE_COLLATOR)); // Round 3 - roll_to_next_round_begin(); + roll_to_round_begin(3); // ACTIVE_COLLATOR has a stake in round 2 assert!(>::contains_key(2, ACTIVE_COLLATOR)); assert!(>::contains_key(2, ACTIVE_COLLATOR)); // End of round 3 - roll_to_current_round_end(); + roll_to_round_end(3); - // ACTIVE_COLLATOR has a no stake in round 1 anymore due to the distribution of rewards - // HadStake is still present - assert!(!>::contains_key(1, ACTIVE_COLLATOR)); - assert!(>::contains_key(1, ACTIVE_COLLATOR)); + assert!( + !>::contains_key(1, ACTIVE_COLLATOR), + "Active collator should have no stake in round 1 due to the distribution of rewards" + ); + assert!( + >::contains_key(1, ACTIVE_COLLATOR), + "Active collator should still be in HadStake for round 1" + ); // Round 4 - roll_to_next_round_begin(); - roll_to_current_round_end(); + roll_to_round_end(4); assert!( !>::contains_key(1, ACTIVE_COLLATOR), @@ -1243,14 +1246,13 @@ fn notify_inactive_collator_works() { // Round 2 - INACTIVE_COLLATOR authors blocks set_block_author(INACTIVE_COLLATOR); - roll_to_next_round_begin(); + roll_to_round_begin(2); // Change block author set_block_author(ACTIVE_COLLATOR); // INACTIVE_COLLATOR does not produce blocks on round 2 and 3 - roll_to_next_round_begin(); - roll_to_next_round_begin(); + roll_to_round_begin(4); roll_blocks(1); // On round 4 notify inactive collator @@ -1290,21 +1292,21 @@ fn notify_inactive_collator_succeeds_even_after_rewards_are_distributed() { set_block_author(ACTIVE_COLLATOR); // Round 2 - roll_to_next_round_begin(); + roll_to_round_begin(2); roll_blocks(1); // INACTIVE_COLLATOR has a stake in round 1 assert!(>::contains_key(1, INACTIVE_COLLATOR)); // Round 3 - roll_to_next_round_begin(); + roll_to_round_begin(3); roll_blocks(1); // INACTIVE_COLLATOR has a stake in round 2 assert!(>::contains_key(2, INACTIVE_COLLATOR)); // End of round 3 - roll_to_current_round_end(); + roll_to_round_end(3); // INACTIVE_COLLATOR has a no stake in round 1 anymore due to the distribution of rewards assert!(!>::contains_key(1, INACTIVE_COLLATOR)); @@ -1465,16 +1467,10 @@ fn notify_inactive_collator_fails_cannot_be_notified_as_inactive() { // Change block author set_block_author(1); - // Finalize the first block of round 2 - ParachainStaking::on_finalize(5); - // Round 3 roll_to_round_begin(3); roll_blocks(1); - // Finalize a block of round 3 - ParachainStaking::on_finalize(11); - // Round 4 roll_to_round_begin(4); roll_blocks(1); @@ -4256,14 +4252,14 @@ fn parachain_bond_inflation_reserve_matches_config() { ); assert_eq!(Balances::free_balance(&11), 1); // ~ set block author as 1 for all blocks this round - set_author(2, 1, 100); + set_author(2, 1, POINTS_PER_ROUND); roll_to_round_begin(4); // distribute total issuance to collator 1 and its delegators 6, 7, 19 assert_eq!(Balances::free_balance(&11), 16); - // ~ set block author as 1 for all blocks this round - set_author(3, 1, 100); - set_author(4, 1, 100); - set_author(5, 1, 100); + // ~ set block author as 1 for all blocks in rounds 3, 4, and 5 + set_author(3, 1, POINTS_PER_ROUND); + set_author(4, 1, POINTS_PER_ROUND); + set_author(5, 1, POINTS_PER_ROUND); // 1. ensure delegators are paid for 2 rounds after they leave assert_noop!( ParachainStaking::schedule_revoke_delegation(RuntimeOrigin::signed(66), 1), @@ -4552,7 +4548,7 @@ fn parachain_bond_inflation_reserve_matches_config() { new: inflation_configs(11, 50, 0, 0), }); // 6 won't be paid for this round because they left already - set_author(6, 1, 100); + set_author(6, 1, POINTS_PER_ROUND); roll_to_round_begin(8); // keep paying 6 assert_events_eq!( @@ -4614,7 +4610,7 @@ fn parachain_bond_inflation_reserve_matches_config() { }, ); assert_eq!(Balances::free_balance(&11), 95); - set_author(7, 1, 100); + set_author(7, 1, POINTS_PER_ROUND); roll_to_round_begin(9); // no more paying 6 assert_events_eq!( @@ -4676,7 +4672,7 @@ fn parachain_bond_inflation_reserve_matches_config() { }, ); assert_eq!(Balances::free_balance(&11), 127); - set_author(8, 1, 100); + set_author(8, 1, POINTS_PER_ROUND); roll_blocks(1); assert_ok!(ParachainStaking::delegate( RuntimeOrigin::signed(8), @@ -4753,8 +4749,8 @@ fn parachain_bond_inflation_reserve_matches_config() { }, ); assert_eq!(Balances::free_balance(&11), 160); - set_author(9, 1, 100); - set_author(10, 1, 100); + set_author(9, 1, POINTS_PER_ROUND); + set_author(10, 1, POINTS_PER_ROUND); roll_to_round_begin(11); // new delegation is still not rewarded yet assert_events_eq!( @@ -4976,7 +4972,7 @@ fn paid_collator_commission_matches_config() { }, ); // only reward author with id 4 - set_author(3, 4, 100); + set_author(3, 4, POINTS_PER_ROUND); roll_to_round_begin(5); // 20% of 10 is commission + due_portion (0) = 2 + 4 = 6 // all delegator payouts are 10-2 = 8 * stake_pct @@ -5003,15 +4999,15 @@ fn paid_collator_commission_matches_config() { assert_events_eq!( Event::Rewarded { account: 4, - rewards: 18, + rewards: 9, }, Event::Rewarded { account: 5, - rewards: 6, + rewards: 3, }, Event::Rewarded { account: 6, - rewards: 6, + rewards: 3, }, ); }); @@ -5233,7 +5229,7 @@ fn payout_distribution_to_solo_collators() { }, ); // ~ set block author as 1 for all blocks this round - set_author(2, 1, 100); + set_author(2, 1, POINTS_PER_ROUND); roll_to_round_begin(4); assert_events_eq!( Event::CollatorChosen { @@ -5267,12 +5263,12 @@ fn payout_distribution_to_solo_collators() { roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 205, + rewards: 102, }); // ~ set block author as 1 for 3 blocks this round - set_author(4, 1, 60); + set_author(4, 1, POINTS_PER_BLOCK * 3); // ~ set block author as 2 for 2 blocks this round - set_author(4, 2, 40); + set_author(4, 2, POINTS_PER_BLOCK * 2); roll_to_round_begin(6); // pay 60% total issuance to 1 and 40% total issuance to 2 assert_events_eq!( @@ -5306,18 +5302,18 @@ fn payout_distribution_to_solo_collators() { roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 129, + rewards: 63, }); roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 2, - rewards: 86, + rewards: 42, },); - // ~ each collator produces 1 block this round - set_author(6, 1, 20); - set_author(6, 2, 20); - set_author(6, 3, 20); - set_author(6, 4, 20); + // ~ each collator produces at least 1 block this round + set_author(6, 1, POINTS_PER_BLOCK * 2); + set_author(6, 2, POINTS_PER_BLOCK); + set_author(6, 3, POINTS_PER_BLOCK); + set_author(6, 4, POINTS_PER_BLOCK); roll_to_round_begin(8); // pay 20% issuance for all collators assert_events_eq!( @@ -5351,22 +5347,22 @@ fn payout_distribution_to_solo_collators() { roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 3, - rewards: 56, + rewards: 21, }); roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 4, - rewards: 56, + rewards: 21, }); roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 56, + rewards: 43, }); roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 2, - rewards: 56, + rewards: 21, }); // check that distributing rewards clears awarded pts assert!(ParachainStaking::awarded_pts(1, 1).is_zero()); @@ -5678,8 +5674,8 @@ fn payouts_follow_delegation_changes() { .build() .execute_with(|| { // ~ set block author as 1 for all blocks this round - set_author(1, 1, 100); - set_author(2, 1, 100); + set_author(1, 1, POINTS_PER_ROUND); + set_author(2, 1, POINTS_PER_ROUND); roll_to_round_begin(2); // chooses top TotalSelectedCandidates (5), in order assert_events_eq!( @@ -5711,8 +5707,8 @@ fn payouts_follow_delegation_changes() { }, ); - set_author(3, 1, 100); - set_author(4, 1, 100); + set_author(3, 1, POINTS_PER_ROUND); + set_author(4, 1, POINTS_PER_ROUND); roll_to_round_begin(4); // distribute total issuance to collator 1 and its delegators 6, 7, 19 @@ -5748,23 +5744,23 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 23, + rewards: 11, }, Event::Rewarded { account: 6, - rewards: 7, + rewards: 4, }, Event::Rewarded { account: 7, - rewards: 7, + rewards: 4, }, Event::Rewarded { account: 10, - rewards: 7, + rewards: 4, }, ); // ~ set block author as 1 for all blocks this round - set_author(5, 1, 100); + set_author(5, 1, POINTS_PER_ROUND); roll_blocks(1); // 1. ensure delegators are paid for 2 rounds after they leave @@ -5816,23 +5812,23 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 24, + rewards: 12, }, Event::Rewarded { account: 6, - rewards: 8, + rewards: 4, }, Event::Rewarded { account: 7, - rewards: 8, + rewards: 4, }, Event::Rewarded { account: 10, - rewards: 8, + rewards: 4, }, ); - set_author(6, 1, 100); + set_author(6, 1, POINTS_PER_ROUND); // keep paying 6 (note: inflation is in terms of total issuance so that's why 1 is 21) roll_to_round_begin(6); assert_ok!(ParachainStaking::execute_delegation_request( @@ -5887,23 +5883,23 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 26, + rewards: 12, }, Event::Rewarded { account: 6, - rewards: 8, + rewards: 4, }, Event::Rewarded { account: 7, - rewards: 8, + rewards: 4, }, Event::Rewarded { account: 10, - rewards: 8, + rewards: 4, }, ); // 6 won't be paid for this round because they left already - set_author(7, 1, 100); + set_author(7, 1, POINTS_PER_ROUND); roll_to_round_begin(7); // keep paying 6 assert_events_eq!( @@ -5938,18 +5934,18 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 31, + rewards: 14, }, Event::Rewarded { account: 7, - rewards: 10, + rewards: 5, }, Event::Rewarded { account: 10, - rewards: 10, + rewards: 5, }, ); - set_author(8, 1, 100); + set_author(8, 1, POINTS_PER_ROUND); roll_to_round_begin(8); assert_events_eq!( Event::CollatorChosen { @@ -5983,18 +5979,18 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 32, + rewards: 15, }, Event::Rewarded { account: 7, - rewards: 11, + rewards: 5, }, Event::Rewarded { account: 10, - rewards: 11, + rewards: 5, }, ); - set_author(9, 1, 100); + set_author(9, 1, POINTS_PER_ROUND); roll_to_round_begin(9); // no more paying 6 assert_events_eq!( @@ -6029,15 +6025,15 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 34, + rewards: 15, }, Event::Rewarded { account: 7, - rewards: 11, + rewards: 5, }, Event::Rewarded { account: 10, - rewards: 11, + rewards: 5, }, ); roll_blocks(1); @@ -6056,7 +6052,7 @@ fn payouts_follow_delegation_changes() { auto_compound: Percent::zero(), }); - set_author(10, 1, 100); + set_author(10, 1, POINTS_PER_ROUND); roll_to_round_begin(10); // new delegation is not rewarded yet assert_events_eq!( @@ -6091,15 +6087,15 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 36, + rewards: 15, }, Event::Rewarded { account: 7, - rewards: 12, + rewards: 5, }, Event::Rewarded { account: 10, - rewards: 12, + rewards: 5, }, ); roll_to_round_begin(11); @@ -6136,15 +6132,15 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 37, + rewards: 15, }, Event::Rewarded { account: 7, - rewards: 12, + rewards: 5, }, Event::Rewarded { account: 10, - rewards: 12, + rewards: 5, }, ); roll_to_round_begin(12); @@ -6182,19 +6178,19 @@ fn payouts_follow_delegation_changes() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 34, + rewards: 14, }, Event::Rewarded { account: 7, - rewards: 10, + rewards: 4, }, Event::Rewarded { account: 10, - rewards: 10, + rewards: 4, }, Event::Rewarded { account: 8, - rewards: 10, + rewards: 4, }, ); }); @@ -6600,11 +6596,9 @@ fn no_rewards_paid_until_after_reward_payment_delay() { .build() .execute_with(|| { // payouts for round 1 - set_author(1, 1, 1); - set_author(1, 2, 1); - set_author(1, 2, 1); - set_author(1, 3, 1); - set_author(1, 3, 1); + set_author(1, 1, POINTS_PER_BLOCK); + set_author(1, 2, POINTS_PER_BLOCK * 2); + set_author(1, 3, POINTS_PER_BLOCK * 2); roll_to_round_begin(2); assert_events_eq!( @@ -6665,7 +6659,7 @@ fn no_rewards_paid_until_after_reward_payment_delay() { roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 1, + rewards: 0, }); roll_blocks(1); @@ -6693,8 +6687,8 @@ fn deferred_payment_storage_items_are_cleaned_up() { .with_candidates(vec![(1, 20), (2, 20)]) .build() .execute_with(|| { - set_author(1, 1, 1); - set_author(1, 2, 1); + set_author(1, 1, POINTS_PER_BLOCK * 3); + set_author(1, 2, POINTS_PER_BLOCK * 2); // reflects genesis? assert!(>::contains_key(1, 1)); @@ -6775,16 +6769,16 @@ fn deferred_payment_storage_items_are_cleaned_up() { "DelayedPayouts should be populated after RewardPaymentDelay" ); assert!(>::contains_key(1)); - assert!(!>::contains_key(2)); + assert!(>::contains_key(2)); assert!( - !>::contains_key(2), - "We never rewarded points for round 2" + >::contains_key(2), + "We awarded points for round 2" ); assert!(!>::contains_key(3)); assert!( - !>::contains_key(3), - "We never awarded points for round 3" + >::contains_key(3), + "We awarded points for round 3" ); // collator 1 has been paid in this last block and associated storage cleaned up @@ -6799,7 +6793,7 @@ fn deferred_payment_storage_items_are_cleaned_up() { roll_blocks(1); assert_events_eq!(Event::Rewarded { account: 2, - rewards: 1, + rewards: 0, },); roll_to_round_begin(4); @@ -6845,8 +6839,8 @@ fn deferred_payment_and_at_stake_storage_items_cleaned_up_for_candidates_not_pro .build() .execute_with(|| { // candidate 3 will not produce blocks - set_author(1, 1, 1); - set_author(1, 2, 1); + set_author(1, 1, POINTS_PER_BLOCK * 3); + set_author(1, 2, POINTS_PER_BLOCK * 2); // reflects genesis? assert!(>::contains_key(1, 1)); @@ -6917,10 +6911,10 @@ fn deferred_payment_steady_state_event_flow() { .execute_with(|| { // convenience to set the round points consistently let set_round_points = |round: BlockNumber| { - set_author(round as BlockNumber, 1, 1); - set_author(round as BlockNumber, 2, 1); - set_author(round as BlockNumber, 3, 1); - set_author(round as BlockNumber, 4, 1); + set_author(round as BlockNumber, 1, 2 * POINTS_PER_ROUND); + set_author(round as BlockNumber, 2, POINTS_PER_ROUND); + set_author(round as BlockNumber, 3, POINTS_PER_ROUND); + set_author(round as BlockNumber, 4, POINTS_PER_ROUND); }; // grab initial issuance -- we will reset it before round issuance is calculated so that @@ -7001,15 +6995,15 @@ fn deferred_payment_steady_state_event_flow() { assert_events_eq!( Event::Rewarded { account: 3, - rewards: 19, + rewards: 13, }, Event::Rewarded { account: 22, - rewards: 6, + rewards: 4, }, Event::Rewarded { account: 33, - rewards: 6, + rewards: 4, }, ); @@ -7017,15 +7011,15 @@ fn deferred_payment_steady_state_event_flow() { assert_events_eq!( Event::Rewarded { account: 4, - rewards: 19, + rewards: 13, }, Event::Rewarded { account: 33, - rewards: 6, + rewards: 4, }, Event::Rewarded { account: 44, - rewards: 6, + rewards: 4, }, ); @@ -7033,15 +7027,15 @@ fn deferred_payment_steady_state_event_flow() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 19, + rewards: 27, }, Event::Rewarded { account: 11, - rewards: 6, + rewards: 9, }, Event::Rewarded { account: 44, - rewards: 6, + rewards: 9, }, ); @@ -7049,15 +7043,15 @@ fn deferred_payment_steady_state_event_flow() { assert_events_eq!( Event::Rewarded { account: 2, - rewards: 19, + rewards: 13, }, Event::Rewarded { account: 11, - rewards: 6, + rewards: 4, }, Event::Rewarded { account: 22, - rewards: 6, + rewards: 4, }, ); @@ -7194,7 +7188,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_for_previous_rounds_but_not_f .build() .execute_with(|| { // preset rewards for rounds 1, 2 and 3 - (1..=3).for_each(|round| set_author(round, 1, 1)); + (1..=3).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_revoke_delegation( RuntimeOrigin::signed(2), @@ -7222,7 +7216,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_for_previous_rounds_but_not_f assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 2, }, Event::Rewarded { account: 2, @@ -7235,7 +7229,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_for_previous_rounds_but_not_f roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 5, + rewards: 2, },); let collator_snapshot = ParachainStaking::at_stake(ParachainStaking::round().current, 1) @@ -7261,7 +7255,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_when_request_cancelled() { .build() .execute_with(|| { // preset rewards for rounds 2, 3 and 4 - (2..=4).for_each(|round| set_author(round, 1, 1)); + (2..=4).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_revoke_delegation( RuntimeOrigin::signed(2), @@ -7294,7 +7288,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_when_request_cancelled() { roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 5, + rewards: 2, },); let collator_snapshot = ParachainStaking::at_stake(ParachainStaking::round().current, 1) @@ -7315,7 +7309,7 @@ fn test_delegator_scheduled_for_revoke_is_rewarded_when_request_cancelled() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 1, }, Event::Rewarded { account: 2, @@ -7335,7 +7329,7 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_for_previous_rounds_bu .build() .execute_with(|| { // preset rewards for rounds 1, 2 and 3 - (1..=3).for_each(|round| set_author(round, 1, 1)); + (1..=3).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_delegator_bond_less( RuntimeOrigin::signed(2), @@ -7364,11 +7358,11 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_for_previous_rounds_bu assert_events_eq!( Event::Rewarded { account: 1, - rewards: 3, + rewards: 2, }, Event::Rewarded { account: 2, - rewards: 2, + rewards: 1, }, ); @@ -7378,7 +7372,7 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_for_previous_rounds_bu assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 1, }, Event::Rewarded { account: 2, @@ -7409,7 +7403,7 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_when_request_cancelled .build() .execute_with(|| { // preset rewards for rounds 2, 3 and 4 - (2..=4).for_each(|round| set_author(round, 1, 1)); + (2..=4).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_delegator_bond_less( RuntimeOrigin::signed(2), @@ -7444,7 +7438,7 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_when_request_cancelled assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 1, }, Event::Rewarded { account: 2, @@ -7470,11 +7464,11 @@ fn test_delegator_scheduled_for_bond_decrease_is_rewarded_when_request_cancelled assert_events_eq!( Event::Rewarded { account: 1, - rewards: 3, + rewards: 1, }, Event::Rewarded { account: 2, - rewards: 2, + rewards: 1, }, ); }); @@ -7489,7 +7483,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_for_previous_rounds_but_not_fo .build() .execute_with(|| { // preset rewards for rounds 1, 2 and 3 - (1..=3).for_each(|round| set_author(round, 1, 1)); + (1..=3).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_revoke_delegation( RuntimeOrigin::signed(2), @@ -7529,7 +7523,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_for_previous_rounds_but_not_fo assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 2, }, Event::Rewarded { account: 2, @@ -7542,7 +7536,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_for_previous_rounds_but_not_fo roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 5, + rewards: 2, },); let collator_snapshot = ParachainStaking::at_stake(ParachainStaking::round().current, 1) @@ -7568,7 +7562,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_when_request_cancelled() { .build() .execute_with(|| { // preset rewards for rounds 2, 3 and 4 - (2..=4).for_each(|round| set_author(round, 1, 1)); + (2..=4).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::schedule_revoke_delegation( RuntimeOrigin::signed(2), @@ -7617,7 +7611,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_when_request_cancelled() { roll_blocks(3); assert_events_eq!(Event::Rewarded { account: 1, - rewards: 5, + rewards: 2, },); let collator_snapshot = ParachainStaking::at_stake(ParachainStaking::round().current, 1) @@ -7638,7 +7632,7 @@ fn test_delegator_scheduled_for_leave_is_rewarded_when_request_cancelled() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 4, + rewards: 1, }, Event::Rewarded { account: 2, @@ -8296,7 +8290,7 @@ fn test_rewards_do_not_auto_compound_on_payment_if_delegation_scheduled_revoke_e .with_delegations(vec![(2, 1, 200), (3, 1, 200)]) .build() .execute_with(|| { - (2..=5).for_each(|round| set_author(round, 1, 1)); + (2..=5).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::set_auto_compound( RuntimeOrigin::signed(2), 1, @@ -8338,22 +8332,20 @@ fn test_rewards_do_not_auto_compound_on_payment_if_delegation_scheduled_revoke_e assert_events_eq!( Event::Rewarded { account: 1, - rewards: 9, + rewards: 4, }, - // no compound since revoke request exists Event::Rewarded { account: 2, - rewards: 8, + rewards: 4, }, - // 50% Event::Rewarded { account: 3, - rewards: 8, + rewards: 4, }, Event::Compounded { candidate: 1, delegator: 3, - amount: 4, + amount: 2, }, ); }); @@ -8367,7 +8359,7 @@ fn test_rewards_auto_compound_on_payment_as_per_auto_compound_config() { .with_delegations(vec![(2, 1, 200), (3, 1, 200), (4, 1, 200), (5, 1, 200)]) .build() .execute_with(|| { - (2..=6).for_each(|round| set_author(round, 1, 1)); + (2..=6).for_each(|round| set_author(round, 1, 100)); assert_ok!(ParachainStaking::set_auto_compound( RuntimeOrigin::signed(2), 1, @@ -8409,37 +8401,33 @@ fn test_rewards_auto_compound_on_payment_as_per_auto_compound_config() { assert_events_eq!( Event::Rewarded { account: 1, - rewards: 13, + rewards: 6, }, - // 0% Event::Rewarded { account: 2, - rewards: 8, + rewards: 4, }, - // 50% Event::Rewarded { account: 3, - rewards: 8, + rewards: 4, }, Event::Compounded { candidate: 1, delegator: 3, - amount: 4, + amount: 2, }, - // 100% Event::Rewarded { account: 4, - rewards: 8, + rewards: 4, }, Event::Compounded { candidate: 1, delegator: 4, - amount: 8, + amount: 4, }, - // no-config Event::Rewarded { account: 5, - rewards: 8, + rewards: 4, }, ); }); @@ -8961,7 +8949,7 @@ fn test_on_initialize_weights() { assert_eq!(Weight::from_parts(277168000, 0), weight); // roll to the end of the round, then run on_init again, we should see round change... - set_author(3, 1, 100); // must set some points for prepare_staking_payouts + set_author(3, 1, POINTS_PER_ROUND); // must set some points for prepare_staking_payouts roll_to_round_end(3); let block = System::block_number() + 1; let weight = ParachainStaking::on_initialize(block);