@@ -5,6 +5,7 @@ use apollo_committer_types::committer_types::{
55 AccessedKeys ,
66 CommitBlockRequest ,
77 ReadPathsAndCommitBlockRequest ,
8+ ReadPathsAndCommitBlockResponse ,
89 RevertBlockRequest ,
910} ;
1011use indexmap:: indexmap;
@@ -172,6 +173,36 @@ fn read_paths_and_commit_block_request(
172173 }
173174}
174175
176+ /// Commits block 0 with `setup_state_diff` via [`crate::committer::Committer::commit_block`]
177+ /// (no witnesses), then calls [`crate::committer::Committer::read_paths_and_commit_block`] at
178+ /// block 1 with `state_diff` and `accessed_keys`, and returns its response.
179+ async fn setup_and_read_paths (
180+ committer : & mut ApolloTestCommitter ,
181+ setup_state_diff : ThinStateDiff ,
182+ state_diff : ThinStateDiff ,
183+ accessed_keys : AccessedKeys ,
184+ ) -> ReadPathsAndCommitBlockResponse {
185+ committer
186+ . commit_block ( CommitBlockRequest {
187+ state_diff : setup_state_diff. clone ( ) ,
188+ state_diff_commitment : Some ( calculate_state_diff_hash ( & setup_state_diff) ) ,
189+ height : BlockNumber ( 0 ) ,
190+ } )
191+ . await
192+ . unwrap ( ) ;
193+
194+ let state_diff_commitment = Some ( calculate_state_diff_hash ( & state_diff) ) ;
195+ committer
196+ . read_paths_and_commit_block ( read_paths_and_commit_block_request (
197+ state_diff,
198+ state_diff_commitment,
199+ 1 ,
200+ accessed_keys,
201+ ) )
202+ . await
203+ . unwrap ( )
204+ }
205+
175206fn leaf_hashes < Key , PatriciaLeaf > (
176207 leaves : & HashMap < Key , PatriciaLeaf > ,
177208 key_into_node_index : impl Fn ( & Key ) -> NodeIndex ,
@@ -325,30 +356,17 @@ async fn read_paths_and_commit_block_happy_flow() {
325356#[ tokio:: test]
326357async fn revert_removes_witnesses_and_digest ( ) {
327358 let mut committer = new_test_committer ( ) . await ;
328- let height_0 = 0 ;
329359 let height_1 = 1 ;
330- let block_0_state_diff = BLOCK_0_STATE_DIFF . clone ( ) ;
331360 let block_1_state_diff = BLOCK_1_STATE_DIFF . clone ( ) ;
332361 let accessed_keys = ACCESSED_KEYS . clone ( ) ;
333362
334- committer
335- . commit_block ( CommitBlockRequest {
336- state_diff : block_0_state_diff. clone ( ) ,
337- state_diff_commitment : Some ( calculate_state_diff_hash ( & block_0_state_diff) ) ,
338- height : BlockNumber ( height_0) ,
339- } )
340- . await
341- . unwrap ( ) ;
342-
343- let block_1_response = committer
344- . read_paths_and_commit_block ( read_paths_and_commit_block_request (
345- block_1_state_diff. clone ( ) ,
346- Some ( calculate_state_diff_hash ( & block_1_state_diff) ) ,
347- height_1,
348- accessed_keys. clone ( ) ,
349- ) )
350- . await
351- . unwrap ( ) ;
363+ let block_1_response = setup_and_read_paths (
364+ & mut committer,
365+ BLOCK_0_STATE_DIFF . clone ( ) ,
366+ block_1_state_diff,
367+ accessed_keys. clone ( ) ,
368+ )
369+ . await ;
352370 assert_witnesses_and_digest_present (
353371 & mut committer,
354372 BlockNumber ( height_1) ,
@@ -394,9 +412,7 @@ async fn test_bottom_of_new_edge_to_an_unmoidifed_subtree_is_present() {
394412 let compiled_class_hash_d_felt = 102_u64 . into ( ) ;
395413
396414 let mut committer = new_test_committer ( ) . await ;
397- let height_0 = 0 ;
398- let height_1 = 1 ;
399- let block_0_state_diff = ThinStateDiff {
415+ let setup_state_diff = ThinStateDiff {
400416 class_hash_to_compiled_class_hash : indexmap ! {
401417 class_hash_a => CompiledClassHash ( compiled_class_hash_a_felt) ,
402418 class_hash_b => CompiledClassHash ( compiled_class_hash_b_felt) ,
@@ -415,24 +431,9 @@ async fn test_bottom_of_new_edge_to_an_unmoidifed_subtree_is_present() {
415431 ..Default :: default ( )
416432 } ;
417433
418- committer
419- . commit_block ( CommitBlockRequest {
420- state_diff : block_0_state_diff. clone ( ) ,
421- state_diff_commitment : Some ( calculate_state_diff_hash ( & block_0_state_diff) ) ,
422- height : BlockNumber ( height_0) ,
423- } )
424- . await
425- . unwrap ( ) ;
426-
427- let response = committer
428- . read_paths_and_commit_block ( read_paths_and_commit_block_request (
429- block_1_state_diff. clone ( ) ,
430- Some ( calculate_state_diff_hash ( & block_1_state_diff) ) ,
431- height_1,
432- accessed_keys,
433- ) )
434- . await
435- . unwrap ( ) ;
434+ let response =
435+ setup_and_read_paths ( & mut committer, setup_state_diff, block_1_state_diff, accessed_keys)
436+ . await ;
436437
437438 let leaf_a_hash = TreeHashFunctionImpl :: compute_leaf_hash ( & CommitterCompiledClassHash (
438439 compiled_class_hash_a_felt,
@@ -483,9 +484,7 @@ async fn test_bottom_of_new_edge_to_a_binary_unmodified_subtree_is_present() {
483484 let compiled_class_hash_d_felt = 102_u64 . into ( ) ;
484485
485486 let mut committer = new_test_committer ( ) . await ;
486- let height_0 = 0 ;
487- let height_1 = 1 ;
488- let block_0_state_diff = ThinStateDiff {
487+ let setup_state_diff = ThinStateDiff {
489488 class_hash_to_compiled_class_hash : indexmap ! {
490489 class_hash_a => CompiledClassHash ( compiled_class_hash_a_felt) ,
491490 class_hash_b => CompiledClassHash ( compiled_class_hash_b_felt) ,
@@ -504,24 +503,9 @@ async fn test_bottom_of_new_edge_to_a_binary_unmodified_subtree_is_present() {
504503 ..Default :: default ( )
505504 } ;
506505
507- committer
508- . commit_block ( CommitBlockRequest {
509- state_diff : block_0_state_diff. clone ( ) ,
510- state_diff_commitment : Some ( calculate_state_diff_hash ( & block_0_state_diff) ) ,
511- height : BlockNumber ( height_0) ,
512- } )
513- . await
514- . unwrap ( ) ;
515-
516- let response = committer
517- . read_paths_and_commit_block ( read_paths_and_commit_block_request (
518- block_1_state_diff. clone ( ) ,
519- Some ( calculate_state_diff_hash ( & block_1_state_diff) ) ,
520- height_1,
521- accessed_keys,
522- ) )
523- . await
524- . unwrap ( ) ;
506+ let response =
507+ setup_and_read_paths ( & mut committer, setup_state_diff, block_1_state_diff, accessed_keys)
508+ . await ;
525509
526510 let leaf_a_hash = TreeHashFunctionImpl :: compute_leaf_hash ( & CommitterCompiledClassHash (
527511 compiled_class_hash_a_felt,
0 commit comments