Skip to content

Commit

Permalink
chore(tests_integration): extract sender address (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 authored Nov 19, 2024
1 parent 66bd6f0 commit b652ffa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
33 changes: 12 additions & 21 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,14 @@ fn create_txs_for_integration_test(
vec![account0_invoke_nonce1, account0_invoke_nonce2, account1_invoke_nonce1]
}

// TODO(Tsabary): Pass the contract address as a function parameter. Also rename the function to
// better reflect its purpose. Then, rename 'run_transaction_generator_test_scenario' accordingly.
fn create_txs_for_tx_generator_test_scenario(
fn create_account_txs(
mut tx_generator: MultiAccountTransactionGenerator,
account_id: AccountId,
n_txs: usize,
) -> (Vec<RpcTransaction>, ContractAddress) {
const ACCOUNT_ID_0: AccountId = 0;
let contract_address = tx_generator.account_with_id(ACCOUNT_ID_0).sender_address();

(
(0..n_txs)
.map(|_| tx_generator.account_with_id(ACCOUNT_ID_0).generate_invoke_with_tip(1))
.collect(),
contract_address,
)
) -> Vec<RpcTransaction> {
(0..n_txs)
.map(|_| tx_generator.account_with_id(account_id).generate_invoke_with_tip(1))
.collect()
}

async fn send_rpc_txs<'a, Fut>(
Expand Down Expand Up @@ -239,20 +232,18 @@ where
vec![tx_hashes[2], tx_hashes[0], tx_hashes[1]]
}

/// Creates and runs the many txs test scenario for the sequencer integration test. Returns
/// a list of transaction hashes, in the order they are expected to be in the mempool.
pub async fn run_transaction_generator_test_scenario<'a, Fut>(
/// Returns a list of the transaction hashes, in the order they are expected to be in the mempool.
pub async fn send_account_txs<'a, Fut>(
tx_generator: MultiAccountTransactionGenerator,
account_id: AccountId,
n_txs: usize,
send_rpc_tx_fn: &'a mut dyn FnMut(RpcTransaction) -> Fut,
) -> (Vec<TransactionHash>, ContractAddress)
) -> Vec<TransactionHash>
where
Fut: Future<Output = TransactionHash> + 'a,
{
let (rpc_txs, contract_address) =
create_txs_for_tx_generator_test_scenario(tx_generator, n_txs);
let tx_hashes = send_rpc_txs(rpc_txs, send_rpc_tx_fn).await;
(tx_hashes, contract_address)
let rpc_txs = create_account_txs(tx_generator, n_txs, account_id);
send_rpc_txs(rpc_txs, send_rpc_tx_fn).await
}

pub async fn create_gateway_config(chain_info: ChainInfo) -> GatewayConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use std::process::Stdio;
use std::time::Duration;

use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator};
use papyrus_execution::execution_utils::get_nonce_at;
use papyrus_storage::state::StateStorageReader;
use papyrus_storage::StorageReader;
Expand All @@ -12,10 +12,7 @@ use starknet_api::block::BlockNumber;
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::state::StateNumber;
use starknet_integration_tests::integration_test_setup::IntegrationTestSetup;
use starknet_integration_tests::utils::{
create_integration_test_tx_generator,
run_transaction_generator_test_scenario,
};
use starknet_integration_tests::utils::{create_integration_test_tx_generator, send_account_txs};
use starknet_sequencer_infra::trace_util::configure_tracing;
use starknet_types_core::felt::Felt;
use tokio::process::{Child, Command};
Expand Down Expand Up @@ -122,7 +119,7 @@ async fn await_block(

#[rstest]
#[tokio::test]
async fn test_end_to_end_integration(tx_generator: MultiAccountTransactionGenerator) {
async fn test_end_to_end_integration(mut tx_generator: MultiAccountTransactionGenerator) {
const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(15);

configure_tracing();
Expand All @@ -147,10 +144,11 @@ async fn test_end_to_end_integration(tx_generator: MultiAccountTransactionGenera
let send_rpc_tx_fn =
&mut |rpc_tx| integration_test_setup.add_tx_http_client.assert_add_tx_success(rpc_tx);

const ACCOUNT_ID_0: AccountId = 0;
let n_txs = 50;
let sender_address = tx_generator.account_with_id(ACCOUNT_ID_0).sender_address();
info!("Sending {n_txs} txs.");
let (tx_hashes, sender_address) =
run_transaction_generator_test_scenario(tx_generator, n_txs, send_rpc_tx_fn).await;
let tx_hashes = send_account_txs(tx_generator, ACCOUNT_ID_0, n_txs, send_rpc_tx_fn).await;

info!("Awaiting until {EXPECTED_BLOCK_NUMBER} blocks have been created.");

Expand Down

0 comments on commit b652ffa

Please sign in to comment.