Skip to content

Commit

Permalink
feat(starknet_integration_tests): init the class manage storage with …
Browse files Browse the repository at this point in the history
…classes
  • Loading branch information
yair-starkware committed Feb 9, 2025
1 parent f0af5d5 commit 55df26f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tempfile::TempDir;
use tracing::{debug, instrument};

use crate::integration_test_setup::NodeExecutionId;
use crate::state_reader::{StorageTestSetup, TempDirHandlePair};
use crate::state_reader::StorageTestSetup;
use crate::utils::{
create_chain_info,
create_consensus_manager_configs_from_network_configs,
Expand Down Expand Up @@ -124,7 +124,7 @@ pub struct FlowSequencerSetup {
// Handlers for the storage files, maintained so the files are not deleted.
pub batcher_storage_file_handle: Option<TempDir>,
pub state_sync_storage_file_handle: Option<TempDir>,
pub class_manager_storage_file_handles: TempDirHandlePair,
pub class_manager_storage_file_handles: Option<starknet_class_manager::test_utils::FileHandles>,

// Node configuration.
pub node_config: SequencerNodeConfig,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl FlowSequencerSetup {
add_tx_http_client,
batcher_storage_file_handle: batcher_storage_handle,
state_sync_storage_file_handle: state_sync_storage_handle,
class_manager_storage_file_handles: class_manager_storage_handles.unwrap(),
class_manager_storage_file_handles: class_manager_storage_handles,
node_config,
monitoring_client,
_clients,
Expand Down
37 changes: 35 additions & 2 deletions crates/starknet_integration_tests/src/state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use starknet_api::block::{
FeeType,
GasPricePerToken,
};
use starknet_api::contract_class::{ContractClass, SierraVersion};
use starknet_api::core::{ClassHash, ContractAddress, Nonce, SequencerContractAddress};
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_api::state::{SierraContractClass, StorageKey, ThinStateDiff};
Expand All @@ -38,6 +39,7 @@ use starknet_api::test_utils::{
};
use starknet_api::transaction::fields::Fee;
use starknet_api::{contract_address, felt};
use starknet_class_manager::class_storage::{ClassStorage, FsClassStorage};
use starknet_class_manager::config::FsClassStorageConfig;
use starknet_class_manager::test_utils::FsClassStorageBuilderForTesting;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -110,8 +112,13 @@ impl StorageTestSetup {
fs_class_storage_builder = fs_class_storage_builder
.with_existing_paths(class_hash_storage_path_prefix, persistent_root);
}
let (_class_manager_storage, class_manager_storage_config, class_manager_storage_handles) =
fs_class_storage_builder.build();
let (
mut class_manager_storage,
class_manager_storage_config,
class_manager_storage_handles,
) = fs_class_storage_builder.build();

initialize_class_manager_test_state(&mut class_manager_storage, classes);

Self {
batcher_storage_config,
Expand Down Expand Up @@ -193,6 +200,32 @@ impl TestClasses {
}
}

fn initialize_class_manager_test_state(
class_manager_storage: &mut FsClassStorage,
classes: TestClasses,
) {
let TestClasses { cairo0_contract_classes, cairo1_contract_classes } = classes;

for (class_hash, cairo_0_class) in cairo0_contract_classes {
class_manager_storage
.set_deprecated_class(class_hash, cairo_0_class.try_into().unwrap())
.unwrap();
}
for (class_hash, (sierra, casm)) in cairo1_contract_classes {
let sierra_version = SierraVersion::extract_from_program(&sierra.sierra_program).unwrap();
let class = ContractClass::V1((casm, sierra_version));
let compiled_class_hash = class.compiled_class_hash();
class_manager_storage
.set_class(
class_hash,
sierra.try_into().unwrap(),
compiled_class_hash,
class.try_into().unwrap(),
)
.unwrap();
}
}

fn initialize_papyrus_test_state(
storage_writer: &mut StorageWriter,
chain_info: &ChainInfo,
Expand Down

0 comments on commit 55df26f

Please sign in to comment.