Skip to content

Commit

Permalink
feat: test test_send_raw_transaction_rpc_forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
eugypalu committed Sep 12, 2024
1 parent ba45abf commit 53b5d6e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
41 changes: 40 additions & 1 deletion tests/tests/kakarot_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 53b5d6e

Please sign in to comment.