Skip to content

Commit

Permalink
Fix clippy warnings in test code
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Oct 4, 2023
1 parent 3aed47b commit 55efa8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
32 changes: 15 additions & 17 deletions src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,12 +1557,13 @@ mod test {
fn setup<Aggregator: AggregatorTrait, Signer: SignerTrait>(
) -> (Coordinator<Aggregator>, Vec<SigningRound<Signer>>) {
unsafe {
match LOG_INIT.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) {
Ok(false) => tracing_subscriber::registry()
if let Ok(false) =
LOG_INIT.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
{
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init(),
_ => {}
.init()
}
}

Expand Down Expand Up @@ -1739,9 +1740,8 @@ mod test {
}

fn get_rng() -> impl RngCore + CryptoRng {
let rnd = OsRng;
//rand::rngs::StdRng::seed_from_u64(rnd.next_u64()) // todo: fix trait `rand_core::RngCore` is not implemented for `StdRng`
rnd
OsRng
}

#[test]
Expand Down Expand Up @@ -1802,7 +1802,7 @@ mod test {
Default::default(),
);
// publich_shares_done starts out as false
assert_eq!(false, signing_round.public_shares_done());
assert!(!signing_round.public_shares_done());

// meet the conditions for all public keys received
signing_round.state = SignerState::DkgPublicGather;
Expand Down Expand Up @@ -1840,7 +1840,7 @@ mod test {
Default::default(),
);
// can_dkg_end starts out as false
assert_eq!(false, signing_round.can_dkg_end());
assert!(!signing_round.can_dkg_end());

// meet the conditions for DKG_END
signing_round.state = SignerState::DkgPrivateGather;
Expand Down Expand Up @@ -1878,15 +1878,13 @@ mod test {
Default::default(),
Default::default(),
);
match signing_round.dkg_ended() {
Ok(dkg_end) => match dkg_end {
Message::DkgEnd(dkg_end) => match dkg_end.status {
DkgStatus::Failure(_) => assert!(true),
_ => assert!(false),
},
_ => assert!(false),
},
_ => assert!(false),
if let Ok(Message::DkgEnd(dkg_end)) = signing_round.dkg_ended() {
match dkg_end.status {
DkgStatus::Failure(_) => {}
_ => panic!("Expected DkgStatus::Failure"),
}
} else {
panic!("Unexpected Error");
}
}
}
12 changes: 6 additions & 6 deletions src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod test {

#[allow(non_snake_case)]
fn taproot_sign_verify_v1(merkle_root: Option<[u8; 32]>) {
let mut rng = OsRng::default();
let mut rng = OsRng;

// First create and verify a frost signature
let msg = "It was many and many a year ago".as_bytes();
Expand Down Expand Up @@ -195,8 +195,8 @@ mod test {
let mut sig_agg = v1::Aggregator::new(N, T);
sig_agg.init(A.clone()).expect("aggregator init failed");
let tweaked_public_key = compute::tweaked_public_key(&sig_agg.poly[0], merkle_root);
let (nonces, sig_shares) = test_helpers::sign(&msg, &mut S, &mut rng, merkle_root);
let proof = match sig_agg.sign_taproot(&msg, &nonces, &sig_shares, &[], merkle_root) {
let (nonces, sig_shares) = test_helpers::sign(msg, &mut S, &mut rng, merkle_root);
let proof = match sig_agg.sign_taproot(msg, &nonces, &sig_shares, &[], merkle_root) {
Err(e) => panic!("Aggregator sign failed: {:?}", e),
Ok(proof) => proof,
};
Expand Down Expand Up @@ -226,7 +226,7 @@ mod test {

#[allow(non_snake_case)]
fn taproot_sign_verify_v2(merkle_root: Option<[u8; 32]>) {
let mut rng = OsRng::default();
let mut rng = OsRng;

// First create and verify a frost signature
let msg = "It was many and many a year ago".as_bytes();
Expand Down Expand Up @@ -258,8 +258,8 @@ mod test {
let mut sig_agg = v2::Aggregator::new(Nk, T);
sig_agg.init(A.clone()).expect("aggregator init failed");
let tweaked_public_key = compute::tweaked_public_key(&sig_agg.poly[0], merkle_root);
let (nonces, sig_shares) = test_helpers::sign(&msg, &mut S, &mut rng, merkle_root);
let proof = match sig_agg.sign_taproot(&msg, &nonces, &sig_shares, &key_ids, merkle_root) {
let (nonces, sig_shares) = test_helpers::sign(msg, &mut S, &mut rng, merkle_root);
let proof = match sig_agg.sign_taproot(msg, &nonces, &sig_shares, &key_ids, merkle_root) {
Err(e) => panic!("Aggregator sign failed: {:?}", e),
Ok(proof) => proof,
};
Expand Down
12 changes: 6 additions & 6 deletions src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ mod tests {

#[test]
fn signer_new() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let id = 1;
let key_ids = [1, 2, 3];
let n: u32 = 10;
Expand All @@ -663,7 +663,7 @@ mod tests {

#[test]
fn signer_gen_nonces() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let id = 1;
let key_ids = [1, 2, 3];
let n: u32 = 10;
Expand All @@ -686,7 +686,7 @@ mod tests {

#[test]
fn signer_save_load() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let id = 1;
let key_ids = [1, 2, 3];
let n: u32 = 10;
Expand All @@ -703,7 +703,7 @@ mod tests {
#[allow(non_snake_case)]
#[test]
fn aggregator_sign() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let msg = "It was many and many a year ago".as_bytes();
let N: u32 = 10;
let T: u32 = 7;
Expand Down Expand Up @@ -733,8 +733,8 @@ mod tests {
let mut sig_agg = v1::Aggregator::new(N, T);
sig_agg.init(comms.clone()).expect("aggregator init failed");

let (nonces, sig_shares) = v1::test_helpers::sign(&msg, &mut signers, &mut rng);
if let Err(e) = sig_agg.sign(&msg, &nonces, &sig_shares, &[]) {
let (nonces, sig_shares) = v1::test_helpers::sign(msg, &mut signers, &mut rng);
if let Err(e) = sig_agg.sign(msg, &nonces, &sig_shares, &[]) {
panic!("Aggregator sign failed: {:?}", e);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ mod tests {

#[test]
fn party_save_load() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let key_ids = [1, 2, 3];
let n: u32 = 10;
let t: u32 = 7;
Expand All @@ -609,7 +609,7 @@ mod tests {
#[allow(non_snake_case)]
#[test]
fn aggregator_sign() {
let mut rng = OsRng::default();
let mut rng = OsRng;
let msg = "It was many and many a year ago".as_bytes();
let Nk: u32 = 10;
let T: u32 = 7;
Expand Down Expand Up @@ -641,9 +641,8 @@ mod tests {

sig_agg.init(comms.clone()).expect("aggregator init failed");

let (nonces, sig_shares, key_ids) =
v2::test_helpers::sign(&msg, &mut signers, &mut rng);
if let Err(e) = sig_agg.sign(&msg, &nonces, &sig_shares, &key_ids) {
let (nonces, sig_shares, key_ids) = v2::test_helpers::sign(msg, &mut signers, &mut rng);
if let Err(e) = sig_agg.sign(msg, &nonces, &sig_shares, &key_ids) {
panic!("Aggregator sign failed: {:?}", e);
}
}
Expand Down

0 comments on commit 55efa8e

Please sign in to comment.