From c9c4006748046d92348b60290afd83ffb11eac9a Mon Sep 17 00:00:00 2001 From: Patrik Date: Fri, 5 May 2023 14:19:18 +0200 Subject: [PATCH] Cleanup/ffi leftovers (#825) Remove StatusCodeMock. Signed-off-by: Patrik Stas --- .../primitives/credential_definition.rs | 5 +-- aries_vcx/src/global/author_agreement.rs | 18 ++++++++ aries_vcx/src/global/mod.rs | 1 + aries_vcx/src/utils/author_agreement.rs | 22 ---------- aries_vcx/src/utils/mockdata/mock_settings.rs | 29 ------------- .../utils/mockdata/profile/mock_anoncreds.rs | 7 --- .../src/utils/mockdata/profile/mock_ledger.rs | 9 ---- aries_vcx/src/utils/mod.rs | 1 - .../src/{utils => global}/author_agreement.rs | 12 +++--- .../src/global/mockdata/mock_settings.rs | 16 +++++++ .../src/{utils => global}/mockdata/mod.rs | 0 aries_vcx_core/src/global/mod.rs | 2 + aries_vcx_core/src/global/settings.rs | 4 ++ .../src/indy/credentials/issuer/mod.rs | 8 ---- aries_vcx_core/src/indy/ledger/pool.rs | 12 ++++-- .../src/indy/ledger/transactions.rs | 19 ++++---- .../src/indy/proofs/prover/prover.rs | 2 +- aries_vcx_core/src/indy/utils/mod.rs | 20 ++++++++- aries_vcx_core/src/ledger/indy_vdr_ledger.rs | 4 +- .../src/utils/mockdata/mock_settings.rs | 43 ------------------- aries_vcx_core/src/utils/mod.rs | 9 ---- aries_vcx_core/src/utils/random.rs | 20 --------- libvcx_core/src/api_vcx/api_global/ledger.rs | 2 +- .../api_vcx/api_handle/issuer_credential.rs | 1 - wrappers/node/package-lock.json | 1 + wrappers/vcx-napi-rs/src/api/ledger.rs | 1 + 26 files changed, 90 insertions(+), 178 deletions(-) create mode 100644 aries_vcx/src/global/author_agreement.rs delete mode 100644 aries_vcx/src/utils/author_agreement.rs rename aries_vcx_core/src/{utils => global}/author_agreement.rs (89%) create mode 100644 aries_vcx_core/src/global/mockdata/mock_settings.rs rename aries_vcx_core/src/{utils => global}/mockdata/mod.rs (100%) delete mode 100644 aries_vcx_core/src/utils/mockdata/mock_settings.rs delete mode 100644 aries_vcx_core/src/utils/random.rs diff --git a/aries_vcx/src/common/primitives/credential_definition.rs b/aries_vcx/src/common/primitives/credential_definition.rs index d9b8b37d9e..c3db10c061 100644 --- a/aries_vcx/src/common/primitives/credential_definition.rs +++ b/aries_vcx/src/common/primitives/credential_definition.rs @@ -4,7 +4,6 @@ use aries_vcx_core::ledger::base_ledger::BaseLedger; use crate::core::profile::profile::Profile; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; use crate::utils::constants::{CRED_DEF_ID, CRED_DEF_JSON, DEFAULT_SERIALIZE_VERSION}; -use crate::utils::mockdata::mock_settings::StatusCodeMock; use crate::utils::serialization::ObjectWithVersion; use crate::global::settings::{self, indy_mocks_enabled}; @@ -109,10 +108,8 @@ async fn _try_get_cred_def_from_ledger( issuer_did: &str, cred_def_id: &str, ) -> VcxResult> { - // TODO - future - may require more customized logic. We set the rc to 309, as the mock for ledger.get_cred_def will return a valid - // mock cred def unless it reads an rc of 309. Returning a valid mock cred def will result in this method returning an error. if indy_mocks_enabled() { - StatusCodeMock::set_next_result(309) + return Ok(None); } match ledger.get_cred_def(cred_def_id, Some(issuer_did)).await { Ok(cred_def) => Ok(Some(cred_def)), diff --git a/aries_vcx/src/global/author_agreement.rs b/aries_vcx/src/global/author_agreement.rs new file mode 100644 index 0000000000..f4cc48da24 --- /dev/null +++ b/aries_vcx/src/global/author_agreement.rs @@ -0,0 +1,18 @@ +use crate::errors::error::VcxResult; +use aries_vcx_core::global::author_agreement::{ + get_txn_author_agreement, set_txn_author_agreement, TxnAuthorAgreementAcceptanceData, +}; + +pub fn proxy_set_txn_author_agreement( + text: Option, + version: Option, + taa_digest: Option, + acc_mech_type: String, + time_of_acceptance: u64, +) -> VcxResult<()> { + set_txn_author_agreement(text, version, taa_digest, acc_mech_type, time_of_acceptance).map_err(|err| err.into()) +} + +pub fn proxy_get_txn_author_agreement() -> VcxResult> { + get_txn_author_agreement().map_err(|err| err.into()) +} diff --git a/aries_vcx/src/global/mod.rs b/aries_vcx/src/global/mod.rs index 6e98cefd04..7efff50d94 100644 --- a/aries_vcx/src/global/mod.rs +++ b/aries_vcx/src/global/mod.rs @@ -1 +1,2 @@ +pub mod author_agreement; pub mod settings; diff --git a/aries_vcx/src/utils/author_agreement.rs b/aries_vcx/src/utils/author_agreement.rs deleted file mode 100644 index 64dbbb98a8..0000000000 --- a/aries_vcx/src/utils/author_agreement.rs +++ /dev/null @@ -1,22 +0,0 @@ -use aries_vcx_core::utils::author_agreement::{ - get_global_txn_author_agreement, set_global_txn_author_agreement, TxnAuthorAgreementAcceptanceData, -}; -use serde_json; - -use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; -use crate::global::settings; - -pub fn set_txn_author_agreement( - text: Option, - version: Option, - taa_digest: Option, - acc_mech_type: String, - time_of_acceptance: u64, -) -> VcxResult<()> { - set_global_txn_author_agreement(text, version, taa_digest, acc_mech_type, time_of_acceptance) - .map_err(|err| err.into()) -} - -pub fn get_txn_author_agreement() -> VcxResult> { - get_global_txn_author_agreement().map_err(|err| err.into()) -} diff --git a/aries_vcx/src/utils/mockdata/mock_settings.rs b/aries_vcx/src/utils/mockdata/mock_settings.rs index 09289fed1a..c01e0f6e57 100644 --- a/aries_vcx/src/utils/mockdata/mock_settings.rs +++ b/aries_vcx/src/utils/mockdata/mock_settings.rs @@ -10,9 +10,6 @@ static MOCKED_VALIDATE_INDY_PROOF: &str = "mocked_validate_indy_proof"; lazy_static! { static ref MOCK_SETTINGS: RwLock> = RwLock::new(HashMap::new()); static ref MOCK_SETTINGS_RESULT_BOOL: RwLock>> = RwLock::new(HashMap::new()); - // todo: get rid of this, we no longer deal with rc return codes from vdrtools - // (this is leftover from times when we talked to vdrtool via FFI) - static ref STATUS_CODE_MOCK: Mutex = Mutex::new(StatusCodeMock::default()); } pub struct MockBuilder; // empty @@ -87,29 +84,3 @@ pub fn get_mock_result_for_validate_indy_proof() -> Option> { Err(err) => Err(AriesVcxError::from_msg(err.kind(), err.to_string())), }) } - -#[derive(Default)] -pub struct StatusCodeMock { - results: Vec, -} - -// todo: get rid of this, we no longer deal with rc return codes from vdrtools -// (this is leftover from times when we talked to vdrtool via FFI) -impl StatusCodeMock { - pub fn set_next_result(rc: u32) { - STATUS_CODE_MOCK - .lock() - .expect("Unabled to access LIBINDY_MOCK") - .results - .push(rc); - } - - pub fn get_result() -> u32 { - STATUS_CODE_MOCK - .lock() - .expect("Unable to access LIBINDY_MOCK") - .results - .pop() - .unwrap_or_default() - } -} diff --git a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs index 2bf6b18750..fcb20154cb 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs @@ -1,4 +1,3 @@ -use crate::utils::mockdata::mock_settings::StatusCodeMock; use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; use async_trait::async_trait; @@ -65,12 +64,6 @@ impl BaseAnonCreds for MockAnoncreds { } async fn issuer_create_credential_offer(&self, _cred_def_id: &str) -> VcxCoreResult { - if StatusCodeMock::get_result() != 0 { - return Err(AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::InvalidState, - "Mocked error result of issuer_create_credential_offer: issuer_create_credential_offer", - )); - }; Ok(LIBINDY_CRED_OFFER.to_string()) } diff --git a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs index c248a2bbb3..368e785f05 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs @@ -1,4 +1,3 @@ -use crate::utils::mockdata::mock_settings::StatusCodeMock; use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; use aries_vcx_core::ledger::base_ledger::BaseLedger; use async_trait::async_trait; @@ -64,14 +63,6 @@ impl BaseLedger for MockLedger { } async fn get_cred_def(&self, cred_def_id: &str, submitter_did: Option<&str>) -> VcxCoreResult { - // TODO - FUTURE - below error is required for tests to pass which require a cred def to not exist (libvcx) - // ideally we can migrate away from it - if StatusCodeMock::get_result() == 309 { - return Err(AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::LedgerItemNotFound, - "Mocked error".to_string(), - )); - }; Ok(CRED_DEF_JSON.to_string()) } diff --git a/aries_vcx/src/utils/mod.rs b/aries_vcx/src/utils/mod.rs index fbaa28330e..7e4609c91d 100644 --- a/aries_vcx/src/utils/mod.rs +++ b/aries_vcx/src/utils/mod.rs @@ -42,7 +42,6 @@ macro_rules! map ( }; ); -pub mod author_agreement; #[rustfmt::skip] pub mod constants; pub mod file; diff --git a/aries_vcx_core/src/utils/author_agreement.rs b/aries_vcx_core/src/global/author_agreement.rs similarity index 89% rename from aries_vcx_core/src/utils/author_agreement.rs rename to aries_vcx_core/src/global/author_agreement.rs index 3fcb88e4d7..19c639e778 100644 --- a/aries_vcx_core/src/utils/author_agreement.rs +++ b/aries_vcx_core/src/global/author_agreement.rs @@ -17,7 +17,7 @@ pub struct TxnAuthorAgreementAcceptanceData { pub time_of_acceptance: u64, } -pub fn set_global_txn_author_agreement( +pub fn set_txn_author_agreement( text: Option, version: Option, taa_digest: Option, @@ -40,7 +40,7 @@ pub fn set_global_txn_author_agreement( Ok(()) } -pub fn get_global_txn_author_agreement() -> VcxCoreResult> { +pub fn get_txn_author_agreement() -> VcxCoreResult> { trace!("get_txn_author_agreement >>>"); match settings::get_config_value(settings::CONFIG_TXN_AUTHOR_AGREEMENT) { Ok(value) => { @@ -67,7 +67,7 @@ mod unit_tests { settings::reset_config_values().unwrap(); assert!(settings::get_config_value(settings::CONFIG_TXN_AUTHOR_AGREEMENT).is_err()); - set_global_txn_author_agreement( + set_txn_author_agreement( Some(TEXT.to_string()), Some(VERSION.to_string()), None, @@ -82,7 +82,7 @@ mod unit_tests { #[test] fn get_txn_author_agreement_works() { settings::reset_config_values().unwrap(); - set_global_txn_author_agreement( + set_txn_author_agreement( Some(TEXT.to_string()), Some(VERSION.to_string()), None, @@ -91,7 +91,7 @@ mod unit_tests { ) .unwrap(); - let meta = get_global_txn_author_agreement().unwrap().unwrap(); + let meta = get_txn_author_agreement().unwrap().unwrap(); let expected_meta = TxnAuthorAgreementAcceptanceData { text: Some(TEXT.to_string()), @@ -107,6 +107,6 @@ mod unit_tests { #[test] fn get_txn_author_agreement_works_for_not_set() { settings::reset_config_values().unwrap(); - assert!(get_global_txn_author_agreement().unwrap().is_none()); + assert!(get_txn_author_agreement().unwrap().is_none()); } } diff --git a/aries_vcx_core/src/global/mockdata/mock_settings.rs b/aries_vcx_core/src/global/mockdata/mock_settings.rs new file mode 100644 index 0000000000..942a75f539 --- /dev/null +++ b/aries_vcx_core/src/global/mockdata/mock_settings.rs @@ -0,0 +1,16 @@ +use std::sync::RwLock; +use std::{collections::HashMap, sync::Mutex}; + +use crate::errors::error::VcxCoreResult; + +static MOCKED_RETRIEVED_CREDS: &str = "mocked_retrieved_creds"; + +lazy_static! { + static ref MOCK_SETTINGS: RwLock> = RwLock::new(HashMap::new()); + static ref MOCK_SETTINGS_RESULT_BOOL: RwLock>> = RwLock::new(HashMap::new()); +} + +pub fn get_mock_creds_retrieved_for_proof_request() -> Option { + let config = MOCK_SETTINGS.read().expect("Unable to access MOCK_SETTINGS"); + config.get(MOCKED_RETRIEVED_CREDS).map(String::from) +} diff --git a/aries_vcx_core/src/utils/mockdata/mod.rs b/aries_vcx_core/src/global/mockdata/mod.rs similarity index 100% rename from aries_vcx_core/src/utils/mockdata/mod.rs rename to aries_vcx_core/src/global/mockdata/mod.rs diff --git a/aries_vcx_core/src/global/mod.rs b/aries_vcx_core/src/global/mod.rs index 6e98cefd04..0ab2c8788f 100644 --- a/aries_vcx_core/src/global/mod.rs +++ b/aries_vcx_core/src/global/mod.rs @@ -1 +1,3 @@ +pub mod author_agreement; +pub(crate) mod mockdata; pub mod settings; diff --git a/aries_vcx_core/src/global/settings.rs b/aries_vcx_core/src/global/settings.rs index eab7560b6b..167ac6481a 100644 --- a/aries_vcx_core/src/global/settings.rs +++ b/aries_vcx_core/src/global/settings.rs @@ -106,3 +106,7 @@ pub fn get_protocol_version() -> usize { protocol_version } } + +pub fn get_sample_did() -> String { + DEFAULT_DID.to_string() +} diff --git a/aries_vcx_core/src/indy/credentials/issuer/mod.rs b/aries_vcx_core/src/indy/credentials/issuer/mod.rs index 30294452f0..b52d96a810 100644 --- a/aries_vcx_core/src/indy/credentials/issuer/mod.rs +++ b/aries_vcx_core/src/indy/credentials/issuer/mod.rs @@ -5,7 +5,6 @@ use crate::global::settings; use crate::indy::anoncreds; use crate::indy::utils::parse_and_validate; use crate::utils::constants::LIBINDY_CRED_OFFER; -use crate::utils::mockdata::mock_settings::StatusCodeMock; use crate::{utils, WalletHandle}; pub async fn libindy_issuer_create_credential_offer( @@ -13,13 +12,6 @@ pub async fn libindy_issuer_create_credential_offer( cred_def_id: &str, ) -> VcxCoreResult { if settings::indy_mocks_enabled() { - let rc = StatusCodeMock::get_result(); - if rc != 0 { - return Err(AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::InvalidState, - "Mocked error result of libindy_issuer_create_credential_offer", - )); - }; return Ok(LIBINDY_CRED_OFFER.to_string()); } diff --git a/aries_vcx_core/src/indy/ledger/pool.rs b/aries_vcx_core/src/indy/ledger/pool.rs index 34d20681e7..bfde384a2f 100644 --- a/aries_vcx_core/src/indy/ledger/pool.rs +++ b/aries_vcx_core/src/indy/ledger/pool.rs @@ -80,14 +80,18 @@ pub async fn delete(pool_name: &str) -> VcxCoreResult<()> { pub mod test_utils { use std::fs; use std::io::Write; + use std::{env, path::PathBuf}; - use crate::utils::{ - constants::{GENESIS_PATH, POOL}, - get_temp_dir_path, - }; + use crate::utils::constants::{GENESIS_PATH, POOL}; use super::*; + pub fn get_temp_dir_path(filename: &str) -> PathBuf { + let mut path = env::temp_dir(); + path.push(filename); + path + } + pub async fn create_test_ledger_config() { create_tmp_genesis_txn_file(); create_pool_ledger_config(POOL, get_temp_dir_path(GENESIS_PATH).to_str().unwrap()).unwrap(); diff --git a/aries_vcx_core/src/indy/ledger/transactions.rs b/aries_vcx_core/src/indy/ledger/transactions.rs index a75eff93cb..21fc1be88f 100644 --- a/aries_vcx_core/src/indy/ledger/transactions.rs +++ b/aries_vcx_core/src/indy/ledger/transactions.rs @@ -3,14 +3,15 @@ use vdrtools::{DidValue, Locator}; use crate::common::ledger::transactions::{Request, Response}; use crate::errors::error::prelude::*; +use crate::global::author_agreement::get_txn_author_agreement; use crate::global::settings; +use crate::global::settings::get_sample_did; use crate::indy::utils::mocks::pool_mocks::PoolMocks; use crate::indy::utils::parse_and_validate; use crate::utils::constants::{ rev_def_json, CRED_DEF_ID, CRED_DEF_JSON, CRED_DEF_REQ, REVOC_REG_TYPE, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_ID, SCHEMA_JSON, SCHEMA_TXN, SUBMIT_SCHEMA_RESPONSE, }; -use crate::utils::random::generate_random_did; use crate::{utils, PoolHandle, WalletHandle}; pub async fn multisign_request(wallet_handle: WalletHandle, did: &str, request: &str) -> VcxCoreResult { @@ -101,7 +102,7 @@ pub async fn libindy_get_txn_author_agreement(pool_handle: PoolHandle) -> VcxCor return Ok(utils::constants::DEFAULT_AUTHOR_AGREEMENT.to_string()); } - let did = &generate_random_did(); + let did = &get_sample_did(); let get_author_agreement_request = Locator::instance() .ledger_controller @@ -139,7 +140,7 @@ pub async fn libindy_get_txn_author_agreement(pool_handle: PoolHandle) -> VcxCor pub async fn append_txn_author_agreement_to_request(request_json: &str) -> VcxCoreResult { trace!("append_txn_author_agreement_to_request >>> request_json: ..."); - if let Some(author_agreement) = utils::author_agreement::get_global_txn_author_agreement()? { + if let Some(author_agreement) = get_txn_author_agreement()? { Locator::instance() .ledger_controller .append_txn_author_agreement_acceptance_to_request( @@ -211,7 +212,7 @@ pub async fn libindy_build_nym_request( } pub async fn get_nym(pool_handle: PoolHandle, did: &str) -> VcxCoreResult { - let submitter_did = generate_random_did(); + let submitter_did = get_sample_did(); let get_nym_req = libindy_build_get_nym_request(Some(&submitter_did), did).await?; @@ -252,7 +253,7 @@ async fn libindy_get_cred_def( pool_handle: PoolHandle, cred_def_id: &str, ) -> VcxCoreResult { - let submitter_did = &generate_random_did(); + let submitter_did = &get_sample_did(); trace!( "libindy_get_cred_def >>> pool_handle: {}, wallet_handle: {:?}, submitter_did: {}", pool_handle, @@ -546,7 +547,7 @@ pub async fn get_rev_reg_def_json(pool_handle: PoolHandle, rev_reg_id: &str) -> return Ok((REV_REG_ID.to_string(), rev_def_json())); } - let submitter_did = generate_random_did(); + let submitter_did = get_sample_did(); let req = libindy_build_get_revoc_reg_def_request(&submitter_did, rev_reg_id).await?; let res = libindy_submit_request(pool_handle, &req).await?; @@ -592,7 +593,7 @@ pub async fn get_rev_reg_delta_json( return Ok((REV_REG_ID.to_string(), REV_REG_DELTA_JSON.to_string(), 1)); } - let submitter_did = generate_random_did(); + let submitter_did = get_sample_did(); let from: i64 = if let Some(_from) = from { _from as i64 } else { -1 }; let to = if let Some(_to) = to { @@ -617,7 +618,7 @@ pub async fn get_rev_reg( return Ok((REV_REG_ID.to_string(), REV_REG_JSON.to_string(), 1)); } - let submitter_did = generate_random_did(); + let submitter_did = get_sample_did(); let req = libindy_build_get_revoc_reg_request(&submitter_did, rev_reg_id, timestamp).await?; @@ -705,7 +706,7 @@ pub async fn get_schema_json( return Ok((SCHEMA_ID.to_string(), SCHEMA_JSON.to_string())); } - let submitter_did = generate_random_did(); + let submitter_did = get_sample_did(); let schema_json = libindy_get_schema(wallet_handle, pool_handle, &submitter_did, schema_id).await?; diff --git a/aries_vcx_core/src/indy/proofs/prover/prover.rs b/aries_vcx_core/src/indy/proofs/prover/prover.rs index b5994992b1..228acef35f 100644 --- a/aries_vcx_core/src/indy/proofs/prover/prover.rs +++ b/aries_vcx_core/src/indy/proofs/prover/prover.rs @@ -2,6 +2,7 @@ use serde_json::{Map, Value}; use vdrtools::{Locator, SearchHandle}; use crate::errors::error::prelude::*; +use crate::global::mockdata::mock_settings::get_mock_creds_retrieved_for_proof_request; use crate::global::settings; use crate::indy::anoncreds::close_search_handle; use crate::indy::utils::parse_and_validate; @@ -89,7 +90,6 @@ pub async fn libindy_prover_get_credentials_for_proof_req( ); { - use crate::utils::mockdata::mock_settings::get_mock_creds_retrieved_for_proof_request; match get_mock_creds_retrieved_for_proof_request() { None => {} Some(mocked_creds) => { diff --git a/aries_vcx_core/src/indy/utils/mod.rs b/aries_vcx_core/src/indy/utils/mod.rs index d64b1f0a04..c783bc3456 100644 --- a/aries_vcx_core/src/indy/utils/mod.rs +++ b/aries_vcx_core/src/indy/utils/mod.rs @@ -29,6 +29,22 @@ where // TODO: move to devsetup, see if we can reuse this / merge with different setup pub mod test_setup { + use rand::distributions::Alphanumeric; + use rand::Rng; + + pub fn generate_random_name() -> String { + rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(25) + .collect::() + } + + pub fn generate_random_seed() -> String { + rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(32) + .collect::() + } use crate::{indy, WalletHandle}; @@ -41,7 +57,7 @@ pub mod test_setup { F: std::future::Future, { let wallet_config = indy::wallet::WalletConfig { - wallet_name: crate::utils::random::generate_random_name(), + wallet_name: generate_random_name(), wallet_key: WALLET_KEY.into(), wallet_key_derivation: WALLET_KEY_DERIVATION.into(), ..Default::default() @@ -65,7 +81,7 @@ pub mod test_setup { } pub async fn create_key(wallet_handle: WalletHandle) -> String { - let seed: String = crate::utils::random::generate_random_seed(); + let seed: String = generate_random_seed(); indy::signing::create_key(wallet_handle, Some(&seed)).await.unwrap() } diff --git a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs index 03d8cd7e05..0c2e90294c 100644 --- a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs +++ b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs @@ -21,8 +21,8 @@ use vdr::utils::Qualifiable; use crate::errors::error::VcxCoreResult; use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; +use crate::global::author_agreement::get_txn_author_agreement; use crate::global::settings; -use crate::utils::author_agreement::get_global_txn_author_agreement; use crate::utils::json::{AsTypeOrDeserializationError, TryGetIndex}; use crate::wallet::base_wallet::BaseWallet; @@ -489,7 +489,7 @@ fn current_epoch_time() -> i64 { } async fn _append_txn_author_agreement_to_request(request: PreparedRequest) -> VcxCoreResult { - if let Some(taa) = get_global_txn_author_agreement()? { + if let Some(taa) = get_txn_author_agreement()? { let mut request = request; let acceptance = TxnAuthrAgrmtAcceptanceData { mechanism: taa.acceptance_mechanism_type, diff --git a/aries_vcx_core/src/utils/mockdata/mock_settings.rs b/aries_vcx_core/src/utils/mockdata/mock_settings.rs deleted file mode 100644 index c7cc6d514e..0000000000 --- a/aries_vcx_core/src/utils/mockdata/mock_settings.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::sync::RwLock; -use std::{collections::HashMap, sync::Mutex}; - -use crate::errors::error::VcxCoreResult; - -static MOCKED_RETRIEVED_CREDS: &str = "mocked_retrieved_creds"; - -lazy_static! { - static ref MOCK_SETTINGS: RwLock> = RwLock::new(HashMap::new()); - static ref MOCK_SETTINGS_RESULT_BOOL: RwLock>> = RwLock::new(HashMap::new()); - static ref STATUS_CODE_MOCK: Mutex = Mutex::new(StatusCodeMock::default()); -} - -pub fn get_mock_creds_retrieved_for_proof_request() -> Option { - let config = MOCK_SETTINGS.read().expect("Unable to access MOCK_SETTINGS"); - config.get(MOCKED_RETRIEVED_CREDS).map(String::from) -} - -#[derive(Default)] -pub struct StatusCodeMock { - results: Vec, -} - -// todo: get rid of this, we no longer deal with rc return codes from vdrtools -// (this is leftover from times when we talked to vdrtool via FFI) -impl StatusCodeMock { - pub fn set_next_result(rc: u32) { - STATUS_CODE_MOCK - .lock() - .expect("Unabled to access LIBINDY_MOCK") - .results - .push(rc); - } - - pub fn get_result() -> u32 { - STATUS_CODE_MOCK - .lock() - .expect("Unable to access LIBINDY_MOCK") - .results - .pop() - .unwrap_or_default() - } -} diff --git a/aries_vcx_core/src/utils/mod.rs b/aries_vcx_core/src/utils/mod.rs index 7cf3f1e900..876ff955e9 100644 --- a/aries_vcx_core/src/utils/mod.rs +++ b/aries_vcx_core/src/utils/mod.rs @@ -1,14 +1,5 @@ use std::{env, path::PathBuf}; pub mod async_fn_iterator; -pub mod author_agreement; pub(crate) mod constants; pub(crate) mod json; -pub(crate) mod mockdata; -pub(crate) mod random; - -pub fn get_temp_dir_path(filename: &str) -> PathBuf { - let mut path = env::temp_dir(); - path.push(filename); - path -} diff --git a/aries_vcx_core/src/utils/random.rs b/aries_vcx_core/src/utils/random.rs deleted file mode 100644 index 1b80680d51..0000000000 --- a/aries_vcx_core/src/utils/random.rs +++ /dev/null @@ -1,20 +0,0 @@ -use rand::distributions::Alphanumeric; -use rand::Rng; - -pub fn generate_random_name() -> String { - rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(25) - .collect::() -} - -pub fn generate_random_seed() -> String { - rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(32) - .collect::() -} - -pub fn generate_random_did() -> String { - crate::global::settings::DEFAULT_DID.to_string() -} diff --git a/libvcx_core/src/api_vcx/api_global/ledger.rs b/libvcx_core/src/api_vcx/api_global/ledger.rs index d6fd4a2023..66a9e67269 100644 --- a/libvcx_core/src/api_vcx/api_global/ledger.rs +++ b/libvcx_core/src/api_vcx/api_global/ledger.rs @@ -105,7 +105,7 @@ pub fn ledger_set_txn_author_agreement( acc_mech_type: String, time_of_acceptance: u64, ) -> LibvcxResult<()> { - map_ariesvcx_result(aries_vcx::utils::author_agreement::set_txn_author_agreement( + map_ariesvcx_result(aries_vcx::global::author_agreement::proxy_set_txn_author_agreement( text, version, hash, diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index e78096631e..72c94de742 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -288,7 +288,6 @@ pub mod tests { use crate::errors::error; use aries_vcx::utils::constants::V3_OBJECT_SERIALIZE_VERSION; use aries_vcx::utils::devsetup::SetupMocks; - use aries_vcx::utils::mockdata::mock_settings::StatusCodeMock; use aries_vcx::utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_REQUEST; use aries_vcx::utils::mockdata::mockdata_mediated_connection::ARIES_CONNECTION_ACK; diff --git a/wrappers/node/package-lock.json b/wrappers/node/package-lock.json index 18d171635d..886c4e7e92 100644 --- a/wrappers/node/package-lock.json +++ b/wrappers/node/package-lock.json @@ -37,6 +37,7 @@ } }, "../vcx-napi-rs": { + "name": "@hyperledger/vcx-napi-rs", "license": "Apache-2.0", "devDependencies": { "@napi-rs/cli": "^2.9.1", diff --git a/wrappers/vcx-napi-rs/src/api/ledger.rs b/wrappers/vcx-napi-rs/src/api/ledger.rs index a7857330f2..66ef00c7a9 100644 --- a/wrappers/vcx-napi-rs/src/api/ledger.rs +++ b/wrappers/vcx-napi-rs/src/api/ledger.rs @@ -20,6 +20,7 @@ fn set_active_txn_author_agreement_meta( acc_mech_type: String, time_of_acceptance: u32, ) -> napi::Result<()> { + info!("set_active_txn_author_agreement_meta >>>"); ledger::ledger_set_txn_author_agreement(text, version, hash, acc_mech_type, time_of_acceptance as u64) .map_err(to_napi_err) }