feat: add rust unit test

This commit is contained in:
georgehao
2024-01-29 15:28:17 +08:00
parent 98c2a6afb4
commit 3e44abf883
2 changed files with 25 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
#![feature(once_cell)]
mod batch;
mod chunk;
pub mod chunk;
mod types;
mod utils;

View File

@@ -0,0 +1,24 @@
use prover::utils::get_block_trace_from_file;
use std::{ffi::CString, path::Path, thread::sleep, time::Duration};
use zkp::chunk;
#[test]
fn chunk_test() {
let params = CString::new("/assets/test_params").expect("test_params conversion failed");
let assets = CString::new("/assets/test_assets").expect("test_assets conversion failed");
let trace_path = "/assets/traces/1_transfer.json".to_string();
let chunk_trace = get_block_trace_from_file(Path::new(&trace_path));
let json_str = serde_json::to_string(&chunk_trace).expect("Serialization failed");
let c_string = CString::new(json_str).expect("CString conversion failed");
let c_str_ptr = c_string.as_ptr();
unsafe {
chunk::init_chunk_prover(params.as_ptr(), assets.as_ptr());
loop {
chunk::gen_chunk_proof(c_str_ptr);
let duration = Duration::from_millis(100);
sleep(duration);
}
}
}