diff --git a/Cargo.lock b/Cargo.lock index 2af689eb0..e8842c353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1151,6 +1151,16 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "155a5a185e42c6b77ac7b88a15143d930a9e9727a5b7b77eed417404ab15c247" +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "assert_fs" version = "1.1.1" @@ -7373,6 +7383,7 @@ dependencies = [ "jsonrpsee 0.23.2", "katana-primitives", "mockall", + "mockito", "mongodb", "num-traits 0.2.19", "opentelemetry", @@ -8330,6 +8341,29 @@ dependencies = [ "syn 2.0.75", ] +[[package]] +name = "mockito" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b34bd91b9e5c5b06338d392463e1318d683cf82ec3d3af4014609be6e2108d" +dependencies = [ + "assert-json-diff", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.4.1", + "hyper-util", + "log", + "rand 0.8.5", + "regex", + "serde_json", + "serde_urlencoded", + "similar", + "tokio", +] + [[package]] name = "modular-bitfield" version = "0.11.2" @@ -12927,6 +12961,12 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "similar" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" + [[package]] name = "simple_asn1" version = "0.6.2" diff --git a/Cargo.toml b/Cargo.toml index 7b2e4263a..6b24b4162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -161,6 +161,7 @@ katana-primitives = { git = 'https://github.com/dojoengine/dojo', tag = "v1.0.0- "serde", ], optional = true } mockall = { version = "0.13.0", default-features = false, optional = true } +mockito = { version = "1.5.0", default-features = false, optional = true } [patch.crates-io] starknet-core = { git = "https://github.com/kariy/starknet-rs", branch = "dojo-patch" } diff --git a/tests/tests/kakarot_api.rs b/tests/tests/kakarot_api.rs index 429ff0e70..55d84cdec 100644 --- a/tests/tests/kakarot_api.rs +++ b/tests/tests/kakarot_api.rs @@ -12,10 +12,49 @@ use kakarot_rpc::{ rpc::{start_kakarot_rpc_server, RawRpcParamsBuilder}, }, }; +use mockito::Server; use reth_primitives::{sign_message, Address, Bytes, Transaction, TransactionSigned, TxEip1559, TxKind, B256, U256}; use rstest::*; use serde_json::Value; -use std::str::FromStr; +use std::{env, str::FromStr}; + +#[cfg(feature = "rpc_forwarding")] +#[rstest] +#[awt] +#[tokio::test(flavor = "multi_thread")] +async fn test_send_raw_transaction_rpc_forwarding(#[future] katana: Katana, _setup: ()) { + let mut server = Server::new(); + let mock_server = server + .mock("POST", "/") + .with_status(200) + .with_header("content-type", "application/json") + .with_body( + r#"{"jsonrpc":"2.0","id":1,"result":"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"}"#, + ) + .create(); + + let (_, _) = start_kakarot_rpc_server(&katana).await.expect("Error setting up Kakarot RPC server"); + + // Set the MAIN_RPC_URL environment variable + env::set_var("MAIN_RPC_URL", server.url()); + drop(server); + + let eth_client = katana.eth_client(); + + // Create a sample raw transaction + let raw_tx = Bytes::from(vec![1, 2, 3, 4]); + + // Call the function + let result = eth_client.send_raw_transaction(raw_tx).await; + + // Assert the result + assert!(result.is_ok()); + let tx_hash = result.unwrap(); + assert_eq!(tx_hash, B256::from_str("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef").unwrap()); + + // Verify that the mock was called + mock_server.assert(); +} #[rstest] #[awt]