diff --git a/crates/starknet_integration_tests/src/end_to_end_integration.rs b/crates/starknet_integration_tests/src/end_to_end_integration.rs index baf546ef2ee..25aad27a18d 100644 --- a/crates/starknet_integration_tests/src/end_to_end_integration.rs +++ b/crates/starknet_integration_tests/src/end_to_end_integration.rs @@ -5,7 +5,8 @@ use starknet_api::block::BlockNumber; use starknet_sequencer_node::test_utils::node_runner::get_node_executable_path; use tracing::info; -use crate::{sequencer_manager::{get_sequencer_setup_configs, IntegrationTestManager}, utils::InvokeTxs}; +use crate::sequencer_manager::{get_sequencer_setup_configs, IntegrationTestManager}; +use crate::utils::{FirstBlock, InvokeTxs, N_TXS_IN_FIRST_BLOCK}; pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGenerator) { const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(15); @@ -30,11 +31,18 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe // Run the nodes. integration_test_manager.run(node_indices).await; + // Run the first block scenario to bootstrap the accounts. + integration_test_manager + .test_and_verify(tx_generator, 0, FirstBlock, SENDER_ACCOUNT, BlockNumber(2)) + .await; + // Run the test. integration_test_manager .test_and_verify( tx_generator, - 0, + // TODO(Yael): consider removing this parameter and take it from the tx_generator + // instead. + N_TXS_IN_FIRST_BLOCK, InvokeTxs(N_TXS), SENDER_ACCOUNT, EXPECTED_BLOCK_NUMBER, @@ -48,7 +56,7 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe integration_test_manager .test_and_verify( tx_generator, - N_TXS, + N_TXS + N_TXS_IN_FIRST_BLOCK, InvokeTxs(N_TXS), SENDER_ACCOUNT, LATE_NODE_EXPECTED_BLOCK_NUMBER, @@ -57,4 +65,6 @@ pub async fn end_to_end_integration(tx_generator: &mut MultiAccountTransactionGe info!("Shutting down nodes."); integration_test_manager.shutdown_nodes(); + + info!("TEST PASSED"); } diff --git a/crates/starknet_integration_tests/src/sequencer_manager.rs b/crates/starknet_integration_tests/src/sequencer_manager.rs index e7bfef7a055..75e16d69bed 100644 --- a/crates/starknet_integration_tests/src/sequencer_manager.rs +++ b/crates/starknet_integration_tests/src/sequencer_manager.rs @@ -231,14 +231,14 @@ impl IntegrationTestManager { // Verify the initial state self.verify_results( tx_generator.account_with_id(sender_account).sender_address(), - expected_initial_value + 1, + expected_initial_value, ) .await; self.run_integration_test_simulator(tx_generator, &test_scenario, sender_account).await; self.await_execution(expected_block_number).await; self.verify_results( tx_generator.account_with_id(sender_account).sender_address(), - expected_initial_value + test_scenario.n_txs() + 1, + expected_initial_value + test_scenario.n_txs(), ) .await; } @@ -330,7 +330,8 @@ fn get_account_nonce(storage_reader: &StorageReader, contract_address: ContractA let state_number = StateNumber::unchecked_right_after_block(block_number); get_nonce_at(&txn, state_number, None, contract_address) .expect("Should always be Ok(Some(Nonce))") - .expect("Should always be Some(Nonce)") + // If the nonce is None, it means that the account was not deployed yet and it's nonce is 0. + .unwrap_or_default() } /// Sample a storage until sufficiently many blocks have been stored. Returns an error if after diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index c43252deb98..75d445dcb1e 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -59,7 +59,7 @@ pub const UNDEPLOYED_ACCOUNT_ID: AccountId = 2; // Transactions per second sent to the gateway. This rate makes each block contain ~10 transactions // with the set [TimeoutsConfig] . pub const TPS: u64 = 2; -const N_TXS_IN_FIRST_BLOCK: usize = 2; +pub const N_TXS_IN_FIRST_BLOCK: usize = 2; pub trait TestScenario { fn create_txs( @@ -240,11 +240,28 @@ pub fn create_mempool_p2p_configs(chain_id: ChainId, ports: Vec) -> Vec MultiAccountTransactionGenerator { let mut tx_generator: MultiAccountTransactionGenerator = MultiAccountTransactionGenerator::new(); + for (i, account) in [ + FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)), + FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0), + ] + .iter() + .enumerate() + { + tx_generator.register_undeployed_account(*account, ContractAddressSalt(Felt::from(i))); + } + tx_generator +} + +/// Creates a multi-account transaction generator for the flow test. +pub fn create_flow_test_tx_generator() -> MultiAccountTransactionGenerator { + let mut tx_generator: MultiAccountTransactionGenerator = + MultiAccountTransactionGenerator::new(); + for account in [ FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)), FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0), diff --git a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs index 629f2e36d28..2f326c58376 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs @@ -20,8 +20,8 @@ use starknet_infra_utils::test_utils::TestIdentifier; use starknet_integration_tests::flow_test_setup::{FlowSequencerSetup, FlowTestSetup}; use starknet_integration_tests::utils::{ create_deploy_account_tx_and_invoke_tx, + create_flow_test_tx_generator, create_funding_txs, - create_integration_test_tx_generator, create_many_invoke_txs, create_multiple_account_txs, run_test_scenario, @@ -38,7 +38,7 @@ const LAST_HEIGHT: BlockNumber = BlockNumber(4); #[fixture] fn tx_generator() -> MultiAccountTransactionGenerator { - create_integration_test_tx_generator() + create_flow_test_tx_generator() } #[rstest]