Skip to content

Commit 091d551

Browse files
committed
Refactor tests for proof generation
1 parent 770e7c4 commit 091d551

File tree

1 file changed

+17
-61
lines changed

1 file changed

+17
-61
lines changed

ledger/src/proofs/transaction.rs

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,7 @@ mod tests_with_wasm {
40414041

40424042
#[cfg(test)]
40434043
mod tests {
4044-
use std::{collections::HashMap, path::Path, str::FromStr};
4044+
use std::{collections::HashMap, path::Path};
40454045

40464046
use kimchi::circuits::gate::CircuitGate;
40474047
use mina_hasher::Fp;
@@ -4098,21 +4098,17 @@ mod tests {
40984098
T::binprot_read(&mut read).unwrap()
40994099
}
41004100

4101-
fn read_witnesses() -> std::io::Result<Vec<Fp>> {
4101+
fn read_witnesses<F: FieldWitness>(filename: &str) -> Result<Vec<F>, ()> {
41024102
let f = std::fs::read_to_string(
4103-
Path::new(env!("CARGO_MANIFEST_DIR")).join("/tmp/fps_rampup4.txt"),
4104-
)?;
4105-
// let f = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("fps.txt"))?;
4106-
4107-
let fps = f
4108-
.lines()
4103+
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
4104+
.join("rampup4")
4105+
.join(filename),
4106+
)
4107+
.unwrap();
4108+
f.lines()
41094109
.filter(|s| !s.is_empty())
4110-
.map(|s| Fp::from_str(s).unwrap())
4111-
.collect::<Vec<_>>();
4112-
4113-
// TODO: Implement [0..652]
4114-
// Ok(fps.split_off(652))
4115-
Ok(fps)
4110+
.map(|s| F::from_str(s).map_err(|_| ()))
4111+
.collect()
41164112
}
41174113

41184114
fn read_constraints_data<F: FieldWitness>(
@@ -4566,22 +4562,7 @@ mod tests {
45664562

45674563
let mut witnesses: Witness<Fp> = Witness::new::<StepTransactionProof>();
45684564

4569-
fn read_witnesses(filename: &str) -> Vec<Fp> {
4570-
let f = std::fs::read_to_string(
4571-
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
4572-
.join("rampup4")
4573-
.join(filename),
4574-
)
4575-
.unwrap();
4576-
let fqs = f
4577-
.lines()
4578-
.filter(|s| !s.is_empty())
4579-
.map(|s| Fp::from_str(s).unwrap())
4580-
.collect::<Vec<_>>();
4581-
fqs
4582-
}
4583-
4584-
witnesses.ocaml_aux = read_witnesses("fps_rampup4.txt");
4565+
witnesses.ocaml_aux = read_witnesses("fps_rampup4.txt").unwrap();
45854566

45864567
let WrapProof { proof, .. } = generate_tx_proof(
45874568
TransactionParams {
@@ -4639,7 +4620,8 @@ mod tests {
46394620
expected_step_proof: Some(
46404621
"fb89b6d51ce5ed6fe7815b86ca37a7dcdc34d9891b4967692d3751dad32842f8",
46414622
),
4642-
ocaml_wrap_witness: Some(read_witnesses_fq("fqs_merge.txt")),
4623+
4624+
ocaml_wrap_witness: Some(read_witnesses("fqs_merge.txt").unwrap()),
46434625
},
46444626
&mut witnesses,
46454627
);
@@ -4744,21 +4726,6 @@ mod tests {
47444726
);
47454727
}
47464728

4747-
fn read_witnesses_fq(filename: &str) -> Vec<Fq> {
4748-
let f = std::fs::read_to_string(
4749-
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
4750-
.join("rampup4")
4751-
.join(filename),
4752-
)
4753-
.unwrap();
4754-
let fqs = f
4755-
.lines()
4756-
.filter(|s| !s.is_empty())
4757-
.map(|s| Fq::from_str(s).unwrap())
4758-
.collect::<Vec<_>>();
4759-
fqs
4760-
}
4761-
47624729
#[test]
47634730
fn test_block_proof() {
47644731
let Ok(data) = std::fs::read(
@@ -4794,7 +4761,7 @@ mod tests {
47944761
expected_step_proof: Some(
47954762
"a82a10e5c276dd6dc251241dcbad005201034ffff5752516a179f317dfe385f5",
47964763
),
4797-
ocaml_wrap_witness: Some(read_witnesses_fq("block_fqs.txt")),
4764+
ocaml_wrap_witness: Some(read_witnesses("block_fqs.txt").unwrap()),
47984765
},
47994766
&mut witnesses,
48004767
);
@@ -4879,7 +4846,7 @@ mod tests {
48794846
expected_step_proof: Some(
48804847
"a82a10e5c276dd6dc251241dcbad005201034ffff5752516a179f317dfe385f5",
48814848
),
4882-
ocaml_wrap_witness: Some(read_witnesses_fq("block_fqs.txt")),
4849+
ocaml_wrap_witness: Some(read_witnesses("block_fqs.txt").unwrap()),
48834850
},
48844851
&mut witnesses,
48854852
);
@@ -4911,7 +4878,7 @@ mod tests {
49114878
expected_step_proof: Some(
49124879
"fb89b6d51ce5ed6fe7815b86ca37a7dcdc34d9891b4967692d3751dad32842f8",
49134880
),
4914-
ocaml_wrap_witness: Some(read_witnesses_fq("fqs_merge.txt")),
4881+
ocaml_wrap_witness: Some(read_witnesses("fqs_merge.txt").unwrap()),
49154882
},
49164883
&mut witnesses,
49174884
);
@@ -4952,25 +4919,14 @@ mod tests {
49524919
// ("fee_transfer_9_rampup4.bin", "087a07eddedf5de18b2f2bd7ded3cd474d00a0030e9c13d7a5fd2433c72fc7d5"),
49534920
];
49544921

4955-
fn read_witnesses(filename: &str) -> Vec<Fp> {
4956-
let f = std::fs::read_to_string(
4957-
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(filename),
4958-
)
4959-
.unwrap();
4960-
f.lines()
4961-
.filter(|s| !s.is_empty())
4962-
.map(|s| Fp::from_str(s).unwrap())
4963-
.collect::<Vec<_>>()
4964-
}
4965-
49664922
for (file, expected_sum) in requests {
49674923
let data = std::fs::read(base_dir.join(file)).unwrap();
49684924
let (statement, tx_witness, message) = extract_request(&data);
49694925

49704926
let mut witnesses: Witness<Fp> = Witness::new::<StepTransactionProof>();
49714927

49724928
if file == "request_payment_0_rampup4.bin" {
4973-
witnesses.ocaml_aux = read_witnesses("fps_rampup4.txt");
4929+
witnesses.ocaml_aux = read_witnesses("fps_rampup4.txt").unwrap();
49744930
}
49754931

49764932
let WrapProof { proof, .. } = generate_tx_proof(

0 commit comments

Comments
 (0)