Skip to content

Commit

Permalink
Reenable test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Mar 19, 2024
1 parent 11c8326 commit 15ce646
Showing 1 changed file with 67 additions and 40 deletions.
107 changes: 67 additions & 40 deletions tests/send_too_many_txs.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,92 @@
mod common;

use tx_sitter::client::ClientError;
use tx_sitter::server::ApiError;
use tx_sitter::types::{RelayerUpdate, TransactionPriority};

use crate::common::prelude::*;

const MAX_QUEUED_TXS: usize = 20;

#[tokio::test]
async fn send_too_many_txs() -> eyre::Result<()> {
setup_tracing();

panic!("UNIMPLEMENTED!");

let (db_url, _db_container) = setup_db().await?;
let anvil = AnvilBuilder::default().spawn().await?;

let (_service, client) =
ServiceBuilder::default().build(&anvil, &db_url).await?;

let CreateApiKeyResponse { api_key } =
let CreateApiKeyResponse { api_key: _api_key } =
client.create_relayer_api_key(DEFAULT_RELAYER_ID).await?;

let CreateRelayerResponse {
relayer_id: secondary_relayer_id,
address: _secondary_relayer_address,
} = client
.create_relayer(&CreateRelayerRequest {
name: "Secondary Relayer".to_string(),
chain_id: DEFAULT_ANVIL_CHAIN_ID,
})
.await?;

let CreateApiKeyResponse {
api_key: secondary_api_key,
} = client.create_relayer_api_key(&secondary_relayer_id).await?;

// Set max queued txs
client
.update_relayer(
&secondary_relayer_id,
RelayerUpdate::default().with_max_queued_txs(MAX_QUEUED_TXS as u64),
)
.await?;

let provider = setup_provider(anvil.endpoint()).await?;

// Send a transaction
let value: U256 = parse_units("10", "ether")?.into();
let num_transfers = 10;

let mut tasks = FuturesUnordered::new();
for _ in 0..num_transfers {
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(())
});
}
let value: U256 = parse_units("0.01", "ether")?.into();

while let Some(result) = tasks.next().await {
let result: eyre::Result<()> = result;
result?;
for _ in 0..=MAX_QUEUED_TXS {
client
.send_tx(
&secondary_api_key,
&SendTxRequest {
to: ARBITRARY_ADDRESS,
value,
data: None,
gas_limit: U256::from(21_000),
priority: TransactionPriority::Regular,
tx_id: None,
},
)
.await?;
}

let expected_balance = value * num_transfers;
for _ in 0..50 {
let balance = provider.get_balance(ARBITRARY_ADDRESS, None).await?;
// Sending one more tx should fail
let result = client
.send_tx(
&secondary_api_key,
&SendTxRequest {
to: ARBITRARY_ADDRESS,
value,
data: None,
gas_limit: U256::from(21_000),
priority: TransactionPriority::Regular,
tx_id: None,
},
)
.await;

tracing::info!(?balance, ?expected_balance, "Checking balance");

if balance == expected_balance {
return Ok(());
} else {
tokio::time::sleep(Duration::from_secs(5)).await;
}
}
assert!(
matches!(
result,
Err(ClientError::TxSitter(ApiError::TooManyTransactions { .. }))
),
"Result {:?} should be too many transactions",
result
);

panic!("Transactions were not sent")
Ok(())
}

0 comments on commit 15ce646

Please sign in to comment.