From 3c7a59e48b7f2a9c8784bf0588e3039bd5aecd6a Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 18:21:37 +0200 Subject: [PATCH] Move issuer test methods, reformat Signed-off-by: Patrik Stas --- .../src/handlers/issuance/mediated_holder.rs | 4 +- .../src/handlers/issuance/mediated_issuer.rs | 49 ++--------------- .../proof_presentation/mediated_prover.rs | 10 ++-- .../proof_presentation/mediated_verifier.rs | 4 +- aries_vcx/tests/test_creds_proofs.rs | 4 +- aries_vcx/tests/utils/devsetup_alice.rs | 6 ++- aries_vcx/tests/utils/devsetup_faber.rs | 4 +- aries_vcx/tests/utils/devsetup_util.rs | 54 ++++++++++++++++--- aries_vcx/tests/utils/scenarios.rs | 11 ++-- 9 files changed, 77 insertions(+), 69 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/mediated_holder.rs b/aries_vcx/src/handlers/issuance/mediated_holder.rs index 88cc123f1e..af892739ea 100644 --- a/aries_vcx/src/handlers/issuance/mediated_holder.rs +++ b/aries_vcx/src/handlers/issuance/mediated_holder.rs @@ -1,7 +1,9 @@ +use std::collections::HashMap; + use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use messages::msg_fields::protocols::notification::Notification; use messages::AriesMessage; -use std::collections::HashMap; + use crate::handlers::issuance::holder::Holder; use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; use crate::protocols::issuance::holder::state_machine::HolderState; diff --git a/aries_vcx/src/handlers/issuance/mediated_issuer.rs b/aries_vcx/src/handlers/issuance/mediated_issuer.rs index 21c2c12289..a819d97e22 100644 --- a/aries_vcx/src/handlers/issuance/mediated_issuer.rs +++ b/aries_vcx/src/handlers/issuance/mediated_issuer.rs @@ -1,33 +1,12 @@ -use crate::errors::error::VcxResult; -use crate::handlers::connection::mediated_connection::MediatedConnection; -use crate::handlers::issuance::issuer::Issuer; -use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; -use crate::protocols::issuance::issuer::state_machine::{IssuerFullState, IssuerSM, IssuerState}; -use agency_client::agency_client::AgencyClient; -use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; -use aries_vcx_core::wallet::base_wallet::BaseWallet; -use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; +use std::collections::HashMap; + use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use messages::msg_fields::protocols::notification::Notification; use messages::AriesMessage; -use std::collections::HashMap; -pub async fn issuer_update_with_mediator( - sm: &mut Issuer, - agency_client: &AgencyClient, - connection: &MediatedConnection, -) -> VcxResult { - trace!("issuer_update_with_mediator >>>"); - let messages = connection.get_messages(agency_client).await?; - if let Some((uid, msg)) = issuer_find_message_to_handle(sm, messages) { - trace!("Issuer::update_state >>> found msg to handle; uid: {uid}, msg: {msg:?}"); - sm.process_aries_msg(msg.into()).await?; - connection.update_message_status(&uid, agency_client).await?; - } else { - trace!("Issuer::update_state >>> found no msg to handle"); - } - Ok(sm.get_state()) -} +use crate::handlers::issuance::issuer::Issuer; +use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; +use crate::protocols::issuance::issuer::state_machine::IssuerState; #[allow(clippy::unwrap_used)] pub fn issuer_find_message_to_handle( @@ -88,21 +67,3 @@ pub fn issuer_find_message_to_handle( } None } - -// todo: returns specific type -pub async fn get_credential_proposal_messages( - agency_client: &AgencyClient, - connection: &MediatedConnection, -) -> VcxResult> { - let credential_proposals: Vec<(String, ProposeCredential)> = connection - .get_messages(agency_client) - .await? - .into_iter() - .filter_map(|(uid, message)| match message { - AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(proposal)) => Some((uid, proposal)), - _ => None, - }) - .collect(); - - Ok(credential_proposals) -} diff --git a/aries_vcx/src/handlers/proof_presentation/mediated_prover.rs b/aries_vcx/src/handlers/proof_presentation/mediated_prover.rs index e13a4d56e2..40826e1582 100644 --- a/aries_vcx/src/handlers/proof_presentation/mediated_prover.rs +++ b/aries_vcx/src/handlers/proof_presentation/mediated_prover.rs @@ -1,10 +1,12 @@ -use crate::handlers::proof_presentation::prover::Prover; -use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; -use crate::protocols::proof_presentation::prover::state_machine::ProverState; +use std::collections::HashMap; + use messages::msg_fields::protocols::notification::Notification; use messages::msg_fields::protocols::present_proof::PresentProof; use messages::AriesMessage; -use std::collections::HashMap; + +use crate::handlers::proof_presentation::prover::Prover; +use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; +use crate::protocols::proof_presentation::prover::state_machine::ProverState; #[allow(clippy::unwrap_used)] pub fn prover_find_message_to_handle( diff --git a/aries_vcx/src/handlers/proof_presentation/mediated_verifier.rs b/aries_vcx/src/handlers/proof_presentation/mediated_verifier.rs index 3f90e926ab..58d4bc8e71 100644 --- a/aries_vcx/src/handlers/proof_presentation/mediated_verifier.rs +++ b/aries_vcx/src/handlers/proof_presentation/mediated_verifier.rs @@ -1,6 +1,8 @@ +use std::collections::HashMap; + use messages::msg_fields::protocols::present_proof::PresentProof; use messages::AriesMessage; -use std::collections::HashMap; + use crate::handlers::proof_presentation::verifier::Verifier; use crate::handlers::util::{matches_opt_thread_id, matches_thread_id}; use crate::protocols::proof_presentation::verifier::state_machine::VerifierState; diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index b434d87bae..ba2cf1b478 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -563,10 +563,10 @@ mod tests { use serde_json::Value; + use crate::utils::devsetup_util::issuer_update_with_mediator; + use crate::utils::devsetup_util::verifier_update_with_mediator; use aries_vcx::common::test_utils::create_and_store_nonrevocable_credential_def; use aries_vcx::handlers::issuance::holder::Holder; - use aries_vcx::handlers::issuance::mediated_issuer::issuer_update_with_mediator; - use crate::utils::devsetup_util::verifier_update_with_mediator; use aries_vcx::handlers::proof_presentation::prover::Prover; use aries_vcx::handlers::proof_presentation::verifier::Verifier; use aries_vcx::protocols::issuance::holder::state_machine::HolderState; diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index b627456e7a..188f586f83 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -1,7 +1,9 @@ use std::collections::HashMap; use std::sync::Arc; -use crate::utils::devsetup_util::{get_credential_offer_messages, get_proof_request_messages, holder_update_with_mediator, prover_update_with_mediator}; +use crate::utils::devsetup_util::{ + get_credential_offer_messages, get_proof_request_messages, holder_update_with_mediator, prover_update_with_mediator, +}; use agency_client::agency_client::AgencyClient; use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; use agency_client::MessageStatusCode; @@ -19,7 +21,7 @@ use aries_vcx::protocols::issuance::holder::state_machine::HolderState; use aries_vcx::protocols::mediated_connection::invitee::state_machine::InviteeState; use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; use aries_vcx::utils::devsetup::{ - AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY, dev_build_featured_profile, dev_setup_wallet_indy, + dev_build_featured_profile, dev_setup_wallet_indy, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY, }; use aries_vcx::utils::provision::provision_cloud_agent; use aries_vcx::utils::random::generate_random_seed; diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 9b776289ee..44cd5664f6 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -3,6 +3,8 @@ use std::sync::Arc; use futures::future::BoxFuture; use serde_json::json; +use crate::utils::devsetup_util::issuer_update_with_mediator; +use crate::utils::devsetup_util::verifier_update_with_mediator; use agency_client::agency_client::AgencyClient; use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; use aries_vcx::common::ledger::transactions::write_endpoint_legacy; @@ -15,8 +17,6 @@ use aries_vcx::global::settings; use aries_vcx::global::settings::{init_issuer_config, DEFAULT_LINK_SECRET_ALIAS}; use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; use aries_vcx::handlers::issuance::issuer::Issuer; -use aries_vcx::handlers::issuance::mediated_issuer::issuer_update_with_mediator; -use crate::utils::devsetup_util::verifier_update_with_mediator; use aries_vcx::handlers::proof_presentation::verifier::Verifier; use aries_vcx::handlers::revocation_notification::sender::RevocationNotificationSender; use aries_vcx::handlers::util::OfferInfo; diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index 134574ad82..af9746e97d 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -2,21 +2,24 @@ use agency_client::agency_client::AgencyClient; use aries_vcx::core::profile::profile::Profile; use aries_vcx::errors::error::VcxResult; use aries_vcx::handlers::connection::mediated_connection::MediatedConnection; -use aries_vcx::handlers::proof_presentation::{mediated_prover, mediated_verifier}; +use aries_vcx::handlers::issuance::holder::Holder; +use aries_vcx::handlers::issuance::issuer::Issuer; +use aries_vcx::handlers::issuance::{mediated_holder, mediated_issuer}; use aries_vcx::handlers::proof_presentation::prover::Prover; use aries_vcx::handlers::proof_presentation::verifier::Verifier; -use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; -use aries_vcx_core::wallet::base_wallet::BaseWallet; -use messages::msg_fields::protocols::present_proof::PresentProof; -use messages::AriesMessage; -use std::sync::Arc; -use aries_vcx::handlers::issuance::holder::Holder; -use aries_vcx::handlers::issuance::mediated_holder; +use aries_vcx::handlers::proof_presentation::{mediated_prover, mediated_verifier}; use aries_vcx::protocols::issuance::holder::state_machine::HolderState; +use aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; +use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; +use aries_vcx_core::wallet::base_wallet::BaseWallet; +use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; +use messages::msg_fields::protocols::present_proof::PresentProof; +use messages::AriesMessage; +use std::sync::Arc; #[cfg(test)] pub mod test_utils { @@ -185,3 +188,38 @@ pub async fn get_credential_offer_messages( Ok(json!(credential_offers).to_string()) } + +pub async fn issuer_update_with_mediator( + sm: &mut Issuer, + agency_client: &AgencyClient, + connection: &MediatedConnection, +) -> VcxResult { + trace!("issuer_update_with_mediator >>>"); + let messages = connection.get_messages(agency_client).await?; + if let Some((uid, msg)) = mediated_issuer::issuer_find_message_to_handle(sm, messages) { + trace!("Issuer::update_state >>> found msg to handle; uid: {uid}, msg: {msg:?}"); + sm.process_aries_msg(msg.into()).await?; + connection.update_message_status(&uid, agency_client).await?; + } else { + trace!("Issuer::update_state >>> found no msg to handle"); + } + Ok(sm.get_state()) +} + +// todo: returns specific type +pub async fn get_credential_proposal_messages( + agency_client: &AgencyClient, + connection: &MediatedConnection, +) -> VcxResult> { + let credential_proposals: Vec<(String, ProposeCredential)> = connection + .get_messages(agency_client) + .await? + .into_iter() + .filter_map(|(uid, message)| match message { + AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(proposal)) => Some((uid, proposal)), + _ => None, + }) + .collect(); + + Ok(credential_proposals) +} diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 19f5eca6ca..a0b6cf2c46 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -29,7 +29,12 @@ pub mod test_utils { use crate::utils::devsetup_alice::Alice; use crate::utils::devsetup_faber::Faber; - use crate::utils::devsetup_util::{get_credential_offer_messages, get_proof_request_messages, holder_update_with_mediator, prover_update_with_mediator}; + use crate::utils::devsetup_util::get_credential_proposal_messages; + use crate::utils::devsetup_util::verifier_update_with_mediator; + use crate::utils::devsetup_util::{ + get_credential_offer_messages, get_proof_request_messages, holder_update_with_mediator, + issuer_update_with_mediator, prover_update_with_mediator, + }; use aries_vcx::common::ledger::transactions::into_did_doc; use aries_vcx::common::primitives::credential_definition::CredentialDef; use aries_vcx::common::primitives::revocation_registry::RevocationRegistry; @@ -38,10 +43,6 @@ pub mod test_utils { use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; use aries_vcx::handlers::issuance::holder::Holder; use aries_vcx::handlers::issuance::issuer::Issuer; - use aries_vcx::handlers::issuance::mediated_issuer::{ - get_credential_proposal_messages, issuer_update_with_mediator, - }; - use crate::utils::devsetup_util::verifier_update_with_mediator; use aries_vcx::handlers::proof_presentation::prover::Prover; use aries_vcx::handlers::proof_presentation::verifier::Verifier; use aries_vcx::protocols::issuance::holder::state_machine::HolderState;