-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests_integration): move http client test util
commit-id:2d145538
- Loading branch information
1 parent
18e06a7
commit 0da3e11
Showing
9 changed files
with
70 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::net::SocketAddr; | ||
|
||
use axum::body::Body; | ||
use mempool_test_utils::starknet_api_test_utils::rpc_tx_to_json; | ||
use reqwest::{Client, Response}; | ||
use starknet_api::rpc_transaction::RpcTransaction; | ||
use starknet_api::transaction::TransactionHash; | ||
use starknet_gateway_types::errors::GatewaySpecError; | ||
use starknet_sequencer_infra::test_utils::get_available_socket; | ||
|
||
use crate::config::HttpServerConfig; | ||
|
||
/// A test utility client for interacting with an http server. | ||
pub struct HttpTestClient { | ||
socket: SocketAddr, | ||
client: Client, | ||
} | ||
|
||
impl HttpTestClient { | ||
pub fn new(socket: SocketAddr) -> Self { | ||
let client = Client::new(); | ||
Self { socket, client } | ||
} | ||
|
||
pub async fn assert_add_tx_success(&self, rpc_tx: RpcTransaction) -> TransactionHash { | ||
let response = self.add_tx(rpc_tx).await; | ||
assert!(response.status().is_success()); | ||
|
||
response.json().await.unwrap() | ||
} | ||
|
||
// TODO: implement when usage eventually arises. | ||
pub async fn assert_add_tx_error(&self, _tx: RpcTransaction) -> GatewaySpecError { | ||
todo!() | ||
} | ||
|
||
// Prefer using assert_add_tx_success or other higher level methods of this client, to ensure | ||
// tests are boilerplate and implementation-detail free. | ||
pub async fn add_tx(&self, rpc_tx: RpcTransaction) -> Response { | ||
let tx_json = rpc_tx_to_json(&rpc_tx); | ||
self.client | ||
.post(format!("http://{}/add_tx", self.socket)) | ||
.header("content-type", "application/json") | ||
.body(Body::from(tx_json)) | ||
.send() | ||
.await | ||
.unwrap() | ||
} | ||
} | ||
|
||
pub async fn create_http_server_config() -> HttpServerConfig { | ||
// TODO(Tsabary): use ser_generated_param. | ||
let socket = get_available_socket().await; | ||
HttpServerConfig { ip: socket.ip(), port: socket.port() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters