Skip to content

Commit

Permalink
core-fellowship: allow infinite demotion period
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Dec 30, 2023
1 parent 8bf5a1c commit 767f19a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions substrate/frame/core-fellowship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ pub mod pallet {
let rank_index = Self::rank_to_index(rank).ok_or(Error::<T, I>::InvalidRank)?;
params.demotion_period[rank_index]
};

if demotion_period.is_zero() {
return Err(Error::<T, I>::NothingDoing.into())
}

let demotion_block = member.last_proof.saturating_add(demotion_period);

// Ensure enough time has passed.
Expand Down
22 changes: 22 additions & 0 deletions substrate/frame/core-fellowship/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ fn offboard_works() {
});
}

#[test]
fn infinite_demotion_works() {
new_test_ext().execute_with(|| {
let params = ParamsType {
active_salary: [10; 9],
passive_salary: [10; 9],
demotion_period: [0; 9],
min_promotion_period: [10; 9],
offboard_timeout: 0,
};
assert_ok!(CoreFellowship::set_params(signed(1), Box::new(params)));

set_rank(0, 0);
assert_ok!(CoreFellowship::import(signed(0)));
set_rank(1, 1);
assert_ok!(CoreFellowship::import(signed(1)));

assert_noop!(CoreFellowship::bump(signed(0), 0), Error::<Test>::NothingDoing);
assert_noop!(CoreFellowship::bump(signed(0), 1), Error::<Test>::NothingDoing);
});
}

#[test]
fn proof_postpones_auto_demote() {
new_test_ext().execute_with(|| {
Expand Down

0 comments on commit 767f19a

Please sign in to comment.