Skip to content

Commit

Permalink
refactor: create tree test
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware committed Jul 24, 2024
1 parent 3c86674 commit 365b798
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use super::OriginalSkeletonTreeImpl;
use crate::block_committer::input::StarknetStorageValue;
use crate::felt::Felt;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::filled_tree::node::{ClassHash, CompiledClassHash, Nonce};
use crate::patricia_merkle_tree::internal_test_utils::OriginalSkeletonMockTrieConfig;
use crate::patricia_merkle_tree::internal_test_utils::{small_tree_index_to_full, MockLeaf};
use crate::patricia_merkle_tree::node_data::inner_node::EdgePath;
use crate::patricia_merkle_tree::node_data::inner_node::{EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::leaf::{ContractState, LeafModifications};
use crate::patricia_merkle_tree::node_data::leaf::LeafModifications;
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::SubTree;
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTree;
Expand Down Expand Up @@ -422,26 +420,6 @@ pub(crate) fn create_mock_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
(leaf.get_db_key(&leaf.0.to_bytes_be()), leaf.serialize())
}

pub(crate) fn create_storage_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let leaf = StarknetStorageValue(Felt::from(val));
(leaf.get_db_key(&leaf.0.to_bytes_be()), leaf.serialize())
}

pub(crate) fn create_compiled_class_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let leaf = CompiledClassHash(Felt::from(val));
(leaf.get_db_key(&leaf.0.to_bytes_be()), leaf.serialize())
}

pub(crate) fn create_contract_state_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let felt = Felt::from(val);
let leaf = ContractState {
nonce: Nonce(felt),
storage_root_hash: HashOutput(felt),
class_hash: ClassHash(felt),
};
(leaf.get_db_key(&felt.to_bytes_be()), leaf.serialize())
}

fn create_patricia_key(val: u128) -> StorageKey {
create_db_key(
StarknetPrefix::InnerNode.to_storage_prefix(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ use crate::felt::Felt;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::filled_tree::node::{ClassHash, CompiledClassHash, Nonce};
use crate::patricia_merkle_tree::node_data::leaf::ContractState;
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::create_tree_test::create_root_edge_entry;
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::create_tree_test::{
create_32_bytes_entry, create_binary_entry, create_binary_skeleton_node, create_edge_entry,
create_edge_skeleton_node, create_expected_skeleton_nodes,
create_unmodified_subtree_skeleton_node,
};
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::create_tree_test::{
create_compiled_class_leaf_entry, create_contract_state_leaf_entry, create_root_edge_entry,
create_storage_leaf_entry,
};
use crate::patricia_merkle_tree::types::NodeIndex;
use crate::patricia_merkle_tree::types::SubTreeHeight;
use crate::patricia_merkle_tree::{
original_skeleton_tree::skeleton_forest::ForestSortedIndices,
original_skeleton_tree::tree::OriginalSkeletonTreeImpl, types::SortedLeafIndices,
};
use crate::storage::db_object::DBObject;
use crate::storage::map_storage::MapStorage;
use crate::storage::storage_trait::{StorageKey, StorageValue};

macro_rules! compare_skeleton_tree {
($actual_skeleton:expr, $expected_skeleton:expr, $expected_indices:expr) => {{
Expand All @@ -38,6 +37,26 @@ macro_rules! compare_skeleton_tree {
}};
}

pub(crate) fn create_storage_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let leaf = StarknetStorageValue(Felt::from(val));
(leaf.get_db_key(&leaf.0.to_bytes_be()), leaf.serialize())
}

pub(crate) fn create_compiled_class_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let leaf = CompiledClassHash(Felt::from(val));
(leaf.get_db_key(&leaf.0.to_bytes_be()), leaf.serialize())
}

pub(crate) fn create_contract_state_leaf_entry(val: u128) -> (StorageKey, StorageValue) {
let felt = Felt::from(val);
let leaf = ContractState {
nonce: Nonce(felt),
storage_root_hash: HashOutput(felt),
class_hash: ClassHash(felt),
};
(leaf.get_db_key(&felt.to_bytes_be()), leaf.serialize())
}

// This test assumes for simplicity that hash is addition (i.e hash(a,b) = a + b).
// I.e., the value of a binary node is the sum of its children's values, and the value of an edge
// node is the sum of its path, bottom value and path length.
Expand Down

0 comments on commit 365b798

Please sign in to comment.