Skip to content

Commit

Permalink
Internal: integration test for the execute+prove RPC endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Desenfans committed Nov 27, 2023
1 parent f7a5428 commit 1b0c97d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
24 changes: 23 additions & 1 deletion integration-tests/tests/test_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod tests {
use tonic::transport::{Endpoint, Uri};
use tower::service_fn;

use madara_prover_rpc_client::client::{execute_program, prove_execution};
use madara_prover_rpc_client::client::{execute_and_prove, execute_program, prove_execution};
use madara_prover_rpc_client::prover::prover_client::ProverClient;
use madara_prover_rpc_server::error::ServerError;
use madara_prover_rpc_server::{run_grpc_server, BindAddress};
Expand Down Expand Up @@ -96,4 +96,26 @@ mod tests {
let proof = result.unwrap();
assert_eq!(proof.proof_hex, test_case.proof.proof_hex);
}

#[rstest]
#[tokio::test]
async fn test_execute_and_prove(
#[future] rpc_client_server: (RpcClient, RpcServer),
#[from(parsed_prover_test_case)] test_case: ParsedProverTestCase,
) {
let (mut client, _server) = rpc_client_server.await;

let result = execute_and_prove(
&mut client,
test_case.compiled_program,
test_case.prover_config,
test_case.prover_parameters,
)
.await;

assert!(result.is_ok(), "{:?}", result);

let proof = result.unwrap();
assert_eq!(proof.proof_hex, test_case.proof.proof_hex);
}
}
10 changes: 0 additions & 10 deletions madara-prover-common/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ pub struct MemorySegmentAddresses {
pub stop_ptr: u32,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct MemorySegments {
pub program: MemorySegmentAddresses,
pub execution: MemorySegmentAddresses,
pub output: MemorySegmentAddresses,
pub pedersen: MemorySegmentAddresses,
pub range_check: MemorySegmentAddresses,
pub ecdsa: MemorySegmentAddresses,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct PublicMemoryEntry {
pub address: u32,
Expand Down
4 changes: 3 additions & 1 deletion madara-prover-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ impl Prover for ProverService {
let prover_parameters: ProverParameters = serde_json::from_str(&prover_parameters_str)
.map_err(|_| Status::invalid_argument("Could not read prover parameters"))?;

let execution_artifacts = run_cairo_program_in_proof_mode(&program)
let execution_artifacts = run_cairo_program_in_proof_mode(&program);
let execution_artifacts = execution_artifacts
.map_err(|e| Status::internal(format!("Failed to run program: {e}")))?;

let prover_result =
call_prover(&execution_artifacts, &prover_config, &prover_parameters).await;

Expand Down
9 changes: 9 additions & 0 deletions test-fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub fn read_proof_file<P: AsRef<Path>>(proof_file: P) -> Proof {

/// All the files forming a complete prover test case.
pub struct ProverTestCase {
pub program_file: PathBuf,
pub compiled_program_file: PathBuf,
pub public_input_file: PathBuf,
pub prover_config_file: PathBuf,
pub prover_parameter_file: PathBuf,
Expand All @@ -39,6 +41,8 @@ pub struct ProverTestCase {

#[fixture]
pub fn fibonacci() -> ProverTestCase {
let program_file = get_test_case_file_path("fibonacci/fibonacci.cairo");
let compiled_program_file = get_test_case_file_path("fibonacci/fibonacci_compiled.json");
let public_input_file = get_test_case_file_path("fibonacci/fibonacci_public_input.json");
let prover_config_file = get_test_case_file_path("fibonacci/cpu_air_prover_config.json");
let prover_parameter_file = get_test_case_file_path("fibonacci/cpu_air_params.json");
Expand All @@ -47,6 +51,8 @@ pub fn fibonacci() -> ProverTestCase {
let proof_file = get_test_case_file_path("fibonacci/fibonacci_proof.json");

ProverTestCase {
program_file,
compiled_program_file,
public_input_file,
prover_config_file,
prover_parameter_file,
Expand Down Expand Up @@ -97,6 +103,7 @@ pub fn prover_cli_test_case(#[from(fibonacci)] files: ProverTestCase) -> ProverC
}

pub struct ParsedProverTestCase {
pub compiled_program: Vec<u8>,
pub public_input: PublicInput,
pub memory: Vec<u8>,
pub trace: Vec<u8>,
Expand All @@ -107,6 +114,7 @@ pub struct ParsedProverTestCase {

#[fixture]
pub fn parsed_prover_test_case(#[from(fibonacci)] files: ProverTestCase) -> ParsedProverTestCase {
let compiled_program = std::fs::read(files.compiled_program_file).unwrap();
let public_input: PublicInput = read_json_from_file(files.public_input_file).unwrap();
let prover_config: ProverConfig = read_json_from_file(files.prover_config_file).unwrap();
let prover_parameters: ProverParameters =
Expand All @@ -117,6 +125,7 @@ pub fn parsed_prover_test_case(#[from(fibonacci)] files: ProverTestCase) -> Pars
let proof = read_proof_file(&files.proof_file);

ParsedProverTestCase {
compiled_program,
public_input,
memory,
trace,
Expand Down

0 comments on commit 1b0c97d

Please sign in to comment.