Skip to content

Commit 10d53ba

Browse files
apollo_storage: create storage_reader_server_test_utils (#10835)
* apollo_batcher: add StateDiffByBlockNumber request to the batcher * apollo_storage: create storage_reader_server_test_utils
1 parent dfed5a3 commit 10d53ba

4 files changed

Lines changed: 34 additions & 22 deletions

File tree

crates/apollo_storage/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license-file.workspace = true
77
description = "A storage implementation for a Starknet node."
88

99
[features]
10-
testing = ["starknet_api/testing", "tempfile"]
10+
testing = ["starknet_api/testing", "tempfile", "tower"]
1111

1212
[dependencies]
1313
apollo_config.workspace = true
@@ -36,6 +36,7 @@ starknet-types-core = { workspace = true, features = ["papyrus-serialization"] }
3636
starknet_api.workspace = true
3737
tempfile = { workspace = true, optional = true }
3838
thiserror.workspace = true
39+
tower = { workspace = true, optional = true }
3940
tracing = { workspace = true, features = ["log"] }
4041
validator = { workspace = true, features = ["derive"] }
4142
zstd.workspace = true

crates/apollo_storage/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ mod open_storage_test;
109109
#[cfg(any(feature = "testing", test))]
110110
pub mod test_utils;
111111

112+
#[cfg(any(feature = "testing", test))]
113+
pub mod storage_reader_server_test_utils;
114+
112115
use std::collections::{BTreeMap, HashMap};
113116
use std::fmt::Debug;
114117
use std::fs;

crates/apollo_storage/src/storage_reader_server_test.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use std::net::{IpAddr, Ipv4Addr};
22

33
use async_trait::async_trait;
4-
use axum::body::{Body, Bytes, HttpBody};
4+
use axum::body::Body;
55
use axum::http::{Request, StatusCode};
6-
use axum::response::Response;
7-
use axum::Router;
86
use pretty_assertions::assert_eq;
97
use serde::{Deserialize, Serialize};
108
use starknet_api::block::{BlockHeader, BlockNumber};
119
use tower::ServiceExt;
1210

1311
use crate::header::{HeaderStorageReader, HeaderStorageWriter};
1412
use crate::storage_reader_server::{ServerConfig, StorageReaderServer, StorageReaderServerHandler};
13+
use crate::storage_reader_server_test_utils::{send_storage_query, to_bytes};
1514
use crate::test_utils::get_test_storage;
1615
use crate::{StorageError, StorageReader};
1716

@@ -109,19 +108,6 @@ async fn test_endpoint_query_nonexistent_block() {
109108
assert!(!test_response.found);
110109
}
111110

112-
async fn send_storage_query<T: Serialize>(app: Router, request: &T) -> Response {
113-
app.oneshot(
114-
Request::builder()
115-
.method("POST")
116-
.uri("/storage/query")
117-
.header("content-type", "application/json")
118-
.body(Body::from(serde_json::to_string(request).unwrap()))
119-
.unwrap(),
120-
)
121-
.await
122-
.unwrap()
123-
}
124-
125111
#[tokio::test]
126112
async fn test_endpoint_handler_error() {
127113
let ((reader, _writer), _temp_dir) = get_test_storage();
@@ -169,8 +155,3 @@ async fn test_endpoint_invalid_json() {
169155
// Should return error status code
170156
assert!(!response.status().is_success());
171157
}
172-
173-
// Helper function to convert response body to bytes
174-
async fn to_bytes(res: Response) -> Bytes {
175-
res.into_body().collect().await.unwrap().to_bytes()
176-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Test utilities for storage reader server testing.
2+
3+
use axum::body::{Body, Bytes, HttpBody};
4+
use axum::http::Request;
5+
use axum::response::Response;
6+
use axum::Router;
7+
use serde::Serialize;
8+
use tower::ServiceExt;
9+
10+
/// Helper function to send a storage query request.
11+
pub async fn send_storage_query<T: Serialize>(app: Router, request: &T) -> Response {
12+
app.oneshot(
13+
Request::builder()
14+
.method("POST")
15+
.uri("/storage/query")
16+
.header("content-type", "application/json")
17+
.body(Body::from(serde_json::to_string(request).unwrap()))
18+
.unwrap(),
19+
)
20+
.await
21+
.unwrap()
22+
}
23+
24+
/// Helper function to convert response body to bytes.
25+
pub async fn to_bytes(res: Response) -> Bytes {
26+
res.into_body().collect().await.unwrap().to_bytes()
27+
}

0 commit comments

Comments
 (0)