-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_class_manager): builder for test storage
- Loading branch information
1 parent
d1c4b7c
commit 85e6a08
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::path::PathBuf; | ||
|
||
use tempfile::TempDir; | ||
|
||
use crate::class_storage::{ClassHashStorage, FsClassStorage}; | ||
use crate::config::{ClassHashStorageConfig, FsClassStorageConfig}; | ||
|
||
pub type FileHandles = (TempDir, TempDir); | ||
|
||
pub struct FsClassStorageBuilderForTesting { | ||
config: FsClassStorageConfig, | ||
handles: Option<FileHandles>, | ||
} | ||
|
||
impl Default for FsClassStorageBuilderForTesting { | ||
fn default() -> Self { | ||
let class_hash_storage_handle = tempfile::tempdir().unwrap(); | ||
let persistent_root_handle = tempfile::tempdir().unwrap(); | ||
let persistent_root = persistent_root_handle.path().to_path_buf(); | ||
let config = FsClassStorageConfig { | ||
persistent_root, | ||
class_hash_storage_config: ClassHashStorageConfig { | ||
path_prefix: class_hash_storage_handle.path().to_path_buf(), | ||
enforce_file_exists: false, | ||
max_size: 1 << 20, // 1MB. | ||
}, | ||
}; | ||
Self { config, handles: Some((class_hash_storage_handle, persistent_root_handle)) } | ||
} | ||
} | ||
|
||
impl FsClassStorageBuilderForTesting { | ||
pub fn with_existing_paths( | ||
mut self, | ||
class_hash_storage_path_prefix: PathBuf, | ||
persistent_path: PathBuf, | ||
) -> Self { | ||
self.config.class_hash_storage_config.path_prefix = class_hash_storage_path_prefix; | ||
self.config.persistent_root = persistent_path; | ||
self.handles = None; | ||
self | ||
} | ||
|
||
pub fn build(self) -> (FsClassStorage, FsClassStorageConfig, Option<FileHandles>) { | ||
let Self { config, handles } = self; | ||
let class_hash_storage = | ||
ClassHashStorage::new(config.class_hash_storage_config.clone()).unwrap(); | ||
let fs_class_storage = | ||
FsClassStorage { persistent_root: config.persistent_root.clone(), class_hash_storage }; | ||
(fs_class_storage, config, handles) | ||
} | ||
} |