Skip to content

Commit d65db53

Browse files
starknet_os_flow_tests: rename TestManager to TestBuilder and move out the OS run (#11428)
1 parent bc634a0 commit d65db53

File tree

2 files changed

+310
-304
lines changed

2 files changed

+310
-304
lines changed

crates/starknet_os_flow_tests/src/test_manager.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(crate) static FUNDED_ACCOUNT_ADDRESS: LazyLock<ContractAddress> =
119119
LazyLock::new(|| get_initial_deploy_account_tx().contract_address);
120120

121121
#[derive(Default)]
122-
pub(crate) struct TestManagerConfig {
122+
pub(crate) struct TestBuilderConfig {
123123
pub(crate) use_kzg_da: bool,
124124
pub(crate) full_output: bool,
125125
pub(crate) private_keys: Option<Vec<Felt>>,
@@ -390,7 +390,7 @@ impl<S: FlowTestState> TestRunner<S> {
390390
let os_output = run_os_stateless(layout, self.os_hints).unwrap();
391391

392392
let decompressed_state_diff =
393-
create_committer_state_diff(TestManager::<S>::get_decompressed_state_diff(
393+
create_committer_state_diff(TestBuilder::<S>::get_decompressed_state_diff(
394394
&os_output,
395395
&final_state,
396396
entire_initial_reads.alias_keys(),
@@ -407,8 +407,9 @@ impl<S: FlowTestState> TestRunner<S> {
407407
}
408408
}
409409

410-
/// Manages the execution of flow tests by maintaining the initial state and transactions.
411-
pub(crate) struct TestManager<S: FlowTestState> {
410+
/// Builds flow tests by maintaining the initial state and transactions.
411+
/// Use the builder methods to configure transactions, then call `build()` to get a `TestRunner`.
412+
pub(crate) struct TestBuilder<S: FlowTestState> {
412413
pub(crate) initial_state: InitialState<S>,
413414
pub(crate) nonce_manager: NonceManager,
414415
pub(crate) execution_contracts: OsExecutionContracts,
@@ -420,11 +421,11 @@ pub(crate) struct TestManager<S: FlowTestState> {
420421
per_block_txs: Vec<Vec<FlowTestTx>>,
421422
}
422423

423-
impl<S: FlowTestState> TestManager<S> {
424-
/// Creates a new `TestManager` with the provided initial state data.
424+
impl<S: FlowTestState> TestBuilder<S> {
425+
/// Creates a new `TestBuilder` with the provided initial state data.
425426
pub(crate) fn new_with_initial_state_data(
426427
initial_state_data: InitialStateData<S>,
427-
config: TestManagerConfig,
428+
config: TestBuilderConfig,
428429
) -> Self {
429430
let public_keys =
430431
config.private_keys.as_ref().map(|private_keys| compute_public_keys(private_keys));
@@ -450,13 +451,12 @@ impl<S: FlowTestState> TestManager<S> {
450451
}
451452
}
452453

453-
/// Creates a new `TestManager` with the default initial state.
454-
/// Returns the manager and a nonce manager to help keep track of nonces.
454+
/// Creates a new `TestBuilder` with the default initial state.
455455
/// Optionally provide an array of extra contracts to declare and deploy - the addresses of
456456
/// these contracts will be returned as an array of the same length.
457457
pub(crate) async fn new_with_default_initial_state<const N: usize>(
458458
extra_contracts: [(FeatureContract, Calldata); N],
459-
config: TestManagerConfig,
459+
config: TestBuilderConfig,
460460
) -> (Self, [ContractAddress; N]) {
461461
let (default_initial_state_data, extra_addresses) =
462462
create_default_initial_state_data::<S, N>(extra_contracts).await;
@@ -692,8 +692,10 @@ impl<S: FlowTestState> TestManager<S> {
692692
decompress(&os_state_diff_maps, state, *ALIAS_CONTRACT_ADDRESS, alias_keys)
693693
}
694694

695-
// Executes the flow test.
696-
pub(crate) async fn execute_flow_test(self) -> OsTestOutput<S> {
695+
/// Builds the test runner from the current state and transactions.
696+
/// Returns a `TestRunner` that can be used to run the OS and get the test output.
697+
pub(crate) async fn build(self) -> TestRunner<S> {
698+
// TODO(Yoni): make this func sync.
697699
let mut os_block_inputs = vec![];
698700
let mut state = CachedState::new(self.initial_state.updatable_state);
699701
let mut map_storage = self.initial_state.commitment_storage;
@@ -791,30 +793,34 @@ impl<S: FlowTestState> TestManager<S> {
791793
let os_hints =
792794
OsHints { os_input: starknet_os_input, os_hints_config: self.os_hints_config };
793795

794-
let test_runner = TestRunner {
796+
TestRunner {
795797
os_hints,
796798
entire_cached_state: state,
797799
messages_to_l1: self.messages_to_l1,
798800
messages_to_l2: self.messages_to_l2,
799801
private_keys: self.private_keys,
800-
};
801-
test_runner.run()
802+
}
803+
}
804+
805+
/// Builds and runs the test, returning the test output.
806+
pub(crate) async fn build_and_run(self) -> OsTestOutput<S> {
807+
self.build().await.run()
802808
}
803809
}
804810

805-
impl TestManager<DictStateReader> {
811+
impl TestBuilder<DictStateReader> {
806812
pub(crate) async fn create_standard<const N: usize>(
807813
extra_contracts: [(FeatureContract, Calldata); N],
808814
) -> (Self, [ContractAddress; N]) {
809-
Self::create_standard_with_config(extra_contracts, TestManagerConfig::default()).await
815+
Self::create_standard_with_config(extra_contracts, TestBuilderConfig::default()).await
810816
}
811817

812-
/// Creates a new `TestManager` with the default initial state and the provided config.
818+
/// Creates a new `TestBuilder` with the default initial state and the provided config.
813819
/// Uses `DictStateReader` as the state type.
814820
/// Returns the manager and an array of addresses for any extra contracts deployed.
815821
pub(crate) async fn create_standard_with_config<const N: usize>(
816822
extra_contracts: [(FeatureContract, Calldata); N],
817-
config: TestManagerConfig,
823+
config: TestBuilderConfig,
818824
) -> (Self, [ContractAddress; N]) {
819825
Self::new_with_default_initial_state(extra_contracts, config).await
820826
}

0 commit comments

Comments
 (0)