Provide simple TestSessionHandler that works with UintAuthorityId (#3962)

This commit is contained in:
Bastian Köcher
2019-10-29 21:20:09 +01:00
committed by GitHub
parent 9ec5ba46f3
commit 93c1e87a36
2 changed files with 15 additions and 2 deletions
-1
View File
@@ -898,7 +898,6 @@ pub mod key_types {
/// Key type for ImOnline module, built-in.
pub const IM_ONLINE: KeyTypeId = KeyTypeId(*b"imon");
/// A key type ID useful for tests.
#[cfg(feature = "std")]
pub const DUMMY: KeyTypeId = KeyTypeId(*b"dumy");
}
+15 -1
View File
@@ -259,7 +259,7 @@ pub trait OneSessionHandler<ValidatorId>: BoundToRuntimeAppPublic {
fn on_disabled(_validator_index: usize);
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
#[impl_trait_for_tuples::impl_for_tuples(1, 30)]
#[tuple_types_no_default_trait_bound]
impl<AId> SessionHandler<AId> for Tuple {
for_tuples!( where #( Tuple: OneSessionHandler<AId> )* );
@@ -307,6 +307,20 @@ impl<AId> SessionHandler<AId> for Tuple {
}
}
/// `SessionHandler` for tests that use `UintAuthorityId` as `Keys`.
pub struct TestSessionHandler;
impl<AId> SessionHandler<AId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[sr_primitives::key_types::DUMMY];
fn on_genesis_session<Ks: OpaqueKeys>(_: &[(AId, Ks)]) {}
fn on_new_session<Ks: OpaqueKeys>(_: bool, _: &[(AId, Ks)], _: &[(AId, Ks)]) {}
fn on_before_session_ending() {}
fn on_disabled(_: usize) {}
}
/// Handler for selecting the genesis validator set.
pub trait SelectInitialValidators<ValidatorId> {
/// Returns the initial validator set. If `None` is returned