1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

add setup and proof generation to integration tests

This commit is contained in:
schaeff 2018-06-15 10:57:27 +02:00
parent bb5d0b4c39
commit bb87e21cbe

View file

@ -58,16 +58,34 @@ mod integration {
let flattened_path = tmp_base.join(program_name).join("out");
let flattened_code_path = tmp_base.join(program_name).join("out").with_extension("code");
let witness_path = tmp_base.join(program_name).join("witness");
let verification_key_path = tmp_base.join(program_name).join("verification").with_extension("key");
let proving_key_path = tmp_base.join(program_name).join("proving").with_extension("key");
let variable_information_path = tmp_base.join(program_name).join("variables").with_extension("inf");
// create a tmp folder to store artifacts
fs::create_dir(test_case_path).unwrap();
// compile
assert_cli::Assert::command(&["cargo", "run", "--", "compile", "-i", program_path.to_str().unwrap(), "-o", flattened_path.to_str().unwrap()])
// COMPILE
assert_cli::Assert::command(&["cargo", "run", "--", "compile",
"-i", program_path.to_str().unwrap(),
"-o", flattened_path.to_str().unwrap()])
.succeeds()
.unwrap();
// compute
// load the expected result
let mut expected_flattened_code_file = File::open(&expected_flattened_code_path).unwrap();
let mut expected_flattened_code = String::new();
expected_flattened_code_file.read_to_string(&mut expected_flattened_code).unwrap();
// load the actual result
let mut flattened_code_file = File::open(&flattened_code_path).unwrap();
let mut flattened_code = String::new();
flattened_code_file.read_to_string(&mut flattened_code).unwrap();
// check equality
assert_eq!(flattened_code, expected_flattened_code, "Flattening failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}", program_path.to_str().unwrap(), expected_flattened_code.as_str(), flattened_code.as_str());
// COMPUTE_WITNESS
let arguments: Value = serde_json::from_reader(File::open(arguments_path).unwrap()).unwrap();
let arguments_str_list: Vec<String> = arguments.as_array().unwrap().iter().map(|i| match *i {
@ -75,7 +93,10 @@ mod integration {
_ => panic!(format!("Cannot read arguments. Check {}", arguments_path.to_str().unwrap()))
}).collect();
let mut compute = vec!["cargo", "run", "--", "compute-witness", "-i", flattened_path.to_str().unwrap(), "-o", witness_path.to_str().unwrap(), "-a"];
let mut compute = vec!["cargo", "run", "--", "compute-witness",
"-i", flattened_path.to_str().unwrap(),
"-o", witness_path.to_str().unwrap(),
"-a"];
for arg in arguments_str_list.iter() {
compute.push(arg);
@ -85,28 +106,39 @@ mod integration {
.succeeds()
.unwrap();
// load the expected result
let mut expected_flattened_code_file = File::open(&expected_flattened_code_path).unwrap();
let mut expected_flattened_code = String::new();
expected_flattened_code_file.read_to_string(&mut expected_flattened_code).unwrap();
// load the expected witness
let mut expected_witness_file = File::open(&expected_witness_path).unwrap();
let mut expected_witness = String::new();
expected_witness_file.read_to_string(&mut expected_witness).unwrap();
// load the actual result
let mut flattened_code_file = File::open(&flattened_code_path).unwrap();
let mut flattened_code = String::new();
flattened_code_file.read_to_string(&mut flattened_code).unwrap();
// load the actual witness
let mut witness_file = File::open(&witness_path).unwrap();
let mut witness = String::new();
witness_file.read_to_string(&mut witness).unwrap();
// check equality
assert_eq!(flattened_code, expected_flattened_code, "Flattening failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}", program_path.to_str().unwrap(), expected_flattened_code.as_str(), flattened_code.as_str());
assert!(witness.contains(expected_witness.as_str()), "Witness generation failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}", program_path.to_str().unwrap(), expected_witness.as_str(), witness.as_str());
assert!(witness.contains(
expected_witness.as_str()),
"Witness generation failed for {}\n\nExpected\n\n{}\n\nGot\n\n{}",
program_path.to_str().unwrap(),
expected_witness.as_str(),
witness.as_str());
// SETUP
assert_cli::Assert::command(&["cargo", "run", "--", "setup",
"-i", flattened_path.to_str().unwrap(),
"-p", proving_key_path.to_str().unwrap(),
"-v", verification_key_path.to_str().unwrap(),
"-m", variable_information_path.to_str().unwrap()])
.succeeds()
.unwrap();
// GENERATE-PROOF
assert_cli::Assert::command(&["cargo", "run", "--", "generate-proof",
"-w", witness_path.to_str().unwrap(),
"-p", proving_key_path.to_str().unwrap(),
"-i", variable_information_path.to_str().unwrap()])
.succeeds()
.unwrap();
}
}