@@ -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 } ;
@@ -426,6 +427,14 @@ fn xor_hash(x: &[u8], y: &[u8]) -> Vec<u8> {
426427 x. iter ( ) . zip ( y. iter ( ) ) . map ( |( a, b) | a ^ b) . collect ( )
427428}
428429
430+ fn db_key < L : Leaf > (
431+ node : & FactDbFilledNode < L > ,
432+ key_context : & <L as HasStaticPrefix >:: KeyContext ,
433+ ) -> DbKey {
434+ let suffix = node. hash . 0 . to_bytes_be ( ) ;
435+ node. get_db_key ( key_context, & suffix)
436+ }
437+
429438/// Creates and serializes storage keys for different node types.
430439///
431440/// This function generates and serializes storage keys for various node types, including binary
@@ -445,17 +454,17 @@ pub(crate) fn test_node_db_key() -> String {
445454 data : NodeData :: Binary ( BinaryData { left_data : hash, right_data : hash } ) ,
446455 hash,
447456 } ;
448- let binary_node_key = binary_node . db_key ( & dummy_contract_address) . 0 ;
457+ let binary_node_key = db_key ( & binary_node , & dummy_contract_address) . 0 ;
449458
450459 let edge_node: FactDbFilledNode < StarknetStorageValue > = FactDbFilledNode {
451460 data : NodeData :: Edge ( EdgeData { bottom_data : hash, path_to_bottom : Default :: default ( ) } ) ,
452461 hash,
453462 } ;
454463
455- let edge_node_key = edge_node . db_key ( & dummy_contract_address) . 0 ;
464+ let edge_node_key = db_key ( & edge_node , & dummy_contract_address) . 0 ;
456465
457466 let storage_leaf = FactDbFilledNode { data : NodeData :: Leaf ( StarknetStorageValue ( zero) ) , hash } ;
458- let storage_leaf_key = storage_leaf . db_key ( & dummy_contract_address) . 0 ;
467+ let storage_leaf_key = db_key ( & storage_leaf , & dummy_contract_address) . 0 ;
459468
460469 let state_tree_leaf = FactDbFilledNode {
461470 data : NodeData :: Leaf ( ContractState {
@@ -465,11 +474,11 @@ pub(crate) fn test_node_db_key() -> String {
465474 } ) ,
466475 hash,
467476 } ;
468- let state_tree_leaf_key = state_tree_leaf . db_key ( & EmptyKeyContext ) . 0 ;
477+ let state_tree_leaf_key = db_key ( & state_tree_leaf , & EmptyKeyContext ) . 0 ;
469478
470479 let compiled_class_leaf =
471480 FactDbFilledNode { data : NodeData :: Leaf ( CompiledClassHash ( zero) ) , hash } ;
472- let compiled_class_leaf_key = compiled_class_leaf . db_key ( & EmptyKeyContext ) . 0 ;
481+ let compiled_class_leaf_key = db_key ( & compiled_class_leaf , & EmptyKeyContext ) . 0 ;
473482
474483 // Store keys in a HashMap.
475484 let mut map: HashMap < String , Vec < u8 > > = HashMap :: new ( ) ;
@@ -544,7 +553,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
544553 // Store the binary node in the storage.
545554 rust_fact_storage
546555 . set (
547- binary_rust . db_key ( & dummy_contract_address) ,
556+ db_key ( & binary_rust , & dummy_contract_address) ,
548557 binary_rust. serialize ( ) . map_err ( |error| {
549558 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
550559 } ) ?,
@@ -578,7 +587,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
578587 // Store the edge node in the storage.
579588 rust_fact_storage
580589 . set (
581- edge_rust . db_key ( & dummy_contract_address) ,
590+ db_key ( & edge_rust , & dummy_contract_address) ,
582591 edge_rust. serialize ( ) . map_err ( |error| {
583592 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
584593 } ) ?,
@@ -601,7 +610,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
601610 // Store the storage leaf node in the storage.
602611 rust_fact_storage
603612 . set (
604- storage_leaf_rust . db_key ( & dummy_contract_address) ,
613+ db_key ( & storage_leaf_rust , & dummy_contract_address) ,
605614 storage_leaf_rust. serialize ( ) . map_err ( |error| {
606615 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
607616 } ) ?,
@@ -633,7 +642,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
633642 // Store the contract state leaf node in the storage.
634643 rust_fact_storage
635644 . set (
636- contract_state_leaf_rust . db_key ( & EmptyKeyContext ) ,
645+ db_key ( & contract_state_leaf_rust , & EmptyKeyContext ) ,
637646 contract_state_leaf_rust. serialize ( ) . map_err ( |error| {
638647 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
639648 } ) ?,
@@ -657,7 +666,7 @@ async fn test_storage_node(data: HashMap<String, String>) -> CommitterPythonTest
657666 // Store the compiled class leaf node in the storage.
658667 rust_fact_storage
659668 . set (
660- compiled_class_leaf_rust . db_key ( & EmptyKeyContext ) ,
669+ db_key ( & compiled_class_leaf_rust , & EmptyKeyContext ) ,
661670 compiled_class_leaf_rust. serialize ( ) . map_err ( |error| {
662671 PythonTestError :: SpecificError ( CommitterSpecificTestError :: Serialization ( error) )
663672 } ) ?,
0 commit comments