summaryrefslogtreecommitdiffstats
path: root/src/remake
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 21:36:09 +0100
committertv <tv@krebsco.de>2026-10-26 21:36:09 +0100
commit137b1547f847ff2402ea9e634b64ee2196a75075 (patch)
treec6bce410e1c8cb2434be268275220df2afa18fdb /src/remake
parentf1f367d1e2438c87e1e90df14d56aa10f2bd7b8b (diff)
add remake tests on the simulator
Diffstat (limited to 'src/remake')
-rw-r--r--src/remake/api.rs55
-rw-r--r--src/remake/mod.rs2
2 files changed, 57 insertions, 0 deletions
diff --git a/src/remake/api.rs b/src/remake/api.rs
index 0c2ab10..309bdbd 100644
--- a/src/remake/api.rs
+++ b/src/remake/api.rs
@@ -1009,3 +1009,58 @@ pub(crate) async fn epochs<H: Host>(State(host): State<H>) -> Response {
}))
.into_response()
}
+
+/// For tests on the simulator (`simtest`): the remake endpoints without HTTP, answering
+/// with the status and the JSON body.
+#[cfg(test)]
+pub(crate) mod testing {
+ use super::*;
+
+ async fn into_json(response: Response) -> (StatusCode, JsonValue) {
+ let status = response.status();
+ let bytes = axum::body::to_bytes(response.into_body(), usize::MAX)
+ .await
+ .expect("response body");
+ (
+ status,
+ serde_json::from_slice(&bytes).unwrap_or(JsonValue::Null),
+ )
+ }
+
+ /// `POST /admin/remakes` with `body` and `?force=`.
+ pub(crate) async fn start<H: Host>(
+ host: H,
+ body: JsonValue,
+ force: Option<&str>,
+ ) -> (StatusCode, JsonValue) {
+ let query = StartQuery {
+ force: force.map(str::to_owned),
+ ..StartQuery::default()
+ };
+ let mut headers = HeaderMap::new();
+ headers.insert(
+ CONTENT_TYPE,
+ axum::http::HeaderValue::from_static("application/json"),
+ );
+ into_json(start_kind(host, query, &headers, Bytes::from(body.to_string())).await).await
+ }
+
+ /// `DELETE /admin/remakes/{id}` with `?force=`.
+ pub(crate) async fn abort<H: Host>(
+ host: H,
+ id: &str,
+ force: Option<&str>,
+ ) -> (StatusCode, JsonValue) {
+ let query = AbortQuery {
+ wait: false,
+ force: force.map(str::to_owned),
+ };
+ into_json(abort_by_id(host, id.to_owned(), query).await).await
+ }
+
+ /// `GET /admin/remakes/{id}`: the report, if the remake exists here.
+ pub(crate) async fn report<H: Host>(host: &H, id: &str) -> Option<JsonValue> {
+ let report = load_report(host, id).await?;
+ Some(serde_json::to_value(report).expect("report"))
+ }
+}
diff --git a/src/remake/mod.rs b/src/remake/mod.rs
index bd04de9..79e0a1b 100644
--- a/src/remake/mod.rs
+++ b/src/remake/mod.rs
@@ -32,6 +32,8 @@ pub(crate) mod snapshot;
mod switch;
mod vote;
+#[cfg(test)]
+pub(crate) use api::testing;
pub(crate) use kind::remake_genesis;
pub(crate) use local::RemakeState;
pub(crate) use switch::run_worker;