Skip to content

Commit

Permalink
Make transfers in tests more parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 12, 2023
1 parent fc36d12 commit 9139faf
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions tests/send_many_txs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod common;

use futures::stream::FuturesUnordered;
use futures::StreamExt;
use tx_sitter::server::routes::relayer::CreateApiKeyResponse;

use crate::common::prelude::*;
Expand Down Expand Up @@ -59,18 +61,29 @@ async fn send_many_txs() -> eyre::Result<()> {
let value: U256 = parse_units("10", "ether")?.into();
let num_transfers = 10;

let mut tasks = FuturesUnordered::new();
for _ in 0..num_transfers {
client
.send_tx(
&api_key,
&SendTxRequest {
to: ARBITRARY_ADDRESS,
value,
gas_limit: U256::from(21_000),
..Default::default()
},
)
.await?;
let client = &client;
tasks.push(async {
client
.send_tx(
&api_key,
&SendTxRequest {
to: ARBITRARY_ADDRESS,
value,
gas_limit: U256::from(21_000),
..Default::default()
},
)
.await?;

Ok(())
});
}

while let Some(result) = tasks.next().await {
let result: eyre::Result<()> = result;
result?;
}

let expected_balance = value * num_transfers;
Expand Down

0 comments on commit 9139faf

Please sign in to comment.