use futures::FutureExt;
use polkadot_node_subsystem::{
messages::ProspectiveParachainsMessage, overseer, SpawnedSubsystem, SubsystemError,
};
use polkadot_node_subsystem_types::OverseerSignal;
use polkadot_primitives::Hash;
pub struct MockProspectiveParachains {}
impl MockProspectiveParachains {
pub fn new() -> Self {
Self {}
}
}
#[overseer::subsystem(ProspectiveParachains, error=SubsystemError, prefix=self::overseer)]
impl<Context> MockProspectiveParachains {
fn start(self, ctx: Context) -> SpawnedSubsystem {
let future = self.run(ctx).map(|_| Ok(())).boxed();
SpawnedSubsystem { name: "test-environment", future }
}
}
#[overseer::contextbounds(ProspectiveParachains, prefix = self::overseer)]
impl MockProspectiveParachains {
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 {
ProspectiveParachainsMessage::GetMinimumRelayParents(_relay_parent, tx) => {
tx.send(vec![]).unwrap();
},
ProspectiveParachainsMessage::GetHypotheticalMembership(req, tx) => {
tx.send(
req.candidates
.iter()
.cloned()
.map(|candidate| (candidate, vec![Hash::repeat_byte(0)]))
.collect(),
)
.unwrap();
},
_ => {
unimplemented!("Unexpected chain-api message")
},
},
}
}
}
}