Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make e2e test more deterministic #143

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/rbuilder/src/integration/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ impl Playground {
Ok(event)
}

pub fn rbuilder_rpc_url(&self) -> &str {
"http://localhost:8645"
}

pub fn el_url(&self) -> &str {
"http://localhost:8545"
}
Expand Down
21 changes: 18 additions & 3 deletions crates/rbuilder/src/integration/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod tests {

use alloy_network::TransactionBuilder;
use alloy_primitives::U256;
use alloy_provider::{Provider, ProviderBuilder};
use alloy_provider::{PendingTransactionBuilder, Provider, ProviderBuilder};
use alloy_rpc_types::TransactionRequest;
use std::str::FromStr;
use test_utils::ignore_if_env_not_set;
Expand All @@ -13,6 +13,7 @@ mod tests {
#[ignore_if_env_not_set("PLAYGROUND_DIR")] // TODO: Change with a custom macro (i.e ignore_if_not_playground)
#[tokio::test]
async fn test_simple_example() {
// This test sends a transaction ONLY to the builder and waits for the block to be built with it.
let srv = Playground::new().unwrap();
srv.wait_for_next_slot().await.unwrap();

Expand All @@ -30,9 +31,23 @@ mod tests {
.with_gas_price(gas_price)
.with_gas_limit(21000);

let pending_tx = provider.send_transaction(tx).await.unwrap();
let receipt = pending_tx.get_receipt().await.unwrap();
let tx = provider.fill(tx).await.unwrap();

// send the transaction ONLY to the builder
let rbuilder_provider =
ProviderBuilder::new().on_http(Url::parse(srv.rbuilder_rpc_url()).unwrap());
let pending_tx = rbuilder_provider
.send_tx_envelope(tx.as_envelope().unwrap().clone())
.await
.unwrap();

// wait for the transaction in the el node since rbuilder does not implement
// the `eth_getTransactionReceipt` method.
let binding = ProviderBuilder::new().on_http(Url::parse(srv.el_url()).unwrap());
let pending_tx = PendingTransactionBuilder::new(&binding, *pending_tx.tx_hash())
.with_timeout(Some(std::time::Duration::from_secs(60)));

let receipt = pending_tx.get_receipt().await.unwrap();
srv.validate_block_built(receipt.block_number.unwrap())
.await
.unwrap();
Expand Down
Loading