Skip to content

Commit

Permalink
refactor(test): move a test to a dkg test module
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jan 31, 2024
1 parent 81bc1cb commit 3d98758
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
32 changes: 31 additions & 1 deletion ferveo/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 1 addition & 28 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 3d98758

Please sign in to comment.