Skip to content

Commit 1ea944f

Browse files
committed
test(red): key change of sitting committee member
1 parent ab11033 commit 1ea944f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

toolkit/committee-selection/pallet/src/pallet_session_support.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ mod tests {
167167
use pallet_session::ShouldEndSession;
168168
pub const IRRELEVANT: u64 = 2;
169169
use sidechain_domain::ScEpochNumber;
170+
use sp_runtime::testing::UintAuthorityId;
170171

171172
type Manager = crate::Pallet<Test>;
172173

@@ -209,6 +210,40 @@ mod tests {
209210
});
210211
}
211212

213+
#[test]
214+
fn reregister_changed_session_keys_for_sitting_authority() {
215+
new_test_ext().execute_with(|| {
216+
set_validators_directly(&[dave(), eve()], 1).unwrap();
217+
// By default, the session keys are not set for the account.
218+
assert_eq!(Session::load_keys(&dave().account_id()), None);
219+
assert_eq!(Session::load_keys(&eve().account_id()), None);
220+
increment_epoch();
221+
222+
start_session(1);
223+
224+
// After setting the keys, they should be stored in the session.
225+
assert_eq!(Session::load_keys(&dave().account_id()), Some(dave().authority_keys));
226+
assert_eq!(Session::load_keys(&eve().account_id()), Some(eve().authority_keys));
227+
228+
let eve_with_different_keys = MockValidator {
229+
name: "Eve with different keys",
230+
authority_keys: SessionKeys { foo: UintAuthorityId(44) },
231+
..eve()
232+
};
233+
234+
// Eve is re-elected to the committee, but is using different keys now
235+
set_validators_directly(&[dave(), eve_with_different_keys.clone()], 2).unwrap();
236+
increment_epoch();
237+
start_session(2);
238+
239+
// Eve's keys were updated
240+
assert_eq!(
241+
Session::load_keys(&eve().account_id()),
242+
Some(eve_with_different_keys.authority_keys)
243+
);
244+
});
245+
}
246+
212247
#[test]
213248
fn ends_two_sessions_and_rotates_once_when_committee_changes() {
214249
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)