Skip to content

Commit

Permalink
Move issuer test methods, reformat
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Aug 23, 2023
1 parent 88c1da4 commit 3c7a59e
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 69 deletions.
4 changes: 3 additions & 1 deletion aries_vcx/src/handlers/issuance/mediated_holder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
49 changes: 5 additions & 44 deletions aries_vcx/src/handlers/issuance/mediated_issuer.rs
Original file line number Diff line number Diff line change
@@ -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<IssuerState> {
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(
Expand Down Expand Up @@ -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<Vec<(String, ProposeCredential)>> {
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)
}
10 changes: 6 additions & 4 deletions aries_vcx/src/handlers/proof_presentation/mediated_prover.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/tests/test_creds_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions aries_vcx/tests/utils/devsetup_alice.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/tests/utils/devsetup_faber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
54 changes: 46 additions & 8 deletions aries_vcx/tests/utils/devsetup_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<IssuerState> {
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<Vec<(String, ProposeCredential)>> {
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)
}
11 changes: 6 additions & 5 deletions aries_vcx/tests/utils/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 3c7a59e

Please sign in to comment.