From 371d3ac770867fd54f1bc4f154ccfe2304f51491 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Tue, 27 Jun 2023 19:48:20 +0200 Subject: [PATCH] Reuse SetupProfile code in Alice/Faber tests Signed-off-by: Patrik Stas --- aries_vcx/src/utils/devsetup.rs | 81 ++++++++----------- aries_vcx/tests/test_connection.rs | 6 +- aries_vcx/tests/test_creds_proofs.rs | 24 +++--- .../tests/test_creds_proofs_revocations.rs | 16 ++-- aries_vcx/tests/utils/devsetup_alice.rs | 23 ++---- aries_vcx/tests/utils/devsetup_faber.rs | 54 +++++-------- aries_vcx/tests/utils/devsetup_util.rs | 56 ------------- aries_vcx/tests/utils/scenarios.rs | 16 ++-- 8 files changed, 90 insertions(+), 186 deletions(-) diff --git a/aries_vcx/src/utils/devsetup.rs b/aries_vcx/src/utils/devsetup.rs index 3a2c25a386..8bc01fdcfe 100644 --- a/aries_vcx/src/utils/devsetup.rs +++ b/aries_vcx/src/utils/devsetup.rs @@ -23,11 +23,14 @@ use aries_vcx_core::{PoolHandle, WalletHandle}; use chrono::{DateTime, Duration, Utc}; use futures::future::BoxFuture; +use uuid::Uuid; use agency_client::agency_client::AgencyClient; use agency_client::configuration::AgentProvisionConfig; use agency_client::testing::mocking::{enable_agency_mocks, AgencyMockDecrypted}; -use aries_vcx_core::indy::ledger::pool::indy_close_pool; +use aries_vcx_core::indy::ledger::pool::{ + create_pool_ledger_config, indy_close_pool, indy_delete_pool, indy_open_pool, +}; #[cfg(feature = "mixed_breed")] use crate::core::profile::mixed_breed_profile::MixedBreedProfile; @@ -42,7 +45,7 @@ use crate::global::settings; use crate::global::settings::{aries_vcx_disable_indy_mocks, aries_vcx_enable_indy_mocks, set_test_configs}; use crate::global::settings::{init_issuer_config, reset_config_values_ariesvcx}; use crate::utils; -use crate::utils::constants::GENESIS_PATH; +use crate::utils::constants::{GENESIS_PATH, POOL}; use crate::utils::file::write_file; use crate::utils::get_temp_dir_path; use crate::utils::provision::provision_cloud_agent; @@ -60,7 +63,7 @@ pub struct SetupMocks { pub struct SetupProfile { pub institution_did: String, pub profile: Arc, - pub(self) teardown: Arc BoxFuture<'static, ()>>, + pub teardown: Arc BoxFuture<'static, ()>>, } pub struct SetupPoolDirectory { @@ -123,72 +126,65 @@ impl Drop for SetupMocks { } impl SetupProfile { - pub async fn init() -> SetupProfile { + pub async fn build_profile(genesis_file_path: String) -> SetupProfile { init_test_logging(); set_test_configs(); #[cfg(feature = "mixed_breed")] return { info!("SetupProfile >> using mixed breed profile"); - SetupProfile::init_mixed_breed().await + SetupProfile::build_profile_mixed_breed(genesis_file_path).await }; #[cfg(feature = "modular_libs")] return { info!("SetupProfile >> using modular profile"); - SetupProfile::init_modular().await + SetupProfile::build_profile_modular(genesis_file_path).await }; #[cfg(feature = "vdr_proxy_ledger")] return { info!("SetupProfile >> using vdr proxy profile"); - SetupProfile::init_vdr_proxy_ledger().await + SetupProfile::build_profile_vdr_proxy_ledger(genesis_file_path).await }; #[cfg(feature = "vdrtools")] return { info!("SetupProfile >> using indy profile"); - SetupProfile::init_indy().await + SetupProfile::build_profile_vdrtools(genesis_file_path).await }; } - // FUTURE - ideally no tests should be using this method, they should be using the generic init - // after modular profile Anoncreds/Ledger methods have all been implemented, all tests should use init() #[cfg(feature = "vdrtools")] - async fn init_indy() -> SetupProfile { - let (institution_did, wallet_handle) = setup_issuer_wallet().await; + async fn build_profile_vdrtools(genesis_file_path: String) -> SetupProfile { + // todo: can remove? + settings::set_config_value(settings::CONFIG_GENESIS_PATH, &genesis_file_path).unwrap(); + let pool_name = Uuid::new_v4().to_string(); + create_pool_ledger_config(&pool_name, get_temp_dir_path(&genesis_file_path).to_str().unwrap()).unwrap(); + let pool_handle = indy_open_pool(&pool_name, None).await.unwrap(); - settings::set_config_value( - settings::CONFIG_GENESIS_PATH, - utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH) - .to_str() - .unwrap(), - ) - .unwrap(); - let pool_handle = open_test_pool().await; + let (institution_did, wallet_handle) = setup_issuer_wallet().await; let profile = Arc::new(VdrtoolsProfile::init(wallet_handle, pool_handle.clone())); - async fn indy_teardown(pool_handle: PoolHandle) { + async fn indy_teardown(pool_handle: PoolHandle, pool_name: String) { indy_close_pool(pool_handle.clone()).await.unwrap(); - delete_test_pool().await; + indy_delete_pool(&pool_name).await.unwrap(); } SetupProfile { institution_did, profile, - teardown: Arc::new(move || Box::pin(indy_teardown(pool_handle))), + teardown: Arc::new(move || Box::pin(indy_teardown(pool_handle, pool_name.clone()))), } } #[cfg(feature = "modular_libs")] - async fn init_modular() -> SetupProfile { + async fn build_profile_modular(genesis_file_path: String) -> SetupProfile { use aries_vcx_core::indy::ledger::pool::test_utils::create_tmp_genesis_txn_file; let (institution_did, wallet_handle) = setup_issuer_wallet().await; - let genesis_file_path = create_tmp_genesis_txn_file(); - let wallet = IndySdkWallet::new(wallet_handle); let profile = @@ -200,14 +196,6 @@ impl SetupProfile { .await .unwrap(); - let indy_read = Arc::clone(&profile).inject_indy_ledger_read(); - match prepare_taa_options(indy_read).await.unwrap() { - None => {} - Some(taa_options) => { - Arc::clone(&profile).update_taa_configuration(taa_options); - } - } - async fn modular_teardown() { // nothing to do } @@ -220,17 +208,13 @@ impl SetupProfile { } #[cfg(feature = "mixed_breed")] - async fn init_mixed_breed() -> SetupProfile { - let (institution_did, wallet_handle) = setup_issuer_wallet().await; + async fn build_profile_mixed_breed(genesis_file_path: String) -> SetupProfile { + // todo: can remove? + settings::set_config_value(settings::CONFIG_GENESIS_PATH, &genesis_file_path).unwrap(); + create_pool_ledger_config(POOL, get_temp_dir_path(&genesis_file_path).to_str().unwrap()).unwrap(); + let pool_handle = indy_open_pool(POOL, None).await.unwrap(); - settings::set_config_value( - settings::CONFIG_GENESIS_PATH, - utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH) - .to_str() - .unwrap(), - ) - .unwrap(); - let pool_handle = open_test_pool().await; + let (institution_did, wallet_handle) = setup_issuer_wallet().await; let profile: Arc = Arc::new(MixedBreedProfile::new(wallet_handle, pool_handle.clone())); @@ -253,18 +237,17 @@ impl SetupProfile { } #[cfg(feature = "vdr_proxy_ledger")] - async fn init_vdr_proxy_ledger() -> SetupProfile { + async fn build_profile_vdr_proxy_ledger(_genesis_file_path: String) -> SetupProfile { use std::env; use crate::core::profile::vdr_proxy_profile::VdrProxyProfile; use aries_vcx_core::VdrProxyClient; - let (institution_did, wallet_handle) = setup_issuer_wallet().await; - - // TODO: Test configuration should be handled uniformly let client_url = env::var("VDR_PROXY_CLIENT_URL").unwrap_or_else(|_| "http://127.0.0.1:3030".to_string()); let client = VdrProxyClient::new(&client_url).unwrap(); + let (institution_did, wallet_handle) = setup_issuer_wallet().await; + let profile: Arc = Arc::new(VdrProxyProfile::init(wallet_handle, client).await.unwrap()); async fn vdr_proxy_teardown() { @@ -282,7 +265,7 @@ impl SetupProfile { where F: Future, { - let init = Self::init().await; + let init = Self::build_profile(GENESIS_PATH.into()).await; let teardown = Arc::clone(&init.teardown); diff --git a/aries_vcx/tests/test_connection.rs b/aries_vcx/tests/test_connection.rs index c2959b7ca0..da03d41f44 100644 --- a/aries_vcx/tests/test_connection.rs +++ b/aries_vcx/tests/test_connection.rs @@ -69,7 +69,7 @@ mod integration_tests { let request_sender = create_proof_request(&mut institution, REQUESTED_ATTRIBUTES, "[]", "{}", None).await; - let did = institution.config_issuer.institution_did.clone(); + let did = institution.institution_did.clone(); let oob_sender = OutOfBandSender::create() .set_label("test-label") .set_goal_code(OobGoalCode::P2PMessaging) @@ -193,7 +193,7 @@ mod integration_tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections_via_public_invite(&mut consumer, &mut institution).await; - let did = institution.config_issuer.institution_did.clone(); + let did = institution.institution_did.clone(); let oob_sender = OutOfBandSender::create() .set_label("test-label") .set_goal_code(OobGoalCode::P2PMessaging) @@ -232,7 +232,7 @@ mod integration_tests { let (mut consumer_to_institution, mut institution_to_consumer) = create_connected_connections_via_public_invite(&mut consumer, &mut institution).await; - let did = institution.config_issuer.institution_did.clone(); + let did = institution.institution_did.clone(); let oob_sender = OutOfBandSender::create() .set_label("test-label") .set_goal_code(OobGoalCode::P2PMessaging) diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 3db7eba153..c65f03e1e9 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -589,7 +589,7 @@ mod tests { { "name": "address1", "restrictions": [{ - "issuer_did": institution.config_issuer.institution_did, + "issuer_did": institution.institution_did, "schema_id": schema_id, "cred_def_id": cred_def_id, }] @@ -757,7 +757,7 @@ mod tests { create_connected_connections(&mut consumer2, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); let _credential_handle1 = _exchange_credential( @@ -910,7 +910,7 @@ mod tests { create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let (address1, address, city, state, zip) = attr_names(); let credential_data = json!({address1.clone(): "5th Avenue", address.clone(): "Suite 1234", city.clone(): "NYC", state.clone(): "NYS", zip.clone(): "84712"}).to_string(); let _credential_handle = _exchange_credential( @@ -1001,7 +1001,7 @@ mod tests { &institution.profile.inject_anoncreds(), &institution.profile.inject_anoncreds_ledger_read(), &institution.profile.inject_anoncreds_ledger_write(), - &institution.config_issuer.institution_did, + &institution.institution_did, &attrs_list, ) .await; @@ -1041,7 +1041,7 @@ mod tests { info!("test_real_proof :: AS INSTITUTION SEND PROOF REQUEST"); - let institution_did = &institution.config_issuer.institution_did.clone(); + let institution_did = &institution.institution_did.clone(); let restrictions = json!({ "issuer_did": institution_did, "schema_id": schema_id, "cred_def_id": cred_def_id, }); let mut attrs: Value = serde_json::Value::Array(vec![]); @@ -1116,7 +1116,7 @@ mod tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); @@ -1196,7 +1196,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); _exchange_credential_with_proposal( @@ -1225,7 +1225,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); let mut holder = send_cred_proposal( @@ -1265,7 +1265,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); let mut holder = send_cred_proposal( @@ -1326,7 +1326,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); _exchange_credential_with_proposal( @@ -1368,7 +1368,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); _exchange_credential_with_proposal( @@ -1400,7 +1400,7 @@ mod tests { let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, _cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let tails_file = rev_reg.get_tails_dir(); _exchange_credential_with_proposal( diff --git a/aries_vcx/tests/test_creds_proofs_revocations.rs b/aries_vcx/tests/test_creds_proofs_revocations.rs index eb9adcc112..b93d63832d 100644 --- a/aries_vcx/tests/test_creds_proofs_revocations.rs +++ b/aries_vcx/tests/test_creds_proofs_revocations.rs @@ -61,7 +61,7 @@ mod integration_tests { .unwrap()); let _requested_attrs = requested_attrs( - &institution.config_issuer.institution_did, + &institution.institution_did, &schema_id, &cred_def_id, None, @@ -282,7 +282,7 @@ mod integration_tests { // Issue and send three credentials of the same schema let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); let issuer_credential1 = _exchange_credential( @@ -516,7 +516,7 @@ mod integration_tests { let from = time_before_revocation - 100; let to = time_before_revocation; let _requested_attrs = requested_attrs( - &institution.config_issuer.institution_did, + &institution.institution_did, &schema_id, &cred_def_id, Some(from), @@ -596,7 +596,7 @@ mod integration_tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); @@ -700,7 +700,7 @@ mod integration_tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _rev_reg_id) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); @@ -801,7 +801,7 @@ mod integration_tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); @@ -898,7 +898,7 @@ mod integration_tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); @@ -999,7 +999,7 @@ mod integration_tests { let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut issuer).await; let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = - _create_address_schema(&issuer.profile, &issuer.config_issuer.institution_did).await; + _create_address_schema(&issuer.profile, &issuer.institution_did).await; let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index 42b99dbc2c..1485738e59 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -23,7 +23,7 @@ use aries_vcx::handlers::util::{AnyInvitation, Status}; 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::{SetupPoolDirectory, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; +use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; use aries_vcx::utils::provision::provision_cloud_agent; use aries_vcx_core::indy::ledger::pool::indy_open_pool; use aries_vcx_core::indy::ledger::pool::test_utils::{create_test_ledger_config_custom, open_test_pool}; @@ -56,20 +56,13 @@ pub struct Alice { } pub async fn create_alice(genesis_file_path: String) -> Alice { - #[cfg(not(feature = "modular_libs"))] - let (alice_profile, teardown) = { - info!("create_alice >> using indy profile"); - setup_vdrtools_profile(genesis_file_path).await - }; - - #[cfg(feature = "modular_libs")] - let (alice_profile, teardown) = { - let config = LedgerPoolConfig { genesis_file_path }; - info!("create_test_alice_instance >> using modular profile"); - setup_modular_profile(config).await - }; - - Alice::setup(alice_profile, teardown).await + let profile_setup = SetupProfile::build_profile(genesis_file_path).await; + let SetupProfile { + institution_did, + profile, + teardown, + } = profile_setup; + Alice::setup(profile, teardown).await } impl Alice { diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 4ab2c58d2e..ce27157a15 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -24,7 +24,7 @@ use aries_vcx::protocols::mediated_connection::inviter::state_machine::InviterSt use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; use aries_vcx::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder; -use aries_vcx::utils::devsetup::{SetupPoolDirectory, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; +use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; use aries_vcx::utils::provision::provision_cloud_agent; use aries_vcx_core::indy::wallet::{ create_wallet_with_master_secret, open_wallet, wallet_configure_issuer, IssuerConfig, WalletConfig, @@ -45,7 +45,7 @@ pub struct Faber { pub profile: Arc, pub is_active: bool, pub config_agency: AgencyClientConfig, - pub config_issuer: IssuerConfig, + pub institution_did: String, pub rev_not_sender: RevocationNotificationSender, pub connection: MediatedConnection, pub schema: Schema, @@ -58,25 +58,22 @@ pub struct Faber { } pub async fn create_faber(genesis_file_path: String) -> Faber { - #[cfg(not(feature = "modular_libs"))] - let (profile, teardown) = { - info!("create_faber >> using indy profile"); - setup_vdrtools_profile(genesis_file_path).await - }; - - #[cfg(feature = "modular_libs")] - let (profile, teardown) = { - let config = LedgerPoolConfig { genesis_file_path }; - info!("create_faber >> using modular profile"); - setup_modular_profile(config).await - }; - Faber::setup(profile, teardown).await + let profile_setup = SetupProfile::build_profile(genesis_file_path).await; + let SetupProfile { + institution_did, + profile, + teardown, + } = profile_setup; + Faber::setup(profile, institution_did, teardown).await } impl Faber { - pub async fn setup(profile: Arc, teardown: Arc BoxFuture<'static, ()>>) -> Faber { + pub async fn setup( + profile: Arc, + institution_did: String, + teardown: Arc BoxFuture<'static, ()>>, + ) -> Faber { settings::reset_config_values_ariesvcx().unwrap(); - let enterprise_seed = "000000000000000000000000Trustee1"; let config_provision_agent = AgentProvisionConfig { agency_did: AGENCY_DID.to_string(), @@ -85,11 +82,8 @@ impl Faber { agent_seed: None, }; - // we shouldn't be getting handle, it's indy wallet specific concept - let wallet_handle = WalletHandle(profile.inject_wallet().get_wallet_handle()); - let config_issuer = wallet_configure_issuer(wallet_handle, enterprise_seed).await.unwrap(); - - init_issuer_config(&config_issuer.institution_did).unwrap(); + // todo: can delete following? + init_issuer_config(&institution_did).unwrap(); let mut agency_client = AgencyClient::new(); let config_agency = provision_cloud_agent(&mut agency_client, profile.inject_wallet(), &config_provision_agent) .await @@ -102,13 +96,9 @@ impl Faber { let service = AriesService::create() .set_service_endpoint(agency_client.get_agency_url_full().unwrap()) .set_recipient_keys(vec![pairwise_info.pw_vk.clone()]); - write_endpoint_legacy( - &profile.inject_indy_ledger_write(), - &config_issuer.institution_did, - &service, - ) - .await - .unwrap(); + write_endpoint_legacy(&profile.inject_indy_ledger_write(), &institution_did, &service) + .await + .unwrap(); let rev_not_sender = RevocationNotificationSender::build(); @@ -117,7 +107,7 @@ impl Faber { agency_client, is_active: false, config_agency, - config_issuer, + institution_did, schema: Schema::default(), cred_def: CredentialDef::default(), connection, @@ -141,7 +131,7 @@ impl Faber { self.schema = Schema::create( &self.profile.inject_anoncreds(), "", - &self.config_issuer.institution_did, + &self.institution_did, &name, &version, &data, @@ -213,7 +203,7 @@ impl Faber { pub fn create_public_invite(&mut self) -> VcxResult { let id = "test_invite_id"; - let content = PublicInvitationContent::new("faber".to_owned(), self.config_issuer.institution_did.clone()); + let content = PublicInvitationContent::new("faber".to_owned(), self.institution_did.clone()); let public_invitation = PublicInvitation::new(id.to_owned(), content); Ok(json!(AriesMessage::from(public_invitation)).to_string()) } diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index b18fdac2ce..170e01aa56 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -108,59 +108,3 @@ pub mod test_utils { .unwrap_or_else(|_| error!("Failed to delete wallet while teardowning: {:?}", config_wallet)); } } - -async fn setup_indy_wallet() -> (WalletHandle, WalletConfig) { - let config_wallet = WalletConfig { - wallet_name: format!("wallet_{}", uuid::Uuid::new_v4().to_string()), - wallet_key: settings::DEFAULT_WALLET_KEY.into(), - wallet_key_derivation: settings::WALLET_KDF_RAW.into(), - wallet_type: None, - storage_config: None, - storage_credentials: None, - rekey: None, - rekey_derivation_method: None, - }; - create_wallet_with_master_secret(&config_wallet).await.unwrap(); - let wallet_handle = open_wallet(&config_wallet).await.unwrap(); - - (wallet_handle, config_wallet) -} - -#[cfg(feature = "modular_libs")] -pub async fn setup_modular_profile( - ledger_pool_config: LedgerPoolConfig, -) -> (Arc, Arc BoxFuture<'static, ()>>) { - let (wallet_handle, config_wallet) = setup_indy_wallet().await; - - let wallet: Arc = Arc::new(IndySdkWallet::new(wallet_handle)); - - let profile = Arc::new(ModularLibsProfile::init(wallet, ledger_pool_config).unwrap()); - - // set up anoncreds link/master secret - Arc::clone(&profile) - .inject_anoncreds() - .prover_create_link_secret(settings::DEFAULT_LINK_SECRET_ALIAS) - .await - .unwrap(); - - ( - profile, - Arc::new(move || Box::pin(teardown_indy_wallet(wallet_handle, config_wallet.clone()))), - ) -} - -pub async fn setup_vdrtools_profile( - genesis_file_path: String, -) -> (Arc, Arc BoxFuture<'static, ()>>) { - let (wallet_handle, config_wallet) = setup_indy_wallet().await; - - let pool_uuid = uuid::Uuid::new_v4().to_string(); - create_test_ledger_config_custom(&pool_uuid, &genesis_file_path).await; - let pool_handle = indy_open_pool(&pool_uuid, None).await.unwrap(); - let indy_profile = VdrtoolsProfile::init(wallet_handle, pool_handle); - - ( - Arc::new(indy_profile), - Arc::new(move || Box::pin(teardown_indy_wallet(wallet_handle, config_wallet.clone()))), - ) -} diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index c8e906e85e..dda88cdbd5 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -922,7 +922,7 @@ pub mod test_utils { .publish_local_revocations( &faber.profile.inject_anoncreds(), &faber.profile.inject_anoncreds_ledger_write(), - &faber.config_issuer.institution_did, + &faber.institution_did, ) .await .unwrap(); @@ -950,7 +950,7 @@ pub mod test_utils { ) -> RevocationRegistry { let mut rev_reg_new = RevocationRegistry::create( &faber.profile.inject_anoncreds(), - &faber.config_issuer.institution_did, + &faber.institution_did, &credential_def.get_cred_def_id(), &rev_reg.get_tails_dir(), 10, @@ -970,7 +970,7 @@ pub mod test_utils { .publish_local_revocations( &institution.profile.inject_anoncreds(), &institution.profile.inject_anoncreds_ledger_write(), - &institution.config_issuer.institution_did, + &institution.institution_did, ) .await .unwrap(); @@ -1095,7 +1095,7 @@ pub mod test_utils { Issuer, ) { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, rev_reg_id) = - _create_address_schema(&institution.profile, &institution.config_issuer.institution_did).await; + _create_address_schema(&institution.profile, &institution.institution_did).await; info!("test_real_proof_with_revocation :: AS INSTITUTION SEND CREDENTIAL OFFER"); let (address1, address2, city, state, zip) = attr_names(); @@ -1124,13 +1124,7 @@ pub mod test_utils { cred_def_id: &str, request_name: Option<&str>, ) -> Verifier { - let _requested_attrs = requested_attrs( - &institution.config_issuer.institution_did, - &schema_id, - &cred_def_id, - None, - None, - ); + let _requested_attrs = requested_attrs(&institution.institution_did, &schema_id, &cred_def_id, None, None); let requested_attrs_string = serde_json::to_string(&_requested_attrs).unwrap(); send_proof_request( institution,