mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-05-18 15:29:26 +00:00
Stabilise tests.
This commit is contained in:
parent
0f169eecb1
commit
b2509b5a84
@ -60,6 +60,17 @@ fn provision_library() -> PathBuf {
|
||||
unpack_library(response, version, &os, &arch, &out_dir)
|
||||
}
|
||||
|
||||
/// Configures the corresponding witness generator library.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `LIB_VAR_NAME` is the name of the environment variable that points to the directory
|
||||
/// containing the library. If it is not set, the library will be downloaded from GitHub.
|
||||
///
|
||||
/// # Output
|
||||
///
|
||||
/// - `LIB_VAR_NAME` is always emitted so internals can refer to it regardless of whether the
|
||||
/// library was downloaded or provided by the user.
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed={LIB_VAR_NAME}");
|
||||
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
|
||||
@ -81,6 +92,7 @@ fn main() {
|
||||
});
|
||||
|
||||
let lib_dir = lib_dir.to_str().expect("Failed to convert the library directory path to a string");
|
||||
println!("cargo:rustc-env={LIB_VAR_NAME}={lib_dir}");
|
||||
println!("cargo:rustc-link-search=native={lib_dir}");
|
||||
println!("cargo:rustc-link-lib=static={CIRCUIT_NAME}");
|
||||
println!("cargo:rustc-link-lib=stdc++");
|
||||
|
||||
132
rust/logos-blockchain-circuits-poq-sys/sample.input.json
Normal file
132
rust/logos-blockchain-circuits-poq-sys/sample.input.json
Normal file
@ -0,0 +1,132 @@
|
||||
{
|
||||
"session": "1",
|
||||
"core_quota": "10",
|
||||
"leader_quota": "5",
|
||||
"core_root": "20423847801203321296654759690878714805328777188198550442842378955293864405749",
|
||||
"pol_ledger_aged": "17903920406556048980238705683215862296511171897974321387437239009873416173088",
|
||||
"K_part_one": "123456",
|
||||
"K_part_two": "654321",
|
||||
"selector": "0",
|
||||
"index": "4",
|
||||
"core_sk": "9648814259696994178754585280937762562521917479862309330976828088416086689502",
|
||||
"core_path": [
|
||||
"7444981793259323545028230817540266139574655346498587207322690091155864366514",
|
||||
"11906618682557735136285409970678605865823718647884839058358264586062323572931",
|
||||
"20134132405688011859463119692951856666179032704702165461712292610201307937895",
|
||||
"14957940720199233077855574470291237736607251243547208306826060526364053594567",
|
||||
"9960019677323356900045391326995069522689045788302673979918902013710931552405",
|
||||
"66857460143066791244205132003829555578944395751024287435105865077587183768",
|
||||
"9684190057075151027164519297536804034845411696380043986044825589786854843890",
|
||||
"5454398284364625202375600088042852298143548338598297694708920725120268102172",
|
||||
"17717838934596276392301608861658238780702831838416312046180761451761658981677",
|
||||
"21049060929819155971068746329904761210986436808741330971979776532239897765447",
|
||||
"11774149665086408677974469133186402228920447314607286251417731337331983592621",
|
||||
"20730401134454070553472357967443459347591806294042271432905369723302561196146",
|
||||
"8683835652829558567596368905844156962511421729430671198119438457363223237488",
|
||||
"15354188356303619925782257044335868802108846851399355235348014093341533049042",
|
||||
"4726038353749363201132655543916148764086757634128462972437143285566298790278",
|
||||
"19793785327783426164764238122458972627129812758755648364664517341770465698137",
|
||||
"12144554112696250636735897359535254161697584560941692171669941649860599557215",
|
||||
"4391930156296016129347969147731784916200749354398548728573386759785083449305",
|
||||
"9056244932796998900758180921717949733339642790698415152308909239074793689860",
|
||||
"20440861423381563032522290464977155181939164858308810772959774388792060977834"
|
||||
],
|
||||
"core_path_selectors": [
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1",
|
||||
"0",
|
||||
"1"
|
||||
],
|
||||
"pol_sl": "2999142337",
|
||||
"pol_epoch_nonce": "13416107872788342879859909752417297479970876884105393946206193406636245124924",
|
||||
"pol_t0": "148409079361904587837471709956458430342187235603420891378597419711486680",
|
||||
"pol_t1": "21888242871336145414933615591437256729835795974444825699352339602896135814447",
|
||||
"pol_secret_key": "5888730225944530149138538772959785628943021630629194621324636699030154327779",
|
||||
"pol_noteid_path": [
|
||||
"11417212955939342484156122492131731680470736064572423108264714804692982132423",
|
||||
"13195529687976077417120457189120231305870945642160590995096417385531885506527",
|
||||
"8472612035444494025196025434618086294389115909303446215474787216226075733233",
|
||||
"4395544485586958768290328184233580023235668872384703046186144832197262227824",
|
||||
"4155097203117131499585729150758272768367941952959383568978188417941807061285",
|
||||
"12408098106443635130911956104856030560309651099061156514970962447957027050139",
|
||||
"18743723426188623742373733557975920292757537418376825891131826727792647674843",
|
||||
"8921759404097162857845142647448014820935511584403450140750072994549272153730",
|
||||
"12780803834914504736250867272694468211504307499239030290058679926157641539231",
|
||||
"14426829036224566782069722269326129726234814130810124541609677896636347739469",
|
||||
"12104693267449791844517047312768375964966170218283608605832423892888932116836",
|
||||
"4883118865130876989815011894870188012768758733041802381045504888060618022896",
|
||||
"221076344526264664133449802750892395792062472746642224588395874880886057862",
|
||||
"5113214819332200669368049090534645222011919607097424838023324847441692662817",
|
||||
"11190105598795402691316927391391967636268949446132854344954730333558274776561",
|
||||
"9497071318258212130830107535590335197992746719505860281792486969560303727415",
|
||||
"748420254289718676536943619836584348410332952487466816579920043963946022247",
|
||||
"14115148735545746869495305176487552481901196697644225252711231121645192222529",
|
||||
"9825912699605171279245430402178700385570068146465368260071935364769450924475",
|
||||
"1501769250930508362584740947030050914124963948804793138968307230445384260381",
|
||||
"17449384761389191557925767178974603169885098072345898391638302374310429932515",
|
||||
"15254499277889636076581272515864557232200527228506352325296439482258130354292",
|
||||
"17609649632230164263025759476016886422378093160688512447628349616375377913864",
|
||||
"3796675673265260264289049510567646443858253346231355244420810954931342727796",
|
||||
"16421896950452608279534605320939669191650110271813875344999112106538557831552",
|
||||
"17833913909116979902116409442832814514923484644816639363063290974377083565699",
|
||||
"6674420083709581276404439792277275401604929658229769714363091874557852768901",
|
||||
"413703733576599351434912508015408034175577472292919474661639467491474199758",
|
||||
"8269883007022448705723402393227587978527160373548295017073655056451421211755",
|
||||
"2524601535002894286006232081527402693925618141420537796447547436812892177839",
|
||||
"18128917825606990579294624696080518601859437342124614427642120271129736700878",
|
||||
"20950332433104838321486108855942309235493780674594737746438717221993421294744"
|
||||
],
|
||||
"pol_noteid_path_selectors": [
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"pol_note_tx_hash": "10190023498178194208361021687460995025878664681917212352967702284591462728108",
|
||||
"pol_note_output_number": "449",
|
||||
"pol_note_value": "50"
|
||||
}
|
||||
@ -51,3 +51,44 @@ pub fn generate_witness_from_files(
|
||||
)
|
||||
}.try_into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
use lbc_types::native::WitnessInput;
|
||||
use std::sync::LazyLock;
|
||||
use super::{generate_witness, generate_witness_from_files};
|
||||
|
||||
static LIB_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
PathBuf::from(
|
||||
std::env::var("POQ_LIB_DIR")
|
||||
.expect("POQ_LIB_DIR must be available, as provided by the build script."),
|
||||
)
|
||||
});
|
||||
static INPUTS: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("sample.input.json")
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_generate_witness() {
|
||||
let dat = LIB_DIR.join("witness_generator");
|
||||
let witness_output_path = std::env::temp_dir().join("poq_test_witness.wtns");
|
||||
|
||||
generate_witness_from_files(&dat, &*INPUTS, &witness_output_path)
|
||||
.expect("generate_witness_from_files failed.");
|
||||
|
||||
let dat_bytes = {
|
||||
let dat_file = dat.with_extension("dat");
|
||||
std::fs::read(&dat_file)
|
||||
.expect(format!("Failed to read {}.", dat_file.display()).as_str())
|
||||
};
|
||||
let inputs_json = std::fs::read_to_string(&*INPUTS)
|
||||
.expect(format!("Failed to read {}.", INPUTS.display()).as_str());
|
||||
|
||||
let input = WitnessInput::new(dat_bytes.as_slice(), inputs_json).expect("Failed to construct the input for the witness generator.");
|
||||
let output = generate_witness(input).expect("generate_witness failed.");
|
||||
|
||||
let expected = std::fs::read(&witness_output_path).expect(format!("Failed to read the generated witness from {}.", witness_output_path.display()).as_str());
|
||||
assert_eq!(output.as_slice(), expected.as_slice());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
use logos_blockchain_circuits_poq_sys::{generate_witness, generate_witness_from_files};
|
||||
use lbc_types::native::WitnessInput;
|
||||
|
||||
fn lib_dir() -> PathBuf {
|
||||
PathBuf::from(
|
||||
std::env::var("POQ_LIB_DIR").expect("POQ_LIB_DIR must point to the poq library directory"),
|
||||
)
|
||||
}
|
||||
|
||||
fn inputs_path() -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../blend/poq-input.json")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generate_witness_matches_from_files() {
|
||||
let dat = lib_dir().join("witness_generator");
|
||||
let inputs = inputs_path();
|
||||
let witness_path = std::env::temp_dir().join("poq_test_witness.wtns");
|
||||
|
||||
generate_witness_from_files(&dat, &inputs, &witness_path)
|
||||
.expect("generate_witness_from_files failed");
|
||||
|
||||
let dat_bytes = std::fs::read(dat.with_extension("dat"))
|
||||
.expect("failed to read witness_generator.dat");
|
||||
let inputs_json = std::fs::read_to_string(&inputs).expect("failed to read poq-input.json");
|
||||
|
||||
let input = WitnessInput::new(dat_bytes.as_slice(), inputs_json).expect("failed to construct WitnessInput");
|
||||
let output = generate_witness(input).expect("generate_witness failed");
|
||||
|
||||
let expected = std::fs::read(&witness_path).expect("failed to read witness output file");
|
||||
assert_eq!(output.as_slice(), expected.as_slice());
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user