diff --git a/dkg-gadget/src/async_protocols/test_utils.rs b/dkg-gadget/src/async_protocols/test_utils.rs index ddbd7cc91..f4674cc8c 100644 --- a/dkg-gadget/src/async_protocols/test_utils.rs +++ b/dkg-gadget/src/async_protocols/test_utils.rs @@ -1,20 +1,17 @@ #![allow(clippy::unwrap_used)] // allow unwraps in tests use crate::{ - async_protocols::{blockchain_interface::BlockchainInterface, types::LocalKeyType, BatchKey}, + async_protocols::{ + blockchain_interface::BlockchainInterface, + types::{LocalKeyType, VoteResult}, + BatchKey, + }, db::DKGDbBackend, }; use codec::Encode; -use curv::{elliptic::curves::Secp256k1, BigInt}; -use dkg_primitives::{ - types::{DKGError, DKGMessage, SessionId, SignedDKGMessage}, - utils::convert_signature, -}; +use dkg_primitives::types::{DKGError, DKGMessage, SessionId, SignedDKGMessage}; use dkg_runtime_primitives::{ crypto::Public, gossip_messages::PublicKeyMessage, BatchId, MaxProposalLength, - MaxProposalsInBatch, MaxSignatureLength, SignedProposalBatch, StoredUnsignedProposalBatch, -}; -use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::{ - party_i::SignatureRecid, state_machine::keygen::LocalKey, + MaxProposalsInBatch, MaxSignatureLength, SignedProposalBatch, }; use parking_lot::Mutex; use std::{collections::HashMap, sync::Arc}; @@ -79,53 +76,50 @@ impl BlockchainInterface for TestDummyIface { Ok(()) } - fn process_vote_result( - &self, - signature: SignatureRecid, - unsigned_proposal_batch: StoredUnsignedProposalBatch< - Self::BatchId, - Self::MaxProposalLength, - Self::MaxProposalsInBatch, - Self::Clock, - >, - _session_id: SessionId, - batch_key: BatchKey, - _message: BigInt, - ) -> Result<(), DKGError> { - let mut lock = self.vote_results.lock(); - - let signature = convert_signature(&signature).ok_or_else(|| DKGError::CriticalError { - reason: "Unable to serialize signature".to_string(), - })?; - - let mut signed_proposals = vec![]; - - // convert all unsigned proposals to signed - for unsigned_proposal in unsigned_proposal_batch.proposals.iter() { - signed_proposals.push(Proposal::Signed { - kind: unsigned_proposal.proposal.kind(), - data: unsigned_proposal - .data() - .clone() - .try_into() - .expect("should not happen since its a valid proposal"), + fn process_vote_result(&self, result: VoteResult) -> Result<(), DKGError> { + if let VoteResult::ECDSA { + signature, + unsigned_proposal_batch, + session_id: _sid, + batch_key, + } = result + { + let mut lock = self.vote_results.lock(); + + let mut signed_proposals = vec![]; + + // convert all unsigned proposals to signed + for unsigned_proposal in unsigned_proposal_batch.proposals.iter() { + signed_proposals.push(Proposal::Signed { + kind: unsigned_proposal.proposal.kind(), + data: unsigned_proposal + .data() + .clone() + .try_into() + .expect("should not happen since its a valid proposal"), + signature: signature + .encode() + .try_into() + .expect("Signature exceeds runtime bounds!"), + }); + } + + let signed_proposal_batch = SignedProposalBatch { + batch_id: unsigned_proposal_batch.batch_id, + proposals: signed_proposals.try_into().expect("Proposals exceeds runtime bounds!"), signature: signature .encode() .try_into() .expect("Signature exceeds runtime bounds!"), - }); - } - - let signed_proposal_batch = SignedProposalBatch { - batch_id: unsigned_proposal_batch.batch_id, - proposals: signed_proposals.try_into().expect("Proposals exceeds runtime bounds!"), - signature: signature.encode().try_into().expect("Signature exceeds runtime bounds!"), - }; + }; - let proposals_for_this_batch = lock.entry(batch_key).or_default(); - proposals_for_this_batch.push(signed_proposal_batch); + let proposals_for_this_batch = lock.entry(batch_key).or_default(); + proposals_for_this_batch.push(signed_proposal_batch); - Ok(()) + Ok(()) + } else { + panic!("Only ECDSA is supported in the test interface"); + } } fn gossip_public_key(&self, _key: PublicKeyMessage) -> Result<(), DKGError> { diff --git a/dkg-gadget/src/dkg_modules/wt_frost.rs b/dkg-gadget/src/dkg_modules/wt_frost.rs index 7f0abb423..9e60001a5 100644 --- a/dkg-gadget/src/dkg_modules/wt_frost.rs +++ b/dkg-gadget/src/dkg_modules/wt_frost.rs @@ -486,6 +486,7 @@ pub trait NetInterface: Send { mod tests { use crate::dkg_modules::wt_frost::{FrostMessage, NetInterface}; use futures::{stream::FuturesUnordered, TryStreamExt}; + use rand::prelude::SliceRandom; struct TestNetworkLayer { tx: tokio::sync::broadcast::Sender, @@ -575,6 +576,8 @@ mod tests { // best authorities, we will choose the best of the best of authorities, so from 0..T let signers = FuturesUnordered::new(); + // parties.shuffle(rng); + for (party, network) in parties.iter_mut().zip(networks.iter_mut()).take(T as _) { let public_key = public_key.clone(); signers.push(Box::pin(async move {