33use alloy_primitives:: { Address , FixedBytes , U256 } ;
44use alloy_rpc_types_engine:: {
55 ExecutionPayloadEnvelopeV3 , ExecutionPayloadEnvelopeV4 , ExecutionPayloadV1 , ExecutionPayloadV2 ,
6- ExecutionPayloadV3 , ForkchoiceState , PayloadId , PayloadStatus , PayloadStatusEnum ,
6+ ExecutionPayloadV3 , ForkchoiceState , ForkchoiceUpdated , PayloadId , PayloadStatus ,
7+ PayloadStatusEnum ,
78} ;
89use commonware_consensus:: simplex:: scheme:: bls12381_multisig;
910use commonware_consensus:: simplex:: types:: { Finalization , Finalize , Proposal } ;
@@ -13,6 +14,8 @@ use commonware_cryptography::{Signer as _, ed25519};
1314use commonware_math:: algebra:: Random ;
1415use commonware_parallel:: Sequential ;
1516use commonware_utils:: ordered:: { BiMap , Map } ;
17+ use std:: collections:: VecDeque ;
18+ use std:: sync:: { Arc , Mutex } ;
1619use summit_types:: network_oracle:: NetworkOracle ;
1720use summit_types:: { Block , Digest , EngineClient , PublicKey } ;
1821
@@ -76,9 +79,52 @@ pub fn make_finalization(
7679 Finalization :: from_finalizes ( & schemes[ 0 ] , & finalizes, & Sequential ) . unwrap ( )
7780}
7881
79- /// Minimal mock EngineClient that accepts all blocks
82+ /// Minimal mock EngineClient that accepts all blocks.
83+ /// Supports queuing override responses for check_payload and commit_hash
84+ /// to simulate SYNCING behavior during tests.
8085#[ derive( Clone ) ]
81- pub struct MockEngineClient ;
86+ pub struct MockEngineClient {
87+ check_payload_overrides : Arc < Mutex < VecDeque < PayloadStatus > > > ,
88+ commit_hash_overrides : Arc < Mutex < VecDeque < ForkchoiceUpdated > > > ,
89+ }
90+
91+ impl MockEngineClient {
92+ pub fn new ( ) -> Self {
93+ Self {
94+ check_payload_overrides : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
95+ commit_hash_overrides : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
96+ }
97+ }
98+
99+ /// Queue SYNCING responses for check_payload. After these are consumed,
100+ /// check_payload falls back to returning VALID.
101+ #[ allow( unused) ]
102+ pub fn queue_check_payload_syncing ( & self , count : usize ) {
103+ let mut overrides = self . check_payload_overrides . lock ( ) . unwrap ( ) ;
104+ for _ in 0 ..count {
105+ overrides. push_back ( PayloadStatus :: new ( PayloadStatusEnum :: Syncing , None ) ) ;
106+ }
107+ }
108+
109+ /// Queue SYNCING responses for commit_hash. After these are consumed,
110+ /// commit_hash falls back to returning VALID.
111+ #[ allow( unused) ]
112+ pub fn queue_commit_hash_syncing ( & self , count : usize ) {
113+ let mut overrides = self . commit_hash_overrides . lock ( ) . unwrap ( ) ;
114+ for _ in 0 ..count {
115+ overrides. push_back ( ForkchoiceUpdated {
116+ payload_status : PayloadStatus :: new ( PayloadStatusEnum :: Syncing , None ) ,
117+ payload_id : None ,
118+ } ) ;
119+ }
120+ }
121+ }
122+
123+ impl Default for MockEngineClient {
124+ fn default ( ) -> Self {
125+ Self :: new ( )
126+ }
127+ }
82128
83129impl EngineClient for MockEngineClient {
84130 #[ allow( unused_variables) ]
@@ -129,13 +175,27 @@ impl EngineClient for MockEngineClient {
129175 }
130176
131177 async fn check_payload ( & mut self , _block : & Block ) -> PayloadStatus {
178+ if let Some ( override_status) = self . check_payload_overrides . lock ( ) . unwrap ( ) . pop_front ( ) {
179+ return override_status;
180+ }
132181 PayloadStatus {
133182 status : PayloadStatusEnum :: Valid ,
134183 latest_valid_hash : Some ( [ 0u8 ; 32 ] . into ( ) ) ,
135184 }
136185 }
137186
138- async fn commit_hash ( & mut self , _fork_choice_state : ForkchoiceState ) { }
187+ async fn commit_hash ( & mut self , _fork_choice_state : ForkchoiceState ) -> ForkchoiceUpdated {
188+ if let Some ( override_response) = self . commit_hash_overrides . lock ( ) . unwrap ( ) . pop_front ( ) {
189+ return override_response;
190+ }
191+ ForkchoiceUpdated {
192+ payload_status : PayloadStatus {
193+ status : PayloadStatusEnum :: Valid ,
194+ latest_valid_hash : Some ( [ 0u8 ; 32 ] . into ( ) ) ,
195+ } ,
196+ payload_id : None ,
197+ }
198+ }
139199}
140200
141201/// Minimal mock NetworkOracle
0 commit comments