-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_integration_tests): sequencer simulator binary
commit-id:9e5db078
- Loading branch information
1 parent
d8f1e98
commit 7210400
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
crates/starknet_integration_tests/src/bin/sequencer_simulator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::env::args; | ||
|
||
use mempool_test_utils::starknet_api_test_utils::AccountId; | ||
use starknet_api::block::BlockNumber; | ||
use starknet_integration_tests::sequencer_simulator_utils::SequencerSimulator; | ||
use starknet_integration_tests::utils::{ | ||
create_integration_test_tx_generator, | ||
BootstrapTxs, | ||
InvokeTxs, | ||
}; | ||
use starknet_sequencer_infra::trace_util::configure_tracing; | ||
use tracing::info; | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
configure_tracing().await; | ||
|
||
// TODO(Tsabary): remove the hook definition once we transition to proper usage of task | ||
// spawning. | ||
let default_panic = std::panic::take_hook(); | ||
std::panic::set_hook(Box::new(move |info| { | ||
default_panic(info); | ||
std::process::exit(1); | ||
})); | ||
const SENDER_ACCOUNT: AccountId = 0; | ||
const EXPECTED_BLOCK_NUMBER: BlockNumber = BlockNumber(10); | ||
const BLOCK_TO_WAIT_FOR_BOOTSTRAP: BlockNumber = BlockNumber(2); | ||
const N_TXS: usize = 50; | ||
|
||
let mut tx_generator = create_integration_test_tx_generator(); | ||
|
||
let sequencer_simulator = SequencerSimulator::new(args().collect()); | ||
|
||
info!("Sending bootstrap txs"); | ||
sequencer_simulator.send_txs(&mut tx_generator, &BootstrapTxs, SENDER_ACCOUNT).await; | ||
|
||
sequencer_simulator.await_execution(BLOCK_TO_WAIT_FOR_BOOTSTRAP).await; | ||
|
||
sequencer_simulator.send_txs(&mut tx_generator, &InvokeTxs(N_TXS), SENDER_ACCOUNT).await; | ||
|
||
sequencer_simulator.await_execution(EXPECTED_BLOCK_NUMBER).await; | ||
|
||
// TODO(Nadin): verfy txs are accepted. | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
crates/starknet_integration_tests/src/sequencer_simulator_utils.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::net::SocketAddr; | ||
|
||
use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator}; | ||
use starknet_api::block::BlockNumber; | ||
use starknet_api::rpc_transaction::RpcTransaction; | ||
use starknet_api::transaction::TransactionHash; | ||
use starknet_http_server::config::HttpServerConfig; | ||
use starknet_http_server::test_utils::HttpTestClient; | ||
use starknet_monitoring_endpoint::config::MonitoringEndpointConfig; | ||
use starknet_monitoring_endpoint::test_utils::MonitoringClient; | ||
use starknet_sequencer_node::utils::load_and_validate_config; | ||
use tracing::info; | ||
|
||
use crate::monitoring_utils::await_execution; | ||
use crate::utils::{send_account_txs, TestScenario}; | ||
|
||
pub struct SequencerSimulator { | ||
monitoring_client: MonitoringClient, | ||
http_client: HttpTestClient, | ||
} | ||
|
||
impl SequencerSimulator { | ||
pub fn new(args: Vec<String>) -> Self { | ||
let config = load_and_validate_config(args).expect("Failed to load and validate config"); | ||
|
||
let MonitoringEndpointConfig { ip, port, .. } = config.monitoring_endpoint_config; | ||
let monitoring_client = MonitoringClient::new(SocketAddr::from((ip, port))); | ||
|
||
let HttpServerConfig { ip, port } = config.http_server_config; | ||
let http_client = HttpTestClient::new(SocketAddr::from((ip, port))); | ||
|
||
Self { monitoring_client, http_client } | ||
} | ||
|
||
pub async fn assert_add_tx_success(&self, tx: RpcTransaction) -> TransactionHash { | ||
info!("Sending transaction: {:?}", tx); | ||
self.http_client.assert_add_tx_success(tx).await | ||
} | ||
|
||
pub async fn send_txs( | ||
&self, | ||
tx_generator: &mut MultiAccountTransactionGenerator, | ||
test_scenario: &impl TestScenario, | ||
sender_account: AccountId, | ||
) { | ||
info!("Sending transactions"); | ||
let send_rpc_tx_fn = &mut |tx| self.assert_add_tx_success(tx); | ||
let tx_hashes = | ||
send_account_txs(tx_generator, sender_account, test_scenario, send_rpc_tx_fn).await; | ||
assert_eq!(tx_hashes.len(), test_scenario.n_txs()); | ||
} | ||
|
||
pub async fn await_execution(&self, expected_block_number: BlockNumber) { | ||
await_execution(&self.monitoring_client, expected_block_number, 0, 0).await; | ||
} | ||
|
||
// TODO(Nadin): Implement this function. | ||
pub async fn verify_txs_accepted(&self) { | ||
unimplemented!(); | ||
} | ||
} |