Skip to content
Merged
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
63 changes: 42 additions & 21 deletions crates/e2e-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,67 @@ use reth_primitives_traits::Account;
use reth_trie_common::{AccountProof, StorageProof};
use url::Url;

/// RPC endpoint URL for the replica node
static REPLICA_RPC: LazyLock<Url> = LazyLock::new(|| {
std::env::var("REPLICA_RPC")
.expect("failed to get REPLICA_RPC env var")
.expect("REPLICA_RPC environment variable is not set")
.parse()
.expect("failed to parse REPLICA_RPC env var")
.expect("REPLICA_RPC environment variable contains invalid URL")
});

/// RPC endpoint URL for the sequencer node
static SEQUENCER_RPC: LazyLock<Url> = LazyLock::new(|| {
std::env::var("SEQUENCER_RPC")
.expect("failed to get SEQUENCER_RPC env var")
.expect("SEQUENCER_RPC environment variable is not set")
.parse()
.expect("failed to parse SEQUENCER_RPC env var")
.expect("SEQUENCER_RPC environment variable contains invalid URL")
});

/// Test account private key
const TEST_PRIVATE_KEY: &str = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";

/// Default delegation address for testing
const DEFAULT_DELEGATION_ADDRESS: &str = "0x90f79bf6eb2c4f870365e785982e1f101e93b906";

/// Tests if the chain is advancing by checking block numbers
#[tokio::test]
async fn assert_chain_advances() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
return Ok(());
}

let block = ProviderBuilder::new().on_http(SEQUENCER_RPC.clone()).get_block_number().await?;
let provider = ProviderBuilder::new().on_http(SEQUENCER_RPC.clone());

let initial_block = provider.get_block_number().await?;

// Wait for new block
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
let new_block =
ProviderBuilder::new().on_http(SEQUENCER_RPC.clone()).get_block_number().await?;

let new_block = provider.get_block_number().await?;

assert!(new_block > block);
assert!(
new_block > initial_block,
"Chain did not advance: initial block {initial_block}, current block {new_block}"
);

Ok(())
}

/// Tests the wallet API functionality with EIP-7702 delegation
#[tokio::test]
async fn test_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
return Ok(());
}

let provider = ProviderBuilder::new().on_http(REPLICA_RPC.clone());
let signer = PrivateKeySigner::from_bytes(&b256!(
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;
let signer = PrivateKeySigner::from_bytes(&b256!(TEST_PRIVATE_KEY))?;

let delegation_address = Address::from_str(
&std::env::var("DELEGATION_ADDRESS")
.unwrap_or_else(|_| "0x90f79bf6eb2c4f870365e785982e1f101e93b906".to_string()),
)
.unwrap();
&std::env::var("DELEGATION_ADDRESS").unwrap_or_else(|_| DEFAULT_DELEGATION_ADDRESS.to_string()),
)?;

// Create and sign authorization
let auth = Authorization {
chain_id: provider.get_chain_id().await?,
address: delegation_address,
Expand All @@ -69,16 +83,20 @@ async fn test_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
let signature = signer.sign_hash_sync(&auth.signature_hash())?;
let auth = auth.into_signed(signature);

let tx =
TransactionRequest::default().with_authorization_list(vec![auth]).with_to(signer.address());
// Prepare and send transaction
let tx = TransactionRequest::default()
.with_authorization_list(vec![auth])
.with_to(signer.address());

let tx_hash: B256 = provider.client().request("wallet_sendTransaction", vec![tx]).await?;

let receipt = PendingTransactionBuilder::new(provider.clone(), tx_hash).get_receipt().await?;

assert!(receipt.status());
// Wait for and verify transaction receipt
let receipt = PendingTransactionBuilder::new(provider.clone(), tx_hash)
.get_receipt()
.await?;

assert!(!provider.get_code_at(signer.address()).await?.is_empty());
assert!(receipt.status(), "Transaction failed");
assert!(!provider.get_code_at(signer.address()).await?.is_empty(), "No code at signer address");

Ok(())
}
Expand Down Expand Up @@ -124,13 +142,16 @@ async fn test_new_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

/// Tests withdrawal proof functionality with fallback behavior
#[tokio::test]
async fn test_withdrawal_proof_with_fallback() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
return Ok(());
}

let provider = ProviderBuilder::new().on_http(REPLICA_RPC.clone());

// Get latest block for proof verification
let block: Block = provider
.client()
.request("eth_getBlockByNumber", (BlockNumberOrTag::Latest, false))
Expand Down