Skip to content

Commit 9601c70

Browse files
refactor(starknet_integration_tests): wrap the storage handles in a sub-struct
1 parent b3d6b16 commit 9601c70

File tree

4 files changed

+35
-45
lines changed

4 files changed

+35
-45
lines changed

crates/starknet_integration_tests/src/flow_test_setup.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ use starknet_sequencer_node::servers::run_component_servers;
4949
use starknet_sequencer_node::utils::create_node_modules;
5050
use starknet_state_sync::config::StateSyncConfig;
5151
use starknet_types_core::felt::Felt;
52-
use tempfile::TempDir;
5352
use tokio::sync::Mutex;
5453
use tracing::{debug, instrument};
5554
use url::Url;
5655

57-
use crate::state_reader::StorageTestSetup;
56+
use crate::state_reader::{StorageTestHandles, StorageTestSetup};
5857
use crate::utils::{
5958
create_consensus_manager_configs_from_network_configs,
6059
create_mempool_p2p_configs,
@@ -179,9 +178,7 @@ pub struct FlowSequencerSetup {
179178
pub add_tx_http_client: HttpTestClient,
180179

181180
// Handlers for the storage files, maintained so the files are not deleted.
182-
pub batcher_storage_file_handle: Option<TempDir>,
183-
pub state_sync_storage_file_handle: Option<TempDir>,
184-
pub class_manager_storage_file_handles: Option<starknet_class_manager::test_utils::FileHandles>,
181+
pub storage_handles: StorageTestHandles,
185182

186183
// Node configuration.
187184
pub node_config: SequencerNodeConfig,
@@ -210,12 +207,8 @@ impl FlowSequencerSetup {
210207
block_max_capacity_sierra_gas: GasAmount,
211208
) -> Self {
212209
let path = None;
213-
let StorageTestSetup {
214-
storage_config,
215-
batcher_storage_handle,
216-
state_sync_storage_handle,
217-
class_manager_storage_handles,
218-
} = StorageTestSetup::new(accounts, &chain_info, path);
210+
let StorageTestSetup { storage_config, storage_handles } =
211+
StorageTestSetup::new(accounts, &chain_info, path);
219212

220213
let (recorder_url, _join_handle) =
221214
spawn_local_success_recorder(available_ports.get_next_port());
@@ -264,9 +257,7 @@ impl FlowSequencerSetup {
264257
Self {
265258
node_index,
266259
add_tx_http_client,
267-
batcher_storage_file_handle: batcher_storage_handle,
268-
state_sync_storage_file_handle: state_sync_storage_handle,
269-
class_manager_storage_file_handles: class_manager_storage_handles,
260+
storage_handles,
270261
node_config,
271262
monitoring_client,
272263
clients,

crates/starknet_integration_tests/src/integration_test_manager.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use starknet_api::core::{ChainId, Nonce};
2121
use starknet_api::execution_resources::GasAmount;
2222
use starknet_api::rpc_transaction::RpcTransaction;
2323
use starknet_api::transaction::TransactionHash;
24-
use starknet_class_manager::test_utils::FileHandles;
2524
use starknet_http_server::config::HttpServerConfig;
2625
use starknet_http_server::test_utils::HttpTestClient;
2726
use starknet_infra_utils::test_utils::{AvailablePortsGenerator, TestIdentifier};
@@ -36,7 +35,6 @@ use starknet_sequencer_node::config::node_config::{
3635
CONFIG_NON_POINTERS_WHITELIST,
3736
};
3837
use starknet_sequencer_node::test_utils::node_runner::{get_node_executable_path, spawn_run_node};
39-
use tempfile::TempDir;
4038
use tokio::join;
4139
use tokio::task::JoinHandle;
4240
use tracing::info;
@@ -55,6 +53,7 @@ use crate::node_component_configs::{
5553
NodeComponentConfigs,
5654
};
5755
use crate::sequencer_simulator_utils::SequencerSimulator;
56+
use crate::state_reader::StorageTestHandles;
5857
use crate::storage::{get_integration_test_storage, CustomPaths};
5958
use crate::utils::{
6059
create_consensus_manager_configs_from_network_configs,
@@ -91,11 +90,7 @@ pub struct NodeSetup {
9190
// these are only maintained to avoid dropping the handlers, private visibility suffices, and
9291
// as such, the '#[allow(dead_code)]' attributes are used to suppress the warning.
9392
#[allow(dead_code)]
94-
batcher_storage_handle: Option<TempDir>,
95-
#[allow(dead_code)]
96-
state_sync_storage_handle: Option<TempDir>,
97-
#[allow(dead_code)]
98-
class_manager_storage_handles: Option<FileHandles>,
93+
storage_handles: StorageTestHandles,
9994
}
10095

10196
// TODO(Nadin): reduce the number of arguments.
@@ -107,9 +102,7 @@ impl NodeSetup {
107102
http_server_index: usize,
108103
state_sync_index: usize,
109104
add_tx_http_client: HttpTestClient,
110-
batcher_storage_handle: Option<TempDir>,
111-
state_sync_storage_handle: Option<TempDir>,
112-
class_manager_storage_handles: Option<FileHandles>,
105+
storage_handles: StorageTestHandles,
113106
) -> Self {
114107
let len = executables.len();
115108

@@ -133,9 +126,7 @@ impl NodeSetup {
133126
http_server_index,
134127
state_sync_index,
135128
add_tx_http_client,
136-
batcher_storage_handle,
137-
state_sync_storage_handle,
138-
class_manager_storage_handles,
129+
storage_handles,
139130
}
140131
}
141132

@@ -807,9 +798,7 @@ pub async fn get_sequencer_setup_configs(
807798
http_server_index,
808799
state_sync_index,
809800
add_tx_http_client,
810-
storage_setup.batcher_storage_handle,
811-
storage_setup.state_sync_storage_handle,
812-
storage_setup.class_manager_storage_handles,
801+
storage_setup.storage_handles,
813802
));
814803
}
815804

crates/starknet_integration_tests/src/state_reader.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,28 @@ impl StorageTestConfig {
7979
}
8080

8181
#[derive(Debug)]
82-
pub struct StorageTestSetup {
83-
pub storage_config: StorageTestConfig,
84-
// TODO(Nadin): wrap the handles in a sub-struct.
82+
pub struct StorageTestHandles {
8583
pub batcher_storage_handle: Option<TempDir>,
8684
pub state_sync_storage_handle: Option<TempDir>,
8785
pub class_manager_storage_handles: Option<TempDirHandlePair>,
8886
}
8987

88+
impl StorageTestHandles {
89+
pub fn new(
90+
batcher_storage_handle: Option<TempDir>,
91+
state_sync_storage_handle: Option<TempDir>,
92+
class_manager_storage_handles: Option<TempDirHandlePair>,
93+
) -> Self {
94+
Self { batcher_storage_handle, state_sync_storage_handle, class_manager_storage_handles }
95+
}
96+
}
97+
98+
#[derive(Debug)]
99+
pub struct StorageTestSetup {
100+
pub storage_config: StorageTestConfig,
101+
pub storage_handles: StorageTestHandles,
102+
}
103+
90104
impl StorageTestSetup {
91105
pub fn new(
92106
test_defined_accounts: Vec<AccountTransactionGenerator>,
@@ -156,9 +170,11 @@ impl StorageTestSetup {
156170
state_sync_storage_config,
157171
class_manager_storage_config,
158172
),
159-
batcher_storage_handle,
160-
state_sync_storage_handle,
161-
class_manager_storage_handles,
173+
storage_handles: StorageTestHandles::new(
174+
batcher_storage_handle,
175+
state_sync_storage_handle,
176+
class_manager_storage_handles,
177+
),
162178
}
163179
}
164180
}

crates/starknet_integration_tests/src/storage.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,8 @@ pub fn get_integration_test_storage(
115115
})
116116
});
117117

118-
let StorageTestSetup {
119-
mut storage_config,
120-
batcher_storage_handle,
121-
state_sync_storage_handle,
122-
class_manager_storage_handles,
123-
} = StorageTestSetup::new(accounts, chain_info, storage_exec_paths);
118+
let StorageTestSetup { mut storage_config, storage_handles } =
119+
StorageTestSetup::new(accounts, chain_info, storage_exec_paths);
124120

125121
// Allow overriding the path with a custom prefix for Docker mode in system tests.
126122
if let Some(paths) = custom_paths {
@@ -156,8 +152,6 @@ pub fn get_integration_test_storage(
156152
storage_config.state_sync_storage_config,
157153
storage_config.class_manager_storage_config,
158154
),
159-
batcher_storage_handle,
160-
state_sync_storage_handle,
161-
class_manager_storage_handles,
155+
storage_handles,
162156
}
163157
}

0 commit comments

Comments
 (0)