Skip to content

Commit

Permalink
feat(host): add test for v1, prunning and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Aug 20, 2024
1 parent 70115b7 commit dc448d2
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion host/src/server/api/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl IntoResponse for CancelStatus {
}
}

#[derive(Debug, Serialize, ToSchema)]
#[derive(Debug, Serialize, ToSchema, Deserialize)]
#[serde(tag = "status", rename_all = "lowercase")]
/// Status of prune request.
/// Can be `ok` for a successful prune or `error` with message and error type for errors.
Expand Down
33 changes: 32 additions & 1 deletion host/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use raiko_host::{
server::{
api::{
v1::Status as StatusV1,
v2::{CancelStatus, Status},
v2::{CancelStatus, PruneStatus, Status},
},
serve,
},
ProverState,
};
use raiko_lib::consts::{Network, SupportedChainSpecs};
use raiko_tasks::{TaskDescriptor, TaskStatus};
use serde::Deserialize;
use tokio_util::sync::CancellationToken;

Expand Down Expand Up @@ -142,6 +143,36 @@ impl ProofClient {
Err(anyhow::anyhow!("Failed to send proof request"))
}
}

pub async fn prune_proof(&self) -> anyhow::Result<PruneStatus> {
let response = self
.reqwest_client
.post(&format!("{URL}/v2/proof/prune"))
.send()
.await?;

if response.status().is_success() {
let prune_response = response.json::<PruneStatus>().await?;
Ok(prune_response)
} else {
Err(anyhow::anyhow!("Failed to send proof request"))
}
}

pub async fn report_proof(&self) -> anyhow::Result<Vec<(TaskDescriptor, TaskStatus)>> {
let response = self
.reqwest_client
.get(&format!("{URL}/v2/proof/report"))
.send()
.await?;

if response.status().is_success() {
let report_response = response.json::<Vec<(TaskDescriptor, TaskStatus)>>().await?;
Ok(report_response)
} else {
Err(anyhow::anyhow!("Failed to send proof request"))
}
}
}

/// Start the Raiko server and return a cancellation token that can be used to stop the server.
Expand Down
53 changes: 51 additions & 2 deletions host/tests/proof_request.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use common::{find_recent_block, start_raiko};
use raiko_core::interfaces::{ProofRequestOpt, ProverSpecificOpts};
use raiko_host::server::api::v2::{CancelStatus, ProofResponse, Status};
use raiko_host::server::api::{
v1,
v2::{self, CancelStatus, ProofResponse, Status},
};
use raiko_lib::consts::Network;
use raiko_tasks::TaskStatus;

use common::{find_recent_block, start_raiko};

mod common;

#[tokio::test]
Expand Down Expand Up @@ -39,6 +43,22 @@ async fn send_proof_request() {
},
};

// Test v1 API interface.
let response = client
.send_proof_v1(request.clone())
.await
.expect("Failed to send proof request");

assert!(
matches!(
response,
v1::Status::Ok {
data: v1::ProofResponse { .. }
}
),
"Got error response from server"
);

let response = client
.send_proof_v2(request.clone())
.await
Expand Down Expand Up @@ -72,6 +92,8 @@ async fn send_proof_request() {
data: ProofResponse::Status {
status: TaskStatus::WorkInProgress
}
} | Status::Ok {
data: ProofResponse::Proof { .. }
}
),
"Got incorrect response from server"
Expand Down Expand Up @@ -106,6 +128,33 @@ async fn send_proof_request() {
"Got error response from server"
);

// We should get a non empty report.
let response = client
.report_proof()
.await
.expect("Failed to report proof request");

assert!(!response.is_empty(), "Got empty report from server");

// Prune the proof requests.
let response = client
.prune_proof()
.await
.expect("Failed to prune proof request");

assert!(
matches!(response, v2::PruneStatus::Ok),
"Got error response from server"
);

// We should get an empty report.
let response = client
.report_proof()
.await
.expect("Failed to report proof request");

assert!(response.is_empty(), "Got non empty report from server");

// Cancel the server.
token.cancel();
}
2 changes: 1 addition & 1 deletion tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum TaskStatus {
SqlDbCorruption = -99999,
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct TaskDescriptor {
pub chain_id: ChainId,
pub blockhash: B256,
Expand Down

0 comments on commit dc448d2

Please sign in to comment.