@@ -30,8 +30,9 @@ use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{
3030 NodeData ,
3131 PathToBottom ,
3232} ;
33+ use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: Leaf ;
3334use starknet_patricia:: patricia_merkle_tree:: types:: SubTreeHeight ;
34- use starknet_patricia_storage:: db_object:: { DBObject , EmptyKeyContext } ;
35+ use starknet_patricia_storage:: db_object:: { DBObject , EmptyKeyContext , HasStaticPrefix } ;
3536use starknet_patricia_storage:: errors:: { DeserializationError , SerializationError } ;
3637use starknet_patricia_storage:: map_storage:: MapStorage ;
3738use starknet_patricia_storage:: storage_trait:: { DbKey , DbValue , Storage } ;
@@ -445,17 +446,17 @@ pub(crate) fn test_node_db_key() -> String {
445446 data : NodeData :: Binary ( BinaryData { left_data : hash, right_data : hash } ) ,
446447 hash,
447448 } ;
448- let binary_node_key = binary_node . db_key ( & dummy_contract_address) . 0 ;
449+ let binary_node_key = db_key ( & binary_node , & dummy_contract_address) . 0 ;
449450
450451 let edge_node: FactDbFilledNode < StarknetStorageValue > = FactDbFilledNode {
451452 data : NodeData :: Edge ( EdgeData { bottom_data : hash, path_to_bottom : Default :: default ( ) } ) ,
452453 hash,
453454 } ;
454455
455- let edge_node_key = edge_node . db_key ( & dummy_contract_address) . 0 ;
456+ let edge_node_key = db_key ( & edge_node , & dummy_contract_address) . 0 ;
456457
457458 let storage_leaf = FactDbFilledNode { data : NodeData :: Leaf ( StarknetStorageValue ( zero) ) , hash } ;
458- let storage_leaf_key = storage_leaf . db_key ( & dummy_contract_address) . 0 ;
459+ let storage_leaf_key = db_key ( & storage_leaf , & dummy_contract_address) . 0 ;
459460
460461 let state_tree_leaf = FactDbFilledNode {
461462 data : NodeData :: Leaf ( ContractState {
@@ -465,11 +466,11 @@ pub(crate) fn test_node_db_key() -> String {
465466 } ) ,
466467 hash,
467468 } ;
468- let state_tree_leaf_key = state_tree_leaf . db_key ( & EmptyKeyContext ) . 0 ;
469+ let state_tree_leaf_key = db_key ( & state_tree_leaf , & EmptyKeyContext ) . 0 ;
469470
470471 let compiled_class_leaf =
471472 FactDbFilledNode { data : NodeData :: Leaf ( CompiledClassHash ( zero) ) , hash } ;
472- let compiled_class_leaf_key = compiled_class_leaf . db_key ( & EmptyKeyContext ) . 0 ;
473+ let compiled_class_leaf_key = db_key ( & compiled_class_leaf , & EmptyKeyContext ) . 0 ;
473474
474475 // Store keys in a HashMap.
475476 let mut map: HashMap < String , Vec < u8 > > = HashMap :: new ( ) ;
@@ -544,7 +545,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
544545 // Store the binary node in the storage.
545546 rust_fact_storage
546547 . set (
547- binary_rust . db_key ( & dummy_contract_address) ,
548+ db_key ( & binary_rust , & dummy_contract_address) ,
548549 binary_rust. serialize ( ) . map_err ( |error| {
549550 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
550551 } ) ?,
@@ -578,7 +579,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
578579 // Store the edge node in the storage.
579580 rust_fact_storage
580581 . set (
581- edge_rust . db_key ( & dummy_contract_address) ,
582+ db_key ( & edge_rust , & dummy_contract_address) ,
582583 edge_rust. serialize ( ) . map_err ( |error| {
583584 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
584585 } ) ?,
@@ -601,7 +602,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
601602 // Store the storage leaf node in the storage.
602603 rust_fact_storage
603604 . set (
604- storage_leaf_rust . db_key ( & dummy_contract_address) ,
605+ db_key ( & storage_leaf_rust , & dummy_contract_address) ,
605606 storage_leaf_rust. serialize ( ) . map_err ( |error| {
606607 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
607608 } ) ?,
@@ -633,7 +634,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
633634 // Store the contract state leaf node in the storage.
634635 rust_fact_storage
635636 . set (
636- contract_state_leaf_rust . db_key ( & EmptyKeyContext ) ,
637+ db_key ( & contract_state_leaf_rust , & EmptyKeyContext ) ,
637638 contract_state_leaf_rust. serialize ( ) . map_err ( |error| {
638639 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
639640 } ) ?,
@@ -657,7 +658,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
657658 // Store the compiled class leaf node in the storage.
658659 rust_fact_storage
659660 . set (
660- compiled_class_leaf_rust . db_key ( & EmptyKeyContext ) ,
661+ db_key ( & compiled_class_leaf_rust , & EmptyKeyContext ) ,
661662 compiled_class_leaf_rust. serialize ( ) . map_err ( |error| {
662663 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
663664 } ) ?,
@@ -677,3 +678,11 @@ pub(crate) async fn filled_forest_output_test() -> CommitterPythonTestResult {
677678 let output_string = serde_json:: to_string ( & output) . expect ( "Failed to serialize" ) ;
678679 Ok ( output_string)
679680}
681+
682+ pub fn db_key < L : Leaf > (
683+ node : & FactDbFilledNode < L > ,
684+ key_context : & <L as HasStaticPrefix >:: KeyContext ,
685+ ) -> DbKey {
686+ let suffix = node. hash . 0 . to_bytes_be ( ) ;
687+ node. get_db_key ( key_context, & suffix)
688+ }
0 commit comments