Skip to content

Commit

Permalink
add test for signer has not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 2, 2024
1 parent f96e25a commit b0c6016
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ pub mod pallet {
let signers_info = pallet_parameters::Pallet::<T>::signers_info();

// removes first signer and pushes new signer to back if total signers not increased
if current_signers.len() < signers_info.total_signers as usize {
if current_signers.len() >= signers_info.total_signers as usize {
current_signers.remove(0);
}
current_signers.push(next_signer_up.clone());
Expand Down
2 changes: 1 addition & 1 deletion pallets/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
pallet_parameters::GenesisConfig::<Test> {
request_limit: 5u32,
max_instructions_per_programs: 5u64,
total_signers: 5u8,
total_signers: 2u8,
threshold: 2u8,
_config: Default::default(),
}
Expand Down
10 changes: 10 additions & 0 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
use codec::Encode;
use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use pallet_parameters::SignersSize;
use pallet_session::SessionManager;
const NULL_ARR: [u8; 32] = [0; 32];

Expand Down Expand Up @@ -382,6 +383,15 @@ fn it_tests_new_session_handler() {
assert_ok!(Staking::new_session_handler(&[1]));
// does nothing as not enough validators
assert_eq!(Staking::next_signers().unwrap().next_signers, vec![6, 3]);

pallet_parameters::SignersInfo::<Test>::put(SignersSize {
total_signers: 3,
threshold: 2,
last_session_change: 0,
});
assert_ok!(Staking::new_session_handler(&[6, 5, 3, 4]));
// Signer size increased is reflected as 5 is not removed from vec
assert_eq!(Staking::next_signers().unwrap().next_signers, vec![5, 6, 3]);
});
}

Expand Down

0 comments on commit b0c6016

Please sign in to comment.