Skip to content

Commit

Permalink
blocklist integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanCorDX committed Jan 30, 2025
1 parent d8f03c7 commit 7c0f89c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
13 changes: 13 additions & 0 deletions crates/rbuilder/src/integration/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ impl Playground {
matches!(self.builder.try_wait(), Ok(None))
}

pub fn blocklist_key(&self) -> EthereumWallet {
// Address: 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
let signer: PrivateKeySigner =
"5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"
.parse()
.unwrap();
EthereumWallet::from(signer)
}

pub fn blocklist_address(&self) -> Address {
address!("3C44CdDdB6a900fa2b585dd299e03d12FA4293BC")
}

pub async fn wait_for_next_slot(
&self,
) -> Result<PayloadAttributesEvent, Box<dyn std::error::Error>> {
Expand Down
86 changes: 68 additions & 18 deletions crates/rbuilder/src/integration/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,100 @@ mod tests {
use std::{path::PathBuf, str::FromStr, time::Duration};
use test_utils::ignore_if_env_not_set;
use url::Url;
#[ignore_if_env_not_set("PLAYGROUND")] // TODO: Change with a custom macro (i.e ignore_if_not_playground)
#[tokio::test]
async fn test_simple_example() {
let config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../crates/rbuilder/src/integration/test_data/config-playground.toml");

// This test sends a transaction ONLY to the builder and waits for the block to be built with it.
let srv = Playground::new(&config_path).unwrap();
srv.wait_for_next_slot().await.unwrap();
async fn send_transaction(
srv: &Playground,
private_key: alloy_network::EthereumWallet,
to: Option<alloy_primitives::Address>,
) -> eyre::Result<alloy_primitives::TxHash> {
let rbuilder_provider =
ProviderBuilder::new().on_http(Url::parse(srv.rbuilder_rpc_url()).unwrap());

// send a transfer to the builder
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(srv.prefunded_key())
.wallet(private_key)
.on_http(Url::parse(srv.el_url()).unwrap());

let gas_price = provider.get_gas_price().await.unwrap();
let gas_price = provider.get_gas_price().await?;

let tx = TransactionRequest::default()
.with_to(srv.builder_address())
.with_to(to.unwrap_or(srv.builder_address()))
.with_value(U256::from_str("10000000000000000000").unwrap())
.with_gas_price(gas_price)
.with_gas_limit(21000);

let tx = provider.fill(tx).await.unwrap();
let tx = provider.fill(tx).await?;

// 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?;

Ok(*pending_tx.tx_hash())
}

#[ignore_if_env_not_set("PLAYGROUND")] // TODO: Change with a custom macro (i.e ignore_if_not_playground)
#[tokio::test]
async fn test_simple_example() {
let config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../crates/rbuilder/src/integration/test_data/config-playground.toml");

// This test sends a transaction ONLY to the builder and waits for the block to be built with it.
let srv = Playground::new(&config_path).unwrap();
srv.wait_for_next_slot().await.unwrap();

// Send transaction using the helper function
let tx_hash = send_transaction(&srv, srv.prefunded_key(), None)
.await
.unwrap();

// wait for the transaction in the el node since rbuilder does not implement
// the `eth_getTransactionReceipt` method.
// Wait for receipt
let binding = ProviderBuilder::new().on_http(Url::parse(srv.el_url()).unwrap());
let pending_tx = PendingTransactionBuilder::new(binding, *pending_tx.tx_hash())
let pending_tx = PendingTransactionBuilder::new(binding.clone(), 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();

// Send a transaction with an account from the blocklist
// TODO: This should be a separated test but the integration framework does use fixed port numbers
// and we need to change it to use dynamic ports.
// Since we only send the transaction to the builder, it should never be included in the block.
{
srv.wait_for_next_slot().await.unwrap();
let tx_hash = send_transaction(&srv, srv.blocklist_key(), None)
.await
.unwrap();

// wait for 20 seconds
let pending_tx = PendingTransactionBuilder::new(binding.clone(), tx_hash)
.with_timeout(Some(std::time::Duration::from_secs(20)));

assert!(
pending_tx.get_receipt().await.is_err(),
"Expected transaction to fail since account is blocklisted"
);
}

// Second blocklist test, send a transaction from a non-blocklisted account to a blocklisted account
{
srv.wait_for_next_slot().await.unwrap();
let tx_hash =
send_transaction(&srv, srv.prefunded_key(), Some(srv.blocklist_address()))
.await
.unwrap();

// wait for 20 seconds
let pending_tx = PendingTransactionBuilder::new(binding, tx_hash)
.with_timeout(Some(std::time::Duration::from_secs(20)));

assert!(
pending_tx.get_receipt().await.is_err(),
"Expected transaction to fail since account is blocklisted"
);
}
}

#[ignore_if_env_not_set("PLAYGROUND")]
Expand Down
3 changes: 3 additions & 0 deletions crates/rbuilder/src/integration/test_data/blocklist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ live_builders = ["mgp-ordering"]
enabled_relays = ["playground"]
log_level = "info,rbuilder=debug"
coinbase_secret_key = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
blocklist_file_path = "./src/integration/test_data/blocklist.json"

0 comments on commit 7c0f89c

Please sign in to comment.