polkadot_subsystem_bench/mock/
prospective_parachains.rs1use futures::FutureExt;
20use polkadot_node_subsystem::{
21 messages::ProspectiveParachainsMessage, overseer, SpawnedSubsystem, SubsystemError,
22};
23use polkadot_node_subsystem_types::OverseerSignal;
24use polkadot_primitives::Hash;
25
26pub struct MockProspectiveParachains {}
27
28impl MockProspectiveParachains {
29 pub fn new() -> Self {
30 Self {}
31 }
32}
33
34#[overseer::subsystem(ProspectiveParachains, error=SubsystemError, prefix=self::overseer)]
35impl<Context> MockProspectiveParachains {
36 fn start(self, ctx: Context) -> SpawnedSubsystem {
37 let future = self.run(ctx).map(|_| Ok(())).boxed();
38
39 SpawnedSubsystem { name: "test-environment", future }
40 }
41}
42
43#[overseer::contextbounds(ProspectiveParachains, prefix = self::overseer)]
44impl MockProspectiveParachains {
45 async fn run<Context>(self, mut ctx: Context) {
46 loop {
47 let msg = ctx.recv().await.expect("Overseer never fails us");
48 match msg {
49 orchestra::FromOrchestra::Signal(signal) =>
50 if signal == OverseerSignal::Conclude {
51 return
52 },
53 orchestra::FromOrchestra::Communication { msg } => match msg {
54 ProspectiveParachainsMessage::GetMinimumRelayParents(_relay_parent, tx) => {
55 tx.send(vec![]).unwrap();
56 },
57 ProspectiveParachainsMessage::GetHypotheticalMembership(req, tx) => {
58 tx.send(
59 req.candidates
60 .iter()
61 .cloned()
62 .map(|candidate| (candidate, vec![Hash::repeat_byte(0)]))
63 .collect(),
64 )
65 .unwrap();
66 },
67 _ => {
68 unimplemented!("Unexpected chain-api message")
69 },
70 },
71 }
72 }
73 }
74}