Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/starknet_os_flow_tests/src/initial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const STRK_DECIMALS: u8 = 18;
/// Gathers the information needed to execute a flow test.
pub(crate) struct InitialStateData<S: FlowTestState> {
pub(crate) initial_state: InitialState<S>,
pub(crate) nonce_manager: NonceManager,
pub(crate) execution_contracts: OsExecutionContracts,
}

Expand Down Expand Up @@ -129,7 +130,7 @@ pub(crate) struct InitialState<S: FlowTestState> {
/// Also deploys extra contracts as requested (and declares them if they are not already declared).
pub(crate) async fn create_default_initial_state_data<S: FlowTestState, const N: usize>(
extra_contracts: [(FeatureContract, Calldata); N],
) -> (InitialStateData<S>, NonceManager, [ContractAddress; N]) {
) -> (InitialStateData<S>, [ContractAddress; N]) {
let (
InitialTransactionsData {
transactions: default_initial_state_txs,
Expand Down Expand Up @@ -183,8 +184,7 @@ pub(crate) async fn create_default_initial_state_data<S: FlowTestState, const N:
};

(
InitialStateData { initial_state, execution_contracts },
nonce_manager,
InitialStateData { initial_state, nonce_manager, execution_contracts },
extra_contracts_addresses,
)
}
Expand Down
20 changes: 13 additions & 7 deletions crates/starknet_os_flow_tests/src/test_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub(crate) struct TestParameters {
/// Manages the execution of flow tests by maintaining the initial state and transactions.
pub(crate) struct TestManager<S: FlowTestState> {
pub(crate) initial_state: InitialState<S>,
pub(crate) nonce_manager: NonceManager,
pub(crate) execution_contracts: OsExecutionContracts,

per_block_transactions: Vec<Vec<BlockifierTransaction>>,
Expand Down Expand Up @@ -236,6 +237,7 @@ impl<S: FlowTestState> TestManager<S> {
pub(crate) fn new_with_initial_state_data(initial_state_data: InitialStateData<S>) -> Self {
Self {
initial_state: initial_state_data.initial_state,
nonce_manager: initial_state_data.nonce_manager,
execution_contracts: initial_state_data.execution_contracts,
per_block_transactions: vec![vec![]],
}
Expand All @@ -247,14 +249,18 @@ impl<S: FlowTestState> TestManager<S> {
/// these contracts will be returned as an array of the same length.
pub(crate) async fn new_with_default_initial_state<const N: usize>(
extra_contracts: [(FeatureContract, Calldata); N],
) -> (Self, NonceManager, [ContractAddress; N]) {
let (default_initial_state_data, nonce_manager, extra_addresses) =
) -> (Self, [ContractAddress; N]) {
let (default_initial_state_data, extra_addresses) =
create_default_initial_state_data::<S, N>(extra_contracts).await;
(
Self::new_with_initial_state_data(default_initial_state_data),
nonce_manager,
extra_addresses,
)
(Self::new_with_initial_state_data(default_initial_state_data), extra_addresses)
}

pub(crate) fn next_nonce(&mut self, account_address: ContractAddress) -> Nonce {
self.nonce_manager.next(account_address)
}

pub(crate) fn get_nonce(&self, account_address: ContractAddress) -> Nonce {
self.nonce_manager.get(account_address)
}

/// Advances the manager to the next block when adding new transactions.
Expand Down
16 changes: 8 additions & 8 deletions crates/starknet_os_flow_tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn declare_deploy_scenario(
// Initialize the test manager with a default initial state and get the nonce manager to help
// keep track of nonces.

let (mut test_manager, mut nonce_manager, _) =
let (mut test_manager, _) =
TestManager::<DictStateReader>::new_with_default_initial_state([]).await;

// Declare a test contract.
Expand All @@ -102,7 +102,7 @@ async fn declare_deploy_scenario(
class_hash,
compiled_class_hash,
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
};
let account_declare_tx = declare_tx(declare_tx_args);
let class_info = get_class_info_of_feature_contract(test_contract);
Expand All @@ -128,7 +128,7 @@ async fn declare_deploy_scenario(
);
let invoke_tx_args = invoke_tx_args! {
sender_address: *FUNDED_ACCOUNT_ADDRESS,
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
calldata: deploy_contract_calldata,
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
};
Expand Down Expand Up @@ -187,7 +187,7 @@ async fn trivial_diff_scenario(
// Initialize the test manager with a default initial state and get the nonce manager to help
// keep track of nonces.

let (mut test_manager, mut nonce_manager, [test_contract_address]) =
let (mut test_manager, [test_contract_address]) =
TestManager::<DictStateReader>::new_with_default_initial_state([(
test_contract,
calldata![Felt::ONE, Felt::TWO],
Expand All @@ -200,7 +200,7 @@ async fn trivial_diff_scenario(
// Invoke a function on the test contract that changes the key to the new value.
let invoke_tx_args = invoke_tx_args! {
sender_address: *FUNDED_ACCOUNT_ADDRESS,
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
calldata: create_calldata(test_contract_address, function_name, &[key, value]),
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
};
Expand All @@ -210,7 +210,7 @@ async fn trivial_diff_scenario(
test_manager.move_to_next_block();
let invoke_tx_args = invoke_tx_args! {
sender_address: *FUNDED_ACCOUNT_ADDRESS,
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
calldata: create_calldata(test_contract_address, function_name, &[key, Felt::ZERO]),
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
};
Expand Down Expand Up @@ -247,7 +247,7 @@ async fn test_reverted_invoke_tx(
) {
let (use_kzg_da, full_output) = (true, false);

let (mut test_manager, mut nonce_manager, [test_contract_address]) =
let (mut test_manager, [test_contract_address]) =
TestManager::<DictStateReader>::new_with_default_initial_state([(
test_contract,
calldata![Felt::ONE, Felt::TWO],
Expand All @@ -257,7 +257,7 @@ async fn test_reverted_invoke_tx(
// Call a reverting function that changes the storage.
let invoke_tx_args = invoke_tx_args! {
sender_address: *FUNDED_ACCOUNT_ADDRESS,
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
calldata: create_calldata(test_contract_address, "write_and_revert", &[]),
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
};
Expand Down