use crate::{
marshal::ancestry::{AncestorStream, BlockProvider},
CertifiableBlock, Epochable,
};
use commonware_runtime::deterministic;
#[derive(Clone)]
pub struct MockVerifyingApp<B, S> {
pub genesis: B,
pub verify_result: bool,
_phantom: std::marker::PhantomData<S>,
}
impl<B, S> MockVerifyingApp<B, S> {
pub fn new(genesis: B) -> Self {
Self {
genesis,
verify_result: true,
_phantom: std::marker::PhantomData,
}
}
pub fn with_verify_result(genesis: B, verify_result: bool) -> Self {
Self {
genesis,
verify_result,
_phantom: std::marker::PhantomData,
}
}
}
impl<B, S> crate::Application<deterministic::Context> for MockVerifyingApp<B, S>
where
B: CertifiableBlock + Clone + Send + Sync + 'static,
B::Context: Epochable + Clone + Send + Sync + 'static,
S: commonware_cryptography::certificate::Scheme + Clone + Send + Sync + 'static,
{
type Block = B;
type Context = B::Context;
type SigningScheme = S;
async fn genesis(&mut self) -> Self::Block {
self.genesis.clone()
}
async fn propose<A: BlockProvider<Block = Self::Block>>(
&mut self,
_context: (deterministic::Context, Self::Context),
_ancestry: AncestorStream<A, Self::Block>,
) -> Option<Self::Block> {
None
}
}
impl<B, S> crate::VerifyingApplication<deterministic::Context> for MockVerifyingApp<B, S>
where
B: CertifiableBlock + Clone + Send + Sync + 'static,
B::Context: Epochable + Clone + Send + Sync + 'static,
S: commonware_cryptography::certificate::Scheme + Clone + Send + Sync + 'static,
{
async fn verify<A: BlockProvider<Block = Self::Block>>(
&mut self,
_context: (deterministic::Context, Self::Context),
_ancestry: AncestorStream<A, Self::Block>,
) -> bool {
self.verify_result
}
}