use std::{collections::HashMap, marker::PhantomData, sync::Arc};
use hotshot::{
traits::{NodeImplementation, TestableNodeImplementation},
MarketplaceConfig,
};
use hotshot_example_types::storage_types::TestStorage;
use hotshot_types::{
traits::{
network::{AsyncGenerator, ConnectedNetwork},
node_implementation::{NodeType, Versions},
},
HotShotConfig, ValidatorConfig,
};
use super::{test_builder::TestDescription, test_runner::TestRunner};
use crate::test_task::TestTaskStateSeed;
pub type Network<TYPES, I> = Arc<<I as NodeImplementation<TYPES>>::Network>;
pub type Generator<T> = Box<dyn Fn(u64) -> T + 'static>;
pub struct ResourceGenerators<TYPES: NodeType, I: TestableNodeImplementation<TYPES>> {
pub channel_generator: AsyncGenerator<Network<TYPES, I>>,
pub storage: Generator<TestStorage<TYPES>>,
pub config: HotShotConfig<TYPES::SignatureKey>,
pub validator_config: ValidatorConfig<TYPES::SignatureKey>,
pub marketplace_config: Generator<MarketplaceConfig<TYPES, I>>,
}
pub struct TestLauncher<TYPES: NodeType, I: TestableNodeImplementation<TYPES>, V: Versions> {
pub resource_generator: ResourceGenerators<TYPES, I>,
pub metadata: TestDescription<TYPES, I, V>,
pub additional_test_tasks: Vec<Box<dyn TestTaskStateSeed<TYPES, I, V>>>,
}
impl<TYPES: NodeType, I: TestableNodeImplementation<TYPES>, V: Versions> TestLauncher<TYPES, I, V> {
#[must_use]
pub fn launch<N: ConnectedNetwork<TYPES::SignatureKey>>(self) -> TestRunner<TYPES, I, V, N> {
TestRunner::<TYPES, I, V, N> {
launcher: self,
nodes: Vec::new(),
solver_server: None,
late_start: HashMap::new(),
next_node_id: 0,
_pd: PhantomData,
}
}
#[must_use]
pub fn modify_default_config(
mut self,
mut f: impl FnMut(&mut HotShotConfig<TYPES::SignatureKey>),
) -> Self {
f(&mut self.resource_generator.config);
self
}
}