Format test

This commit is contained in:
cygnet 2023-07-23 22:36:23 +02:00
parent 6c83881619
commit 74d6050151
1 changed files with 75 additions and 94 deletions

View File

@ -8,20 +8,23 @@ mod utils;
mod tests {
use std::{collections::HashSet, str::FromStr};
use secp256k1::XOnlyPublicKey;
use crate::{input::{self, ComparableHashMap}, sending::create_outputs, receiving::{derive_silent_payment_key_pair, get_receiving_addresses, get_A_sum_public_keys, scanning, verify_and_calculate_signatures}, utils::hash_outpoints};
use crate::{input::{self, ComparableHashMap, TestData}, sending::create_outputs, receiving::{derive_silent_payment_key_pair, get_receiving_addresses, get_A_sum_public_keys, scanning, verify_and_calculate_signatures}, utils::hash_outpoints};
#[test]
fn test_with_test_vectors() {
let testdata = input::read_file();
for test in testdata {
process_test_case(test);
}
}
fn process_test_case(test_case: TestData) {
let mut sending_outputs: HashSet<String> = HashSet::new();
eprintln!("test.comment = {:?}", test.comment);
for sendingtest in test.sending {
eprintln!("test.comment = {:?}", test_case.comment);
for sendingtest in test_case.sending {
let given = sendingtest.given;
let expected = sendingtest.expected;
@ -40,16 +43,9 @@ mod tests {
outputs.into_iter().map(|x| x.into()).collect();
assert_eq!(outputs_comparable, expected_comparable);
// if outputs_comparable == expected_comparable {
// println!("sending succeeded");
// } else {
// eprintln!("sending expected = {:#?}", expected_comparable);
// eprintln!("sending outputs = {:#?}", outputs_comparable);
// std::process::exit(0);
// }
}
for receivingtest in test.receiving {
for receivingtest in &test_case.receiving {
let given = &receivingtest.given;
let expected = &receivingtest.expected;
@ -69,12 +65,6 @@ mod tests {
let set2: HashSet<_> = expected.addresses.iter().collect();
assert_eq!(set1, set2);
// if !set1.eq(&set2) {
// println!("receiving addressess failed");
// eprintln!("receiving_addresses = {:#?}", receiving_addresses);
// eprintln!("expected.addresses = {:#?}", expected.addresses);
// std::process::exit(0);
// }
// can be even or odd !
let outputs_to_check: Vec<XOnlyPublicKey> = given
@ -101,16 +91,7 @@ mod tests {
let res = verify_and_calculate_signatures(&mut add_to_wallet, b_spend).unwrap();
assert_eq!(res, expected.outputs);
// if res.eq(&expected.outputs) {
// println!("receiving succeeded");
// } else {
// eprintln!("res = {:#?}", res);
// eprintln!("expected.outputs = {:#?}", expected.outputs);
// println!("receiving failed");
// std::process::exit(0);
// }
}
}
}
}
}