Migrate execution_engine_integration to alloy (#8140)

#6022


  Migrate the `execution_engine_integration`  tests to the `alloy` ecosystem. This removes the last remaining `ethers` dependencies


Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
Mac L
2025-11-12 08:43:19 +04:00
committed by GitHub
parent 53e73fa376
commit fff248d41b
6 changed files with 546 additions and 1058 deletions

View File

@@ -7,12 +7,13 @@ edition = { workspace = true }
portable = ["types/portable"]
[dependencies]
alloy-network = "1.0"
alloy-primitives = { workspace = true }
alloy-provider = "1.0"
alloy-rpc-types-eth = { workspace = true }
alloy-signer-local = "1.0"
async-channel = { workspace = true }
deposit_contract = { workspace = true }
ethers-core = { workspace = true }
ethers-middleware = { workspace = true }
ethers-providers = { workspace = true }
ethers-signers = { workspace = true }
execution_layer = { workspace = true }
fork_choice = { workspace = true }
futures = { workspace = true }

View File

@@ -1,6 +1,7 @@
use ethers_providers::{Http, Provider};
use alloy_provider::ProviderBuilder;
use execution_layer::DEFAULT_JWT_FILE;
use network_utils::unused_port::unused_tcp4_port;
use reqwest::Url;
use sensitive_url::SensitiveUrl;
use std::path::PathBuf;
use std::process::Child;
@@ -34,7 +35,7 @@ pub struct ExecutionEngine<E> {
http_port: u16,
http_auth_port: u16,
child: Child,
pub provider: Provider<Http>,
pub provider: Box<dyn alloy_provider::Provider + Send + Sync>,
}
impl<E> Drop for ExecutionEngine<E> {
@@ -53,8 +54,9 @@ impl<E: GenericExecutionEngine> ExecutionEngine<E> {
let http_port = unused_tcp4_port().unwrap();
let http_auth_port = unused_tcp4_port().unwrap();
let child = E::start_client(&datadir, http_port, http_auth_port, jwt_secret_path);
let provider = Provider::<Http>::try_from(format!("http://localhost:{}", http_port))
.expect("failed to instantiate ethers provider");
let provider = Box::new(ProviderBuilder::new().connect_http(
Url::parse(&format!("http://localhost:{}", http_port)).expect("failed to parse URL"),
));
Self {
engine,
datadir,

View File

@@ -2,9 +2,10 @@ use crate::execution_engine::{
ACCOUNT1, ACCOUNT2, ExecutionEngine, GenericExecutionEngine, KEYSTORE_PASSWORD, PRIVATE_KEYS,
};
use crate::transactions::transactions;
use ethers_middleware::SignerMiddleware;
use ethers_providers::Middleware;
use ethers_signers::LocalWallet;
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::Address as AlloyAddress;
use alloy_provider::{Provider, ProviderBuilder};
use alloy_signer_local::PrivateKeySigner;
use execution_layer::test_utils::DEFAULT_GAS_LIMIT;
use execution_layer::{
BlockProposalContentsType, BuilderParams, ChainHealth, ExecutionLayer, PayloadAttributes,
@@ -202,12 +203,13 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
self.wait_until_synced().await;
// Create a local signer in case we need to sign transactions locally
let wallet1: LocalWallet = PRIVATE_KEYS[0].parse().expect("Invalid private key");
let signer = SignerMiddleware::new(&self.ee_a.execution_engine.provider, wallet1);
let private_key_signer: PrivateKeySigner =
PRIVATE_KEYS[0].parse().expect("Invalid private key");
let wallet = EthereumWallet::from(private_key_signer);
// We hardcode the accounts here since some EEs start with a default unlocked account
let account1 = ethers_core::types::Address::from_slice(&hex::decode(ACCOUNT1).unwrap());
let account2 = ethers_core::types::Address::from_slice(&hex::decode(ACCOUNT2).unwrap());
let account1 = AlloyAddress::from_slice(&hex::decode(ACCOUNT1).unwrap());
let account2 = AlloyAddress::from_slice(&hex::decode(ACCOUNT2).unwrap());
/*
* Read the terminal block hash from both pairs, check it's equal.
@@ -237,11 +239,18 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
if self.use_local_signing {
// Sign locally with the Signer middleware
for (i, tx) in txs.clone().into_iter().enumerate() {
for (i, mut tx) in txs.clone().into_iter().enumerate() {
// The local signer uses eth_sendRawTransaction, so we need to manually set the nonce
let mut tx = tx.clone();
tx.set_nonce(i as u64);
let pending_tx = signer.send_transaction(tx, None).await.unwrap();
tx = tx.with_nonce(i as u64);
let wallet_provider = ProviderBuilder::new().wallet(wallet.clone()).connect_http(
self.ee_a
.execution_engine
.http_url()
.to_string()
.parse()
.unwrap(),
);
let pending_tx = wallet_provider.send_transaction(tx).await.unwrap();
pending_txs.push(pending_tx);
}
} else {
@@ -261,7 +270,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
.ee_a
.execution_engine
.provider
.send_transaction(tx, None)
.send_transaction(tx)
.await
.unwrap();
pending_txs.push(pending_tx);
@@ -446,11 +455,10 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
// Verify that all submitted txs were successful
for pending_tx in pending_txs {
let tx_receipt = pending_tx.await.unwrap().unwrap();
assert_eq!(
tx_receipt.status,
Some(1.into()),
"Tx index {} has invalid status ",
let tx_receipt = pending_tx.get_receipt().await.unwrap();
assert!(
tx_receipt.status(),
"Tx index {:?} has invalid status ",
tx_receipt.transaction_index
);
}

View File

@@ -1,8 +1,7 @@
use alloy_network::TransactionBuilder;
use alloy_primitives::{Address, U256};
use alloy_rpc_types_eth::{AccessList, TransactionRequest};
use deposit_contract::{BYTECODE, CONTRACT_DEPLOY_GAS, DEPOSIT_GAS, encode_eth1_tx_data};
use ethers_core::types::{
Address, Bytes, Eip1559TransactionRequest, TransactionRequest, U256,
transaction::{eip2718::TypedTransaction, eip2930::AccessList},
};
use types::{DepositData, EthSpec, FixedBytesExtended, Hash256, Keypair, Signature};
/// Hardcoded deposit contract address based on sender address and nonce
@@ -21,7 +20,7 @@ pub enum Transaction {
}
/// Get a list of transactions to publish to the execution layer.
pub fn transactions<E: EthSpec>(account1: Address, account2: Address) -> Vec<TypedTransaction> {
pub fn transactions<E: EthSpec>(account1: Address, account2: Address) -> Vec<TransactionRequest> {
vec![
Transaction::Transfer(account1, account2).transaction::<E>(),
Transaction::TransferLegacy(account1, account2).transaction::<E>(),
@@ -29,7 +28,7 @@ pub fn transactions<E: EthSpec>(account1: Address, account2: Address) -> Vec<Typ
Transaction::DeployDepositContract(account1).transaction::<E>(),
Transaction::DepositDepositContract {
sender: account1,
deposit_contract_address: ethers_core::types::Address::from_slice(
deposit_contract_address: Address::from_slice(
&hex::decode(DEPOSIT_CONTRACT_ADDRESS).unwrap(),
),
}
@@ -38,33 +37,36 @@ pub fn transactions<E: EthSpec>(account1: Address, account2: Address) -> Vec<Typ
}
impl Transaction {
pub fn transaction<E: EthSpec>(&self) -> TypedTransaction {
pub fn transaction<E: EthSpec>(&self) -> TransactionRequest {
match &self {
Self::TransferLegacy(from, to) => TransactionRequest::new()
Self::TransferLegacy(from, to) => TransactionRequest::default()
.from(*from)
.to(*to)
.value(1)
.into(),
Self::Transfer(from, to) => Eip1559TransactionRequest::new()
.value(U256::from(1))
.with_gas_price(1_000_000_000u128), // 1 gwei
Self::Transfer(from, to) => TransactionRequest::default()
.from(*from)
.to(*to)
.value(1)
.into(),
Self::TransferAccessList(from, to) => TransactionRequest::new()
.value(U256::from(1))
.with_max_fee_per_gas(2_000_000_000u128)
.with_max_priority_fee_per_gas(1_000_000_000u128),
Self::TransferAccessList(from, to) => TransactionRequest::default()
.from(*from)
.to(*to)
.value(1)
.value(U256::from(1))
.with_access_list(AccessList::default())
.into(),
.with_gas_price(1_000_000_000u128), // 1 gwei
Self::DeployDepositContract(addr) => {
let mut bytecode = String::from_utf8(BYTECODE.to_vec()).unwrap();
bytecode.retain(|c| c.is_ascii_hexdigit());
let bytecode = hex::decode(&bytecode[1..]).unwrap();
TransactionRequest::new()
let mut req = TransactionRequest::default()
.from(*addr)
.data(Bytes::from(bytecode))
.gas(CONTRACT_DEPLOY_GAS)
.into()
.with_input(bytecode)
.with_gas_limit(CONTRACT_DEPLOY_GAS.try_into().unwrap())
.with_gas_price(1_000_000_000u128); // 1 gwei
req.set_create();
req
}
Self::DepositDepositContract {
sender,
@@ -80,13 +82,13 @@ impl Transaction {
signature: Signature::empty().into(),
};
deposit.signature = deposit.create_signature(&keypair.sk, &E::default_spec());
TransactionRequest::new()
TransactionRequest::default()
.from(*sender)
.to(*deposit_contract_address)
.data(Bytes::from(encode_eth1_tx_data(&deposit).unwrap()))
.gas(DEPOSIT_GAS)
.value(U256::from(amount) * U256::exp10(9))
.into()
.with_input(encode_eth1_tx_data(&deposit).unwrap())
.with_gas_limit(DEPOSIT_GAS.try_into().unwrap())
.value(U256::from(amount) * U256::from(10).pow(U256::from(9)))
.with_gas_price(1_000_000_000u128) // 1 gwei
}
}
}