refactor tps test

This commit is contained in:
Sergio Chouhy 2025-10-28 16:43:13 -03:00
parent ad9ad8d1d3
commit 719a8dcafe
2 changed files with 98 additions and 85 deletions

View File

@ -16,7 +16,7 @@ use sequencer_runner::startup_sequencer;
use tempfile::TempDir; use tempfile::TempDir;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use crate::test_suite_map::prepare_function_map; use crate::test_suite_map::{prepare_function_map, tps_test};
#[macro_use] #[macro_use]
extern crate proc_macro_test_attribute; extern crate proc_macro_test_attribute;
@ -99,7 +99,6 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)
//So they are dropped and tempdirs will be dropped too, //So they are dropped and tempdirs will be dropped too,
} }
pub async fn main_tests_runner() -> Result<()> { pub async fn main_tests_runner() -> Result<()> {
env_logger::init(); env_logger::init();
@ -113,9 +112,12 @@ pub async fn main_tests_runner() -> Result<()> {
match test_name.as_str() { match test_name.as_str() {
"all" => { "all" => {
// Tests that use default config
for (_, fn_pointer) in function_map { for (_, fn_pointer) in function_map {
fn_pointer(home_dir.clone()).await; fn_pointer(home_dir.clone()).await;
} }
// Run TPS test with its own specific config
tps_test().await;
} }
_ => { _ => {
let fn_pointer = function_map.get(&test_name).expect("Unknown test name"); let fn_pointer = function_map.get(&test_name).expect("Unknown test name");

View File

@ -1,10 +1,17 @@
use std::{collections::HashMap, path::PathBuf, pin::Pin, time::Duration}; use anyhow::Result;
use std::{
collections::HashMap,
path::PathBuf,
pin::Pin,
time::{Duration, Instant},
};
use actix_web::dev::ServerHandle; use actix_web::dev::ServerHandle;
use common::sequencer_client::SequencerClient; use common::sequencer_client::SequencerClient;
use log::info; use log::info;
use nssa::{Address, ProgramDeploymentTransaction, program::Program}; use nssa::{Address, ProgramDeploymentTransaction, program::Program};
use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point}; use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point};
use sequencer_runner::startup_sequencer;
use tempfile::TempDir; use tempfile::TempDir;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use wallet::{ use wallet::{
@ -29,7 +36,10 @@ use wallet::{
}; };
use crate::{ use crate::{
fetch_privacy_preserving_tx, tps_test_utils::TpsTestManager, ACC_RECEIVER, ACC_RECEIVER_PRIVATE, ACC_SENDER, ACC_SENDER_PRIVATE, NSSA_PROGRAM_FOR_TEST_DATA_CHANGER, TIME_TO_WAIT_FOR_BLOCK_SECONDS ACC_RECEIVER, ACC_RECEIVER_PRIVATE, ACC_SENDER, ACC_SENDER_PRIVATE,
NSSA_PROGRAM_FOR_TEST_DATA_CHANGER, TIME_TO_WAIT_FOR_BLOCK_SECONDS,
fetch_privacy_preserving_tx, replace_home_dir_with_temp_dir_in_configs,
tps_test_utils::TpsTestManager,
}; };
use crate::{post_test, pre_test, verify_commitment_is_in_state}; use crate::{post_test, pre_test, verify_commitment_is_in_state};
@ -1572,84 +1582,85 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
function_map function_map
} }
//
// #[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
// async fn pre_tps_test( async fn pre_tps_test(
// test: &TpsTestManager, test: &TpsTestManager,
// ) -> Result<(ServerHandle, JoinHandle<Result<()>>, TempDir)> { ) -> Result<(ServerHandle, JoinHandle<Result<()>>, TempDir)> {
// info!("Generating tps test config"); info!("Generating tps test config");
// let mut sequencer_config = test.generate_tps_test_config(); let mut sequencer_config = test.generate_tps_test_config();
// info!("Done"); info!("Done");
//
// let temp_dir_sequencer = replace_home_dir_with_temp_dir_in_configs(&mut sequencer_config); let temp_dir_sequencer = replace_home_dir_with_temp_dir_in_configs(&mut sequencer_config);
//
// let (seq_http_server_handle, sequencer_loop_handle) = let (seq_http_server_handle, sequencer_loop_handle) =
// startup_sequencer(sequencer_config).await?; startup_sequencer(sequencer_config).await?;
//
// Ok(( Ok((
// seq_http_server_handle, seq_http_server_handle,
// sequencer_loop_handle, sequencer_loop_handle,
// temp_dir_sequencer, temp_dir_sequencer,
// )) ))
// } }
//
// pub async fn tps_test() {
// pub async fn tps_test() { let num_transactions = 300 * 5;
// let num_transactions = 300 * 5; let target_tps = 12;
// let target_tps = 12; let tps_test = TpsTestManager::new(target_tps, num_transactions);
// let tps_test = TpsTestManager::new(target_tps, num_transactions);
// let res = pre_tps_test(&tps_test);
// let res = pre_tps_test(&tps_test);
// let target_time = tps_test.target_time();
// let target_time = tps_test.target_time(); info!("Target time: {:?} seconds", target_time.as_secs());
// info!("Target time: {:?} seconds", target_time.as_secs()); let res = pre_tps_test(&tps_test).await.unwrap();
// let res = pre_tps_test(&tps_test).await.unwrap();
// let wallet_config = fetch_config().await.unwrap();
// let wallet_config = fetch_config().await.unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
// let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
// info!("TPS test begin");
// info!("TPS test begin"); let txs = tps_test.build_public_txs();
// let txs = tps_test.build_public_txs(); let now = Instant::now();
// let now = Instant::now();
// let mut tx_hashes = vec![];
// let mut tx_hashes = vec![]; for (i, tx) in txs.into_iter().enumerate() {
// for (i, tx) in txs.into_iter().enumerate() { let tx_hash = seq_client.send_tx_public(tx).await.unwrap().tx_hash;
// let tx_hash = seq_client.send_tx_public(tx).await.unwrap().tx_hash; info!("Sent tx {i}");
// info!("Sent tx {i}"); tx_hashes.push(tx_hash);
// tx_hashes.push(tx_hash); }
// }
// for (i, tx_hash) in tx_hashes.iter().enumerate() {
// for (i, tx_hash) in tx_hashes.iter().enumerate() { loop {
// loop { if now.elapsed().as_millis() > target_time.as_millis() {
// if now.elapsed().as_millis() > target_time.as_millis() { panic!("TPS test failed by timout");
// panic!("TPS test failed by timout"); }
// }
// let tx_obj = seq_client
// let tx_obj = seq_client .get_transaction_by_hash(tx_hash.clone())
// .get_transaction_by_hash(tx_hash.clone()) .await
// .await .inspect_err(|err| {
// .inspect_err(|err| { log::warn!(
// warn!("Failed to get transaction by hash {tx_hash:#?} with error: {err:#?}") "Failed to get transaction by hash {tx_hash:#?} with error: {err:#?}"
// }); )
// });
// if let Ok(tx_obj) = tx_obj
// && tx_obj.transaction.is_some() if let Ok(tx_obj) = tx_obj
// { && tx_obj.transaction.is_some()
// info!("Found tx {i} with hash {tx_hash}"); {
// break; info!("Found tx {i} with hash {tx_hash}");
// } break;
// } }
// } }
// let time_elapsed = now.elapsed().as_secs(); }
// let time_elapsed = now.elapsed().as_secs();
// info!("TPS test finished successfully");
// info!("Target TPS: {}", target_tps); info!("TPS test finished successfully");
// info!( info!("Target TPS: {}", target_tps);
// "Processed {} transactions in {}s", info!(
// tx_hashes.len(), "Processed {} transactions in {}s",
// time_elapsed tx_hashes.len(),
// ); time_elapsed
// info!("Target time: {:?}s", target_time.as_secs()); );
// info!("Target time: {:?}s", target_time.as_secs());
// post_test(res).await;
// } post_test(res).await;
}