use futures::FutureExt;
use polkadot_node_primitives::ValidationResult;
use polkadot_node_subsystem::{
messages::CandidateValidationMessage, overseer, SpawnedSubsystem, SubsystemError,
};
use polkadot_node_subsystem_types::OverseerSignal;
use polkadot_primitives::{CandidateCommitments, Hash, HeadData, PersistedValidationData};
pub struct MockCandidateValidation {}
impl MockCandidateValidation {
pub fn new() -> Self {
Self {}
}
}
#[overseer::subsystem(CandidateValidation, error=SubsystemError, prefix=self::overseer)]
impl<Context> MockCandidateValidation {
fn start(self, ctx: Context) -> SpawnedSubsystem {
let future = self.run(ctx).map(|_| Ok(())).boxed();
SpawnedSubsystem { name: "test-environment", future }
}
}
#[overseer::contextbounds(CandidateValidation, prefix = self::overseer)]
impl MockCandidateValidation {
async fn run<Context>(self, mut ctx: Context) {
loop {
let msg = ctx.recv().await.expect("Overseer never fails us");
match msg {
orchestra::FromOrchestra::Signal(signal) =>
if signal == OverseerSignal::Conclude {
return
},
orchestra::FromOrchestra::Communication { msg } => match msg {
CandidateValidationMessage::ValidateFromExhaustive {
response_sender, ..
} => response_sender
.send(Ok(ValidationResult::Valid(
CandidateCommitments::default(),
PersistedValidationData {
parent_head: HeadData(Vec::new()),
relay_parent_number: 0,
relay_parent_storage_root: Hash::default(),
max_pov_size: 2,
},
)))
.unwrap(),
_ => unimplemented!("Unexpected chain-api message"),
},
}
}
}
}