Skip to content

Commit

Permalink
Reuse SetupProfile code in Alice/Faber tests
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 Jun 27, 2023
1 parent 7f1908a commit 371d3ac
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 186 deletions.
81 changes: 32 additions & 49 deletions aries_vcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -60,7 +63,7 @@ pub struct SetupMocks {
pub struct SetupProfile {
pub institution_did: String,
pub profile: Arc<dyn Profile>,
pub(self) teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>,
pub teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>,
}

pub struct SetupPoolDirectory {
Expand Down Expand Up @@ -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 =
Expand All @@ -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
}
Expand All @@ -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<dyn Profile> = Arc::new(MixedBreedProfile::new(wallet_handle, pool_handle.clone()));

Expand All @@ -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<dyn Profile> = Arc::new(VdrProxyProfile::init(wallet_handle, client).await.unwrap());

async fn vdr_proxy_teardown() {
Expand All @@ -282,7 +265,7 @@ impl SetupProfile {
where
F: Future<Output = ()>,
{
let init = Self::init().await;
let init = Self::build_profile(GENESIS_PATH.into()).await;

let teardown = Arc::clone(&init.teardown);

Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/tests/test_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions aries_vcx/tests/test_creds_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}]
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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![]);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 371d3ac

Please sign in to comment.