Skip to content

Commit

Permalink
Post-rebase sync up with wallet migration changes
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 Jul 4, 2023
1 parent 276cab8 commit 568c796
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion aries_vcx/src/core/profile/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::sync::Arc;

use crate::errors::error::VcxResult;
use aries_vcx_core::ledger::base_ledger::TxnAuthrAgrmtOptions;
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds,
ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite},
wallet::base_wallet::BaseWallet,
};

use async_trait::async_trait;
Expand Down
41 changes: 26 additions & 15 deletions aries_vcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct SetupProfile {
pub institution_did: String,
pub profile: Arc<dyn Profile>,
pub teardown: Arc<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>,
pub genesis_file_path: String,
}

pub struct SetupPoolDirectory {
Expand Down Expand Up @@ -124,16 +125,20 @@ impl Drop for SetupMocks {
}
}

#[cfg(feature = "migration")]
pub fn make_modular_profile(wallet_handle: WalletHandle, genesis_file_path: String) -> Arc<ModularLibsProfile> {
let wallet = IndySdkWallet::new(wallet_handle);
Arc::new(ModularLibsProfile::init(Arc::new(wallet), LedgerPoolConfig { genesis_file_path }).unwrap())
}

impl SetupProfile {
pub async fn build_profile(genesis_file_path: String) -> SetupProfile {
// We have to start with the vdrtools profile
// in order to perform the migration
#[cfg(feature = "migration")]
// In case of migration test setup, we are starting with vdrtools, then we migrate
#[cfg(any(feature = "vdrtools", feature = "migration"))]
return {
info!("SetupProfile >> using indy profile");
SetupProfile::init_indy(genesis_file_path).await
SetupProfile::build_profile_vdrtools(genesis_file_path).await
};

#[cfg(feature = "mixed_breed")]
return {
info!("SetupProfile >> using mixed breed profile");
Expand All @@ -151,12 +156,6 @@ impl SetupProfile {
info!("SetupProfile >> using vdr proxy profile");
SetupProfile::build_profile_vdr_proxy_ledger(genesis_file_path).await
};

#[cfg(feature = "vdrtools")]
return {
info!("SetupProfile >> using indy profile");
SetupProfile::build_profile_vdrtools(genesis_file_path).await
};
}

#[cfg(feature = "vdrtools")]
Expand All @@ -175,6 +174,7 @@ impl SetupProfile {
}

SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown: Arc::new(move || Box::pin(indy_teardown(pool_handle, pool_name.clone()))),
Expand All @@ -187,9 +187,17 @@ impl SetupProfile {

let wallet = IndySdkWallet::new(wallet_handle);

let profile =
Arc::new(ModularLibsProfile::init(Arc::new(wallet), LedgerPoolConfig { genesis_file_path }).unwrap());

let profile = Arc::new(
ModularLibsProfile::init(
Arc::new(wallet),
LedgerPoolConfig {
genesis_file_path: genesis_file_path.clone(),
},
)
.unwrap(),
);

// todo: this setup should be extracted out, is shared between profiles
Arc::clone(&profile)
.inject_anoncreds()
.prover_create_link_secret(settings::DEFAULT_LINK_SECRET_ALIAS)
Expand All @@ -201,6 +209,7 @@ impl SetupProfile {
}

SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown: Arc::new(move || Box::pin(modular_teardown())),
Expand Down Expand Up @@ -230,14 +239,15 @@ impl SetupProfile {
}

SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown: Arc::new(move || Box::pin(indy_teardown(pool_handle, pool_name.clone()))),
}
}

#[cfg(feature = "vdr_proxy_ledger")]
async fn build_profile_vdr_proxy_ledger(_genesis_file_path: String) -> SetupProfile {
async fn build_profile_vdr_proxy_ledger(genesis_file_path: String) -> SetupProfile {
use std::env;

use crate::core::profile::vdr_proxy_profile::VdrProxyProfile;
Expand All @@ -255,6 +265,7 @@ impl SetupProfile {
}

SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown: Arc::new(move || Box::pin(vdr_proxy_teardown())),
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 @@ -577,7 +577,7 @@ mod tests {
use aries_vcx::utils::devsetup::*;

use crate::utils::devsetup_alice::create_alice;
use crate::utils::devsetup_faber::{create_faber, Faber};
use crate::utils::devsetup_faber::create_faber;
use crate::utils::devsetup_util::test_utils::PayloadKinds;
use crate::utils::scenarios::test_utils::{
_create_address_schema, _exchange_credential, _exchange_credential_with_proposal, accept_cred_proposal,
Expand All @@ -590,7 +590,7 @@ mod tests {
send_proof_proposal_1, send_proof_request, verifier_create_proof_and_send_request, verify_proof,
};

#[cfg(feature = "migration")]
// #[cfg(feature = "migration")]
use crate::utils::migration::Migratable;

#[tokio::test]
Expand Down
13 changes: 10 additions & 3 deletions aries_vcx/tests/utils/devsetup_alice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,28 @@ pub struct Alice {
pub rev_not_receiver: Option<RevocationNotificationReceiver>,
pub prover: Prover,
pub agency_client: AgencyClient,
pub teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>,
pub genesis_file_path: String,
pub(self) teardown: Arc<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>,
}

pub async fn create_alice(genesis_file_path: String) -> Alice {
let profile_setup = SetupProfile::build_profile(genesis_file_path).await;
let SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown,
} = profile_setup;
Alice::setup(profile, teardown).await
Alice::setup(profile, genesis_file_path, teardown).await
}

impl Alice {
// todo: we could rather have Drop in Profile, why is Alice doing this ...
pub async fn setup(profile: Arc<dyn Profile>, teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>) -> Alice {
pub async fn setup(
profile: Arc<dyn Profile>,
genesis_file_path: String,
teardown: Arc<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>,
) -> Alice {
let config_provision_agent = AgentProvisionConfig {
agency_did: AGENCY_DID.to_string(),
agency_verkey: AGENCY_VERKEY.to_string(),
Expand All @@ -78,6 +84,7 @@ impl Alice {
.await
.unwrap();
let alice = Alice {
genesis_file_path,
profile,
agency_client,
is_active: false,
Expand Down
10 changes: 7 additions & 3 deletions aries_vcx/tests/utils/devsetup_faber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,27 @@ pub struct Faber {
pub verifier: Verifier,
pub pairwise_info: PairwiseInfo,
pub agency_client: AgencyClient,
pub teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>,
pub genesis_file_path: String,
pub(self) teardown: Arc<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>,
}

pub async fn create_faber(genesis_file_path: String) -> Faber {
let profile_setup = SetupProfile::build_profile(genesis_file_path).await;
let SetupProfile {
genesis_file_path,
institution_did,
profile,
teardown,
} = profile_setup;
Faber::setup(profile, institution_did, teardown).await
Faber::setup(profile, genesis_file_path, institution_did, teardown).await
}

impl Faber {
pub async fn setup(
profile: Arc<dyn Profile>,
genesis_file_path: String,
institution_did: String,
teardown: Arc<dyn Fn() -> BoxFuture<'static, ()>>,
teardown: Arc<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>,
) -> Faber {
settings::reset_config_values_ariesvcx().unwrap();

Expand Down Expand Up @@ -99,6 +102,7 @@ impl Faber {
let rev_not_sender = RevocationNotificationSender::build();

let faber = Faber {
genesis_file_path,
profile,
agency_client,
is_active: false,
Expand Down
31 changes: 14 additions & 17 deletions aries_vcx/tests/utils/migration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::sync::Arc;

use crate::utils::devsetup_alice::Alice;
use crate::utils::devsetup_faber::Faber;
use aries_vcx::utils::devsetup::make_modular_profile;
use aries_vcx::{
core::profile::modular_libs_profile::ModularLibsProfile,
global::settings::WALLET_KDF_RAW,
utils::{constants::GENESIS_PATH, devsetup::SetupProfile, get_temp_dir_path},
utils::{devsetup::SetupProfile, get_temp_dir_path},
};
use aries_vcx_core::{
indy::wallet::{create_and_open_wallet, WalletConfig},
Expand All @@ -14,8 +17,6 @@ use aries_vcx_core::{
use async_trait::async_trait;
use uuid::Uuid;

use super::devsetup_agent::test_utils::{Alice, Faber};

#[async_trait]
pub trait Migratable {
async fn migrate(&mut self);
Expand All @@ -24,18 +25,20 @@ pub trait Migratable {
#[async_trait]
impl Migratable for SetupProfile {
async fn migrate(&mut self) {
info!("SetupProfile::migrate >>>");
let old_wh = self.profile.wallet_handle().unwrap();
let new_wh = migrate_and_replace_profile(old_wh).await;
self.profile = make_modular_profile(new_wh);
let new_wh = migrate_to_new_wallet(old_wh).await;
self.profile = make_modular_profile(new_wh, self.genesis_file_path.clone());
}
}

#[async_trait]
impl Migratable for Alice {
async fn migrate(&mut self) {
info!("Alice::migrate >>>");
let old_wh = self.profile.wallet_handle().unwrap();
let new_wh = migrate_and_replace_profile(old_wh).await;
self.profile = make_modular_profile(new_wh);
let new_wh = migrate_to_new_wallet(old_wh).await;
self.profile = make_modular_profile(new_wh, self.genesis_file_path.clone());
let new_wallet: Arc<dyn BaseWallet> = Arc::new(IndySdkWallet::new(new_wh));
self.agency_client.wallet = new_wallet.to_base_agency_client_wallet();
}
Expand All @@ -44,15 +47,16 @@ impl Migratable for Alice {
#[async_trait]
impl Migratable for Faber {
async fn migrate(&mut self) {
info!("Faber::migrate >>>");
let old_wh = self.profile.wallet_handle().unwrap();
let new_wh = migrate_and_replace_profile(old_wh).await;
self.profile = make_modular_profile(new_wh);
let new_wh = migrate_to_new_wallet(old_wh).await;
self.profile = make_modular_profile(new_wh, self.genesis_file_path.clone());
let new_wallet: Arc<dyn BaseWallet> = Arc::new(IndySdkWallet::new(new_wh));
self.agency_client.wallet = new_wallet.to_base_agency_client_wallet();
}
}

async fn migrate_and_replace_profile(src_wallet_handle: WalletHandle) -> WalletHandle {
async fn migrate_to_new_wallet(src_wallet_handle: WalletHandle) -> WalletHandle {
let wallet_config = make_wallet_config();
let dest_wallet_handle = create_and_open_wallet(&wallet_config).await.unwrap();

Expand All @@ -67,13 +71,6 @@ async fn migrate_and_replace_profile(src_wallet_handle: WalletHandle) -> WalletH
dest_wallet_handle
}

pub fn make_modular_profile(wallet_handle: WalletHandle) -> Arc<ModularLibsProfile> {
let genesis_file_path = String::from(get_temp_dir_path(GENESIS_PATH).to_str().unwrap());
let wallet = IndySdkWallet::new(wallet_handle);

Arc::new(ModularLibsProfile::init(Arc::new(wallet), LedgerPoolConfig { genesis_file_path }).unwrap())
}

fn make_wallet_config() -> WalletConfig {
let wallet_key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY".to_owned();
let wallet_name = format!("wallet_{}", Uuid::new_v4());
Expand Down
2 changes: 0 additions & 2 deletions aries_vcx_core/src/indy/ledger/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ pub mod test_utils {
use std::io::Write;
use std::{env, path::PathBuf};

use crate::utils::constants::{GENESIS_PATH, POOL};

use super::*;

pub fn get_temp_dir_path(filename: &str) -> PathBuf {
Expand Down

0 comments on commit 568c796

Please sign in to comment.