clippy fixes

This commit is contained in:
Jędrzej Stuczyński
2024-01-26 10:38:48 +00:00
parent 761b6c2cac
commit 46a482cfcb
11 changed files with 65 additions and 57 deletions
@@ -1,4 +1,4 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2022-2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::collect_paged;
@@ -16,7 +16,7 @@ pub use nym_coconut_dkg_common::{
},
msg::QueryMsg as DkgQueryMsg,
types::{
DealerDetails, DealingIndex, Epoch, EpochId, InitialReplacementData,
DealerDetails, DealingIndex, Epoch, EpochId, EpochState, InitialReplacementData,
PartialContractDealing, State,
},
verification_key::{ContractVKShare, PagedVKSharesResponse, VkShareResponse},
+1 -1
View File
@@ -14,7 +14,7 @@ pub use nym_coconut::{
aggregate_signature_shares, aggregate_verification_keys, blind_sign, hash_to_scalar,
prepare_blind_sign, prove_bandwidth_credential, Attribute, Base58, BlindSignRequest,
BlindedSignature, Bytable, CoconutError, KeyPair, Parameters, PrivateAttribute,
PublicAttribute, Signature, SignatureShare, Theta, VerificationKey, SecretKey
PublicAttribute, SecretKey, Signature, SignatureShare, Theta, VerificationKey,
};
#[derive(Debug, Serialize, Deserialize, Getters, CopyGetters, Clone, PartialEq, Eq)]
@@ -69,9 +69,9 @@ pub fn to_cosmos_msg(
// if they have more than one, we can safely ignore it
pub fn owner_from_cosmos_msgs(msgs: &[CosmosMsg]) -> Option<Addr> {
if msgs.len() != 1 {
return None
return None;
}
if let Some(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: _,
msg,
+1 -1
View File
@@ -13,7 +13,7 @@ pub mod dealing;
pub(crate) mod share;
pub(crate) mod utils;
pub use bls12_381::{Scalar, G2Projective};
pub use bls12_381::{G2Projective, Scalar};
pub use dealing::*;
pub use share::*;
@@ -23,7 +23,8 @@ type Dealer<'a> = &'a Addr;
pub(crate) struct StoredDealing;
// part of `StoredDealing` to make existence lookup cheaper
pub(crate) struct UNIMPLEMENTED_DealingLookup;
// TODO: do it later since we need to chunk the dealings anyway
// pub(crate) struct UNIMPLEMENTED_DealingLookup;
impl StoredDealing {
const NAMESPACE: &'static [u8] = b"dealing";
@@ -12,7 +12,7 @@ use cw4::Member;
use cw_multi_test::Executor;
use cw_utils::{Duration, Threshold};
use nym_coconut_dkg_common::msg::ExecuteMsg::{
AdvanceEpochState, CommitVerificationKeyShare, RegisterDealer,
AdvanceEpochState, CommitVerificationKeyShare, InitiateDkg, RegisterDealer,
};
use nym_coconut_dkg_common::msg::InstantiateMsg as DkgInstantiateMsg;
use nym_coconut_dkg_common::msg::QueryMsg::GetVerificationKeys;
@@ -100,6 +100,14 @@ fn dkg_proposal() {
)
.unwrap();
app.execute_contract(
Addr::unchecked(OWNER),
coconut_dkg_contract_addr.clone(),
&InitiateDkg {},
&[],
)
.unwrap();
app.execute_contract(
Addr::unchecked(MEMBER1),
coconut_dkg_contract_addr.clone(),
@@ -622,7 +622,6 @@ impl<R: RngCore + CryptoRng> DkgController<R> {
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::coconut::tests::helpers::{
exchange_dealings, initialise_controllers, initialise_dkg, submit_public_keys,
};
+23 -22
View File
@@ -249,7 +249,6 @@ impl<R: RngCore + CryptoRng> DkgController<R> {
#[cfg(test)]
mod tests {
use super::*;
use crate::coconut::tests::helpers::{
derive_keypairs, exchange_dealings, initialise_controllers, initialise_dkg,
submit_public_keys,
@@ -305,16 +304,17 @@ mod tests {
let first_dealer = controllers[0].dkg_client.get_address().await;
let mut guard = chain.lock().unwrap();
let shares = guard
.dkg_contract
.verification_shares
.get_mut(&epoch)
.unwrap();
let share = shares.get_mut(first_dealer.as_ref()).unwrap();
// mess up the share
share.share.push('x');
drop(guard);
{
let mut guard = chain.lock().unwrap();
let shares = guard
.dkg_contract
.verification_shares
.get_mut(&epoch)
.unwrap();
let share = shares.get_mut(first_dealer.as_ref()).unwrap();
// mess up the share
share.share.push('x');
}
for controller in controllers.iter_mut() {
let res = controller.verification_key_validation(epoch).await;
@@ -357,18 +357,19 @@ mod tests {
let first_dealer = controllers[0].dkg_client.get_address().await;
let second_dealer = controllers[1].dkg_client.get_address().await;
let mut guard = chain.lock().unwrap();
let shares = guard
.dkg_contract
.verification_shares
.get_mut(&epoch)
.unwrap();
let second_share = shares.get(second_dealer.as_ref()).unwrap().clone();
{
let mut guard = chain.lock().unwrap();
let shares = guard
.dkg_contract
.verification_shares
.get_mut(&epoch)
.unwrap();
let second_share = shares.get(second_dealer.as_ref()).unwrap().clone();
let share = shares.get_mut(first_dealer.as_ref()).unwrap();
// mess up the share
share.share = second_share.share;
drop(guard);
let share = shares.get_mut(first_dealer.as_ref()).unwrap();
// mess up the share
share.share = second_share.share;
}
for controller in controllers.iter_mut() {
let res = controller.verification_key_validation(epoch).await;
+1 -3
View File
@@ -11,17 +11,15 @@ pub(crate) fn params() -> &'static nym_dkg::bte::Params {
pub(crate) mod client;
pub(crate) mod controller;
pub(crate) mod dealing;
mod helpers;
pub(crate) mod key_derivation;
pub(crate) mod key_finalization;
pub(crate) mod key_validation;
pub(crate) mod public_key;
pub(crate) mod state;
mod helpers;
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
#[ignore] // expensive test
async fn reshare_preserves_keys() {
+23 -22
View File
@@ -44,13 +44,14 @@ pub(crate) async fn initialise_dkg(controllers: &mut [TestingDkgController], res
EpochState::WaitingInitialisation
);
let mut chain = controllers[0].chain_state.lock().unwrap();
// add every dealer to group contract
for controller in controllers.iter() {
chain.add_member(controller.dkg_client.get_address().await.as_ref(), 10);
let address = controller.dkg_client.get_address().await;
let mut chain = controllers[0].chain_state.lock().unwrap();
chain.add_member(address.as_ref(), 10);
}
let mut chain = controllers[0].chain_state.lock().unwrap();
chain.dkg_contract.epoch.state = EpochState::PublicKeySubmission { resharing }
}
@@ -131,22 +132,22 @@ pub(crate) async fn validate_keys(controllers: &mut [TestingDkgController], resh
guard.dkg_contract.epoch.state = EpochState::VerificationKeyFinalization { resharing }
}
pub(crate) async fn finalize(controllers: &mut [TestingDkgController]) {
let epoch = controllers[0]
.chain_state
.lock()
.unwrap()
.dkg_contract
.epoch
.epoch_id;
for controller in controllers.iter_mut() {
controller
.verification_key_finalization(epoch)
.await
.unwrap();
}
let mut guard = controllers[0].chain_state.lock().unwrap();
guard.dkg_contract.epoch.state = EpochState::InProgress {}
}
// pub(crate) async fn finalize(controllers: &mut [TestingDkgController]) {
// let epoch = controllers[0]
// .chain_state
// .lock()
// .unwrap()
// .dkg_contract
// .epoch
// .epoch_id;
//
// for controller in controllers.iter_mut() {
// controller
// .verification_key_finalization(epoch)
// .await
// .unwrap();
// }
//
// let mut guard = controllers[0].chain_state.lock().unwrap();
// guard.dkg_contract.epoch.state = EpochState::InProgress {}
// }
+1 -1
View File
@@ -212,7 +212,7 @@ fn proposal_to_response(
proposal: Proposal,
) -> ProposalResponse {
// replicate behaviour from `query_proposal` of cw3
let status = proposal.current_status(&block);
let status = proposal.current_status(block);
let threshold = proposal.threshold.to_response(proposal.total_weight);
ProposalResponse {
id: proposal_id,