From 3d987585e28c5543107af5cb3705af28fae88461 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Wed, 31 Jan 2024 11:53:26 +0100 Subject: [PATCH] refactor(test): move a test to a dkg test module --- ferveo/src/dkg.rs | 32 +++++++++++++++++++++++++++++++- ferveo/src/pvss.rs | 29 +---------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/ferveo/src/dkg.rs b/ferveo/src/dkg.rs index be5f6cec..b6560691 100644 --- a/ferveo/src/dkg.rs +++ b/ferveo/src/dkg.rs @@ -390,7 +390,37 @@ mod test_dkg_init { mod test_dealing { use ark_ec::AffineRepr; - use crate::{test_common::*, DkgState, DkgState::Dealt, Validator}; + use crate::{ + test_common::*, DkgParams, DkgState, DkgState::Dealt, Error, + PubliclyVerifiableDkg, Validator, + }; + + /// Check that the canonical share indices of validators are expected and enforced + /// by the DKG methods. + #[test] + fn test_canonical_share_indices_are_enforced() { + let shares_num = 4; + let security_threshold = shares_num - 1; + let keypairs = gen_keypairs(shares_num); + let mut validators = gen_validators(&keypairs); + let me = validators[0].clone(); + + // Validators (share indices) are not unique + let duplicated_index = 0; + validators.insert(duplicated_index, me.clone()); + + // And because of that the DKG should fail + let result = PubliclyVerifiableDkg::new( + &validators, + &DkgParams::new(0, security_threshold, shares_num).unwrap(), + &me, + ); + assert!(result.is_err()); + assert_eq!( + result.unwrap_err().to_string(), + Error::DuplicatedShareIndex(duplicated_index as u32).to_string() + ); + } /// Test that dealing correct PVSS transcripts /// pass verification an application and that diff --git a/ferveo/src/pvss.rs b/ferveo/src/pvss.rs index 6bc074c2..7be4fac2 100644 --- a/ferveo/src/pvss.rs +++ b/ferveo/src/pvss.rs @@ -425,7 +425,7 @@ mod test_pvss { use test_case::test_case; use super::*; - use crate::{test_common::*, DkgParams}; + use crate::test_common::*; /// Test the happy flow such that the PVSS with the correct form is created /// and that appropriate validations pass @@ -502,33 +502,6 @@ mod test_pvss { assert!(!bad_pvss.verify_full(&dkg)); } - /// Check that the canonical share indices of validators are expected and enforced - /// by the DKG methods. - #[test] - fn test_canonical_share_indices_are_enforced() { - let shares_num = 4; - let security_threshold = shares_num - 1; - let keypairs = gen_keypairs(shares_num); - let mut validators = gen_validators(&keypairs); - let me = validators[0].clone(); - - // Validators (share indices) are not unique - let duplicated_index = 0; - validators.insert(duplicated_index, me.clone()); - - // And because of that the DKG should fail - let result = PubliclyVerifiableDkg::new( - &validators, - &DkgParams::new(0, security_threshold, shares_num).unwrap(), - &me, - ); - assert!(result.is_err()); - assert_eq!( - result.unwrap_err().to_string(), - Error::DuplicatedShareIndex(duplicated_index as u32).to_string() - ); - } - /// Check that happy flow of aggregating PVSS transcripts /// has the correct form and it's validations passes #[test_case(4,4; "number of validators is equal to the number of shares")]