mirror of
https://github.com/logos-storage/logos-storage-proofs.git
synced 2026-01-02 13:33:10 +00:00
setting up tests
This commit is contained in:
parent
f141f3ae44
commit
73c7e684bf
70
src/ffi.rs
70
src/ffi.rs
@ -219,7 +219,7 @@ mod tests {
|
|||||||
use ruint::aliases::U256;
|
use ruint::aliases::U256;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit_tests::utils::{digest, treehash}, storage_proofs::EXT_ID_U256_LE,
|
circuit_tests::utils::{digest, treehash}, storage_proofs::EXT_ID_U256_LE, ffi::prove_mpack,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{init, prove, Buffer};
|
use super::{init, prove, Buffer};
|
||||||
@ -237,7 +237,7 @@ mod tests {
|
|||||||
// we build them up in mpack Value enums
|
// we build them up in mpack Value enums
|
||||||
let data = (0..4)
|
let data = (0..4)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let rng = ThreadRng::default();
|
let rng = StdRng::seed_from_u64(42);
|
||||||
let preimages: Vec<U256> = rng
|
let preimages: Vec<U256> = rng
|
||||||
.sample_iter(Alphanumeric)
|
.sample_iter(Alphanumeric)
|
||||||
.take(256)
|
.take(256)
|
||||||
@ -301,6 +301,72 @@ mod tests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_storer_ffi_mpack() {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
let val = Value::from("le message");
|
||||||
|
|
||||||
|
// example of serializing the random chunk data
|
||||||
|
// we build them up in mpack Value enums
|
||||||
|
let data = (0..4)
|
||||||
|
.map(|_| {
|
||||||
|
let rng = StdRng::seed_from_u64(42);
|
||||||
|
let preimages: Vec<U256> = rng
|
||||||
|
.sample_iter(Alphanumeric)
|
||||||
|
.take(256)
|
||||||
|
.map(|c| U256::from(c))
|
||||||
|
.collect();
|
||||||
|
let hash = digest(&preimages, Some(16));
|
||||||
|
(preimages, hash)
|
||||||
|
})
|
||||||
|
.collect::<Vec<(Vec<U256>, U256)>>();
|
||||||
|
|
||||||
|
let chunks = data.iter()
|
||||||
|
.map(|c| {
|
||||||
|
let x = c.0.iter()
|
||||||
|
.map(|c| Value::Ext(EXT_ID_U256_LE, c.to_le_bytes_vec()))
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
Value::Array(x)
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
let chunks = Value::Array(chunks);
|
||||||
|
let mut data = Value::Map(vec![(Value::String("chunks".into()), chunks.clone() )]);
|
||||||
|
|
||||||
|
println!("Debug: chunks: {:?}", chunks[0][0]);
|
||||||
|
|
||||||
|
// Serialize the value types to an array pointer
|
||||||
|
write_value(&mut buf, &data).unwrap();
|
||||||
|
let mut rd: &[u8] = &buf[..];
|
||||||
|
|
||||||
|
let args_buff = Buffer {
|
||||||
|
data: rd.as_ptr() as *const u8,
|
||||||
|
len: rd.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let r1cs_path = "src/circuit_tests/artifacts/storer-test.r1cs";
|
||||||
|
let wasm_path = "src/circuit_tests/artifacts/storer-test_js/storer-test.wasm";
|
||||||
|
|
||||||
|
let r1cs = &Buffer {
|
||||||
|
data: r1cs_path.as_ptr(),
|
||||||
|
len: r1cs_path.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let wasm = &Buffer {
|
||||||
|
data: wasm_path.as_ptr(),
|
||||||
|
len: wasm_path.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let prover_ptr = unsafe { init(&r1cs, &wasm, std::ptr::null()) };
|
||||||
|
let prove_ctx = unsafe {
|
||||||
|
prove_mpack(
|
||||||
|
prover_ptr,
|
||||||
|
&args_buff as *const Buffer,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_storer_ffi() {
|
fn test_storer_ffi() {
|
||||||
// generate a tuple of (preimages, hash), where preimages is a vector of 256 U256s
|
// generate a tuple of (preimages, hash), where preimages is a vector of 256 U256s
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user