Do cargo fmt for the incoming codes and fix some details
@@ -543,9 +543,9 @@ pub mod pallet {
Ok(())
}
- /// manually assign rewards to pools by root for fixing issue 763
+ /// Manually assign rewards to pools by miningSwitchOrigin for fixing issue 763
///
- ///Reuires:
+ /// Requires:
/// 1. The caller is root
/// 2. assigned pool must currently exist
/// 3. reeward is positive
@@ -554,11 +554,11 @@ pub mod pallet {
origin: OriginFor<T>,
reward_arr: Vec<(u64, BalanceOf<T>)>,
) -> DispatchResult {
- // origin must be root
+ // Origin must be MiningSwitchOrigin
T::MiningSwitchOrigin::ensure_origin(origin)?;
- for pair in reward_arr {
- let (pid, reward) = pair;
- //assigned pool must exist
+
+ for (pid, reward) in reward_arr {
+ //The assigned pool must exist
let mut pool_info = Self::ensure_pool(pid)?;
//reward must be positive
if reward <= Zero::zero() {
@@ -567,11 +567,11 @@ pub mod pallet {
//assign reward
Self::handle_pool_new_reward(&mut pool_info, reward);
StakePools::<T>::insert(&pid, &pool_info);
+
}
Ok(())
}
-
/// Claims all the pending rewards of the sender and send to the `target`
///
/// Requires:
@@ -2324,6 +2324,41 @@ pub mod pallet {
});
}
+ #[test]
+ fn test_force_assign_reward() {
+ use crate::mining::pallet::OnReward;
+ new_test_ext().execute_with(|| {
+ set_block_1();
+ setup_workers(1);
+ setup_pool_with_workers(1, &[1]); // pid = 0
+
+ // Check stake before receiving any rewards
+ assert_ok!(PhalaStakePool::contribute(
+ Origin::signed(1),
+ 0,
+ 100 * DOLLARS
+ ));
+ assert_ok!(PhalaStakePool::contribute(
+ Origin::signed(2),
+ 0,
+ 400 * DOLLARS
+ ));
+ assert_ok!(PhalaStakePool::set_payout_pref(
+ Origin::signed(1),
+ 0,
+ Permill::from_percent(50)
+ ));
+ let pool = PhalaStakePool::stake_pools(0).unwrap();
+ assert_eq!(pool.reward_acc.get(), fp!(0));
+ assert_eq!(pool.owner_reward, fp!(0));
+ let input = vec![(0, 500 * DOLLARS)];
+ PhalaStakePool::force_assign_reward(Origin::root(), input);
+ let pool = PhalaStakePool::stake_pools(0).unwrap();
+ assert_eq!(pool.reward_acc.get(), fp!(0.5));
+ assert_eq!(pool.owner_reward, 250 * DOLLARS);
+ });
+ }
+
#[test]
fn test_reward_management() {
use crate::mining::pallet::OnReward;
