diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index d8014a41e2..6b56b1785d 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -212,7 +212,7 @@ impl MultiAccountTransactionGenerator { /// Registers a new account with the given contract, assuming it is already deployed. /// Note: the state should reflect it if the account is already deployed. - pub fn register_deployed_account(&mut self, account_contract: FeatureContract) { + pub fn register_deployed_account(&mut self, account_contract: FeatureContract) -> AccountId { let new_account_id = self.account_tx_generators.len(); let salt = ContractAddressSalt(new_account_id.into()); let (account_tx_generator, _default_deploy_account_tx) = AccountTransactionGenerator::new( @@ -222,6 +222,7 @@ impl MultiAccountTransactionGenerator { true, ); self.account_tx_generators.push(account_tx_generator); + new_account_id } /// Registers a new undeployed account with the given contract. @@ -229,7 +230,8 @@ impl MultiAccountTransactionGenerator { &mut self, account_contract: FeatureContract, contract_address_salt: ContractAddressSalt, - ) { + ) -> AccountId { + let new_account_id = self.account_tx_generators.len(); let (account_tx_generator, _default_deploy_account_tx) = AccountTransactionGenerator::new( account_contract, self.nonce_manager.clone(), @@ -237,6 +239,7 @@ impl MultiAccountTransactionGenerator { false, ); self.account_tx_generators.push(account_tx_generator); + new_account_id } pub fn account_with_id_mut( diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index f8c340df04..49e9a0d60f 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -37,6 +37,9 @@ use starknet_sequencer_node::config::test_utils::RequiredParams; use starknet_state_sync::config::StateSyncConfig; use starknet_types_core::felt::Felt; +pub const ACCOUNT_ID_0: AccountId = 0; +pub const ACCOUNT_ID_1: AccountId = 1; + 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 @@ -156,9 +159,6 @@ pub fn create_integration_test_tx_generator() -> MultiAccountTransactionGenerato pub fn create_txs_for_integration_test( tx_generator: &mut MultiAccountTransactionGenerator, ) -> Vec { - const ACCOUNT_ID_0: AccountId = 0; - const ACCOUNT_ID_1: AccountId = 1; - // Create RPC transactions. let account0_invoke_nonce1 = tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_invoke_with_tip(2); 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 4d29c7b825..713990e08b 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 @@ -1,5 +1,7 @@ use std::collections::HashSet; +use blockifier::test_utils::contracts::FeatureContract; +use blockifier::test_utils::{CairoVersion, RunnableCairo1}; use futures::StreamExt; use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator; use papyrus_consensus::types::ValidatorId; @@ -15,6 +17,8 @@ use papyrus_storage::test_utils::CHAIN_ID_FOR_TESTS; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; use starknet_api::block::{BlockHash, BlockNumber}; +use starknet_api::rpc_transaction::RpcTransaction; +use starknet_api::transaction::fields::ContractAddressSalt; use starknet_api::transaction::TransactionHash; use starknet_integration_tests::flow_test_setup::{FlowTestSetup, SequencerSetup}; use starknet_integration_tests::utils::{ @@ -22,13 +26,15 @@ use starknet_integration_tests::utils::{ create_txs_for_integration_test, run_integration_test_scenario, test_tx_hashes_for_integration_test, + ACCOUNT_ID_0, }; use starknet_sequencer_infra::trace_util::configure_tracing; use starknet_types_core::felt::Felt; use tracing::debug; const INITIAL_HEIGHT: BlockNumber = BlockNumber(0); -const LAST_HEIGHT: BlockNumber = BlockNumber(2); +const LAST_HEIGHT: BlockNumber = BlockNumber(3); +const NEW_ACCOUNT_SALT: ContractAddressSalt = ContractAddressSalt(Felt::THREE); #[fixture] fn tx_generator() -> MultiAccountTransactionGenerator { @@ -60,6 +66,9 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) { Felt::from_hex_unchecked( "0x572373fe992ac8c2413d5e727036316023ed6a2e8a2256b4952e223969e0221", ), + Felt::from_hex_unchecked( + "0x36e1f3e0c71b77474494a5baa0a04a4e406626141eba2b2944e4b568f70ff48", + ), ]; let sequencers = [&mock_running_system.sequencer_0, &mock_running_system.sequencer_1]; @@ -70,10 +79,10 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) { expected_proposer_iter.next().unwrap(); let create_rpc_txs_scenarios = - [create_txs_for_integration_test, create_txs_for_integration_test]; + [create_txs_for_integration_test, create_txs_for_integration_test, fund_new_account]; let test_tx_hashes_scenarios = - [test_tx_hashes_for_integration_test, test_tx_hashes_for_integration_test]; + [test_tx_hashes_for_integration_test, test_tx_hashes_for_integration_test, test_funding]; assert_eq!( n_heights, @@ -222,3 +231,20 @@ async fn listen_to_broadcasted_messages( "Unexpected transactions" ); } + +fn fund_new_account(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec { + let new_account_id = tx_generator.register_undeployed_account( + FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)), + NEW_ACCOUNT_SALT, + ); + + let to = tx_generator.account_with_id(new_account_id).account; + + let funding_tx = tx_generator.account_with_id_mut(ACCOUNT_ID_0).generate_transfer(&to); + vec![funding_tx] +} + +fn test_funding(tx_hashes: &[TransactionHash]) -> Vec{ + assert_eq!(tx_hashes.len(), 1, "Expected a single transaction"); + tx_hashes.to_vec() +}