From 3764f02221708950a24823389f5d39c77f429fad Mon Sep 17 00:00:00 2001 From: Eugenio Paluello Date: Mon, 16 Sep 2024 16:36:54 +0200 Subject: [PATCH] fix: refactoring --- src/eth_rpc/servers/eth_rpc.rs | 10 +++------- src/providers/eth_provider/constant.rs | 7 +++++-- tests/tests/kakarot_api.rs | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/eth_rpc/servers/eth_rpc.rs b/src/eth_rpc/servers/eth_rpc.rs index e7ae5154c..b70caeca4 100644 --- a/src/eth_rpc/servers/eth_rpc.rs +++ b/src/eth_rpc/servers/eth_rpc.rs @@ -20,7 +20,7 @@ use starknet::providers::Provider; use std::sync::Arc; #[cfg(feature = "rpc_forwarding")] use { - crate::providers::eth_provider::{constant::MAIN_RPC_URL, error::EthereumDataFormatError}, + crate::providers::eth_provider::constant::MAIN_RPC_URL, alloy_provider::{Provider as provider_alloy, ProviderBuilder}, url::Url, }; @@ -264,12 +264,8 @@ where tracing::info!("Serving eth_sendRawTransaction"); #[cfg(feature = "rpc_forwarding")] { - let provider_builded = ProviderBuilder::new().on_http(Url::parse(&MAIN_RPC_URL).expect("invalid rpc url")); - - let tx_hash = provider_builded - .send_raw_transaction(&bytes) - .await - .map_err(|_| EthApiError::EthereumDataFormat(EthereumDataFormatError::TransactionConversion))?; + let provider = ProviderBuilder::new().on_http(Url::parse(MAIN_RPC_URL.as_ref()).unwrap()); + let tx_hash = provider.send_raw_transaction(&bytes).await.expect("failed to send transaction"); return Ok(*tx_hash.tx_hash()); } diff --git a/src/providers/eth_provider/constant.rs b/src/providers/eth_provider/constant.rs index 0edd95f7f..7e99efc0f 100644 --- a/src/providers/eth_provider/constant.rs +++ b/src/providers/eth_provider/constant.rs @@ -6,6 +6,7 @@ use std::{ str::FromStr, sync::{LazyLock, OnceLock}, }; +use url::Url; /// Maximum priority fee per gas pub static MAX_PRIORITY_FEE_PER_GAS: LazyLock = LazyLock::new(|| 0); @@ -79,5 +80,7 @@ pub mod hive { pub static DEPLOY_WALLET_NONCE: LazyLock>> = LazyLock::new(|| Arc::new(Mutex::new(Felt::ZERO))); } -pub static MAIN_RPC_URL: LazyLock = - LazyLock::new(|| std::env::var("MAIN_RPC_URL").expect("Missing MAIN_RPC_URL environment variable")); +pub static MAIN_RPC_URL: LazyLock = LazyLock::new(|| { + Url::parse(&std::env::var("MAIN_RPC_URL").expect("Missing MAIN_RPC_URL environment variable")) + .expect("Invalid MAIN_RPC_URL environment variable") +}); diff --git a/tests/tests/kakarot_api.rs b/tests/tests/kakarot_api.rs index e8ffcc36d..de155d57e 100644 --- a/tests/tests/kakarot_api.rs +++ b/tests/tests/kakarot_api.rs @@ -12,14 +12,14 @@ use reth_primitives::{sign_message, Address, Bytes, Transaction, TransactionSign use rstest::*; use serde_json::Value; use std::str::FromStr; -#[cfg(feature = "rpc_forwarding")] -use {mockito::Server, std::env}; #[cfg(feature = "rpc_forwarding")] #[rstest] #[awt] #[tokio::test(flavor = "multi_thread")] async fn test_send_raw_transaction_rpc_forwarding(#[future] katana: Katana, _setup: ()) { + use mockito::Server; + use std::env; let mut server = Server::new(); let mock_server = server .mock("POST", "/")