@@ -33,6 +33,7 @@ use apollo_state_sync_types::communication::MockStateSyncClient;
3333use apollo_time:: time:: { Clock , DefaultClock } ;
3434use futures:: channel:: mpsc;
3535use futures:: executor:: block_on;
36+ use mockall:: Sequence ;
3637use starknet_api:: block:: {
3738 BlockNumber ,
3839 GasPrice ,
@@ -140,67 +141,81 @@ impl TestDeps {
140141 . withf ( move |input| input. height == block_number)
141142 . return_const ( Ok ( ( ) ) ) ;
142143 let proposal_id_clone = Arc :: clone ( & proposal_id) ;
143- self . batcher . expect_get_proposal_content ( ) . times ( number_of_times) . returning ( move |input| {
144- assert_eq ! ( input. proposal_id, * proposal_id_clone. get( ) . unwrap( ) ) ;
145- Ok ( GetProposalContentResponse {
146- content : GetProposalContent :: Txs ( INTERNAL_TX_BATCH . clone ( ) ) ,
147- } )
148- } ) ;
144+ self . batcher
145+ . expect_get_proposal_content ( )
146+ . times ( number_of_times)
147+ . withf ( move |input| input. proposal_id == * proposal_id_clone. get ( ) . unwrap ( ) )
148+ . returning ( move |_input| {
149+ Ok ( GetProposalContentResponse {
150+ content : GetProposalContent :: Txs ( INTERNAL_TX_BATCH . clone ( ) ) ,
151+ } )
152+ } ) ;
149153 let proposal_id_clone = Arc :: clone ( & proposal_id) ;
150- self . batcher . expect_get_proposal_content ( ) . times ( number_of_times) . returning ( move |input| {
151- assert_eq ! ( input. proposal_id, * proposal_id_clone. get( ) . unwrap( ) ) ;
152- Ok ( GetProposalContentResponse {
153- content : GetProposalContent :: Finished {
154- id : ProposalCommitment { state_diff_commitment : STATE_DIFF_COMMITMENT } ,
155- final_n_executed_txs,
156- } ,
157- } )
158- } ) ;
154+ self . batcher
155+ . expect_get_proposal_content ( )
156+ . times ( number_of_times)
157+ . withf ( move |input| input. proposal_id == * proposal_id_clone. get ( ) . unwrap ( ) )
158+ . returning ( move |_input| {
159+ Ok ( GetProposalContentResponse {
160+ content : GetProposalContent :: Finished {
161+ id : ProposalCommitment { state_diff_commitment : STATE_DIFF_COMMITMENT } ,
162+ final_n_executed_txs,
163+ } ,
164+ } )
165+ } ) ;
159166 }
160167
161168 pub ( crate ) fn setup_deps_for_validate (
162169 & mut self ,
163- block_number : BlockNumber ,
170+ mut block_number : BlockNumber ,
164171 final_n_executed_txs : usize ,
165172 number_of_times : usize ,
166173 ) {
167174 assert ! ( final_n_executed_txs <= INTERNAL_TX_BATCH . len( ) ) ;
168175 self . setup_default_expectations ( ) ;
169- let proposal_id = Arc :: new ( OnceLock :: new ( ) ) ;
170- let proposal_id_clone = Arc :: clone ( & proposal_id) ;
171- self . batcher . expect_validate_block ( ) . times ( number_of_times) . returning (
172- move |input : ValidateBlockInput | {
173- proposal_id_clone. set ( input. proposal_id ) . unwrap ( ) ;
174- Ok ( ( ) )
175- } ,
176- ) ;
177- self . batcher
178- . expect_start_height ( )
179- . withf ( move |input| input. height == block_number)
180- . return_const ( Ok ( ( ) ) ) ;
181- let proposal_id_clone = Arc :: clone ( & proposal_id) ;
182- self . batcher . expect_send_proposal_content ( ) . times ( number_of_times) . returning (
183- move |input : SendProposalContentInput | {
184- assert_eq ! ( input. proposal_id, * proposal_id_clone. get( ) . unwrap( ) ) ;
185- let SendProposalContent :: Txs ( txs) = input. content else {
186- panic ! ( "Expected SendProposalContent::Txs, got {:?}" , input. content) ;
187- } ;
188- assert_eq ! ( txs, * INTERNAL_TX_BATCH ) ;
189- Ok ( SendProposalContentResponse { response : ProposalStatus :: Processing } )
190- } ,
191- ) ;
192- let proposal_id_clone = Arc :: clone ( & proposal_id) ;
193- self . batcher . expect_send_proposal_content ( ) . times ( number_of_times) . returning (
194- move |input : SendProposalContentInput | {
195- assert_eq ! ( input. proposal_id, * proposal_id_clone. get( ) . unwrap( ) ) ;
196- assert_eq ! ( input. content, SendProposalContent :: Finish ( final_n_executed_txs) ) ;
197- Ok ( SendProposalContentResponse {
198- response : ProposalStatus :: Finished ( ProposalCommitment {
199- state_diff_commitment : STATE_DIFF_COMMITMENT ,
200- } ) ,
201- } )
202- } ,
203- ) ;
176+ let mut seq = Sequence :: new ( ) ;
177+ for _ in 0 ..number_of_times {
178+ let proposal_id = Arc :: new ( OnceLock :: new ( ) ) ;
179+ let proposal_id_clone = Arc :: clone ( & proposal_id) ;
180+ self . batcher . expect_validate_block ( ) . times ( 1 ) . in_sequence ( & mut seq) . returning (
181+ move |input : ValidateBlockInput | {
182+ proposal_id_clone. set ( input. proposal_id ) . unwrap ( ) ;
183+ Ok ( ( ) )
184+ } ,
185+ ) ;
186+ self . batcher
187+ . expect_start_height ( )
188+ . withf ( move |input| input. height == block_number)
189+ . return_const ( Ok ( ( ) ) ) ;
190+ let proposal_id_clone = Arc :: clone ( & proposal_id) ;
191+ self . batcher
192+ . expect_send_proposal_content ( )
193+ . times ( 1 )
194+ . in_sequence ( & mut seq)
195+ . withf ( move |input| input. proposal_id == * proposal_id_clone. get ( ) . unwrap ( ) )
196+ . returning ( move |input : SendProposalContentInput | {
197+ let SendProposalContent :: Txs ( txs) = input. content else {
198+ panic ! ( "Expected SendProposalContent::Txs, got {:?}" , input. content) ;
199+ } ;
200+ assert_eq ! ( txs, INTERNAL_TX_BATCH . clone( ) ) ;
201+ Ok ( SendProposalContentResponse { response : ProposalStatus :: Processing } )
202+ } ) ;
203+ let proposal_id_clone = Arc :: clone ( & proposal_id) ;
204+ self . batcher
205+ . expect_send_proposal_content ( )
206+ . times ( 1 )
207+ . in_sequence ( & mut seq)
208+ . withf ( move |input| input. proposal_id == * proposal_id_clone. get ( ) . unwrap ( ) )
209+ . returning ( move |input : SendProposalContentInput | {
210+ assert_eq ! ( input. content, SendProposalContent :: Finish ( final_n_executed_txs) ) ;
211+ Ok ( SendProposalContentResponse {
212+ response : ProposalStatus :: Finished ( ProposalCommitment {
213+ state_diff_commitment : STATE_DIFF_COMMITMENT ,
214+ } ) ,
215+ } )
216+ } ) ;
217+ block_number = block_number. unchecked_next ( ) ;
218+ }
204219 }
205220
206221 pub ( crate ) fn setup_default_transaction_converter ( & mut self ) {
0 commit comments