Skip to content

Commit

Permalink
chore: add mock_system_mode to create config function
Browse files Browse the repository at this point in the history
commit-id:94b908d4
  • Loading branch information
nadin-Starkware committed Dec 10, 2024
1 parent 5103d58 commit 14d78b9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
10 changes: 9 additions & 1 deletion crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tokio::runtime::Handle;
use tokio::task::JoinHandle;
use tracing::{debug, instrument};

use crate::definitions::MockSystemMode;
use crate::state_reader::{spawn_test_rpc_state_reader, StorageTestSetup};
use crate::utils::{
create_chain_info,
Expand All @@ -43,7 +44,10 @@ pub struct FlowTestSetup {

impl FlowTestSetup {
#[instrument(skip(tx_generator), level = "debug")]
pub async fn new_from_tx_generator(tx_generator: &MultiAccountTransactionGenerator) -> Self {
pub async fn new_from_tx_generator(
tx_generator: &MultiAccountTransactionGenerator,
mock_system_mode: MockSystemMode,
) -> Self {
let handle = Handle::current();
let task_executor = TokioExecutor::new(handle);
let chain_info = create_chain_info();
Expand All @@ -61,6 +65,7 @@ impl FlowTestSetup {
chain_info.clone(),
&task_executor,
sequencer_0_consensus_manager_config,
mock_system_mode.clone(),
)
.await;

Expand All @@ -71,6 +76,7 @@ impl FlowTestSetup {
chain_info,
&task_executor,
sequencer_1_consensus_manager_config,
mock_system_mode,
)
.await;

Expand Down Expand Up @@ -110,6 +116,7 @@ impl SequencerSetup {
chain_info: ChainInfo,
task_executor: &TokioExecutor,
consensus_manager_config: ConsensusManagerConfig,
mock_system_mode: MockSystemMode,
) -> Self {
let storage_for_test = StorageTestSetup::new(accounts, &chain_info);

Expand All @@ -127,6 +134,7 @@ impl SequencerSetup {
rpc_server_addr,
storage_for_test.batcher_storage_config,
consensus_manager_config,
mock_system_mode,
)
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use starknet_monitoring_endpoint::test_utils::IsAliveClient;
use tempfile::{tempdir, TempDir};

use crate::config_utils::dump_config_file_changes;
use crate::definitions::MockSystemMode;
use crate::state_reader::{spawn_test_rpc_state_reader, StorageTestSetup};
use crate::utils::{
create_chain_info,
Expand Down Expand Up @@ -63,6 +64,7 @@ impl IntegrationTestSetup {
rpc_server_addr,
storage_for_test.batcher_storage_config,
consensus_manager_configs.pop().unwrap(),
MockSystemMode::Local,
)
.await;

Expand Down
35 changes: 25 additions & 10 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ use starknet_http_server::config::HttpServerConfig;
use starknet_mempool_p2p::config::MempoolP2pConfig;
use starknet_monitoring_endpoint::config::MonitoringEndpointConfig;
use starknet_sequencer_infra::test_utils::get_available_socket;
use starknet_sequencer_node::config::component_config::ComponentConfig;
use starknet_sequencer_node::config::component_execution_config::ActiveComponentExecutionMode;
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_sequencer_node::config::test_utils::RequiredParams;
use starknet_types_core::felt::Felt;

use crate::config_utils::get_remote_flow_test_config;
use crate::definitions::MockSystemMode;

pub fn create_chain_info() -> ChainInfo {
let mut chain_info = ChainInfo::create_for_testing();
// Note that the chain_id affects hashes of transactions and blocks, therefore affecting the
Expand All @@ -50,6 +54,7 @@ pub async fn create_config(
rpc_server_addr: SocketAddr,
batcher_storage_config: StorageConfig,
mut consensus_manager_config: ConsensusManagerConfig,
mock_system_mode: MockSystemMode,
) -> (Vec<SequencerNodeConfig>, RequiredParams) {
set_validator_id(&mut consensus_manager_config, sequencer_index);
let fee_token_addresses = chain_info.fee_token_addresses.clone();
Expand All @@ -60,18 +65,28 @@ pub async fn create_config(
let mempool_p2p_config =
create_mempool_p2p_config(sequencer_index, chain_info.chain_id.clone());
let monitoring_endpoint_config = create_monitoring_endpoint_config(sequencer_index);
let component_configs = match mock_system_mode {
MockSystemMode::Remote => get_remote_flow_test_config().await,
MockSystemMode::Local => async { vec![ComponentConfig::default()] }.await,
};

let sequencer_node_configs: Vec<SequencerNodeConfig> = component_configs
.iter()
.map(|component_config| SequencerNodeConfig {
batcher_config: batcher_config.clone(),
consensus_manager_config: consensus_manager_config.clone(),
gateway_config: gateway_config.clone(),
http_server_config: http_server_config.clone(),
rpc_state_reader_config: rpc_state_reader_config.clone(),
mempool_p2p_config.clone(),
monitoring_endpoint_config.clone(),
components: component_config.clone(),
..SequencerNodeConfig::default()
})
.collect();

(
vec![SequencerNodeConfig {
batcher_config,
consensus_manager_config,
gateway_config,
http_server_config,
rpc_state_reader_config,
mempool_p2p_config,
monitoring_endpoint_config,
..Default::default()
}],
sequencer_node_configs,
RequiredParams {
chain_id: chain_info.chain_id,
eth_fee_token_address: fee_token_addresses.eth_fee_token_address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::transaction::TransactionHash;
use starknet_integration_tests::definitions::MockSystemMode;
use starknet_integration_tests::flow_test_setup::FlowTestSetup;
use starknet_integration_tests::utils::{
create_integration_test_tx_generator,
Expand All @@ -41,7 +42,8 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) {
const LISTEN_TO_BROADCAST_MESSAGES_TIMEOUT: std::time::Duration =
std::time::Duration::from_secs(50);
// Setup.
let mut mock_running_system = FlowTestSetup::new_from_tx_generator(&tx_generator).await;
let mut mock_running_system =
FlowTestSetup::new_from_tx_generator(&tx_generator, MockSystemMode::Local).await;

let next_height = INITIAL_HEIGHT.unchecked_next();
let heights_to_build = next_height.iter_up_to(LAST_HEIGHT.unchecked_next());
Expand Down

0 comments on commit 14d78b9

Please sign in to comment.