Skip to content

Commit

Permalink
Add test for round 1 output for participant (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
natalieesk committed Jul 7, 2023
1 parent fe7111e commit 3f89f74
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 3 additions & 3 deletions participant/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use frost::round1;
use frost_ed25519 as frost;
use participant::round1::{generate_key_package, print_values, request_inputs};
use participant::round2::{generate_signature, round_2_request_inputs};
use participant::round2::{generate_signature, print_round_2_values, round_2_request_inputs};
use participant::Logger;
use rand::thread_rng;
use std::io::BufRead;
Expand All @@ -23,7 +23,7 @@ pub fn cli(input: &mut impl BufRead, logger: &mut dyn Logger) {

// Sign

let _signature = generate_signature(round_2_config, &key_package, &nonces);
let signature = generate_signature(round_2_config, &key_package, &nonces).unwrap(); // TODO: handle errors

// print_round_2_values(_signature);
print_round_2_values(signature);
}
2 changes: 2 additions & 0 deletions participant/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ pub fn generate_signature(
let signature = round2::sign(&signing_package, signing_nonces, key_package)?;
Ok(signature)
}

pub fn print_round_2_values(_signature: SignatureShare) {}
37 changes: 35 additions & 2 deletions participant/src/tests/round1.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use frost::{
keys::{KeyPackage, SigningShare, VerifyingShare},
VerifyingKey,
round1, VerifyingKey,
};
#[cfg(test)]
use frost::{Error, Identifier};
use frost_ed25519 as frost;
use hex::FromHex;
use participant::round1::{generate_key_package, request_inputs, Round1Config};
use participant::round1::{generate_key_package, print_values, request_inputs, Round1Config};

use participant::Logger;
use rand::thread_rng;

const IDENTIFIER: &str = "1";
const PUBLIC_KEY: &str = "adf6ab1f882d04988eadfaa52fb175bf37b6247785d7380fde3fb9d68032470d";
Expand Down Expand Up @@ -183,3 +184,35 @@ fn check_key_package_generation_fails_with_invalid_secret_share() {
let key_package = generate_key_package(&config);
assert!(key_package.is_err());
}

#[test]
fn check_print_values() {
let mut test_logger = TestLogger(Vec::new());
let signing_share =
SigningShare::from_bytes(<[u8; 32]>::from_hex(SIGNING_SHARE).unwrap()).unwrap();
let mut rng = thread_rng();
let (nonces, commitments) =
round1::commit(Identifier::try_from(1).unwrap(), &signing_share, &mut rng);

print_values(&nonces, commitments, &mut test_logger);

let log = [
"=== Round 1 ===".to_string(),
format!("Hiding nonce: {}", hex::encode(nonces.hiding().to_bytes())),
format!(
"Binding nonce: {}",
hex::encode(nonces.binding().to_bytes())
),
format!(
"Hiding commitment: {}",
hex::encode(commitments.hiding().to_bytes())
),
format!(
"Binding commitment: {}",
hex::encode(commitments.binding().to_bytes())
),
"=== Round 1 Completed ===".to_string(),
"Please send your Hiding and Binding Commitments to the coordinator".to_string(),
];
assert_eq!(test_logger.0, log)
}

0 comments on commit 3f89f74

Please sign in to comment.