//! Mock verifying application for Marshaled wrapper tests. //! //! This module provides a generic mock application that implements both //! `Application` and `VerifyingApplication` traits, suitable for testing //! the `Marshaled` wrapper in both standard and coding variants. use crate::{ marshal::ancestry::{AncestorStream, BlockProvider}, CertifiableBlock, Epochable, }; use commonware_runtime::deterministic; /// A mock application that implements `VerifyingApplication` for testing. /// /// This mock: /// - Returns the provided genesis block from `genesis()` /// - Returns `None` from `propose()` (never proposes) /// - Returns a configurable result from `verify()` #[derive(Clone)] pub struct MockVerifyingApp { /// The genesis block to return. pub genesis: B, /// The result returned by `verify`. pub verify_result: bool, _phantom: std::marker::PhantomData, } impl MockVerifyingApp { /// Create a new mock verifying application with the given genesis block. pub fn new(genesis: B) -> Self { Self { genesis, verify_result: true, _phantom: std::marker::PhantomData, } } /// Create a new mock verifying application with a fixed verify result. pub fn with_verify_result(genesis: B, verify_result: bool) -> Self { Self { genesis, verify_result, _phantom: std::marker::PhantomData, } } } impl crate::Application for MockVerifyingApp 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>( &mut self, _context: (deterministic::Context, Self::Context), _ancestry: AncestorStream, ) -> Option { None } } impl crate::VerifyingApplication for MockVerifyingApp 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>( &mut self, _context: (deterministic::Context, Self::Context), _ancestry: AncestorStream, ) -> bool { self.verify_result } }