mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
min collator check (#498)
* min collator check * change statemint/mine min candidates * Ci pass * Update pallets/collator-selection/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update pallets/collator-selection/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Apply suggestions from code review * build fixes * add error messages to errors * added validator register check Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -106,6 +106,21 @@ fn cannot_register_candidate_if_too_many() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_unregister_candidate_if_too_few() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// reset desired candidates:
|
||||
<crate::DesiredCandidates<Test>>::put(1);
|
||||
assert_ok!(CollatorSelection::register_as_candidate(Origin::signed(4)));
|
||||
|
||||
// can not remove too few
|
||||
assert_noop!(
|
||||
CollatorSelection::leave_intent(Origin::signed(4)),
|
||||
Error::<Test>::TooFewCandidates,
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_register_as_candidate_if_invulnerable() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -119,6 +134,17 @@ fn cannot_register_as_candidate_if_invulnerable() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_register_as_candidate_if_keys_not_registered() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// can't 7 because keys not registered.
|
||||
assert_noop!(
|
||||
CollatorSelection::register_as_candidate(Origin::signed(7)),
|
||||
Error::<Test>::ValidatorNotRegistered
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_register_dupe_candidate() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -184,6 +210,10 @@ fn leave_intent() {
|
||||
assert_ok!(CollatorSelection::register_as_candidate(Origin::signed(3)));
|
||||
assert_eq!(Balances::free_balance(3), 90);
|
||||
|
||||
// register too so can leave above min candidates
|
||||
assert_ok!(CollatorSelection::register_as_candidate(Origin::signed(5)));
|
||||
assert_eq!(Balances::free_balance(5), 90);
|
||||
|
||||
// cannot leave if not candidate.
|
||||
assert_noop!(
|
||||
CollatorSelection::leave_intent(Origin::signed(4)),
|
||||
@@ -318,6 +348,34 @@ fn kick_mechanism() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_kick_mechanism_too_few() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// add a new collator
|
||||
assert_ok!(CollatorSelection::register_as_candidate(Origin::signed(3)));
|
||||
assert_ok!(CollatorSelection::register_as_candidate(Origin::signed(5)));
|
||||
initialize_to_block(10);
|
||||
assert_eq!(CollatorSelection::candidates().len(), 2);
|
||||
initialize_to_block(20);
|
||||
assert_eq!(SessionChangeBlock::get(), 20);
|
||||
// 4 authored this block, 5 gets to stay too few 3 was kicked
|
||||
assert_eq!(CollatorSelection::candidates().len(), 1);
|
||||
// 3 will be kicked after 1 session delay
|
||||
assert_eq!(SessionHandlerCollators::get(), vec![1, 2, 3, 5]);
|
||||
let collator = CandidateInfo {
|
||||
who: 5,
|
||||
deposit: 10,
|
||||
};
|
||||
assert_eq!(CollatorSelection::candidates(), vec![collator]);
|
||||
assert_eq!(CollatorSelection::last_authored_block(4), 20);
|
||||
initialize_to_block(30);
|
||||
// 3 gets kicked after 1 session delay
|
||||
assert_eq!(SessionHandlerCollators::get(), vec![1, 2, 5]);
|
||||
// kicked collator gets funds back
|
||||
assert_eq!(Balances::free_balance(3), 100);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[should_panic = "duplicate invulnerables in genesis."]
|
||||
|
||||
Reference in New Issue
Block a user