diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6ae50b4cf..04136990da 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -385,7 +385,7 @@ jobs: uses: ./.github/actions/setup-codecov-rust with: skip-docker-setup: true - - name: "Run workspace tests: general_test" + - name: "Run aries-vcx unit tests" run: | RUSTFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ RUSTDOCFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ @@ -415,7 +415,7 @@ jobs: uses: actions/checkout@v3 - name: "Setup rust codecov environment" uses: ./.github/actions/setup-codecov-rust - - name: "Run workspace tests: pool_tests agency_pool_tests" + - name: "Run workspace tests: vdrtools profile" run: | RUSTFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ RUSTDOCFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ @@ -436,8 +436,7 @@ jobs: name: code-coverage-report-unit-aries-vcx path: /tmp/artifacts/coverage - #TODO - can this be included within code-coverage-aries-vcx-integration-tests? - code-coverage-aries-vcx-modular-dependencies-integration-tests: + code-coverage-aries-vcx-integration-modular-libs: needs: workflow-setup if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }} runs-on: ubuntu-20.04 @@ -446,7 +445,7 @@ jobs: uses: actions/checkout@v3 - name: "Setup rust codecov environment" uses: ./.github/actions/setup-codecov-rust - - name: "Run workspace tests: modular_libs_tests pool_tests agency_pool_tests" + - name: "Run workspace tests: modular libs profile" run: | RUSTFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ RUSTDOCFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' \ @@ -480,7 +479,7 @@ jobs: uses: ./.github/actions/setup-testing-rust with: skip-docker-setup: true - - name: "Run workspace tests: general_test" + - name: "Run workspace unit tests" run: RUST_TEST_THREADS=1 cargo test --workspace --lib --exclude aries-vcx-agent --exclude libvdrtools --exclude wallet_migrator test-integration-aries-vcx: @@ -491,8 +490,8 @@ jobs: uses: actions/checkout@v3 - name: "Setup rust testing environment" uses: ./.github/actions/setup-testing-rust - - name: "Run aries-vcx tests: pool_tests agency_pool_tests" - run: RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" -- --ignored; + - name: "Run aries-vcx integration tests" + run: RUST_LOG=trace RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" -- --ignored; test-integration-aries-vcx-mysql: needs: workflow-setup @@ -526,7 +525,7 @@ jobs: with: skip-vdrproxy-setup: false - name: "Run aries-vcx tests: vdrproxy_test" - run: cargo test --manifest-path="aries_vcx/Cargo.toml" -F vdr_proxy_ledger -- --ignored + run: RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F vdr_proxy_ledger -- --ignored - name: "Collect docker logs on failure" if: failure() uses: ./.github/actions/upload-docker-logs @@ -541,7 +540,7 @@ jobs: uses: actions/checkout@v3 - name: "Setup rust testing environment" uses: ./.github/actions/setup-testing-rust - - name: "Run aries-vcx tests: pool_tests agency_pool_tests" + - name: "Run aries-vcx integration tests" run: RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F mixed_breed -- --include-ignored; test-integration-aries-vcx-migration: @@ -567,10 +566,10 @@ jobs: uses: actions/checkout@v3 - name: "Setup rust testing environment" uses: ./.github/actions/setup-testing-rust - - name: "Run libvcx tests: pool_tests" + - name: "Run libvcx integration tests" run: | - RUST_TEST_THREADS=1 cargo test --manifest-path="libvcx/Cargo.toml" -F "pool_tests"; - RUST_TEST_THREADS=1 cargo test --manifest-path="libvcx_core/Cargo.toml" -F "pool_tests"; + RUST_TEST_THREADS=1 cargo test --manifest-path="libvcx/Cargo.toml" -- --include-ignored; + RUST_TEST_THREADS=1 cargo test --manifest-path="libvcx_core/Cargo.toml" -- --include-ignored; test-integration-resolver: needs: workflow-setup diff --git a/agents/rust/aries-vcx-agent/src/agent/init.rs b/agents/rust/aries-vcx-agent/src/agent/init.rs index 86202d3a11..2a009a41cb 100644 --- a/agents/rust/aries-vcx-agent/src/agent/init.rs +++ b/agents/rust/aries-vcx-agent/src/agent/init.rs @@ -7,7 +7,7 @@ use aries_vcx::{ utils::provision::provision_cloud_agent, }; use aries_vcx_core::indy::{ - ledger::pool::{create_pool_ledger_config, open_pool_ledger, PoolConfigBuilder}, + ledger::pool::{create_pool_ledger_config, indy_open_pool, PoolConfigBuilder}, wallet::{create_wallet_with_master_secret, open_wallet, wallet_configure_issuer, WalletConfig}, }; use url::Url; @@ -83,7 +83,7 @@ impl Agent { &init_config.pool_config.genesis_path, ) .unwrap(); - let pool_handle = open_pool_ledger(&init_config.pool_config.pool_name, Some(pool_config)) + let pool_handle = indy_open_pool(&init_config.pool_config.pool_name, pool_config.pool_config) .await .unwrap(); diff --git a/aries_vcx/src/common/credentials/mod.rs b/aries_vcx/src/common/credentials/mod.rs index dba2bc742f..69d0470fe3 100644 --- a/aries_vcx/src/common/credentials/mod.rs +++ b/aries_vcx/src/common/credentials/mod.rs @@ -4,7 +4,6 @@ use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use time::OffsetDateTime; -use crate::core::profile::profile::Profile; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; use super::primitives::revocation_registry_delta::RevocationRegistryDelta; diff --git a/aries_vcx/src/common/keys.rs b/aries_vcx/src/common/keys.rs index 1ed511655b..e0936aa02c 100644 --- a/aries_vcx/src/common/keys.rs +++ b/aries_vcx/src/common/keys.rs @@ -4,7 +4,6 @@ use aries_vcx_core::ledger::base_ledger::{IndyLedgerRead, IndyLedgerWrite}; use aries_vcx_core::wallet::base_wallet::BaseWallet; use serde_json::Value; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; pub async fn rotate_verkey_apply( diff --git a/aries_vcx/src/common/ledger/transactions.rs b/aries_vcx/src/common/ledger/transactions.rs index 6620271fc0..8830def00f 100644 --- a/aries_vcx/src/common/ledger/transactions.rs +++ b/aries_vcx/src/common/ledger/transactions.rs @@ -12,7 +12,7 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; use serde_json::Value; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; -use crate::{common::keys::get_verkey_from_ledger, core::profile::profile::Profile, global::settings}; +use crate::{common::keys::get_verkey_from_ledger, global::settings}; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] diff --git a/aries_vcx/src/common/primitives/credential_definition.rs b/aries_vcx/src/common/primitives/credential_definition.rs index 6748c9b514..7d28ac8324 100644 --- a/aries_vcx/src/common/primitives/credential_definition.rs +++ b/aries_vcx/src/common/primitives/credential_definition.rs @@ -5,7 +5,7 @@ use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; use crate::utils::constants::{CRED_DEF_ID, CRED_DEF_JSON, DEFAULT_SERIALIZE_VERSION}; use crate::utils::serialization::ObjectWithVersion; -use crate::global::settings::{self, indy_mocks_enabled}; +use crate::global::settings::indy_mocks_enabled; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use std::fmt; use std::sync::Arc; diff --git a/aries_vcx/src/common/primitives/revocation_registry_delta.rs b/aries_vcx/src/common/primitives/revocation_registry_delta.rs index 05487aa0b3..0a0371e0cb 100644 --- a/aries_vcx/src/common/primitives/revocation_registry_delta.rs +++ b/aries_vcx/src/common/primitives/revocation_registry_delta.rs @@ -1,7 +1,6 @@ use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use std::sync::Arc; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; #[derive(Clone, Deserialize, Debug, Serialize, Default)] diff --git a/aries_vcx/src/common/proofs/proof_request.rs b/aries_vcx/src/common/proofs/proof_request.rs index a4dc8f5874..b3838c3afa 100644 --- a/aries_vcx/src/common/proofs/proof_request.rs +++ b/aries_vcx/src/common/proofs/proof_request.rs @@ -5,7 +5,6 @@ use std::vec::Vec; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use serde_json; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use super::proof_request_internal::{AttrInfo, NonRevokedInterval, PredicateInfo}; diff --git a/aries_vcx/src/common/proofs/prover/prover.rs b/aries_vcx/src/common/proofs/prover/prover.rs index 1c50ce92b4..7775bbbc8a 100644 --- a/aries_vcx/src/common/proofs/prover/prover.rs +++ b/aries_vcx/src/common/proofs/prover/prover.rs @@ -8,7 +8,6 @@ use crate::common::proofs::prover::prover_internal::{ build_cred_defs_json_prover, build_requested_credentials_json, build_rev_states_json, build_schemas_json_prover, credential_def_identifiers, }; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::global::settings; use crate::handlers::proof_presentation::types::SelectedCredentials; diff --git a/aries_vcx/src/common/proofs/prover/prover_internal.rs b/aries_vcx/src/common/proofs/prover/prover_internal.rs index 9090e499e2..b5d77d6fd9 100644 --- a/aries_vcx/src/common/proofs/prover/prover_internal.rs +++ b/aries_vcx/src/common/proofs/prover/prover_internal.rs @@ -5,12 +5,9 @@ use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use serde_json::Value; +use crate::common::proofs::{proof_request::ProofRequestData, proof_request_internal::NonRevokedInterval}; use crate::errors::error::prelude::*; use crate::handlers::proof_presentation::types::SelectedCredentials; -use crate::{ - common::proofs::{proof_request::ProofRequestData, proof_request_internal::NonRevokedInterval}, - core::profile::profile::Profile, -}; #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct CredInfoProver { @@ -370,59 +367,6 @@ pub mod unit_tests { assert!(credential_def.contains(r#""id":"V4SGRU86Z58d6TV7PBUe6f:3:CL:47:tag1","schemaId":"47""#)); } - #[tokio::test] - async fn test_find_credential_def_fails() { - SetupLibraryWallet::run(|setup| async move { - let profile = Arc::new(VdrtoolsProfile::init(setup.wallet_handle, INVALID_POOL_HANDLE)); - let credential_ids = vec![CredInfoProver { - referent: "1".to_string(), - credential_referent: "2".to_string(), - schema_id: "3".to_string(), - cred_def_id: "3".to_string(), - rev_reg_id: Some("4".to_string()), - cred_rev_id: Some("5".to_string()), - revocation_interval: None, - tails_file: None, - timestamp: None, - revealed: None, - }]; - let err_kind = build_cred_defs_json_prover(&profile.inject_anoncreds_ledger_read(), &credential_ids) - .await - .unwrap_err() - .kind(); - assert_eq!(err_kind, AriesVcxErrorKind::InvalidProofCredentialData); - }) - .await; - } - - #[tokio::test] - async fn test_find_schemas_fails() { - SetupLibraryWallet::run(|setup| async move { - let profile = Arc::new(VdrtoolsProfile::init(setup.wallet_handle, INVALID_POOL_HANDLE)); - let credential_ids = vec![CredInfoProver { - referent: "1".to_string(), - credential_referent: "2".to_string(), - schema_id: "3".to_string(), - cred_def_id: "3".to_string(), - rev_reg_id: Some("4".to_string()), - cred_rev_id: Some("5".to_string()), - revocation_interval: None, - tails_file: None, - timestamp: None, - revealed: None, - }]; - - assert_eq!( - build_schemas_json_prover(&profile.inject_anoncreds_ledger_read(), &credential_ids) - .await - .unwrap_err() - .kind(), - AriesVcxErrorKind::InvalidSchema - ); - }) - .await; - } - #[tokio::test] async fn test_find_schemas() { let _setup = SetupMocks::init(); diff --git a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs index a6ae535784..e88b244329 100644 --- a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs +++ b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs @@ -5,7 +5,6 @@ use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use serde_json; use serde_json::Value; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::global::settings; use crate::utils::openssl::encode; diff --git a/aries_vcx/src/common/test_utils.rs b/aries_vcx/src/common/test_utils.rs index 6900175f39..b78d80a3d2 100644 --- a/aries_vcx/src/common/test_utils.rs +++ b/aries_vcx/src/common/test_utils.rs @@ -7,18 +7,14 @@ use std::thread; use std::time::Duration; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use aries_vcx_core::PoolHandle; -use aries_vcx_core::WalletHandle; use crate::common::credentials::encoding::encode_attributes; use crate::common::primitives::credential_definition::CredentialDef; use crate::common::primitives::credential_definition::CredentialDefConfigBuilder; use crate::common::primitives::revocation_registry::RevocationRegistry; -use crate::core::profile::profile::Profile; use crate::global::settings; use crate::utils::constants::{DEFAULT_SCHEMA_ATTRS, TAILS_DIR, TEST_TAILS_URL, TRUSTEE_SEED}; use crate::utils::get_temp_dir_path; -use crate::utils::mockdata::profile::mock_profile::MockProfile; pub async fn create_schema( anoncreds: &Arc, diff --git a/aries_vcx/src/core/profile/mod.rs b/aries_vcx/src/core/profile/mod.rs index bda0e738bf..6473a68336 100644 --- a/aries_vcx/src/core/profile/mod.rs +++ b/aries_vcx/src/core/profile/mod.rs @@ -8,8 +8,10 @@ pub mod vdr_proxy_profile; #[cfg(feature = "vdrtools")] pub mod vdrtools_profile; +#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))] const DEFAULT_AML_LABEL: &str = "eula"; +#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))] use std::sync::Arc; #[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))] diff --git a/aries_vcx/src/core/profile/vdrtools_profile.rs b/aries_vcx/src/core/profile/vdrtools_profile.rs index d3c379dc9a..ec0ec0e6fd 100644 --- a/aries_vcx/src/core/profile/vdrtools_profile.rs +++ b/aries_vcx/src/core/profile/vdrtools_profile.rs @@ -25,11 +25,11 @@ pub struct VdrtoolsProfile { } impl VdrtoolsProfile { - pub fn init(indy_wallet_handle: WalletHandle, indy_pool_handle: PoolHandle) -> Self { - let wallet = Arc::new(IndySdkWallet::new(indy_wallet_handle)); - let anoncreds = Arc::new(IndySdkAnonCreds::new(indy_wallet_handle)); - let ledger_read = Arc::new(IndySdkLedgerRead::new(indy_wallet_handle, indy_pool_handle)); - let ledger_write = Arc::new(IndySdkLedgerWrite::new(indy_wallet_handle, indy_pool_handle)); + pub fn init(wallet_handle: WalletHandle, pool_handle: PoolHandle) -> Self { + let wallet = Arc::new(IndySdkWallet::new(wallet_handle)); + let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet_handle)); + let ledger_read = Arc::new(IndySdkLedgerRead::new(wallet_handle, pool_handle)); + let ledger_write = Arc::new(IndySdkLedgerWrite::new(wallet_handle, pool_handle)); VdrtoolsProfile { wallet, anoncreds, diff --git a/aries_vcx/src/global/settings.rs b/aries_vcx/src/global/settings.rs index 9e11e54453..1b4f121f11 100644 --- a/aries_vcx/src/global/settings.rs +++ b/aries_vcx/src/global/settings.rs @@ -5,7 +5,6 @@ use aries_vcx_core::global::settings::{disable_indy_mocks, enable_indy_mocks}; use crate::errors::error::prelude::*; -pub static CONFIG_POOL_NAME: &str = "pool_name"; pub static CONFIG_SDK_TO_REMOTE_ROLE: &str = "sdk_to_remote_role"; pub static CONFIG_INSTITUTION_DID: &str = "institution_did"; pub static CONFIG_INSTITUTION_VERKEY: &str = "institution_verkey"; @@ -16,7 +15,6 @@ pub static CONFIG_ENABLE_TEST_MODE: &str = "enable_test_mode"; pub static CONFIG_GENESIS_PATH: &str = "genesis_path"; pub static CONFIG_LOG_CONFIG: &str = "log_config"; pub static CONFIG_EXPORTED_WALLET_PATH: &str = "exported_wallet_path"; -pub static CONFIG_WALLET_BACKUP_KEY: &str = "backup_key"; pub static CONFIG_WALLET_KEY: &str = "wallet_key"; pub static CONFIG_WALLET_NAME: &str = "wallet_name"; pub static CONFIG_WALLET_TYPE: &str = "wallet_type"; @@ -99,32 +97,13 @@ pub fn set_config_value(key: &str, value: &str) -> VcxResult<()> { Ok(()) } -pub fn reset_config_values() -> VcxResult<()> { +pub fn reset_config_values_ariesvcx() -> VcxResult<()> { trace!("reset_config_values >>>"); let mut config = SETTINGS.write()?; config.clear(); Ok(()) } -pub fn set_test_configs() -> String { - trace!("set_testing_defaults >>>"); - let mut settings = SETTINGS - .write() - .expect("Unabled to access SETTINGS while setting test configs"); - let institution_did = CONFIG_INSTITUTION_DID; - settings.insert(CONFIG_POOL_NAME.to_string(), DEFAULT_POOL_NAME.to_string()); - settings.insert(institution_did.to_string(), DEFAULT_DID.to_string()); - settings.insert( - CONFIG_PROTOCOL_VERSION.to_string(), - DEFAULT_PROTOCOL_VERSION.to_string(), - ); - settings.insert( - CONFIG_WALLET_BACKUP_KEY.to_string(), - DEFAULT_WALLET_BACKUP_KEY.to_string(), - ); - institution_did.to_string() -} - pub fn get_protocol_version() -> usize { let protocol_version = match get_config_value(CONFIG_PROTOCOL_VERSION) { Ok(ver) => ver.parse::().unwrap_or_else(|err| { diff --git a/aries_vcx/src/handlers/connection/mediated_connection.rs b/aries_vcx/src/handlers/connection/mediated_connection.rs index 4b8cc71598..a486a06fa0 100644 --- a/aries_vcx/src/handlers/connection/mediated_connection.rs +++ b/aries_vcx/src/handlers/connection/mediated_connection.rs @@ -28,7 +28,6 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; use url::Url; use uuid::Uuid; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::cloud_agent::CloudAgentInfo; use crate::handlers::connection::legacy_agent_info::LegacyAgentInfo; diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 0363a79534..00c56d2ed6 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -13,7 +13,6 @@ use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use aries_vcx_core::wallet::base_wallet::BaseWallet; use crate::common::credentials::get_cred_rev_id; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::revocation_notification::receiver::RevocationNotificationReceiver; diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index f04c1279e9..650e889210 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -14,7 +14,6 @@ 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 crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::revocation_notification::sender::RevocationNotificationSender; diff --git a/aries_vcx/src/handlers/out_of_band/receiver.rs b/aries_vcx/src/handlers/out_of_band/receiver.rs index 3952047db5..6356964030 100644 --- a/aries_vcx/src/handlers/out_of_band/receiver.rs +++ b/aries_vcx/src/handlers/out_of_band/receiver.rs @@ -22,7 +22,6 @@ use serde::Deserialize; use serde_json::Value; use crate::common::ledger::transactions::resolve_service; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::util::{AnyInvitation, AttachmentId}; diff --git a/aries_vcx/src/handlers/proof_presentation/prover.rs b/aries_vcx/src/handlers/proof_presentation/prover.rs index 79019ec41d..0dbd0aa8f0 100644 --- a/aries_vcx/src/handlers/proof_presentation/prover.rs +++ b/aries_vcx/src/handlers/proof_presentation/prover.rs @@ -12,7 +12,6 @@ use messages::msg_fields::protocols::present_proof::propose::PresentationPreview use messages::msg_fields::protocols::present_proof::request::RequestPresentation; use messages::AriesMessage; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::util::{get_attach_as_string, PresentationProposalData}; @@ -284,36 +283,3 @@ pub mod test_utils { Ok(json!(presentation_requests).to_string()) } } - -// #[cfg(test)] -// #[allow(clippy::unwrap_used)] -// mod tests { -// use messages::msg_fields::protocols::present_proof::request::{ -// RequestPresentationContent, RequestPresentationDecorators, -// }; -// use uuid::Uuid; - -// use crate::{common::test_utils::indy_handles_to_profile, utils::devsetup::*}; -// use aries_vcx_core::INVALID_POOL_HANDLE; - -// use super::*; - -// #[tokio::test] -// async fn test_retrieve_credentials_fails_with_no_proof_req() { -// SetupLibraryWallet::run(|setup| async move { -// let profile = indy_handles_to_profile(setup.wallet_handle, INVALID_POOL_HANDLE); - -// let id = Uuid::new_v4().to_string(); -// let content = RequestPresentationContent::new(vec![]); -// let decorators = RequestPresentationDecorators::default(); - -// let proof_req = RequestPresentation::with_decorators(id, content, decorators); -// let proof = Prover::create_from_request("1", proof_req).unwrap(); -// assert_eq!( -// proof.retrieve_credentials(&profile).await.unwrap_err().kind(), -// AriesVcxErrorKind::InvalidJson -// ); -// }) -// .await; -// } -// } diff --git a/aries_vcx/src/handlers/proof_presentation/verifier.rs b/aries_vcx/src/handlers/proof_presentation/verifier.rs index e18e3648d4..74478697a7 100644 --- a/aries_vcx/src/handlers/proof_presentation/verifier.rs +++ b/aries_vcx/src/handlers/proof_presentation/verifier.rs @@ -12,7 +12,6 @@ use messages::msg_fields::protocols::present_proof::request::RequestPresentation use messages::AriesMessage; use crate::common::proofs::proof_request::PresentationRequestData; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::util::get_attach_as_string; diff --git a/aries_vcx/src/protocols/connection/invitee/mod.rs b/aries_vcx/src/protocols/connection/invitee/mod.rs index 2d2f5326fa..747219d614 100644 --- a/aries_vcx/src/protocols/connection/invitee/mod.rs +++ b/aries_vcx/src/protocols/connection/invitee/mod.rs @@ -23,7 +23,6 @@ use uuid::Uuid; use crate::{ common::ledger::transactions::into_did_doc, - core::profile::profile::Profile, errors::error::VcxResult, handlers::util::{matches_thread_id, AnyInvitation}, protocols::connection::trait_bounds::ThreadId, diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 1e40a3443e..70bafe343e 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -22,7 +22,6 @@ use messages::AriesMessage; use uuid::Uuid; use crate::common::credentials::{get_cred_rev_id, is_cred_revoked}; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::global::settings; use crate::handlers::util::{ diff --git a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs index 537830d488..5c876bbc41 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs @@ -1,7 +1,6 @@ use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use std::sync::Arc; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::util::get_attach_as_string; use crate::protocols::issuance::holder::state_machine::parse_cred_def_id_from_cred_offer; diff --git a/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs b/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs index 031b94fd59..484e1b89ad 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::protocols::issuance::is_cred_def_revokable; diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 6bc9b687fb..1c8afba3fd 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::fmt::Display; use std::sync::Arc; -use crate::core::profile::profile::Profile; use crate::handlers::util::{ get_attach_as_string, make_attach_from_str, matches_opt_thread_id, matches_thread_id, AttachmentId, OfferInfo, Status, diff --git a/aries_vcx/src/protocols/issuance/mod.rs b/aries_vcx/src/protocols/issuance/mod.rs index 37e60a2931..4bafe2d522 100644 --- a/aries_vcx/src/protocols/issuance/mod.rs +++ b/aries_vcx/src/protocols/issuance/mod.rs @@ -1,8 +1,6 @@ -use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use std::sync::Arc; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::global::settings; use crate::protocols::issuance::actions::CredentialIssuanceAction; diff --git a/aries_vcx/src/protocols/proof_presentation/prover/state_machine.rs b/aries_vcx/src/protocols/proof_presentation/prover/state_machine.rs index 5513bd7618..aac3886002 100644 --- a/aries_vcx/src/protocols/proof_presentation/prover/state_machine.rs +++ b/aries_vcx/src/protocols/proof_presentation/prover/state_machine.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::fmt; use std::sync::Arc; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::proof_presentation::types::SelectedCredentials; use crate::handlers::util::{ diff --git a/aries_vcx/src/protocols/proof_presentation/prover/states/presentation_request_received.rs b/aries_vcx/src/protocols/proof_presentation/prover/states/presentation_request_received.rs index d6f4ed914e..9e2479473d 100644 --- a/aries_vcx/src/protocols/proof_presentation/prover/states/presentation_request_received.rs +++ b/aries_vcx/src/protocols/proof_presentation/prover/states/presentation_request_received.rs @@ -11,7 +11,6 @@ use messages::msg_fields::protocols::report_problem::ProblemReport; use uuid::Uuid; use crate::common::proofs::prover::prover::generate_indy_proof; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::proof_presentation::types::SelectedCredentials; use crate::handlers::util::{get_attach_as_string, Status}; diff --git a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs index e0365203b9..dc823dc561 100644 --- a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs +++ b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs @@ -3,7 +3,6 @@ use std::fmt::Display; use std::sync::Arc; use crate::common::proofs::proof_request::PresentationRequestData; -use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; use crate::handlers::util::{make_attach_from_str, matches_opt_thread_id, matches_thread_id, AttachmentId, Status}; use crate::protocols::common::build_problem_report_msg; diff --git a/aries_vcx/src/protocols/proof_presentation/verifier/states/presentation_request_sent.rs b/aries_vcx/src/protocols/proof_presentation/verifier/states/presentation_request_sent.rs index aa00a85ff1..e5eae8cc7c 100644 --- a/aries_vcx/src/protocols/proof_presentation/verifier/states/presentation_request_sent.rs +++ b/aries_vcx/src/protocols/proof_presentation/verifier/states/presentation_request_sent.rs @@ -7,7 +7,6 @@ use messages::msg_fields::protocols::present_proof::request::RequestPresentation use messages::msg_fields::protocols::report_problem::ProblemReport; use crate::common::proofs::verifier::verifier::validate_indy_proof; -use crate::core::profile::profile::Profile; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; use crate::global::settings; use crate::handlers::util::{get_attach_as_string, matches_thread_id, Status}; diff --git a/aries_vcx/src/utils/constants.rs b/aries_vcx/src/utils/constants.rs index d205466b63..7bc0eea4bd 100644 --- a/aries_vcx/src/utils/constants.rs +++ b/aries_vcx/src/utils/constants.rs @@ -1815,8 +1815,7 @@ pub static DEFAULT_PROOF_NAME: &str = "PROOF_NAME"; pub static DEMO_AGENT_PW_SEED: &str = "00000000000000000000001DIRECTION"; pub static DEMO_ISSUER_PW_SEED: &str = "000000000000000000000000Issuer08"; pub static CONSUMER_SEED: &str = "00000000000000000000002DIRECTION"; -pub static POOL: &str = "pool1"; -pub static GENESIS_PATH: &str = "pool1.txn"; +pub static POOL1_TXN: &str = "pool1.txn"; pub static INSTITUTION_DID: &str = "2hoqvcwupRTUNkXn6ArYzs"; pub static DEV_GENESIS_NODE_TXNS: &[&str; 4] = &[ r#"{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"35.164.240.131","client_port":9702,"node_ip":"35.164.240.131","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv","identifier":"Th7MpTaRZVRYnPiabds81Y","txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62","type":"0"}"#, diff --git a/aries_vcx/src/utils/devsetup.rs b/aries_vcx/src/utils/devsetup.rs index 9005b33017..395afc83b7 100644 --- a/aries_vcx/src/utils/devsetup.rs +++ b/aries_vcx/src/utils/devsetup.rs @@ -6,14 +6,12 @@ use std::sync::{Arc, Once}; use aries_vcx_core::global::settings::{ disable_indy_mocks as disable_indy_mocks_core, enable_indy_mocks as enable_indy_mocks_core, + reset_config_values_ariesvcxcore, }; -use aries_vcx_core::indy::ledger::pool::test_utils::{create_test_ledger_config, delete_test_pool, open_test_pool}; -use aries_vcx_core::indy::ledger::pool::PoolConfig; use aries_vcx_core::indy::utils::mocks::did_mocks::DidMocks; use aries_vcx_core::indy::utils::mocks::pool_mocks::PoolMocks; use aries_vcx_core::indy::wallet::{ - close_wallet, create_and_open_wallet, create_indy_wallet, create_wallet_with_master_secret, delete_wallet, - open_wallet, wallet_configure_issuer, WalletConfig, + create_wallet_with_master_secret, open_wallet, wallet_configure_issuer, WalletConfig, }; #[cfg(feature = "modular_libs")] @@ -24,10 +22,15 @@ 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::{disable_agency_mocks, enable_agency_mocks, AgencyMockDecrypted}; +use agency_client::testing::mocking::{enable_agency_mocks, AgencyMockDecrypted}; +use aries_vcx_core::indy::ledger::pool::test_utils::create_testpool_genesis_txn_file; +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; @@ -39,10 +42,12 @@ use crate::core::profile::profile::Profile; #[cfg(feature = "vdrtools")] use crate::core::profile::vdrtools_profile::VdrtoolsProfile; use crate::global::settings; -use crate::global::settings::init_issuer_config; -use crate::global::settings::{aries_vcx_disable_indy_mocks, aries_vcx_enable_indy_mocks, set_test_configs}; +use crate::global::settings::{ + aries_vcx_disable_indy_mocks, aries_vcx_enable_indy_mocks, set_config_value, CONFIG_INSTITUTION_DID, DEFAULT_DID, +}; +use crate::global::settings::{init_issuer_config, reset_config_values_ariesvcx}; use crate::utils; -use crate::utils::constants::GENESIS_PATH; +use crate::utils::constants::POOL1_TXN; use crate::utils::file::write_file; use crate::utils::get_temp_dir_path; use crate::utils::provision::provision_cloud_agent; @@ -52,64 +57,28 @@ pub struct SetupEmpty; pub struct SetupDefaults; -pub struct SetupMocks { - pub institution_did: String, -} - -pub struct SetupIndyMocks; - -pub struct TestSetupCreateWallet { - pub wallet_config: WalletConfig, - skip_cleanup: bool, -} - -pub struct SetupPoolConfig { - pub pool_config: PoolConfig, -} - -pub struct SetupLibraryWallet { - pub wallet_config: WalletConfig, - pub wallet_handle: WalletHandle, -} - -pub struct SetupWalletPoolAgency { - pub agency_client: AgencyClient, - pub institution_did: String, - pub wallet_handle: WalletHandle, - pub pool_handle: PoolHandle, -} - -pub struct SetupWalletPool { - pub institution_did: String, - pub wallet_handle: WalletHandle, - pub pool_handle: PoolHandle, -} +pub struct SetupMocks {} #[derive(Clone)] pub struct SetupProfile { pub institution_did: String, pub profile: Arc, - pub(self) teardown: Arc BoxFuture<'static, ()> + Send + Sync>, + pub teardown: Arc BoxFuture<'static, ()> + Send + Sync>, } -pub struct SetupInstitutionWallet { - pub institution_did: String, - pub wallet_handle: WalletHandle, -} - -pub struct SetupPool { - pub pool_handle: PoolHandle, +pub struct SetupPoolDirectory { pub genesis_file_path: String, } -fn reset_global_state() { +pub fn reset_global_state() { warn!("reset_global_state >>"); AgencyMockDecrypted::clear_mocks(); PoolMocks::clear_mocks(); DidMocks::clear_mocks(); aries_vcx_disable_indy_mocks().unwrap(); disable_indy_mocks_core().unwrap(); - settings::reset_config_values().unwrap(); + reset_config_values_ariesvcx().unwrap(); + reset_config_values_ariesvcxcore().unwrap() } impl SetupEmpty { @@ -128,7 +97,6 @@ impl Drop for SetupEmpty { impl SetupDefaults { pub fn init() -> SetupDefaults { init_test_logging(); - set_test_configs(); SetupDefaults {} } } @@ -142,11 +110,11 @@ impl Drop for SetupDefaults { impl SetupMocks { pub fn init() -> SetupMocks { init_test_logging(); - let institution_did = set_test_configs(); enable_agency_mocks(); aries_vcx_enable_indy_mocks().unwrap(); enable_indy_mocks_core().unwrap(); - SetupMocks { institution_did } + set_config_value(CONFIG_INSTITUTION_DID, DEFAULT_DID).unwrap(); + SetupMocks {} } } @@ -156,290 +124,67 @@ impl Drop for SetupMocks { } } -impl SetupLibraryWallet { - async fn init() -> SetupLibraryWallet { - init_test_logging(); - - debug!("SetupLibraryWallet::init >>"); - - set_test_configs(); - - let wallet_name: String = format!("Test_SetupLibraryWallet_{}", uuid::Uuid::new_v4()); - let wallet_key: String = settings::DEFAULT_WALLET_KEY.into(); - let wallet_kdf: String = settings::WALLET_KDF_RAW.into(); - let wallet_config = WalletConfig { - wallet_name, - wallet_key, - wallet_key_derivation: wallet_kdf, - wallet_type: None, - storage_config: None, - storage_credentials: None, - rekey: None, - rekey_derivation_method: None, - }; - - let wallet_handle = create_and_open_wallet(&wallet_config).await.unwrap(); - SetupLibraryWallet { - wallet_config, - wallet_handle, - } - } - - pub async fn run(f: impl FnOnce(Self) -> F) - where - F: Future, - { - let init = Self::init().await; - - let handle = init.wallet_handle; - let config = init.wallet_config.clone(); - - f(init).await; - - close_wallet(handle).await.unwrap(); - - delete_wallet(&config).await.unwrap(); - - reset_global_state(); - } -} - -impl TestSetupCreateWallet { - async fn init() -> TestSetupCreateWallet { - init_test_logging(); - set_test_configs(); - let wallet_name: String = format!("Test_SetupWallet_{}", uuid::Uuid::new_v4().to_string()); - disable_agency_mocks(); - let wallet_config = WalletConfig { - wallet_name: wallet_name.clone(), - 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_indy_wallet(&wallet_config).await.unwrap(); - - TestSetupCreateWallet { - wallet_config, - skip_cleanup: false, - } - } - - pub fn skip_cleanup(&mut self) -> &mut TestSetupCreateWallet { - self.skip_cleanup = true; - self - } - - pub async fn run(f: impl FnOnce(Self) -> F) - where - F: Future, - { - let init = Self::init().await; - - let config = init.wallet_config.clone(); - - let skip_cleanup = f(init).await; - - if skip_cleanup == false { - delete_wallet(&config) - .await - .unwrap_or_else(|_e| error!("Failed to delete wallet while dropping SetupWallet test config.")); - } - - reset_global_state(); - } -} - -impl SetupPoolConfig { - pub async fn init() -> SetupPoolConfig { - init_test_logging(); - - create_test_ledger_config().await; - let genesis_path = utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH) - .to_str() - .unwrap() - .to_string(); - - let pool_config = PoolConfig { - genesis_path, - pool_name: None, - pool_config: None, - }; - - SetupPoolConfig { pool_config } - } -} - -impl Drop for SetupPoolConfig { - fn drop(&mut self) { - reset_global_state(); - } -} - -impl SetupIndyMocks { - pub fn init() -> SetupIndyMocks { - init_test_logging(); - aries_vcx_enable_indy_mocks().unwrap(); - enable_indy_mocks_core().unwrap(); - enable_agency_mocks(); - SetupIndyMocks {} - } -} - -impl Drop for SetupIndyMocks { - fn drop(&mut self) { - reset_global_state(); - } -} - -impl SetupWalletPoolAgency { - pub async fn init() -> SetupWalletPoolAgency { - init_test_logging(); - set_test_configs(); - let (institution_did, wallet_handle, agency_client) = setup_issuer_wallet_and_agency_client().await; - 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; - SetupWalletPoolAgency { - agency_client, - institution_did, - wallet_handle, - pool_handle, - } - } - - pub async fn run(f: impl FnOnce(Self) -> F) - where - F: Future, - { - let init = Self::init().await; - - let pool_handle = init.pool_handle; - - f(init).await; - - delete_test_pool(pool_handle).await; - - reset_global_state(); - } -} - -impl SetupWalletPool { - async fn init() -> SetupWalletPool { - init_test_logging(); - set_test_configs(); - let (institution_did, wallet_handle) = setup_issuer_wallet().await; - 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; - SetupWalletPool { - institution_did, - wallet_handle, - pool_handle, - } - } - - pub async fn run(f: impl FnOnce(Self) -> F) - where - F: Future, - { - let init = Self::init().await; - - let pool_handle = init.pool_handle; - - f(init).await; - - delete_test_pool(pool_handle).await; - - reset_global_state(); - } -} - impl SetupProfile { - pub async fn init() -> SetupProfile { - init_test_logging(); - set_test_configs(); - + 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")] return { info!("SetupProfile >> using indy profile"); - SetupProfile::init_indy().await + SetupProfile::init_indy(genesis_file_path).await }; #[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 }; } #[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 { + let pool_name = Uuid::new_v4().to_string(); + create_pool_ledger_config(&pool_name, &genesis_file_path).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) { - delete_test_pool(pool_handle.clone()).await; + async fn indy_teardown(pool_handle: PoolHandle, pool_name: String) { + indy_close_pool(pool_handle.clone()).await.unwrap(); + 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 { - use aries_vcx_core::indy::ledger::pool::test_utils::create_tmp_genesis_txn_file; - + async fn build_profile_modular(genesis_file_path: String) -> SetupProfile { 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 = @@ -451,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 } @@ -471,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? + let pool_name = Uuid::new_v4().to_string(); + create_pool_ledger_config(&pool_name, &genesis_file_path).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 = Arc::new(MixedBreedProfile::new(wallet_handle, pool_handle.clone())); @@ -491,30 +224,30 @@ impl SetupProfile { .await .unwrap(); - async fn indy_teardown(pool_handle: PoolHandle) { - delete_test_pool(pool_handle.clone()).await; + async fn indy_teardown(pool_handle: PoolHandle, pool_name: String) { + indy_close_pool(pool_handle.clone()).await.unwrap(); + 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 = "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() { @@ -532,7 +265,13 @@ impl SetupProfile { where F: Future, { - let init = Self::init().await; + init_test_logging(); + + let genesis_file_path = get_temp_dir_path(POOL1_TXN).to_str().unwrap().to_string(); + create_testpool_genesis_txn_file(&genesis_file_path); + + warn!("genesis_file_path: {}", genesis_file_path); + let init = Self::build_profile(genesis_file_path).await; let teardown = Arc::clone(&init.teardown); @@ -544,39 +283,16 @@ impl SetupProfile { } } -impl SetupInstitutionWallet { - pub async fn init() -> SetupInstitutionWallet { - init_test_logging(); - set_test_configs(); - let (institution_did, wallet_handle) = setup_issuer_wallet().await; - SetupInstitutionWallet { - institution_did, - wallet_handle, - } - } -} - -impl Drop for SetupInstitutionWallet { - fn drop(&mut self) { - reset_global_state(); - } -} - -impl SetupPool { - async fn init() -> SetupPool { +impl SetupPoolDirectory { + async fn init() -> SetupPoolDirectory { debug!("SetupPool init >> going to setup agency environment"); init_test_logging(); - let genesis_file_path = utils::get_temp_dir_path(GENESIS_PATH).to_str().unwrap().to_string(); - settings::set_config_value(settings::CONFIG_GENESIS_PATH, &genesis_file_path).unwrap(); - - let pool_handle = open_test_pool().await; + let genesis_file_path = get_temp_dir_path(POOL1_TXN).to_str().unwrap().to_string(); + create_testpool_genesis_txn_file(&genesis_file_path); debug!("SetupPool init >> completed"); - SetupPool { - pool_handle, - genesis_file_path, - } + SetupPoolDirectory { genesis_file_path } } pub async fn run(f: impl FnOnce(Self) -> F) @@ -585,11 +301,10 @@ impl SetupPool { { let init = Self::init().await; - let handle = init.pool_handle; - f(init).await; - delete_test_pool(handle).await; + // todo: delete the directory instead? + // delete_test_pool(handle).await; reset_global_state(); } diff --git a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs index 9c441fe651..aba2a23f1a 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs @@ -12,7 +12,7 @@ use crate::{ use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; #[derive(Debug)] -pub(crate) struct MockAnoncreds; +pub struct MockAnoncreds; // NOTE : currently matches the expected results if indy_mocks are enabled /// Implementation of [BaseAnoncreds] which responds with mock data diff --git a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs index eedf24bd9d..2491ff510c 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs @@ -6,7 +6,7 @@ use crate::utils; use crate::utils::constants::{rev_def_json, CRED_DEF_JSON, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_JSON}; #[derive(Debug)] -pub(crate) struct MockLedger; +pub struct MockLedger; #[allow(unused)] #[async_trait] diff --git a/aries_vcx/src/utils/mockdata/profile/mock_profile.rs b/aries_vcx/src/utils/mockdata/profile/mock_profile.rs index da5a8b76fc..9d479afd6c 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_profile.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_profile.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use aries_vcx_core::ledger::base_ledger::{TaaConfigurator, TxnAuthrAgrmtOptions}; +use aries_vcx_core::ledger::base_ledger::TxnAuthrAgrmtOptions; use aries_vcx_core::{ anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}, diff --git a/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs b/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs index e8317e6379..36dc0f92cf 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs @@ -7,13 +7,17 @@ use crate::utils::{self}; use std::collections::HashMap; #[derive(Debug)] -pub(crate) struct MockWallet; +pub struct MockWallet; // NOTE : currently matches the expected results if did_mocks and indy_mocks are enabled /// Implementation of [BaseAnoncreds] which responds with mock data #[allow(unused)] #[async_trait] impl BaseWallet for MockWallet { + fn get_wallet_handle(&self) -> i32 { + 1 + } + async fn create_and_store_my_did( &self, seed: Option<&str>, diff --git a/aries_vcx/tests/test_agency.rs b/aries_vcx/tests/test_agency.rs index 9e59ae78e9..22866d287d 100644 --- a/aries_vcx/tests/test_agency.rs +++ b/aries_vcx/tests/test_agency.rs @@ -11,27 +11,27 @@ mod integration_tests { use std::sync::Arc; use std::time::Duration; + use crate::utils::devsetup_alice::create_alice; + use crate::utils::devsetup_faber::{create_faber, Faber}; use agency_client::agency_client::AgencyClient; use agency_client::api::downloaded_message::DownloadedMessage; use agency_client::messages::update_message::UIDsByConn; use agency_client::MessageStatusCode; use aries_vcx::global::settings; - use aries_vcx::utils::devsetup::SetupPool; + use aries_vcx::utils::devsetup::SetupPoolDirectory; use aries_vcx_core::wallet::agency_client_wallet::ToBaseAgencyClientWallet; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredentialDecorators; use messages::msg_fields::protocols::cred_issuance::{CredentialAttr, CredentialPreview}; use messages::msg_fields::protocols::notification::Notification; - use crate::utils::devsetup_agent::test_utils::create_test_alice_instance; - use crate::utils::devsetup_agent::test_utils::Faber; use crate::utils::scenarios::test_utils::create_connected_connections; #[tokio::test] #[ignore] async fn test_agency_pool_send_and_download_messages() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (alice_to_faber, faber_to_alice) = create_connected_connections(&mut consumer, &mut institution).await; @@ -125,9 +125,9 @@ mod integration_tests { AriesMessage, }; - SetupPool::run(|setup| async move { - let mut faber = Faber::setup(setup.pool_handle).await; - let mut alice = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path.clone()).await; let invite = faber.create_invite().await; alice.accept_invite(&invite).await; @@ -280,10 +280,10 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_download_messages() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer1 = create_test_alice_instance(&setup).await; - let mut consumer2 = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_alice(setup.genesis_file_path.clone()).await; + let mut consumer2 = create_alice(setup.genesis_file_path).await; let (consumer1_to_institution, institution_to_consumer1) = create_connected_connections(&mut consumer1, &mut institution).await; @@ -337,9 +337,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_update_agency_messages() { - SetupPool::run(|setup| async move { - let mut faber = Faber::setup(setup.pool_handle).await; - let mut alice = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path).await; let (alice_to_faber, faber_to_alice) = create_connected_connections(&mut alice, &mut faber).await; @@ -413,10 +413,10 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_download_messages_from_multiple_connections() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer1 = create_test_alice_instance(&setup).await; - let mut consumer2 = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_alice(setup.genesis_file_path.clone()).await; + let mut consumer2 = create_alice(setup.genesis_file_path.clone()).await; let (consumer1_to_institution, institution_to_consumer1) = create_connected_connections(&mut consumer1, &mut institution).await; @@ -455,7 +455,7 @@ mod integration_tests { wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet}, }; - SetupPool::run(|_setup| async move { + SetupPoolDirectory::run(|_setup| async move { let wallet_config = WalletConfig { wallet_name: format!("wallet_{}", uuid::Uuid::new_v4().to_string()), wallet_key: settings::DEFAULT_WALLET_KEY.into(), diff --git a/aries_vcx/tests/test_connection.rs b/aries_vcx/tests/test_connection.rs index 71caefc1db..da03d41f44 100644 --- a/aries_vcx/tests/test_connection.rs +++ b/aries_vcx/tests/test_connection.rs @@ -8,6 +8,8 @@ pub mod utils; #[cfg(test)] mod integration_tests { + use crate::utils::devsetup_alice::create_alice; + use crate::utils::devsetup_faber::{create_faber, Faber}; use aries_vcx::agency_client::MessageStatusCode; use aries_vcx::common::ledger::transactions::into_did_doc; use aries_vcx::handlers::connection::mediated_connection::ConnectionState; @@ -26,7 +28,6 @@ mod integration_tests { use messages::msg_types::Protocol; use messages::AriesMessage; - use crate::utils::devsetup_agent::test_utils::{create_test_alice_instance, Faber}; use crate::utils::scenarios::test_utils::{ _send_message, connect_using_request_sent_to_public_agent, create_connected_connections, create_connected_connections_via_public_invite, create_proof_request, @@ -37,9 +38,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_establish_connection_via_public_invite() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections_via_public_invite(&mut consumer, &mut institution).await; @@ -61,14 +62,14 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_oob_connection_bootstrap() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (sender, receiver) = bounded::(1); 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) @@ -185,14 +186,14 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_oob_connection_reuse() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; 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) @@ -224,14 +225,14 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_oob_connection_handshake_reuse() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; 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) @@ -330,9 +331,9 @@ mod integration_tests { #[tokio::test] #[ignore] pub async fn test_agency_pool_two_enterprise_connections() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer1 = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_alice(setup.genesis_file_path).await; let (_faber, _alice) = create_connected_connections(&mut consumer1, &mut institution).await; let (_faber, _alice) = create_connected_connections(&mut consumer1, &mut institution).await; @@ -343,9 +344,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_aries_demo_handle_connection_related_messages() { - SetupPool::run(|setup| async move { - let mut faber = Faber::setup(setup.pool_handle).await; - let mut alice = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path).await; // Connection let invite = faber.create_invite().await; diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 87a04cf23c..8212867510 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -576,7 +576,9 @@ mod tests { use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; use aries_vcx::utils::devsetup::*; - use crate::utils::devsetup_agent::test_utils::{create_test_alice_instance, Faber, PayloadKinds}; + use crate::utils::devsetup_alice::create_alice; + use crate::utils::devsetup_faber::{create_faber, 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, accept_cred_proposal_1, accept_offer, accept_proof_proposal, attr_names, @@ -594,9 +596,9 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_proof_should_be_validated() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -616,7 +618,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, }] @@ -664,9 +666,9 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_proof_with_predicates_should_be_validated() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -734,9 +736,9 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_it_should_fail_to_select_credentials_for_predicate() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -786,11 +788,11 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_double_issuance_separate_issuer_and_consumers() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer1 = create_test_alice_instance(&setup).await; - let mut consumer2 = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_alice(setup.genesis_file_path.clone()).await; + let mut consumer2 = create_alice(setup.genesis_file_path).await; let (consumer1_to_verifier, verifier_to_consumer1) = create_connected_connections(&mut consumer1, &mut verifier).await; @@ -805,7 +807,7 @@ mod tests { issuer.migrate().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( @@ -894,10 +896,10 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_double_issuance_separate_issuer() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; @@ -974,15 +976,15 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_double_issuance_issuer_is_verifier() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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 (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( @@ -1060,9 +1062,9 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_real_proof() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; let (consumer_to_issuer, issuer_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -1081,7 +1083,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; @@ -1128,7 +1130,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![]); @@ -1193,17 +1195,17 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_one_rev_reg() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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(); @@ -1288,14 +1290,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_credential_exchange_via_proposal() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; 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(); #[cfg(feature = "migration")] @@ -1320,14 +1322,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_credential_exchange_via_proposal_failed() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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( @@ -1364,14 +1366,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_credential_exchange_via_proposal_with_negotiation() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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(); #[cfg(feature = "migration")] @@ -1432,14 +1434,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_presentation_via_proposal() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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(); #[cfg(feature = "migration")] @@ -1481,14 +1483,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_presentation_via_proposal_with_rejection() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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(); #[cfg(feature = "migration")] @@ -1516,14 +1518,14 @@ mod tests { #[tokio::test] #[ignore] async fn test_agency_pool_presentation_via_proposal_with_negotiation() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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(); #[cfg(feature = "migration")] @@ -1568,9 +1570,9 @@ mod tests { #[ignore] async fn test_agency_pool_aries_demo() { let _setup = SetupEmpty::init(); - SetupPool::run(|pool| async move { - let mut faber = Faber::setup(pool.pool_handle).await; - let mut alice = create_test_alice_instance(&pool).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path.clone()).await; // Publish Schema and Credential Definition faber.create_schema().await; @@ -1612,9 +1614,9 @@ mod tests { #[ignore] async fn test_agency_pool_aries_demo_create_with_message_id_flow() { let _setup = SetupEmpty::init(); - SetupPool::run(|pool| async move { - let mut faber = Faber::setup(pool.pool_handle).await; - let mut alice = create_test_alice_instance(&pool).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path.clone()).await; // Publish Schema and Credential Definition faber.create_schema().await; @@ -1717,9 +1719,9 @@ mod tests { #[ignore] async fn test_agency_pool_aries_demo_download_message_flow() { SetupEmpty::init(); - SetupPool::run(|pool| async move { - let mut faber = Faber::setup(pool.pool_handle).await; - let mut alice = create_test_alice_instance(&pool).await; + SetupPoolDirectory::run(|setup| async move { + let mut faber = create_faber(setup.genesis_file_path.clone()).await; + let mut alice = create_alice(setup.genesis_file_path.clone()).await; // Publish Schema and Credential Definition faber.create_schema().await; diff --git a/aries_vcx/tests/test_creds_proofs_revocations.rs b/aries_vcx/tests/test_creds_proofs_revocations.rs index dc42677673..e8359e9f4f 100644 --- a/aries_vcx/tests/test_creds_proofs_revocations.rs +++ b/aries_vcx/tests/test_creds_proofs_revocations.rs @@ -8,12 +8,13 @@ pub mod utils; mod integration_tests { use std::time::Duration; + use crate::utils::devsetup_alice::create_alice; + use crate::utils::devsetup_faber::{create_faber, Faber}; use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; use aries_vcx::utils::devsetup::*; - use crate::utils::devsetup_agent::test_utils::{create_test_alice_instance, Faber}; use crate::utils::scenarios::test_utils::{ _create_address_schema, _exchange_credential, attr_names, create_connected_connections, create_proof, generate_and_send_proof, issue_address_credential, prover_select_credentials_and_send_proof, @@ -30,9 +31,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_basic_revocation() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -68,7 +69,7 @@ mod integration_tests { .unwrap()); let _requested_attrs = requested_attrs( - &institution.config_issuer.institution_did, + &institution.institution_did, &schema_id, &cred_def_id, None, @@ -118,9 +119,9 @@ mod integration_tests { async fn test_agency_pool_revocation_notification() { use messages::decorators::please_ack::AckOn; - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -188,9 +189,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_local_revocation() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; @@ -287,63 +288,66 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_batch_revocation() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer1 = create_test_alice_instance(&setup).await; - let mut consumer2 = create_test_alice_instance(&setup).await; - let mut consumer3 = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_alice(setup.genesis_file_path.clone()).await; + let mut consumer2 = create_alice(setup.genesis_file_path.clone()).await; + let mut consumer3 = create_alice(setup.genesis_file_path).await; let (consumer_to_institution1, institution_to_consumer1) = create_connected_connections(&mut consumer1, &mut institution).await; let (consumer_to_institution2, institution_to_consumer2) = create_connected_connections(&mut consumer2, &mut institution).await; let (consumer_to_institution3, institution_to_consumer3) = create_connected_connections(&mut consumer3, &mut institution).await; - // 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; - 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( - &mut consumer1, - &mut institution, - credential_data1, - &cred_def, - &rev_reg, - &consumer_to_institution1, - &institution_to_consumer1, - None, - ) - .await; + // 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.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( + &mut consumer1, + &mut institution, + credential_data1, + &cred_def, + &rev_reg, + &consumer_to_institution1, + &institution_to_consumer1, + None, + ) + .await; - #[cfg(feature = "migration")] - institution.migrate().await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer2, - &mut institution, - credential_data2, - &cred_def, - &rev_reg, - &consumer_to_institution2, - &institution_to_consumer2, - None, - ) - .await; + #[cfg(feature = "migration")] + institution.migrate().await; + + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer2, + &mut institution, + credential_data2, + &cred_def, + &rev_reg, + &consumer_to_institution2, + &institution_to_consumer2, + None, + ) + .await; - #[cfg(feature = "migration")] - consumer1.migrate().await; - let credential_data3 = json!({address1.clone(): "5th Avenue", address2.clone(): "Suite 1234", city.clone(): "NYC", state.clone(): "NYS", zip.clone(): "84712"}).to_string(); - let issuer_credential3 = _exchange_credential( - &mut consumer3, - &mut institution, - credential_data3, - &cred_def, - &rev_reg, - &consumer_to_institution3, - &institution_to_consumer3, - None, - ) - .await; + #[cfg(feature = "migration")] + consumer1.migrate().await; + + let credential_data3 = json!({address1.clone(): "5th Avenue", address2.clone(): "Suite 1234", city.clone(): "NYC", state.clone(): "NYS", zip.clone(): "84712"}).to_string(); + let issuer_credential3 = _exchange_credential( + &mut consumer3, + &mut institution, + credential_data3, + &cred_def, + &rev_reg, + &consumer_to_institution3, + &institution_to_consumer3, + None, + ) + .await; revoke_credential_local(&mut institution, &issuer_credential1, &rev_reg.rev_reg_id).await; revoke_credential_local(&mut institution, &issuer_credential2, &rev_reg.rev_reg_id).await; @@ -462,9 +466,9 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_revoked_credential_might_still_work() { - SetupPool::run(|setup| async move { - let mut institution = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut institution = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_institution, institution_to_consumer) = create_connected_connections(&mut consumer, &mut institution).await; let (schema_id, cred_def_id, _, _cred_def, rev_reg, issuer_credential) = @@ -487,7 +491,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, &schema_id, &cred_def_id, Some(from), Some(to)); + let _requested_attrs = requested_attrs(&institution.institution_did, &schema_id, &cred_def_id, Some(from), Some(to)); let interval = json!({"from": from, "to": to}).to_string(); let requested_attrs_string = serde_json::to_string(&_requested_attrs).unwrap(); @@ -532,46 +536,47 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_one_rev_reg_revoke_first() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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; - 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(); - let issuer_credential1 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req1, - ) - .await; - - #[cfg(feature = "migration")] - issuer.migrate().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.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(); + let issuer_credential1 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req1, + ) + .await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req2, - ) - .await; + #[cfg(feature = "migration")] + issuer.migrate().await; + + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req2, + ) + .await; assert!(!issuer_credential1.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); assert!(!issuer_credential2.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); @@ -623,45 +628,46 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_one_rev_reg_revoke_second() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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; - 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(); - let issuer_credential1 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req1, - ) - .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.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(); + let issuer_credential1 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req1, + ) + .await; #[cfg(feature = "migration")] issuer.migrate().await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req2, - ) - .await; + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req2, + ) + .await; assert!(!issuer_credential1.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); assert!(!issuer_credential2.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); @@ -712,45 +718,57 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_two_rev_reg_id() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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; - 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(); - let issuer_credential1 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req1, - ) - .await; + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = + _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(); + let issuer_credential1 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req1, + ) + .await; #[cfg(feature = "migration")] issuer.migrate().await; - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - &consumer_to_issuer, - &issuer_to_consumer, - req2, - ) + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + &consumer_to_issuer, + &issuer_to_consumer, + req2, + ) + .await; + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &verifier_to_consumer, + &schema_id, + &cred_def_id, + req1, + ) + .await; + prover_select_credentials_and_send_proof(&mut consumer, &consumer_to_verifier, req1, Some(&credential_data1)) .await; let mut proof_verifier = verifier_create_proof_and_send_request(&mut verifier, &verifier_to_consumer, &schema_id, &cred_def_id, req1).await; @@ -797,46 +815,47 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_first() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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; - 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(); - let issuer_credential1 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req1, - ) - .await; + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = + _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(); + let issuer_credential1 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req1, + ) + .await; #[cfg(feature = "migration")] issuer.migrate().await; - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - &consumer_to_issuer, - &issuer_to_consumer, - req2, - ) - .await; + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + &consumer_to_issuer, + &issuer_to_consumer, + req2, + ) + .await; assert!(!issuer_credential1.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); assert!(!issuer_credential2.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); @@ -886,46 +905,47 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_second() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut verifier = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut verifier = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path).await; let (consumer_to_verifier, verifier_to_consumer) = create_connected_connections(&mut consumer, &mut verifier).await; 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; - 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(); - let issuer_credential1 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - &consumer_to_issuer, - &issuer_to_consumer, - req1, - ) - .await; + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def, rev_reg, _) = + _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(); + let issuer_credential1 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + &consumer_to_issuer, + &issuer_to_consumer, + req1, + ) + .await; #[cfg(feature = "migration")] issuer.migrate().await; - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let issuer_credential2 = _exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - &consumer_to_issuer, - &issuer_to_consumer, - req2, - ) - .await; + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let issuer_credential2 = _exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + &consumer_to_issuer, + &issuer_to_consumer, + req2, + ) + .await; assert!(!issuer_credential1.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); assert!(!issuer_credential2.is_revoked(&issuer.profile.inject_anoncreds_ledger_read()).await.unwrap()); @@ -977,15 +997,15 @@ mod integration_tests { #[tokio::test] #[ignore] async fn test_agency_pool_three_creds_one_rev_reg_revoke_all() { - SetupPool::run(|setup| async move { - let mut issuer = Faber::setup(setup.pool_handle).await; - let mut consumer = create_test_alice_instance(&setup).await; + SetupPoolDirectory::run(|setup| async move { + let mut issuer = create_faber(setup.genesis_file_path.clone()).await; + let mut consumer = create_alice(setup.genesis_file_path.clone()).await; 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, req3) = (Some("request1"), Some("request2"), Some("request3")); diff --git a/aries_vcx/tests/test_pool.rs b/aries_vcx/tests/test_pool.rs index e3b469cb9b..3737a5dabe 100644 --- a/aries_vcx/tests/test_pool.rs +++ b/aries_vcx/tests/test_pool.rs @@ -14,21 +14,13 @@ mod integration_tests { }; use aries_vcx::common::test_utils::create_and_store_nonrevocable_credential_def; use aries_vcx::utils::constants::DEFAULT_SCHEMA_ATTRS; - use aries_vcx::utils::devsetup::{SetupProfile, SetupWalletPool}; + use aries_vcx::utils::devsetup::SetupProfile; use diddoc_legacy::aries::service::AriesService; use std::sync::Arc; use std::thread; use std::time::Duration; - #[tokio::test] - #[ignore] - async fn test_pool_open_close_pool() { - SetupWalletPool::run(|setup| async move { - assert!(setup.pool_handle > 0); - }) - .await; - } - + #[cfg(foobar)] #[tokio::test] #[ignore] async fn test_pool_get_credential_def() { diff --git a/aries_vcx/tests/utils/devsetup_agent.rs b/aries_vcx/tests/utils/devsetup_agent.rs deleted file mode 100644 index acf191ff20..0000000000 --- a/aries_vcx/tests/utils/devsetup_agent.rs +++ /dev/null @@ -1,882 +0,0 @@ -#[cfg(test)] -pub mod test_utils { - use std::collections::HashMap; - use std::sync::Arc; - - #[cfg(feature = "modular_libs")] - use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; - use aries_vcx::core::profile::profile::Profile; - use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; - use aries_vcx::handlers::proof_presentation::types::SelectedCredentials; - use aries_vcx::handlers::revocation_notification::receiver::RevocationNotificationReceiver; - use aries_vcx::handlers::revocation_notification::sender::RevocationNotificationSender; - use aries_vcx::handlers::util::{AnyInvitation, OfferInfo, Status}; - use aries_vcx::protocols::mediated_connection::pairwise_info::PairwiseInfo; - use aries_vcx::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder; - use aries_vcx_core::indy::wallet::{ - close_wallet, create_wallet_with_master_secret, delete_wallet, open_wallet, wallet_configure_issuer, - IssuerConfig, WalletConfig, - }; - #[cfg(feature = "modular_libs")] - use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; - use aries_vcx_core::wallet::base_wallet::BaseWallet; - use aries_vcx_core::wallet::indy_wallet::IndySdkWallet; - use aries_vcx_core::{PoolHandle, WalletHandle}; - use diddoc_legacy::aries::service::AriesService; - use futures::future::BoxFuture; - - use agency_client::agency_client::AgencyClient; - use agency_client::api::downloaded_message::DownloadedMessage; - use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; - use agency_client::MessageStatusCode; - use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; - - use aries_vcx::common::ledger::transactions::{into_did_doc, write_endpoint_legacy}; - use aries_vcx::common::primitives::credential_definition::CredentialDef; - use aries_vcx::common::primitives::credential_definition::CredentialDefConfigBuilder; - use aries_vcx::common::primitives::credential_schema::Schema; - use aries_vcx::common::proofs::proof_request::PresentationRequestData; - use aries_vcx::global::settings; - use aries_vcx::global::settings::init_issuer_config; - use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; - use aries_vcx::handlers::issuance::holder::test_utils::get_credential_offer_messages; - use aries_vcx::handlers::issuance::holder::Holder; - use aries_vcx::handlers::issuance::issuer::Issuer; - use aries_vcx::handlers::proof_presentation::prover::test_utils::get_proof_request_messages; - 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; - use aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; - use aries_vcx::protocols::mediated_connection::invitee::state_machine::InviteeState; - use aries_vcx::protocols::mediated_connection::inviter::state_machine::InviterState; - use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; - use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; - use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; - use aries_vcx::utils::devsetup::*; - use aries_vcx::utils::provision::provision_cloud_agent; - use messages::decorators::please_ack::AckOn; - use messages::msg_fields::protocols::connection::invitation::{PublicInvitation, PublicInvitationContent}; - use messages::msg_fields::protocols::connection::Connection; - use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; - use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; - use messages::msg_fields::protocols::present_proof::request::RequestPresentation; - use messages::msg_fields::protocols::present_proof::PresentProof; - use messages::msg_fields::protocols::revocation::ack::AckRevoke; - use messages::msg_fields::protocols::revocation::revoke::Revoke; - use messages::AriesMessage; - - #[derive(Debug)] - pub struct VcxAgencyMessage { - pub uid: String, - pub decrypted_msg: String, - } - - #[derive(Debug, Clone, PartialEq)] - pub enum PayloadKinds { - CredOffer, - CredReq, - Cred, - Proof, - ProofRequest, - ConnRequest, - Other(String), - } - - fn determine_message_type(a2a_message: AriesMessage) -> PayloadKinds { - debug!("determine_message_type >>> a2a_message: {:?}", a2a_message); - match a2a_message.clone() { - AriesMessage::PresentProof(PresentProof::RequestPresentation(_)) => PayloadKinds::ProofRequest, - AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(_)) => PayloadKinds::CredOffer, - AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(_)) => PayloadKinds::Cred, - AriesMessage::PresentProof(PresentProof::Presentation(_)) => PayloadKinds::Proof, - AriesMessage::Connection(Connection::Request(_)) => PayloadKinds::ConnRequest, - _msg => PayloadKinds::Other(String::from("aries")), - } - } - - fn str_message_to_a2a_message(message: &str) -> VcxResult { - Ok(serde_json::from_str(message).map_err(|err| { - AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidJson, - format!("Cannot deserialize A2A message: {}", err), - ) - })?) - } - - fn str_message_to_payload_type(message: &str) -> VcxResult { - let a2a_message = str_message_to_a2a_message(message)?; - Ok(determine_message_type(a2a_message)) - } - - async fn filter_messages( - messages: Vec, - filter_msg_type: PayloadKinds, - ) -> Option { - for message in messages.into_iter() { - let decrypted_msg = &message.decrypted_msg; - let msg_type = str_message_to_payload_type(decrypted_msg).unwrap(); - if filter_msg_type == msg_type { - return Some(VcxAgencyMessage { - uid: message.uid, - decrypted_msg: decrypted_msg.to_string(), - }); - } - } - None - } - - pub struct Faber { - pub profile: Arc, - pub is_active: bool, - pub config_agency: AgencyClientConfig, - pub config_issuer: IssuerConfig, - pub rev_not_sender: RevocationNotificationSender, - pub connection: MediatedConnection, - pub schema: Schema, - pub cred_def: CredentialDef, - pub issuer_credential: Issuer, - pub verifier: Verifier, - pub pairwise_info: PairwiseInfo, - pub agency_client: AgencyClient, - pub(self) teardown: Arc BoxFuture<'static, ()> + Send + Sync>, - } - - impl Faber { - pub async fn setup(pool_handle: PoolHandle) -> Faber { - settings::reset_config_values().unwrap(); - let enterprise_seed = "000000000000000000000000Trustee1"; - let config_wallet = WalletConfig { - wallet_name: format!("faber_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, - }; - let config_provision_agent = AgentProvisionConfig { - agency_did: AGENCY_DID.to_string(), - agency_verkey: AGENCY_VERKEY.to_string(), - agency_endpoint: AGENCY_ENDPOINT.parse().unwrap(), - agent_seed: None, - }; - create_wallet_with_master_secret(&config_wallet).await.unwrap(); - let wallet_handle = open_wallet(&config_wallet).await.unwrap(); - - let indy_profile = VdrtoolsProfile::init(wallet_handle, pool_handle); - let profile: Arc = Arc::new(indy_profile); - - let config_issuer = wallet_configure_issuer(wallet_handle, enterprise_seed).await.unwrap(); - init_issuer_config(&config_issuer.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 - .unwrap(); - let connection = MediatedConnection::create("faber", &profile.inject_wallet(), &agency_client, true) - .await - .unwrap(); - - let pairwise_info = PairwiseInfo::create(&profile.inject_wallet()).await.unwrap(); - 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(); - - let rev_not_sender = RevocationNotificationSender::build(); - - let faber = Faber { - profile, - agency_client, - is_active: false, - config_agency, - config_issuer, - schema: Schema::default(), - cred_def: CredentialDef::default(), - connection, - issuer_credential: Issuer::default(), - verifier: Verifier::default(), - rev_not_sender, - pairwise_info, - teardown: Arc::new(move || Box::pin(teardown_indy_wallet(wallet_handle, config_wallet.clone()))), - }; - faber - } - - pub async fn create_schema(&mut self) { - let data = vec!["name", "date", "degree", "empty_param"] - .iter() - .map(|s| s.to_string()) - .collect(); - let name: String = aries_vcx::utils::random::generate_random_schema_name(); - let version: String = String::from("1.0"); - - self.schema = Schema::create( - &self.profile.inject_anoncreds(), - "", - &self.config_issuer.institution_did, - &name, - &version, - &data, - ) - .await - .unwrap() - .publish(&self.profile.inject_anoncreds_ledger_write(), None) - .await - .unwrap(); - } - - pub async fn create_nonrevocable_credential_definition(&mut self) { - let config = CredentialDefConfigBuilder::default() - .issuer_did("V4SGRU86Z58d6TV7PBUe6f") - .schema_id(self.schema.get_schema_id()) - .tag("tag") - .build() - .unwrap(); - - self.cred_def = CredentialDef::create( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - String::from("test_cred_def"), - config, - false, - ) - .await - .unwrap() - .publish_cred_def( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds_ledger_write(), - ) - .await - .unwrap(); - } - - pub async fn create_presentation_request(&self) -> Verifier { - let requested_attrs = json!([ - {"name": "name"}, - {"name": "date"}, - {"name": "degree"}, - {"name": "empty_param", "restrictions": {"attr::empty_param::value": ""}} - ]) - .to_string(); - let presentation_request_data = PresentationRequestData::create(&self.profile.inject_anoncreds(), "1") - .await - .unwrap() - .set_requested_attributes_as_string(requested_attrs) - .unwrap(); - Verifier::create_from_request(String::from("alice_degree"), &presentation_request_data).unwrap() - } - - pub async fn create_invite(&mut self) -> String { - self.connection - .connect(&self.profile.inject_wallet(), &self.agency_client, None) - .await - .unwrap(); - self.connection - .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!( - ConnectionState::Inviter(InviterState::Invited), - self.connection.get_state() - ); - - json!(self.connection.get_invite_details().unwrap()).to_string() - } - - 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 public_invitation = PublicInvitation::new(id.to_owned(), content); - Ok(json!(AriesMessage::from(public_invitation)).to_string()) - } - - pub async fn update_state(&mut self, expected_state: u32) { - self.connection - .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!(expected_state, u32::from(self.connection.get_state())); - } - - pub async fn handle_messages(&mut self) { - self.connection - .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - } - - pub async fn respond_messages(&mut self, expected_state: u32) { - self.connection - .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!(expected_state, u32::from(self.connection.get_state())); - } - - pub async fn ping(&mut self) { - self.connection - .send_ping(self.profile.inject_wallet(), None) - .await - .unwrap(); - } - - pub async fn discovery_features(&mut self) { - self.connection - .send_discovery_query(&self.profile.inject_wallet(), None, None) - .await - .unwrap(); - } - - pub async fn connection_info(&mut self) -> serde_json::Value { - let details = self.connection.get_connection_info(&self.agency_client).await.unwrap(); - serde_json::from_str(&details).unwrap() - } - - pub async fn offer_non_revocable_credential(&mut self) { - let credential_json = json!({ - "name": "alice", - "date": "05-2018", - "degree": "maths", - "empty_param": "" - }) - .to_string(); - - let offer_info = OfferInfo { - credential_json, - cred_def_id: self.cred_def.get_cred_def_id(), - rev_reg_id: None, - tails_file: None, - }; - self.issuer_credential = Issuer::create("alice_degree").unwrap(); - self.issuer_credential - .build_credential_offer_msg(&self.profile.inject_anoncreds(), offer_info, None) - .await - .unwrap(); - self.issuer_credential - .send_credential_offer( - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - self.issuer_credential - .update_state( - &self.profile.inject_wallet(), - &self.profile.inject_anoncreds(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(IssuerState::OfferSent, self.issuer_credential.get_state()); - } - - pub async fn send_credential(&mut self) { - self.issuer_credential - .update_state( - &self.profile.inject_wallet(), - &self.profile.inject_anoncreds(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(IssuerState::RequestReceived, self.issuer_credential.get_state()); - - self.issuer_credential - .send_credential( - &self.profile.inject_anoncreds(), - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - self.issuer_credential - .update_state( - &self.profile.inject_wallet(), - &self.profile.inject_anoncreds(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(IssuerState::CredentialSent, self.issuer_credential.get_state()); - } - - pub async fn request_presentation(&mut self) { - self.verifier = self.create_presentation_request().await; - assert_eq!(VerifierState::PresentationRequestSet, self.verifier.get_state()); - - self.verifier - .send_presentation_request( - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - self.verifier - .update_state( - &self.profile.inject_wallet(), - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - - assert_eq!(VerifierState::PresentationRequestSent, self.verifier.get_state()); - } - - pub async fn verify_presentation(&mut self) { - self.update_proof_state(VerifierState::Finished, PresentationVerificationStatus::Valid) - .await - } - - pub async fn update_proof_state( - &mut self, - expected_state: VerifierState, - expected_verification_status: PresentationVerificationStatus, - ) { - self.verifier - .update_state( - &self.profile.inject_wallet(), - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(expected_state, self.verifier.get_state()); - assert_eq!(expected_verification_status, self.verifier.get_verification_status()); - } - - pub async fn send_revocation_notification(&mut self, ack_on: Vec) { - let config = SenderConfigBuilder::default() - .ack_on(ack_on) - .rev_reg_id(self.issuer_credential.get_rev_reg_id().unwrap()) - .cred_rev_id(self.issuer_credential.get_rev_id().unwrap()) - .build() - .unwrap(); - let send_message = self - .connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(); - self.rev_not_sender = self - .rev_not_sender - .clone() - .send_revocation_notification(config, send_message) - .await - .unwrap(); - } - - pub async fn handle_revocation_notification_ack(&mut self, ack: AckRevoke) { - self.rev_not_sender = self - .rev_not_sender - .clone() - .handle_revocation_notification_ack(ack) - .await - .unwrap(); - } - } - - pub struct Alice { - pub profile: Arc, - pub is_active: bool, - pub config_agency: AgencyClientConfig, - pub connection: MediatedConnection, - pub credential: Holder, - pub rev_not_receiver: Option, - pub prover: Prover, - pub agency_client: AgencyClient, - pub(self) teardown: Arc BoxFuture<'static, ()> + Send + Sync>, - } - - pub async fn create_test_alice_instance(setup: &SetupPool) -> Alice { - #[cfg(any(not(feature = "modular_libs"), feature = "migration"))] - let (alice_profile, teardown) = { - info!("create_test_alice_instance >> using indy profile"); - Alice::setup_indy_profile(setup.pool_handle).await - }; - - #[cfg(all(feature = "modular_libs", not(feature = "migration")))] - let (alice_profile, teardown) = { - let genesis_file_path = setup.genesis_file_path.clone(); - let config = LedgerPoolConfig { genesis_file_path }; - info!("create_test_alice_instance >> using modular profile"); - Alice::setup_modular_profile(config).await - }; - - Alice::setup(alice_profile, teardown).await - } - - impl Alice { - async fn setup_indy_wallet() -> (WalletHandle, WalletConfig) { - settings::reset_config_values().unwrap(); - let config_wallet = WalletConfig { - wallet_name: format!("alice_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, ()> + Send + Sync>) { - let (wallet_handle, config_wallet) = Alice::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_indy_profile( - pool_handle: PoolHandle, - ) -> (Arc, Arc BoxFuture<'static, ()> + Send + Sync>) { - let (wallet_handle, config_wallet) = Alice::setup_indy_wallet().await; - - 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()))), - ) - } - - pub async fn setup( - profile: Arc, - teardown: Arc BoxFuture<'static, ()> + Send + Sync>, - ) -> Alice { - let config_provision_agent = AgentProvisionConfig { - agency_did: AGENCY_DID.to_string(), - agency_verkey: AGENCY_VERKEY.to_string(), - agency_endpoint: AGENCY_ENDPOINT.parse().unwrap(), - agent_seed: None, - }; - let mut agency_client = AgencyClient::new(); - let config_agency = - provision_cloud_agent(&mut agency_client, profile.inject_wallet(), &config_provision_agent) - .await - .unwrap(); - let connection = MediatedConnection::create("tmp_empoty", &profile.inject_wallet(), &agency_client, true) - .await - .unwrap(); - let alice = Alice { - profile, - agency_client, - is_active: false, - config_agency, - connection, - credential: Holder::create("test").unwrap(), - prover: Prover::default(), - rev_not_receiver: None, - teardown, - }; - alice - } - - pub async fn accept_invite(&mut self, invite: &str) { - let invite: AnyInvitation = serde_json::from_str(invite).unwrap(); - let ddo = into_did_doc(&self.profile.inject_indy_ledger_read(), &invite) - .await - .unwrap(); - self.connection = MediatedConnection::create_with_invite( - "faber", - &self.profile.inject_wallet(), - &self.agency_client, - invite, - ddo, - true, - ) - .await - .unwrap(); - self.connection - .connect(&self.profile.inject_wallet(), &self.agency_client, None) - .await - .unwrap(); - self.connection - .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!( - ConnectionState::Invitee(InviteeState::Requested), - self.connection.get_state() - ); - } - - pub async fn update_state(&mut self, expected_state: u32) { - self.connection - .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!(expected_state, u32::from(self.connection.get_state())); - } - - pub async fn handle_messages(&mut self) { - self.connection - .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - } - - pub async fn respond_messages(&mut self, expected_state: u32) { - self.connection - .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) - .await - .unwrap(); - assert_eq!(expected_state, u32::from(self.connection.get_state())); - } - - pub async fn download_message(&mut self, message_type: PayloadKinds) -> VcxResult { - let _did = self.connection.pairwise_info().pw_did.to_string(); - let messages = self - .connection - .download_messages(&self.agency_client, Some(vec![MessageStatusCode::Received]), None) - .await - .unwrap(); - filter_messages(messages, message_type) - .await - .ok_or(AriesVcxError::from_msg( - AriesVcxErrorKind::UnknownError, - format!("Failed to download a message"), - )) - } - - pub async fn accept_offer(&mut self) { - let offers = get_credential_offer_messages(&self.agency_client, &self.connection) - .await - .unwrap(); - let offer = serde_json::from_str::>(&offers).unwrap()[0].clone(); - let offer = serde_json::to_string(&offer).unwrap(); - let cred_offer: OfferCredential = serde_json::from_str(&offer) - .map_err(|err| { - AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidJson, - format!( - "Strict `aries` protocol is enabled. Can not parse `aries` formatted Credential Offer: {}", - err - ), - ) - }) - .unwrap(); - - self.credential = Holder::create_from_offer("degree", cred_offer).unwrap(); - assert_eq!(HolderState::OfferReceived, self.credential.get_state()); - - let pw_did = self.connection.pairwise_info().pw_did.to_string(); - self.credential - .send_request( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - pw_did, - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - assert_eq!(HolderState::RequestSent, self.credential.get_state()); - } - - pub async fn accept_credential(&mut self) { - self.credential - .update_state( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - &self.profile.inject_wallet(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(HolderState::Finished, self.credential.get_state()); - assert_eq!(Status::Success.code(), self.credential.get_credential_status().unwrap()); - } - - pub async fn get_proof_request_messages(&mut self) -> RequestPresentation { - let presentation_requests = get_proof_request_messages(&self.agency_client, &self.connection) - .await - .unwrap(); - let presentation_request = - serde_json::from_str::>(&presentation_requests).unwrap()[0].clone(); - let presentation_request_json = serde_json::to_string(&presentation_request).unwrap(); - let presentation_request: RequestPresentation = serde_json::from_str(&presentation_request_json).unwrap(); - presentation_request - } - - pub async fn get_proof_request_by_msg_id(&mut self, msg_id: &str) -> VcxResult { - match self - .connection - .get_message_by_id(msg_id, &self.agency_client) - .await - .unwrap() - { - AriesMessage::PresentProof(PresentProof::RequestPresentation(presentation_request)) => { - Ok(presentation_request) - } - msg => Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidMessages, - format!("Message of different type was received: {:?}", msg), - )), - } - } - - pub async fn get_credential_offer_by_msg_id(&mut self, msg_id: &str) -> VcxResult { - match self - .connection - .get_message_by_id(msg_id, &self.agency_client) - .await - .unwrap() - { - AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(cred_offer)) => Ok(cred_offer), - msg => Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidMessages, - format!("Message of different type was received: {:?}", msg), - )), - } - } - - pub async fn get_credentials_for_presentation(&mut self) -> SelectedCredentials { - let credentials = self - .prover - .retrieve_credentials(&self.profile.inject_anoncreds()) - .await - .unwrap(); - - let mut use_credentials = SelectedCredentials { - credential_for_referent: HashMap::new(), - }; - - for (referent, credentials) in credentials.credentials_by_referent { - use_credentials.select_credential_for_referent_from_retrieved(referent, credentials[0].clone(), None); - } - - use_credentials - } - - pub async fn send_presentation(&mut self) { - let presentation_request = self.get_proof_request_messages().await; - - self.prover = Prover::create_from_request("degree", presentation_request).unwrap(); - - let credentials = self.get_credentials_for_presentation().await; - - self.prover - .generate_presentation( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - credentials, - HashMap::new(), - ) - .await - .unwrap(); - assert_eq!(ProverState::PresentationPrepared, self.prover.get_state()); - - self.prover - .send_presentation( - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - assert_eq!(ProverState::PresentationSent, self.prover.get_state()); - } - - pub async fn ensure_presentation_verified(&mut self) { - self.prover - .update_state( - &self.profile.inject_anoncreds_ledger_read(), - &self.profile.inject_anoncreds(), - &self.profile.inject_wallet(), - &self.agency_client, - &self.connection, - ) - .await - .unwrap(); - assert_eq!(Status::Success.code(), self.prover.presentation_status()); - } - - pub async fn receive_revocation_notification(&mut self, rev_not: Revoke) { - let rev_reg_id = self.credential.get_rev_reg_id().unwrap(); - let cred_rev_id = self - .credential - .get_cred_rev_id(&self.profile.inject_anoncreds()) - .await - .unwrap(); - let send_message = self - .connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(); - let rev_not_receiver = RevocationNotificationReceiver::build(rev_reg_id, cred_rev_id) - .handle_revocation_notification(rev_not, send_message) - .await - .unwrap(); - self.rev_not_receiver = Some(rev_not_receiver); - } - } - - async fn teardown_indy_wallet(wallet_handle: WalletHandle, config_wallet: WalletConfig) { - info!("Closing test indy wallet: {:?}", config_wallet); - close_wallet(wallet_handle) - .await - .unwrap_or_else(|_| error!("Failed to close wallet while teardowning: {:?}", config_wallet)); - info!("Deleting test indy wallet: {:?}", config_wallet); - delete_wallet(&config_wallet) - .await - .unwrap_or_else(|_| error!("Failed to delete wallet while teardowning: {:?}", config_wallet)); - } - - impl Drop for Faber { - fn drop(&mut self) { - futures::executor::block_on((self.teardown)()); - } - } - - impl Drop for Alice { - fn drop(&mut self) { - futures::executor::block_on((self.teardown)()); - } - } -} diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs new file mode 100644 index 0000000000..c3d0189c75 --- /dev/null +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -0,0 +1,342 @@ +use crate::utils::devsetup_util::test_utils::{filter_messages, PayloadKinds, VcxAgencyMessage}; +use agency_client::agency_client::AgencyClient; +use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; +use agency_client::MessageStatusCode; +use aries_vcx::common::ledger::transactions::into_did_doc; +#[cfg(feature = "modular_libs")] +use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; +use aries_vcx::core::profile::profile::Profile; +use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; +use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; +use aries_vcx::global::settings; +use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; +use aries_vcx::handlers::issuance::holder::test_utils::get_credential_offer_messages; +use aries_vcx::handlers::issuance::holder::Holder; +use aries_vcx::handlers::proof_presentation::prover::test_utils::get_proof_request_messages; +use aries_vcx::handlers::proof_presentation::prover::Prover; +use aries_vcx::handlers::proof_presentation::types::SelectedCredentials; +use aries_vcx::handlers::revocation_notification::receiver::RevocationNotificationReceiver; +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, 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::wallet::{create_wallet_with_master_secret, open_wallet, WalletConfig}; +#[cfg(feature = "modular_libs")] +use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; +use aries_vcx_core::wallet::base_wallet::BaseWallet; +use aries_vcx_core::wallet::indy_wallet::IndySdkWallet; +use aries_vcx_core::{PoolHandle, WalletHandle}; +use futures::future::BoxFuture; +use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; +use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; +use messages::msg_fields::protocols::present_proof::request::RequestPresentation; +use messages::msg_fields::protocols::present_proof::PresentProof; +use messages::msg_fields::protocols::revocation::revoke::Revoke; +use messages::AriesMessage; +use std::collections::HashMap; +use std::sync::Arc; + +pub struct Alice { + pub profile: Arc, + pub is_active: bool, + pub config_agency: AgencyClientConfig, + pub connection: MediatedConnection, + pub credential: Holder, + pub rev_not_receiver: Option, + pub prover: Prover, + pub agency_client: AgencyClient, + pub teardown: Arc BoxFuture<'static, ()>>, +} + +pub async fn create_alice(genesis_file_path: String) -> Alice { + 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 { + // todo: we could rather have Drop in Profile, why is Alice doing this ... + pub async fn setup(profile: Arc, teardown: Arc BoxFuture<'static, ()>>) -> Alice { + let config_provision_agent = AgentProvisionConfig { + agency_did: AGENCY_DID.to_string(), + agency_verkey: AGENCY_VERKEY.to_string(), + agency_endpoint: AGENCY_ENDPOINT.parse().unwrap(), + agent_seed: None, + }; + let mut agency_client = AgencyClient::new(); + let config_agency = provision_cloud_agent(&mut agency_client, profile.inject_wallet(), &config_provision_agent) + .await + .unwrap(); + let connection = MediatedConnection::create("tmp_empoty", &profile.inject_wallet(), &agency_client, true) + .await + .unwrap(); + let alice = Alice { + profile, + agency_client, + is_active: false, + config_agency, + connection, + credential: Holder::create("test").unwrap(), + prover: Prover::default(), + rev_not_receiver: None, + teardown, + }; + alice + } + + pub async fn accept_invite(&mut self, invite: &str) { + let invite: AnyInvitation = serde_json::from_str(invite).unwrap(); + let ddo = into_did_doc(&self.profile.inject_indy_ledger_read(), &invite) + .await + .unwrap(); + self.connection = MediatedConnection::create_with_invite( + "faber", + &self.profile.inject_wallet(), + &self.agency_client, + invite, + ddo, + true, + ) + .await + .unwrap(); + self.connection + .connect(&self.profile.inject_wallet(), &self.agency_client, None) + .await + .unwrap(); + self.connection + .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!( + ConnectionState::Invitee(InviteeState::Requested), + self.connection.get_state() + ); + } + + pub async fn update_state(&mut self, expected_state: u32) { + self.connection + .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!(expected_state, u32::from(self.connection.get_state())); + } + + pub async fn handle_messages(&mut self) { + self.connection + .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + } + + pub async fn respond_messages(&mut self, expected_state: u32) { + self.connection + .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!(expected_state, u32::from(self.connection.get_state())); + } + + pub async fn download_message(&mut self, message_type: PayloadKinds) -> VcxResult { + let _did = self.connection.pairwise_info().pw_did.to_string(); + let messages = self + .connection + .download_messages(&self.agency_client, Some(vec![MessageStatusCode::Received]), None) + .await + .unwrap(); + filter_messages(messages, message_type) + .await + .ok_or(AriesVcxError::from_msg( + AriesVcxErrorKind::UnknownError, + format!("Failed to download a message"), + )) + } + + pub async fn accept_offer(&mut self) { + let offers = get_credential_offer_messages(&self.agency_client, &self.connection) + .await + .unwrap(); + let offer = serde_json::from_str::>(&offers).unwrap()[0].clone(); + let offer = serde_json::to_string(&offer).unwrap(); + let cred_offer: OfferCredential = serde_json::from_str(&offer) + .map_err(|err| { + AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidJson, + format!( + "Strict `aries` protocol is enabled. Can not parse `aries` formatted Credential Offer: {}", + err + ), + ) + }) + .unwrap(); + + self.credential = Holder::create_from_offer("degree", cred_offer).unwrap(); + assert_eq!(HolderState::OfferReceived, self.credential.get_state()); + + let pw_did = self.connection.pairwise_info().pw_did.to_string(); + self.credential + .send_request( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + pw_did, + self.connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(HolderState::RequestSent, self.credential.get_state()); + } + + pub async fn accept_credential(&mut self) { + self.credential + .update_state( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + &self.profile.inject_wallet(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(HolderState::Finished, self.credential.get_state()); + assert_eq!(Status::Success.code(), self.credential.get_credential_status().unwrap()); + } + + pub async fn get_proof_request_messages(&mut self) -> RequestPresentation { + let presentation_requests = get_proof_request_messages(&self.agency_client, &self.connection) + .await + .unwrap(); + let presentation_request = + serde_json::from_str::>(&presentation_requests).unwrap()[0].clone(); + let presentation_request_json = serde_json::to_string(&presentation_request).unwrap(); + let presentation_request: RequestPresentation = serde_json::from_str(&presentation_request_json).unwrap(); + presentation_request + } + + pub async fn get_proof_request_by_msg_id(&mut self, msg_id: &str) -> VcxResult { + match self + .connection + .get_message_by_id(msg_id, &self.agency_client) + .await + .unwrap() + { + AriesMessage::PresentProof(PresentProof::RequestPresentation(presentation_request)) => { + Ok(presentation_request) + } + msg => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidMessages, + format!("Message of different type was received: {:?}", msg), + )), + } + } + + pub async fn get_credential_offer_by_msg_id(&mut self, msg_id: &str) -> VcxResult { + match self + .connection + .get_message_by_id(msg_id, &self.agency_client) + .await + .unwrap() + { + AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(cred_offer)) => Ok(cred_offer), + msg => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidMessages, + format!("Message of different type was received: {:?}", msg), + )), + } + } + + pub async fn get_credentials_for_presentation(&mut self) -> SelectedCredentials { + let credentials = self + .prover + .retrieve_credentials(&self.profile.inject_anoncreds()) + .await + .unwrap(); + + let mut use_credentials = SelectedCredentials { + credential_for_referent: HashMap::new(), + }; + + for (referent, credentials) in credentials.credentials_by_referent { + use_credentials.select_credential_for_referent_from_retrieved(referent, credentials[0].clone(), None); + } + + use_credentials + } + + pub async fn send_presentation(&mut self) { + let presentation_request = self.get_proof_request_messages().await; + + self.prover = Prover::create_from_request("degree", presentation_request).unwrap(); + + let credentials = self.get_credentials_for_presentation().await; + + self.prover + .generate_presentation( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + credentials, + HashMap::new(), + ) + .await + .unwrap(); + assert_eq!(ProverState::PresentationPrepared, self.prover.get_state()); + + self.prover + .send_presentation( + self.connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(ProverState::PresentationSent, self.prover.get_state()); + } + + pub async fn ensure_presentation_verified(&mut self) { + self.prover + .update_state( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + &self.profile.inject_wallet(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(Status::Success.code(), self.prover.presentation_status()); + } + + pub async fn receive_revocation_notification(&mut self, rev_not: Revoke) { + let rev_reg_id = self.credential.get_rev_reg_id().unwrap(); + let cred_rev_id = self + .credential + .get_cred_rev_id(&self.profile.inject_anoncreds()) + .await + .unwrap(); + let send_message = self + .connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(); + let rev_not_receiver = RevocationNotificationReceiver::build(rev_reg_id, cred_rev_id) + .handle_revocation_notification(rev_not, send_message) + .await + .unwrap(); + self.rev_not_receiver = Some(rev_not_receiver); + } +} + +impl Drop for Alice { + fn drop(&mut self) { + futures::executor::block_on((self.teardown)()); + } +} diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs new file mode 100644 index 0000000000..5f833520ad --- /dev/null +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -0,0 +1,409 @@ +use agency_client::agency_client::AgencyClient; +use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; +use aries_vcx::common::ledger::transactions::write_endpoint_legacy; +use aries_vcx::common::primitives::credential_definition::{CredentialDef, CredentialDefConfigBuilder}; +use aries_vcx::common::primitives::credential_schema::Schema; +use aries_vcx::common::proofs::proof_request::PresentationRequestData; +use aries_vcx::core::profile::profile::Profile; +use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; +use aries_vcx::errors::error::VcxResult; +use aries_vcx::global::settings; +use aries_vcx::global::settings::init_issuer_config; +use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; +use aries_vcx::handlers::issuance::issuer::Issuer; +use aries_vcx::handlers::proof_presentation::verifier::Verifier; +use aries_vcx::handlers::revocation_notification::sender::RevocationNotificationSender; +use aries_vcx::handlers::util::OfferInfo; +use aries_vcx::protocols::connection::pairwise_info::PairwiseInfo; +use aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; +use aries_vcx::protocols::mediated_connection::inviter::state_machine::InviterState; +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, 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, +}; +#[cfg(feature = "modular_libs")] +use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; +use aries_vcx_core::{PoolHandle, WalletHandle}; +use diddoc_legacy::aries::service::AriesService; +use futures::future::BoxFuture; +use messages::decorators::please_ack::AckOn; +use messages::msg_fields::protocols::connection::invitation::public::{PublicInvitation, PublicInvitationContent}; +use messages::msg_fields::protocols::revocation::ack::AckRevoke; +use messages::AriesMessage; +use serde_json::json; +use std::sync::Arc; + +pub struct Faber { + pub profile: Arc, + pub is_active: bool, + pub config_agency: AgencyClientConfig, + pub institution_did: String, + pub rev_not_sender: RevocationNotificationSender, + pub connection: MediatedConnection, + pub schema: Schema, + pub cred_def: CredentialDef, + pub issuer_credential: Issuer, + pub verifier: Verifier, + pub pairwise_info: PairwiseInfo, + pub agency_client: AgencyClient, + pub teardown: Arc BoxFuture<'static, ()>>, +} + +pub async fn create_faber(genesis_file_path: String) -> Faber { + 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, + institution_did: String, + teardown: Arc BoxFuture<'static, ()>>, + ) -> Faber { + settings::reset_config_values_ariesvcx().unwrap(); + + let config_provision_agent = AgentProvisionConfig { + agency_did: AGENCY_DID.to_string(), + agency_verkey: AGENCY_VERKEY.to_string(), + agency_endpoint: AGENCY_ENDPOINT.parse().unwrap(), + agent_seed: None, + }; + + // 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 + .unwrap(); + let connection = MediatedConnection::create("faber", &profile.inject_wallet(), &agency_client, true) + .await + .unwrap(); + + let pairwise_info = PairwiseInfo::create(&profile.inject_wallet()).await.unwrap(); + 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(), &institution_did, &service) + .await + .unwrap(); + + let rev_not_sender = RevocationNotificationSender::build(); + + let faber = Faber { + profile, + agency_client, + is_active: false, + config_agency, + institution_did, + schema: Schema::default(), + cred_def: CredentialDef::default(), + connection, + issuer_credential: Issuer::default(), + verifier: Verifier::default(), + rev_not_sender, + pairwise_info, + teardown, + }; + faber + } + + pub async fn create_schema(&mut self) { + let data = vec!["name", "date", "degree", "empty_param"] + .iter() + .map(|s| s.to_string()) + .collect(); + let name: String = aries_vcx::utils::random::generate_random_schema_name(); + let version: String = String::from("1.0"); + + self.schema = Schema::create( + &self.profile.inject_anoncreds(), + "", + &self.institution_did, + &name, + &version, + &data, + ) + .await + .unwrap() + .publish(&self.profile.inject_anoncreds_ledger_write(), None) + .await + .unwrap(); + } + + pub async fn create_nonrevocable_credential_definition(&mut self) { + let config = CredentialDefConfigBuilder::default() + .issuer_did("V4SGRU86Z58d6TV7PBUe6f") + .schema_id(self.schema.get_schema_id()) + .tag("tag") + .build() + .unwrap(); + + self.cred_def = CredentialDef::create( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + String::from("test_cred_def"), + config, + false, + ) + .await + .unwrap() + .publish_cred_def( + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds_ledger_write(), + ) + .await + .unwrap(); + } + + pub async fn create_presentation_request(&self) -> Verifier { + let requested_attrs = json!([ + {"name": "name"}, + {"name": "date"}, + {"name": "degree"}, + {"name": "empty_param", "restrictions": {"attr::empty_param::value": ""}} + ]) + .to_string(); + let presentation_request_data = PresentationRequestData::create(&self.profile.inject_anoncreds(), "1") + .await + .unwrap() + .set_requested_attributes_as_string(requested_attrs) + .unwrap(); + Verifier::create_from_request(String::from("alice_degree"), &presentation_request_data).unwrap() + } + + pub async fn create_invite(&mut self) -> String { + self.connection + .connect(&self.profile.inject_wallet(), &self.agency_client, None) + .await + .unwrap(); + self.connection + .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!( + ConnectionState::Inviter(InviterState::Invited), + self.connection.get_state() + ); + + json!(self.connection.get_invite_details().unwrap()).to_string() + } + + pub fn create_public_invite(&mut self) -> VcxResult { + let id = "test_invite_id"; + 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()) + } + + pub async fn update_state(&mut self, expected_state: u32) { + self.connection + .find_message_and_update_state(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!(expected_state, u32::from(self.connection.get_state())); + } + + pub async fn handle_messages(&mut self) { + self.connection + .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + } + + pub async fn respond_messages(&mut self, expected_state: u32) { + self.connection + .find_and_handle_message(&self.profile.inject_wallet(), &self.agency_client) + .await + .unwrap(); + assert_eq!(expected_state, u32::from(self.connection.get_state())); + } + + pub async fn ping(&mut self) { + self.connection + .send_ping(self.profile.inject_wallet(), None) + .await + .unwrap(); + } + + pub async fn discovery_features(&mut self) { + self.connection + .send_discovery_query(&self.profile.inject_wallet(), None, None) + .await + .unwrap(); + } + + pub async fn connection_info(&mut self) -> serde_json::Value { + let details = self.connection.get_connection_info(&self.agency_client).await.unwrap(); + serde_json::from_str(&details).unwrap() + } + + pub async fn offer_non_revocable_credential(&mut self) { + let credential_json = json!({ + "name": "alice", + "date": "05-2018", + "degree": "maths", + "empty_param": "" + }) + .to_string(); + + let offer_info = OfferInfo { + credential_json, + cred_def_id: self.cred_def.get_cred_def_id(), + rev_reg_id: None, + tails_file: None, + }; + self.issuer_credential = Issuer::create("alice_degree").unwrap(); + self.issuer_credential + .build_credential_offer_msg(&self.profile.inject_anoncreds(), offer_info, None) + .await + .unwrap(); + self.issuer_credential + .send_credential_offer( + self.connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(), + ) + .await + .unwrap(); + self.issuer_credential + .update_state( + &self.profile.inject_wallet(), + &self.profile.inject_anoncreds(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(IssuerState::OfferSent, self.issuer_credential.get_state()); + } + + pub async fn send_credential(&mut self) { + self.issuer_credential + .update_state( + &self.profile.inject_wallet(), + &self.profile.inject_anoncreds(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(IssuerState::RequestReceived, self.issuer_credential.get_state()); + + self.issuer_credential + .send_credential( + &self.profile.inject_anoncreds(), + self.connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(), + ) + .await + .unwrap(); + self.issuer_credential + .update_state( + &self.profile.inject_wallet(), + &self.profile.inject_anoncreds(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(IssuerState::CredentialSent, self.issuer_credential.get_state()); + } + + pub async fn request_presentation(&mut self) { + self.verifier = self.create_presentation_request().await; + assert_eq!(VerifierState::PresentationRequestSet, self.verifier.get_state()); + + self.verifier + .send_presentation_request( + self.connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(), + ) + .await + .unwrap(); + self.verifier + .update_state( + &self.profile.inject_wallet(), + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + + assert_eq!(VerifierState::PresentationRequestSent, self.verifier.get_state()); + } + + pub async fn verify_presentation(&mut self) { + self.update_proof_state(VerifierState::Finished, PresentationVerificationStatus::Valid) + .await + } + + pub async fn update_proof_state( + &mut self, + expected_state: VerifierState, + expected_verification_status: PresentationVerificationStatus, + ) { + self.verifier + .update_state( + &self.profile.inject_wallet(), + &self.profile.inject_anoncreds_ledger_read(), + &self.profile.inject_anoncreds(), + &self.agency_client, + &self.connection, + ) + .await + .unwrap(); + assert_eq!(expected_state, self.verifier.get_state()); + assert_eq!(expected_verification_status, self.verifier.get_verification_status()); + } + + pub async fn send_revocation_notification(&mut self, ack_on: Vec) { + let config = SenderConfigBuilder::default() + .ack_on(ack_on) + .rev_reg_id(self.issuer_credential.get_rev_reg_id().unwrap()) + .cred_rev_id(self.issuer_credential.get_rev_id().unwrap()) + .build() + .unwrap(); + let send_message = self + .connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(); + self.rev_not_sender = self + .rev_not_sender + .clone() + .send_revocation_notification(config, send_message) + .await + .unwrap(); + } + + pub async fn handle_revocation_notification_ack(&mut self, ack: AckRevoke) { + self.rev_not_sender = self + .rev_not_sender + .clone() + .handle_revocation_notification_ack(ack) + .await + .unwrap(); + } +} + +impl Drop for Faber { + fn drop(&mut self) { + futures::executor::block_on((self.teardown)()); + } +} diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs new file mode 100644 index 0000000000..7c343c6e9c --- /dev/null +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -0,0 +1,97 @@ +use std::sync::Arc; + +use futures::future::BoxFuture; + +#[cfg(feature = "modular_libs")] +use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; +use aries_vcx::core::profile::profile::Profile; +use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; +use aries_vcx::global::settings; +use aries_vcx_core::indy::ledger::pool::indy_open_pool; +use aries_vcx_core::indy::wallet::{create_wallet_with_master_secret, open_wallet, WalletConfig}; +#[cfg(feature = "modular_libs")] +use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; +use aries_vcx_core::wallet::base_wallet::BaseWallet; +use aries_vcx_core::wallet::indy_wallet::IndySdkWallet; +use aries_vcx_core::WalletHandle; + +use crate::utils::devsetup_alice::Alice; + +#[cfg(test)] +pub mod test_utils { + use std::collections::HashMap; + use std::sync::Arc; + + use agency_client::api::downloaded_message::DownloadedMessage; + #[cfg(feature = "modular_libs")] + use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; + use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; + use aries_vcx_core::indy::wallet::{close_wallet, delete_wallet, WalletConfig}; + #[cfg(feature = "modular_libs")] + use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; + use aries_vcx_core::WalletHandle; + use messages::msg_fields::protocols::connection::Connection; + use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; + use messages::msg_fields::protocols::present_proof::PresentProof; + use messages::AriesMessage; + + #[derive(Debug)] + pub struct VcxAgencyMessage { + pub uid: String, + pub decrypted_msg: String, + } + + #[derive(Debug, Clone, PartialEq)] + pub enum PayloadKinds { + CredOffer, + CredReq, + Cred, + Proof, + ProofRequest, + ConnRequest, + Other(String), + } + + fn determine_message_type(a2a_message: AriesMessage) -> PayloadKinds { + debug!("determine_message_type >>> a2a_message: {:?}", a2a_message); + match a2a_message.clone() { + AriesMessage::PresentProof(PresentProof::RequestPresentation(_)) => PayloadKinds::ProofRequest, + AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(_)) => PayloadKinds::CredOffer, + AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(_)) => PayloadKinds::Cred, + AriesMessage::PresentProof(PresentProof::Presentation(_)) => PayloadKinds::Proof, + AriesMessage::Connection(Connection::Request(_)) => PayloadKinds::ConnRequest, + _msg => PayloadKinds::Other(String::from("aries")), + } + } + + fn str_message_to_a2a_message(message: &str) -> VcxResult { + Ok(serde_json::from_str(message).map_err(|err| { + AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidJson, + format!("Cannot deserialize A2A message: {}", err), + ) + })?) + } + + fn str_message_to_payload_type(message: &str) -> VcxResult { + let a2a_message = str_message_to_a2a_message(message)?; + Ok(determine_message_type(a2a_message)) + } + + pub async fn filter_messages( + messages: Vec, + filter_msg_type: PayloadKinds, + ) -> Option { + for message in messages.into_iter() { + let decrypted_msg = &message.decrypted_msg; + let msg_type = str_message_to_payload_type(decrypted_msg).unwrap(); + if filter_msg_type == msg_type { + return Some(VcxAgencyMessage { + uid: message.uid, + decrypted_msg: decrypted_msg.to_string(), + }); + } + } + None + } +} diff --git a/aries_vcx/tests/utils/mod.rs b/aries_vcx/tests/utils/mod.rs index 1db6f6bb26..1b3d0ce771 100644 --- a/aries_vcx/tests/utils/mod.rs +++ b/aries_vcx/tests/utils/mod.rs @@ -1,4 +1,6 @@ -pub mod devsetup_agent; +pub mod devsetup_alice; +pub mod devsetup_faber; +pub mod devsetup_util; #[cfg(feature = "migration")] pub mod migration; pub mod scenarios; diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 4edeb3df59..737f413beb 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -27,6 +27,8 @@ pub mod test_utils { use messages::AriesMessage; use serde_json::{json, Value}; + use crate::utils::devsetup_alice::Alice; + use crate::utils::devsetup_faber::Faber; 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; @@ -51,8 +53,6 @@ pub mod test_utils { use aries_vcx::utils::filters::{filter_credential_offers_by_comment, filter_proof_requests_by_name}; use aries_vcx::utils::get_temp_dir_path; - use crate::utils::devsetup_agent::test_utils::{Alice, Faber}; - pub fn _send_message(sender: Sender) -> Option { Some(Box::new( move |message: AriesMessage, _sender_vk: String, _did_doc: AriesDidDoc| { @@ -923,7 +923,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(); @@ -954,7 +954,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, @@ -974,7 +974,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(); @@ -1099,7 +1099,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(); @@ -1128,13 +1128,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, diff --git a/aries_vcx_core/src/anoncreds/indy_anoncreds.rs b/aries_vcx_core/src/anoncreds/indy_anoncreds.rs index 505f3c91d7..cc8e148db9 100644 --- a/aries_vcx_core/src/anoncreds/indy_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/indy_anoncreds.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use crate::errors::error::VcxCoreResult; use crate::indy::wallet_non_secrets::{clear_rev_reg_delta, get_rev_reg_delta}; -use crate::{indy, PoolHandle, WalletHandle}; +use crate::{indy, WalletHandle}; use super::base_anoncreds::BaseAnonCreds; diff --git a/aries_vcx_core/src/global/author_agreement.rs b/aries_vcx_core/src/global/author_agreement.rs index 19c639e778..a3be3555d6 100644 --- a/aries_vcx_core/src/global/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_txn_author_agreement( +pub fn set_vdrtools_config_txn_author_agreement( text: Option, version: Option, taa_digest: Option, @@ -40,7 +40,7 @@ pub fn set_txn_author_agreement( Ok(()) } -pub fn get_txn_author_agreement() -> VcxCoreResult> { +pub fn get_vdrtools_config_txn_author_agreement() -> VcxCoreResult> { trace!("get_txn_author_agreement >>>"); match settings::get_config_value(settings::CONFIG_TXN_AUTHOR_AGREEMENT) { Ok(value) => { @@ -64,10 +64,10 @@ mod unit_tests { #[test] fn set_txn_author_agreement_works() { - settings::reset_config_values().unwrap(); + settings::reset_config_values_ariesvcxcore().unwrap(); assert!(settings::get_config_value(settings::CONFIG_TXN_AUTHOR_AGREEMENT).is_err()); - set_txn_author_agreement( + set_vdrtools_config_txn_author_agreement( Some(TEXT.to_string()), Some(VERSION.to_string()), None, @@ -81,8 +81,8 @@ mod unit_tests { #[test] fn get_txn_author_agreement_works() { - settings::reset_config_values().unwrap(); - set_txn_author_agreement( + settings::reset_config_values_ariesvcxcore().unwrap(); + set_vdrtools_config_txn_author_agreement( Some(TEXT.to_string()), Some(VERSION.to_string()), None, @@ -91,7 +91,7 @@ mod unit_tests { ) .unwrap(); - let meta = get_txn_author_agreement().unwrap().unwrap(); + let meta = get_vdrtools_config_txn_author_agreement().unwrap().unwrap(); let expected_meta = TxnAuthorAgreementAcceptanceData { text: Some(TEXT.to_string()), @@ -106,7 +106,7 @@ mod unit_tests { #[test] fn get_txn_author_agreement_works_for_not_set() { - settings::reset_config_values().unwrap(); - assert!(get_txn_author_agreement().unwrap().is_none()); + settings::reset_config_values_ariesvcxcore().unwrap(); + assert!(get_vdrtools_config_txn_author_agreement().unwrap().is_none()); } } diff --git a/aries_vcx_core/src/global/settings.rs b/aries_vcx_core/src/global/settings.rs index 167ac6481a..6bc3130fb5 100644 --- a/aries_vcx_core/src/global/settings.rs +++ b/aries_vcx_core/src/global/settings.rs @@ -3,7 +3,6 @@ use std::sync::RwLock; use crate::errors::error::prelude::*; -pub static CONFIG_POOL_NAME: &str = "pool_name"; pub static CONFIG_INSTITUTION_DID: &str = "institution_did"; // functionally not used @@ -72,7 +71,7 @@ pub fn set_config_value(key: &str, value: &str) -> VcxCoreResult<()> { Ok(()) } -pub fn reset_config_values() -> VcxCoreResult<()> { +pub fn reset_config_values_ariesvcxcore() -> VcxCoreResult<()> { trace!("reset_config_values >>>"); let mut config = SETTINGS.write()?; config.clear(); diff --git a/aries_vcx_core/src/indy/anoncreds.rs b/aries_vcx_core/src/indy/anoncreds.rs index c230baf7bd..8d9be00fb8 100644 --- a/aries_vcx_core/src/indy/anoncreds.rs +++ b/aries_vcx_core/src/indy/anoncreds.rs @@ -30,68 +30,5 @@ pub(super) async fn close_search_handle(search_handle: SearchHandle) -> VcxCoreR pub async fn generate_nonce() -> VcxCoreResult { let res = Locator::instance().verifier_controller.generate_nonce()?; - Ok(res) } - -// #[cfg(test)] -// mod unit_tests { -// use vdrtools::WalletHandle; - -// use crate::indy::ledger::transactions::get_schema_json; -// use crate::utils::constants::{SCHEMA_ID, SCHEMA_JSON}; -// use crate::utils::devsetup::SetupMocks; - -// #[tokio::test] -// async fn from_ledger_schema_id() { -// let _setup = SetupMocks::init(); -// let (id, retrieved_schema) = get_schema_json(WalletHandle(0), 1, SCHEMA_ID).await.unwrap(); -// assert_eq!(&retrieved_schema, SCHEMA_JSON); -// assert_eq!(&id, SCHEMA_ID); -// } -// } - -// #[cfg(test)] -// pub mod integration_tests { - -// use crate::common::test_utils::{create_and_store_credential, indy_handles_to_profile}; -// use crate::indy::primitives::revocation_registry::libindy_issuer_revoke_credential; -// use crate::utils::constants::TAILS_DIR; -// use crate::utils::devsetup::SetupWalletPool; -// use crate::utils::get_temp_dir_path; - -// #[tokio::test] -// #[ignore] -// async fn test_pool_issuer_revoke_credential() { -// SetupWalletPool::run(|setup| async move { -// let rc = libindy_issuer_revoke_credential( -// setup.wallet_handle, -// get_temp_dir_path(TAILS_DIR).to_str().unwrap(), -// "", -// "", -// ) -// .await; -// assert!(rc.is_err()); - -// let profile = indy_handles_to_profile(setup.wallet_handle, setup.pool_handle); -// let (_, _, _, _, _, _, _, _, rev_reg_id, cred_rev_id, _) = create_and_store_credential( -// &profile, -// &profile, -// &setup.institution_did, -// crate::utils::constants::DEFAULT_SCHEMA_ATTRS, -// ) -// .await; - -// let rc = libindy_issuer_revoke_credential( -// setup.wallet_handle, -// get_temp_dir_path(TAILS_DIR).to_str().unwrap(), -// &rev_reg_id, -// &cred_rev_id, -// ) -// .await; - -// assert!(rc.is_ok()); -// }) -// .await; -// } -// } diff --git a/aries_vcx_core/src/indy/ledger/pool.rs b/aries_vcx_core/src/indy/ledger/pool.rs index bfde384a2f..0615fbfc33 100644 --- a/aries_vcx_core/src/indy/ledger/pool.rs +++ b/aries_vcx_core/src/indy/ledger/pool.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use vdrtools::domain::pool::VdrtoolsPoolOpenConfig; use vdrtools::Locator; use vdrtools::types::errors::IndyErrorKind; @@ -7,14 +8,6 @@ use crate::errors::error::prelude::*; use crate::global::settings; use crate::PoolHandle; -pub fn set_protocol_version() -> VcxCoreResult<()> { - Locator::instance() - .pool_controller - .set_protocol_version(settings::get_protocol_version())?; - - Ok(()) -} - pub fn create_pool_ledger_config(pool_name: &str, path: &str) -> VcxCoreResult<()> { let res = Locator::instance().pool_controller.create( pool_name.into(), @@ -37,20 +30,12 @@ pub fn create_pool_ledger_config(pool_name: &str, path: &str) -> VcxCoreResult<( } } -pub async fn open_pool_ledger(pool_name: &str, config: Option) -> VcxCoreResult { - set_protocol_version()?; - - let handle = Locator::instance() +pub async fn indy_open_pool(pool_name: &str, config: Option) -> VcxCoreResult { + Locator::instance() .pool_controller - .open( - pool_name.into(), - config - .and_then(|c| c.pool_config) - .as_deref() - .map(serde_json::from_str) - .transpose()?, - ) - .await; + .set_protocol_version(settings::get_protocol_version())?; + + let handle = Locator::instance().pool_controller.open(pool_name.into(), config).await; match handle { Ok(handle) => Ok(handle), @@ -61,7 +46,7 @@ pub async fn open_pool_ledger(pool_name: &str, config: Option) -> Vc } } -pub async fn close(handle: PoolHandle) -> VcxCoreResult<()> { +pub async fn indy_close_pool(handle: PoolHandle) -> VcxCoreResult<()> { // TODO there was timeout here (before future-based Rust wrapper) Locator::instance().pool_controller.close(handle).await?; @@ -69,7 +54,7 @@ pub async fn close(handle: PoolHandle) -> VcxCoreResult<()> { Ok(()) } -pub async fn delete(pool_name: &str) -> VcxCoreResult<()> { +pub async fn indy_delete_pool(pool_name: &str) -> VcxCoreResult<()> { trace!("delete >>> pool_name: {}", pool_name); Locator::instance().pool_controller.delete(pool_name.into()).await?; @@ -92,26 +77,6 @@ pub mod test_utils { 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(); - } - - pub async fn delete_named_test_pool(pool_handle: PoolHandle, pool_name: &str) { - close(pool_handle).await.ok(); - delete(pool_name).await.unwrap(); - } - - pub async fn delete_test_pool(pool_handle: PoolHandle) { - close(pool_handle).await.unwrap(); - delete(POOL).await.unwrap(); - } - - pub async fn open_test_pool() -> PoolHandle { - create_test_ledger_config().await; - open_pool_ledger(POOL, None).await.unwrap() - } - pub fn get_txns(test_pool_ip: &str) -> Vec { vec![ format!( @@ -129,17 +94,15 @@ pub mod test_utils { ] } - pub fn create_tmp_genesis_txn_file() -> String { - let test_pool_ip = ::std::env::var("TEST_POOL_IP").unwrap_or("127.0.0.1".to_string()); + pub fn create_testpool_genesis_txn_file(genesis_file_path: &str) { + let test_pool_ip = env::var("TEST_POOL_IP").unwrap_or("127.0.0.1".to_string()); let node_txns = get_txns(&test_pool_ip); let txn_file_data = node_txns[0..4].join("\n"); - let file_path = String::from(get_temp_dir_path(GENESIS_PATH).to_str().unwrap()); - let mut f = fs::File::create(&file_path).unwrap(); + let mut f = fs::File::create(&genesis_file_path).unwrap(); f.write_all(txn_file_data.as_bytes()).unwrap(); f.flush().unwrap(); f.sync_all().unwrap(); - file_path } } @@ -148,5 +111,5 @@ pub mod test_utils { pub struct PoolConfig { pub genesis_path: String, pub pool_name: Option, - pub pool_config: Option, + pub pool_config: Option, } diff --git a/aries_vcx_core/src/indy/ledger/transactions.rs b/aries_vcx_core/src/indy/ledger/transactions.rs index b715718a1a..63b882988a 100644 --- a/aries_vcx_core/src/indy/ledger/transactions.rs +++ b/aries_vcx_core/src/indy/ledger/transactions.rs @@ -3,7 +3,7 @@ use vdrtools::{DidValue, Locator}; use crate::common::ledger::transactions::{verify_transaction_can_be_endorsed, Response}; use crate::errors::error::prelude::*; -use crate::global::author_agreement::get_txn_author_agreement; +use crate::global::author_agreement::get_vdrtools_config_txn_author_agreement; use crate::global::settings; use crate::global::settings::get_sample_did; use crate::indy::utils::mocks::pool_mocks::PoolMocks; @@ -140,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) = get_txn_author_agreement()? { + if let Some(author_agreement) = get_vdrtools_config_txn_author_agreement()? { Locator::instance() .ledger_controller .append_txn_author_agreement_acceptance_to_request( @@ -704,54 +704,3 @@ pub async fn get_cred_def_json( Ok((cred_def_id.to_string(), cred_def_json)) } - -// #[cfg(test)] -// mod test { -// use crate::utils::devsetup::*; - -// use super::*; - -// #[test] -// fn test_verify_transaction_can_be_endorsed() { -// let _setup = SetupDefaults::init(); - -// // success -// let transaction = r#"{"reqId":1, "identifier": "EbP4aYNeTHL6q385GuVpRV", "signature": "gkVDhwe2", "endorser": "NcYxiDXkpYi6ov5FcYDi1e"}"#; -// assert!(_verify_transaction_can_be_endorsed(transaction, "NcYxiDXkpYi6ov5FcYDi1e").is_ok()); - -// // no author signature -// let transaction = -// r#"{"reqId":1, "identifier": "EbP4aYNeTHL6q385GuVpRV", "endorser": "NcYxiDXkpYi6ov5FcYDi1e"}"#; -// assert!(_verify_transaction_can_be_endorsed(transaction, "NcYxiDXkpYi6ov5FcYDi1e").is_err()); - -// // different endorser did -// let transaction = -// r#"{"reqId":1, "identifier": "EbP4aYNeTHL6q385GuVpRV", "endorser": "NcYxiDXkpYi6ov5FcYDi1e"}"#; -// assert!(_verify_transaction_can_be_endorsed(transaction, "EbP4aYNeTHL6q385GuVpRV").is_err()); -// } -// } - -// #[cfg(test)] -// pub mod integration_tests { -// use crate::indy::ledger::transactions::get_ledger_txn; -// use crate::utils::devsetup::SetupWalletPool; - -// #[tokio::test] -// #[ignore] -// async fn test_pool_get_txn() { -// SetupWalletPool::run(|setup| async move { -// get_ledger_txn(setup.wallet_handle, setup.pool_handle, 0, None) -// .await -// .unwrap_err(); -// let txn = get_ledger_txn(setup.wallet_handle, setup.pool_handle, 1, None).await; -// assert!(txn.is_ok()); - -// get_ledger_txn(setup.wallet_handle, setup.pool_handle, 0, Some(&setup.institution_did)) -// .await -// .unwrap_err(); -// let txn = get_ledger_txn(setup.wallet_handle, setup.pool_handle, 1, Some(&setup.institution_did)).await; -// assert!(txn.is_ok()); -// }) -// .await; -// } -// } diff --git a/aries_vcx_core/src/indy/wallet.rs b/aries_vcx_core/src/indy/wallet.rs index d5372d8aa0..1f5772db03 100644 --- a/aries_vcx_core/src/indy/wallet.rs +++ b/aries_vcx_core/src/indy/wallet.rs @@ -582,24 +582,3 @@ pub async fn close_wallet(wallet_handle: WalletHandle) -> VcxCoreResult<()> { Ok(()) } - -// #[cfg(test)] -// mod test { -// use crate::errors::error::AriesVcxCoreErrorKind; -// use crate::indy::wallet::add_wallet_record; -// use crate::utils::devsetup::SetupLibraryWallet; - -// #[tokio::test] -// async fn test_add_record() { -// SetupLibraryWallet::run(|setup| async move { -// add_wallet_record(setup.wallet_handle.0, "record_type", "123", "Record Value", Some("{}")) -// .await -// .unwrap(); -// let err = add_wallet_record(setup.wallet_handle.0, "record_type", "123", "Record Value", Some("{}")) -// .await -// .unwrap_err(); -// assert_eq!(err.kind(), AriesVcxCoreErrorKind::DuplicationWalletRecord); -// }) -// .await; -// } -// } diff --git a/aries_vcx_core/src/wallet/agency_client_wallet.rs b/aries_vcx_core/src/wallet/agency_client_wallet.rs index f8f31c53c0..517334fcab 100644 --- a/aries_vcx_core/src/wallet/agency_client_wallet.rs +++ b/aries_vcx_core/src/wallet/agency_client_wallet.rs @@ -105,6 +105,10 @@ impl BaseWallet for AgencyClientWallet { async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult> { Ok(self.inner.unpack_message(msg).await?) } + + fn get_wallet_handle(&self) -> i32 { + unimplemented!("AgencyClientWallet::get_wallet_handle - this was not expected to be called") + } } pub trait ToBaseWallet { diff --git a/aries_vcx_core/src/wallet/base_wallet.rs b/aries_vcx_core/src/wallet/base_wallet.rs index 95e22a5c13..42ccbb3db9 100644 --- a/aries_vcx_core/src/wallet/base_wallet.rs +++ b/aries_vcx_core/src/wallet/base_wallet.rs @@ -10,8 +10,10 @@ use std::collections::HashMap; /// see: #[async_trait] pub trait BaseWallet: std::fmt::Debug + Send + Sync { - // ----- DIDs + // todo: workaround, this needs to be removed, vdrtools wallet specific concept + fn get_wallet_handle(&self) -> i32; + // ----- DIDs async fn create_and_store_my_did( &self, seed: Option<&str>, diff --git a/aries_vcx_core/src/wallet/indy_wallet.rs b/aries_vcx_core/src/wallet/indy_wallet.rs index 8175e696f6..be88665a2f 100644 --- a/aries_vcx_core/src/wallet/indy_wallet.rs +++ b/aries_vcx_core/src/wallet/indy_wallet.rs @@ -132,6 +132,10 @@ impl BaseWallet for IndySdkWallet { async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult> { indy::signing::unpack_message(self.wallet_handle, msg).await } + + fn get_wallet_handle(&self) -> i32 { + self.wallet_handle.0 + } } struct IndyWalletRecordIterator { diff --git a/libvcx/Cargo.toml b/libvcx/Cargo.toml index d5b3c3f008..24e7a34b76 100644 --- a/libvcx/Cargo.toml +++ b/libvcx/Cargo.toml @@ -12,9 +12,6 @@ crate-type = ["staticlib", "cdylib", "lib"] doctest = false [features] -test_utils = [ "libvcx_core/test_utils" ] -pool_tests = [ "test_utils" ] -general_test = [ "test_utils" ] fatal_warnings = [] [dependencies] diff --git a/libvcx/README.md b/libvcx/README.md index 2f3cb74c5b..af4b0db033 100644 --- a/libvcx/README.md +++ b/libvcx/README.md @@ -29,11 +29,11 @@ Before you try to build/test `libvcx` crate on your machine, make sure you can b - Run unit tests: ``` -cargo test --features "general_test" -- --test-threads=1 +cargo test -- --test-threads=1 ``` - Run integration tests (you need to have Indy pool running) ``` -TEST_POOL_IP=127.0.0.1 cargo test --features "pool_tests" -- --test-threads=1 +TEST_POOL_IP=127.0.0.1 cargo test -- --include-ignored --test-threads=1 ``` ## Architecture diff --git a/libvcx/src/api_c/cutils/callback.rs b/libvcx/src/api_c/cutils/callback.rs index 114e7d86c5..2519068c3b 100644 --- a/libvcx/src/api_c/cutils/callback.rs +++ b/libvcx/src/api_c/cutils/callback.rs @@ -43,7 +43,7 @@ pub fn get_cb(command_handle: H, map: &Mutex>) -> } #[cfg(test)] -#[cfg(feature = "general_test")] + mod tests { use crate::api_c::cutils::callback::{build_string, get_cb}; use std::collections::HashMap; @@ -55,7 +55,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_build_string() { let test_str = "Journey before destination".to_string(); @@ -64,7 +63,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_get_cb() { let mutex_map: Mutex>> = Default::default(); assert!(get_cb(2123, &mutex_map).is_none()); diff --git a/libvcx/src/api_c/cutils/callback_u32.rs b/libvcx/src/api_c/cutils/callback_u32.rs index 1a2d8e1f11..551090b01b 100644 --- a/libvcx/src/api_c/cutils/callback_u32.rs +++ b/libvcx/src/api_c/cutils/callback_u32.rs @@ -132,7 +132,7 @@ pub extern "C" fn call_cb_u32_u32_str_str_str( } #[cfg(test)] -#[cfg(feature = "general_test")] + mod tests { use std::ffi::CString; @@ -143,7 +143,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_build_string() { let test_str = "Journey before destination".to_string(); @@ -153,7 +152,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_get_cb() { let mutex_map: Mutex>> = Default::default(); assert!(get_cb(2123, &mutex_map).is_none()); diff --git a/libvcx/src/api_c/cutils/logger.rs b/libvcx/src/api_c/cutils/logger.rs index a94074c2a0..aefbb10ee7 100644 --- a/libvcx/src/api_c/cutils/logger.rs +++ b/libvcx/src/api_c/cutils/logger.rs @@ -328,40 +328,4 @@ mod tests { ) { unsafe { COUNT = COUNT + 1 } } - - // #[ignore] - // #[test] - // #[cfg(feature = "general_test")] - // fn test_logging_get_logger() { - // LibvcxDefaultLogger::init(Some("debug".to_string())).unwrap(); - // unsafe { - // let (context, enabled_cb, _log_cb, _flush_cb) = LOGGER_STATE.get(); - // assert_eq!(context, ptr::null()); - // let target = CStringUtils::string_to_cstring("target".to_string()); - // let level = 1; - // let b = LibvcxDefaultLogger::enabled(ptr::null(), 1, target.as_ptr()); - - // assert_eq!(enabled_cb.unwrap()(ptr::null(), level, target.as_ptr()), b); - // } - // } - - // Can only have one test that initializes logging. - #[ignore] - #[test] - #[cfg(feature = "general_test")] - fn test_custom_logger() { - unsafe { - LibvcxLogger::init( - get_custom_context(), - Some(custom_enabled), - custom_log, - Some(custom_flush), - ) - .unwrap(); - } - error!("error level message"); // first call of log function - unsafe { - assert_eq!(COUNT, 2) // second-time log function was called inside libindy - } - } } diff --git a/libvcx/src/api_c/cutils/return_types_u32.rs b/libvcx/src/api_c/cutils/return_types_u32.rs index f33ee1e3fa..7aae9ef53f 100644 --- a/libvcx/src/api_c/cutils/return_types_u32.rs +++ b/libvcx/src/api_c/cutils/return_types_u32.rs @@ -393,7 +393,7 @@ impl Return_U32_U32_STR_STR_STR { } #[cfg(test)] -#[cfg(feature = "general_test")] + mod tests { use std::ffi::CString; use std::ptr; @@ -405,7 +405,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_return_u32() { let rtn = Return_U32::new().unwrap(); rtn.get_callback()(rtn.command_handle, 0); @@ -419,7 +418,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_return_u32_u32() { let test_val = 23455; @@ -436,7 +434,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_return_u32_str() { let test_str = "Journey before destination".to_string(); diff --git a/libvcx/src/api_c/ledger/credential_def.rs b/libvcx/src/api_c/ledger/credential_def.rs index 341f0bee76..f40b107e41 100644 --- a/libvcx/src/api_c/ledger/credential_def.rs +++ b/libvcx/src/api_c/ledger/credential_def.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::credential_def; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -431,13 +430,12 @@ pub extern "C" fn vcx_credentialdef_get_state( SUCCESS_ERR_CODE } -#[cfg(feature = "general_test")] #[cfg(test)] mod tests { use std::ffi::CString; use aries_vcx::utils::constants::SCHEMA_ID; - use aries_vcx::utils::devsetup::{SetupLibraryWallet, SetupMocks}; + use aries_vcx::utils::devsetup::SetupMocks; use libvcx_core::errors; use crate::api_c::cutils::return_types_u32; @@ -446,7 +444,6 @@ mod tests { use super::*; #[test] - #[cfg(feature = "general_test")] fn test_vcx_create_credentialdef_success() { let _setup = SetupMocks::init(); @@ -465,29 +462,7 @@ mod tests { cb.receive(TimeoutUtils::some_medium()).unwrap(); } - #[cfg(feature = "general_test")] - #[tokio::test] - async fn test_vcx_create_credentialdef_fails() { - SetupLibraryWallet::run(|_setup| async { - let cb = return_types_u32::Return_U32_U32::new().unwrap(); - assert_eq!( - vcx_credentialdef_create_v2( - cb.command_handle, - CString::new("Test Source ID").unwrap().into_raw(), - CString::new(SCHEMA_ID).unwrap().into_raw(), - CString::new("tag").unwrap().into_raw(), - true, - Some(cb.get_callback()), - ), - SUCCESS_ERR_CODE - ); - assert!(cb.receive(TimeoutUtils::some_medium()).is_err()); - }) - .await; - } - #[test] - #[cfg(feature = "general_test")] fn test_vcx_credentialdef_serialize() { let _setup = SetupMocks::init(); @@ -515,7 +490,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credentialdef_deserialize_succeeds() { let _setup = SetupMocks::init(); @@ -536,7 +510,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credentialdef_deserialize_succeeds_with_old_data() { let _setup = SetupMocks::init(); @@ -557,7 +530,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_creddef_get_id() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/ledger/revocation_registry.rs b/libvcx/src/api_c/ledger/revocation_registry.rs index 243861180e..d92bbd71ad 100644 --- a/libvcx/src/api_c/ledger/revocation_registry.rs +++ b/libvcx/src/api_c/ledger/revocation_registry.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::{revocation_registry, revocation_registry::RevocationRegistryConfig}; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; diff --git a/libvcx/src/api_c/ledger/schema.rs b/libvcx/src/api_c/ledger/schema.rs index 559dd83569..a79dbfd83d 100644 --- a/libvcx/src/api_c/ledger/schema.rs +++ b/libvcx/src/api_c/ledger/schema.rs @@ -5,7 +5,6 @@ use libc::c_char; use serde_json; use libvcx_core::api_vcx::api_handle::schema; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -487,7 +486,6 @@ pub extern "C" fn vcx_schema_get_state( } #[cfg(test)] -#[cfg(feature = "test_utils")] mod tests { use std::ffi::CString; @@ -536,7 +534,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_create_schema_success() { let _setup = SetupMocks::init(); @@ -546,7 +543,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_schema_serialize() { let _setup = SetupMocks::init(); @@ -557,7 +553,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_schema_deserialize_succeeds() { let _setup = SetupMocks::init(); @@ -573,7 +568,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_schema_get_schema_id_succeeds() { let _setup = SetupMocks::init(); @@ -590,7 +584,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_schema_get_attrs() { let _setup = SetupMocks::init(); @@ -612,7 +605,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_schema_get_state() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/protocols/credential.rs b/libvcx/src/api_c/protocols/credential.rs index 494a5f1be3..9491899d0d 100644 --- a/libvcx/src/api_c/protocols/credential.rs +++ b/libvcx/src/api_c/protocols/credential.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::credential; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -1188,7 +1187,6 @@ pub extern "C" fn vcx_credential_release(handle: u32) -> u32 { } } -#[cfg(feature = "general_test")] #[cfg(test)] mod tests { use std::ffi::CString; @@ -1231,7 +1229,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credential_create_with_offer_success() { let _setup = SetupMocks::init(); @@ -1240,7 +1237,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credential_create_with_offer_fails() { let _setup = SetupMocks::init(); @@ -1249,7 +1245,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credential_serialize_and_deserialize() { let _setup = SetupMocks::init(); @@ -1280,7 +1275,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_credential_get_new_offers() { let _setup = SetupMocks::init(); @@ -1295,7 +1290,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_credential_create() { let _setup = SetupMocks::init(); @@ -1316,7 +1311,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credential_get_state() { let _setup = SetupMocks::init(); @@ -1334,7 +1328,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_credential_update_state() { let _setup = SetupMocks::init(); @@ -1383,7 +1377,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_get_credential() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/protocols/disclosed_proof.rs b/libvcx/src/api_c/protocols/disclosed_proof.rs index c4c4a9e8df..239e57f022 100644 --- a/libvcx/src/api_c/protocols/disclosed_proof.rs +++ b/libvcx/src/api_c/protocols/disclosed_proof.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::disclosed_proof; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -1130,7 +1129,6 @@ pub extern "C" fn vcx_disclosed_proof_release(handle: u32) -> u32 { } #[cfg(test)] -#[cfg(feature = "test_utils")] mod tests { use std::ffi::CString; @@ -1171,7 +1169,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_create_with_request_success() { let _setup = SetupMocks::init(); @@ -1180,7 +1177,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_create_with_request() { let _setup = SetupMocks::init(); @@ -1189,7 +1185,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_create_with_msgid() { let _setup = SetupMocks::init(); @@ -1211,7 +1207,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_disclosed_proof_serialize_and_deserialize() { let _setup = SetupMocks::init(); @@ -1242,7 +1237,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_generate_msg() { let _setup = SetupMocks::init(); @@ -1269,7 +1263,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_send_proof() { let _setup = SetupMocks::init(); @@ -1291,7 +1285,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_reject_proof_request() { let _setup = SetupMocks::init(); @@ -1313,7 +1307,7 @@ mod tests { #[tokio::test] #[cfg(feature = "to_restore")] - #[cfg(feature = "general_test")] // todo: generate_reject_proof_msg is not implemented for aries + // todo: generate_reject_proof_msg is not implemented for aries async fn test_vcx_get_reject_msg() { let _setup = SetupMocks::init(); @@ -1335,7 +1329,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_proof_get_requests() { let _setup = SetupMocks::init(); @@ -1353,7 +1347,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_get_state() { let _setup = SetupMocks::init(); @@ -1369,7 +1362,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_disclosed_proof_retrieve_credentials() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_creds_retrieved_for_proof_request(CREDS_FROM_PROOF_REQ); @@ -1386,7 +1378,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_disclosed_proof_generate_proof() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/protocols/issuer_credential.rs b/libvcx/src/api_c/protocols/issuer_credential.rs index cdcfba4776..5d1d8a62a7 100644 --- a/libvcx/src/api_c/protocols/issuer_credential.rs +++ b/libvcx/src/api_c/protocols/issuer_credential.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::issuer_credential; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -968,7 +967,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_issuer_create_credential_success() { let _setup = SetupMocks::init(); @@ -977,7 +975,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_issuer_create_credential_fails() { let _setup = SetupMocks::init(); @@ -990,7 +987,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_issuer_credential_serialize_deserialize() { let _setup = SetupMocks::init(); @@ -1019,7 +1015,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_create_credential_arguments_correct() { let _setup = SetupMocks::init(); @@ -1034,7 +1029,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_issuer_credential_get_state() { let _setup = SetupMocks::init(); @@ -1050,7 +1044,7 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_issuer_revoke_credential_local() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/protocols/mediated_connection.rs b/libvcx/src/api_c/protocols/mediated_connection.rs index cd8b674383..8ceb2a2cab 100644 --- a/libvcx/src/api_c/protocols/mediated_connection.rs +++ b/libvcx/src/api_c/protocols/mediated_connection.rs @@ -6,7 +6,6 @@ use libc::c_char; use aries_vcx::protocols::mediated_connection::pairwise_info::PairwiseInfo; use libvcx_core::api_vcx::api_handle::mediated_connection; use libvcx_core::api_vcx::api_handle::mediated_connection::*; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils; @@ -1581,7 +1580,7 @@ pub extern "C" fn vcx_connection_messages_download( } #[cfg(test)] -#[cfg(feature = "general_test")] + mod tests { use std::ffi::CString; use std::ptr; @@ -1607,7 +1606,6 @@ mod tests { use super::*; #[test] - #[cfg(feature = "general_test")] fn test_vcx_connection_create() { let _setup = SetupMocks::init(); @@ -1622,7 +1620,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_connection_create_fails() { let _setup = SetupMocks::init(); @@ -1634,7 +1631,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_connect() { let _setup = SetupMocks::init(); @@ -1664,7 +1661,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_connect_returns_invitation() { let _setup = SetupMocks::init(); @@ -1679,7 +1676,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_update_state() { let _setup = SetupMocks::init(); @@ -1710,7 +1707,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_update_state_with_message() { let _setup = SetupMocks::init(); @@ -1745,7 +1742,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_connection_update_state_fails() { let _setup = SetupMocks::init(); @@ -1754,7 +1750,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_serialize() { let _setup = SetupMocks::init(); @@ -1769,7 +1765,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_connection_deserialize_succeeds() { let _setup = SetupMocks::init(); @@ -1785,7 +1780,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_get_state() { let _setup = SetupMocks::init(); @@ -1812,7 +1807,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_delete_connection() { let _setup = SetupMocks::init(); @@ -1836,7 +1831,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_send_message() { let _setup = SetupMocks::init(); @@ -1862,7 +1857,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_sign() { let _setup = SetupMocks::init(); @@ -1887,7 +1882,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_verify_signature() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/protocols/out_of_band.rs b/libvcx/src/api_c/protocols/out_of_band.rs index 4627f9f20c..90e3c4fdf9 100644 --- a/libvcx/src/api_c/protocols/out_of_band.rs +++ b/libvcx/src/api_c/protocols/out_of_band.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::out_of_band; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; diff --git a/libvcx/src/api_c/protocols/proof.rs b/libvcx/src/api_c/protocols/proof.rs index de6f3527a9..ad0f051d3a 100644 --- a/libvcx/src/api_c/protocols/proof.rs +++ b/libvcx/src/api_c/protocols/proof.rs @@ -4,7 +4,6 @@ use futures::future::BoxFuture; use libc::c_char; use libvcx_core::api_vcx::api_handle::proof; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -781,7 +780,6 @@ pub extern "C" fn vcx_proof_get_thread_id( } #[cfg(test)] -#[cfg(feature = "test_utils")] mod tests { use std::ffi::CString; use std::ptr; @@ -821,7 +819,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_create_proof_success() { let _setup = SetupMocks::init(); @@ -830,7 +827,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_create_proof_fails() { let _setup = SetupMocks::init(); @@ -850,7 +846,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_get_request_msg() { let _setup = SetupMocks::init(); @@ -865,7 +860,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_serialize() { let _setup = SetupMocks::init(); @@ -880,7 +874,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_proof_deserialize_succeeds() { let _setup = SetupMocks::init(); @@ -900,7 +893,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_proof_update_state() { let _setup = SetupMocks::init(); @@ -922,7 +915,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_proof_send_request() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -969,7 +962,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_get_proof_fails_when_not_ready_with_proof() { let _setup = SetupMocks::init(); @@ -984,7 +976,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] + async fn test_vcx_connection_get_state() { let _setup = SetupMocks::init(); diff --git a/libvcx/src/api_c/utils.rs b/libvcx/src/api_c/utils.rs index 6fa2b18ab9..2ac72507e7 100644 --- a/libvcx/src/api_c/utils.rs +++ b/libvcx/src/api_c/utils.rs @@ -21,7 +21,6 @@ use libvcx_core::api_vcx::api_global::wallet::{ }; use libvcx_core::api_vcx::api_handle::mediated_connection; use libvcx_core::api_vcx::api_handle::mediated_connection::{parse_connection_handles, parse_status_codes}; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -380,13 +379,7 @@ pub extern "C" fn vcx_messages_update_status( /// Error code as u32 #[no_mangle] pub extern "C" fn vcx_pool_set_handle(handle: i32) -> i32 { - if handle <= 0 { - libvcx_core::api_vcx::api_global::pool::set_main_pool_handle(None); - } else { - libvcx_core::api_vcx::api_global::pool::set_main_pool_handle(Some(handle)); - } - - handle + unimplemented!("vcx_pool_set_handle is not supported") } /// Endorse transaction to the ledger preserving an original author diff --git a/libvcx/src/api_c/vcx.rs b/libvcx/src/api_c/vcx.rs index 5455a70978..d30e4cf1a9 100644 --- a/libvcx/src/api_c/vcx.rs +++ b/libvcx/src/api_c/vcx.rs @@ -13,8 +13,6 @@ use libvcx_core::api_vcx::api_global::pool::open_main_pool; use libvcx_core::api_vcx::api_global::settings::{enable_mocks, settings_init_issuer_config}; use libvcx_core::api_vcx::api_global::state::state_vcx_shutdown; use libvcx_core::api_vcx::api_global::VERSION_STRING; -use libvcx_core::api_vcx::utils::version_constants; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; @@ -287,10 +285,9 @@ pub extern "C" fn vcx_version() -> *const c_char { /// #Returns /// Success #[no_mangle] -pub extern "C" fn vcx_shutdown(delete: bool) -> u32 { +pub extern "C" fn vcx_shutdown(_delete: bool) -> u32 { info!("vcx_shutdown >>>"); - trace!("vcx_shutdown(delete: {})", delete); - state_vcx_shutdown(delete); + state_vcx_shutdown(); SUCCESS_ERR_CODE } @@ -473,7 +470,7 @@ pub extern "C" fn vcx_get_current_error(error_json_p: *mut *const c_char) { trace!("vcx_get_current_error: <<<"); } -#[cfg(feature = "test_utils")] +#[cfg(test)] pub mod test_utils { use uuid; @@ -595,36 +592,27 @@ pub mod test_utils { #[cfg(test)] #[allow(unused_imports)] // TODO: remove it mod tests { - #[cfg(feature = "general_test")] + use std::ptr; use aries_vcx::aries_vcx_core::indy; - #[cfg(feature = "pool_tests")] - use aries_vcx::aries_vcx_core::indy::ledger::pool::{ - test_utils::{create_tmp_genesis_txn_file, delete_named_test_pool, delete_test_pool}, - PoolConfig, - }; use aries_vcx::aries_vcx_core::indy::wallet::{import, RestoreWalletConfigs, WalletConfig}; use aries_vcx::aries_vcx_core::INVALID_POOL_HANDLE; use aries_vcx::global::settings::{ - set_config_value, set_test_configs, CONFIG_GENESIS_PATH, CONFIG_TXN_AUTHOR_AGREEMENT, - DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW, - }; - use aries_vcx::utils::constants::GENESIS_PATH; - use aries_vcx::utils::devsetup::{ - SetupDefaults, SetupEmpty, SetupMocks, SetupPoolConfig, TempFile, TestSetupCreateWallet, + set_config_value, CONFIG_GENESIS_PATH, CONFIG_TXN_AUTHOR_AGREEMENT, DEFAULT_WALLET_BACKUP_KEY, + DEFAULT_WALLET_KEY, WALLET_KDF_RAW, }; + use aries_vcx::utils::constants::POOL1_TXN; + use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, SetupMocks, TempFile}; use aries_vcx::utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_OFFER; use aries_vcx::utils::mockdata::mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION; use libvcx_core; - #[cfg(feature = "pool_tests")] - use libvcx_core::api_vcx::api_global::pool::get_main_pool_handle; - use libvcx_core::api_vcx::api_global::pool::reset_main_pool_handle; + use libvcx_core::api_vcx::api_global::pool::reset_global_ledger_components; use libvcx_core::api_vcx::api_global::settings; - #[cfg(feature = "test_utils")] + use libvcx_core::api_vcx::api_global::wallet::close_main_wallet; + #[cfg(test)] use libvcx_core::api_vcx::api_global::wallet::test_utils::_create_main_wallet_and_its_backup; use libvcx_core::api_vcx::api_global::wallet::wallet_import; - use libvcx_core::api_vcx::api_global::wallet::{close_main_wallet, get_main_wallet_handle}; use libvcx_core::api_vcx::api_handle::{ credential, credential_def, disclosed_proof, issuer_credential, mediated_connection, proof, schema, }; @@ -636,7 +624,7 @@ mod tests { use crate::api_c::cutils::return_types_u32; use crate::api_c::cutils::timeout::TimeoutUtils; use crate::api_c::protocols::mediated_connection::vcx_connection_create; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_c::vcx::test_utils::{ _vcx_init_threadpool, _vcx_init_threadpool_c_closure, _vcx_open_main_pool_c_closure, _vcx_open_main_wallet_c_closure, _vcx_open_pool, @@ -645,33 +633,7 @@ mod tests { use super::*; - #[cfg(feature = "pool_tests")] - #[tokio::test] - async fn test_vcx_init_called_twice_passes_after_shutdown() { - let _setup_defaults = SetupDefaults::init(); - for _ in 0..2 { - TestSetupCreateWallet::run(|_| async { - let setup_pool = SetupPoolConfig::init().await; - - _vcx_init_threadpool("{}").unwrap(); - _vcx_open_pool(&json!(setup_pool.pool_config).to_string()).unwrap(); - - // Assert config values were set correctly - assert_ne!(get_main_pool_handle().unwrap(), INVALID_POOL_HANDLE); - - // Verify shutdown was successful - vcx_shutdown(true); - let err = get_main_pool_handle().unwrap_err(); - assert_eq!(err.kind, LibvcxErrorKind::NoPoolOpen); - - return true; // skip_cleanup in TestSetupCreateWallet - }) - .await; - } - } - #[test] - #[cfg(feature = "general_test")] fn test_error_c_message() { let _setup = SetupMocks::init(); @@ -695,7 +657,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_init_threadpool_fails_with_null_ptr_config() { let _setup = SetupEmpty::init(); assert_eq!( @@ -705,7 +666,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_shutdown_with_no_previous_config() { let _setup = SetupDefaults::init(); @@ -714,7 +674,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_version() { let _setup = SetupDefaults::init(); @@ -723,7 +682,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn get_current_error_works_for_no_error() { let _setup = SetupDefaults::init(); @@ -736,7 +694,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn get_current_error_works_for_sync_error() { let _setup = SetupDefaults::init(); @@ -749,7 +706,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn get_current_error_works_for_async_error() { let _setup = SetupDefaults::init(); @@ -765,7 +721,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_call_c_callable_api_without_threadpool() { let _setup = SetupMocks::init(); @@ -778,19 +733,4 @@ mod tests { assert!(cb.receive(TimeoutUtils::some_medium()).unwrap() > 0); } - - #[cfg(feature = "pool_tests")] - #[tokio::test] - async fn test_full_init() { - let _setup_defaults = SetupDefaults::init(); - let setup_pool = SetupPoolConfig::init().await; - - _vcx_init_threadpool("{}").unwrap(); - _vcx_open_pool(&json!(setup_pool.pool_config).to_string()).unwrap(); - - // Assert pool was initialized - assert_ne!(get_main_pool_handle().unwrap(), 0); - delete_test_pool(get_main_pool_handle().unwrap()).await; - reset_main_pool_handle(); - } } diff --git a/libvcx/src/api_c/wallet.rs b/libvcx/src/api_c/wallet.rs index a5c05e8457..ec08499da1 100644 --- a/libvcx/src/api_c/wallet.rs +++ b/libvcx/src/api_c/wallet.rs @@ -7,16 +7,13 @@ use libc::c_char; use aries_vcx::aries_vcx_core::indy::wallet::{RestoreWalletConfigs, WalletConfig}; use libvcx_core; -use libvcx_core::errors; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use crate::api_c::cutils::cstring::CStringUtils; use crate::api_c::cutils::current_error::{set_current_error, set_current_error_vcx}; use crate::api_c::cutils::runtime::execute_async; use crate::error::SUCCESS_ERR_CODE; -use libvcx_core::api_vcx::api_global::wallet::{ - close_main_wallet, create_main_wallet, open_as_main_wallet, set_main_wallet_handle, -}; +use libvcx_core::api_vcx::api_global::wallet::{close_main_wallet, create_main_wallet, open_as_main_wallet}; use libvcx_core::api_vcx::api_global::wallet::{ export_main_wallet, wallet_add_wallet_record, wallet_add_wallet_record_tags, wallet_close_search_wallet, wallet_configure_issuer, wallet_delete_wallet_record, wallet_delete_wallet_record_tags, @@ -1084,16 +1081,3 @@ pub extern "C" fn vcx_wallet_import( SUCCESS_ERR_CODE } - -/// Set the wallet handle before calling vcx_init_minimal -/// -/// #params -/// -/// handle: wallet handle that libvcx should use -/// -/// #Returns -/// Error code as u32 -#[no_mangle] -pub extern "C" fn vcx_wallet_set_handle(handle: WalletHandle) -> WalletHandle { - set_main_wallet_handle(handle) -} diff --git a/libvcx_core/Cargo.toml b/libvcx_core/Cargo.toml index e8ddfddde8..a08bee6b22 100644 --- a/libvcx_core/Cargo.toml +++ b/libvcx_core/Cargo.toml @@ -6,9 +6,6 @@ license.workspace = true edition.workspace = true [features] -test_utils = [] -pool_tests = [ "test_utils" ] -general_test = [ "test_utils" ] fatal_warnings = [] [dependencies] diff --git a/libvcx_core/README.md b/libvcx_core/README.md index b84e222159..42b8608682 100644 --- a/libvcx_core/README.md +++ b/libvcx_core/README.md @@ -9,11 +9,11 @@ Before you try to build/test `libvcx` crate on your machine, make sure you can b - Run unit tests: ``` -cargo test --features "general_test" -- --test-threads=1 +cargo test --features -- --test-threads=1 ``` - Run integration tests (you need to have Indy pool running) ``` -TEST_POOL_IP=127.0.0.1 cargo test --features "pool_tests" -- --test-threads=1 +TEST_POOL_IP=127.0.0.1 cargo test -- --ignored --test-threads=1 ``` ## Architecture diff --git a/libvcx_core/src/api_vcx/api_global/agency_client.rs b/libvcx_core/src/api_vcx/api_global/agency_client.rs index 3237380a7b..3de3369042 100644 --- a/libvcx_core/src/api_vcx/api_global/agency_client.rs +++ b/libvcx_core/src/api_vcx/api_global/agency_client.rs @@ -26,7 +26,7 @@ pub fn get_main_agency_client() -> LibvcxResult { } pub fn create_agency_client_for_main_wallet(config: &AgencyClientConfig) -> LibvcxResult<()> { - let client = get_main_agency_client()?.configure(get_main_wallet().to_base_agency_client_wallet(), config)?; + let client = get_main_agency_client()?.configure(get_main_wallet()?.to_base_agency_client_wallet(), config)?; set_main_agency_client(client); Ok(()) } @@ -63,7 +63,7 @@ pub async fn update_webhook_url(webhook_url: &str) -> LibvcxResult<()> { } pub async fn provision_cloud_agent(agency_config: &AgentProvisionConfig) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; let mut client = get_main_agency_client()?; let res = aries_vcx::utils::provision::provision_cloud_agent(&mut client, wallet, agency_config).await; map_ariesvcx_result(res) @@ -82,14 +82,12 @@ pub mod tests { use aries_vcx::utils::devsetup::SetupMocks; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_update_institution_webhook() { let _setup = SetupMocks::init(); update_webhook_url("https://example.com").await.unwrap(); } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_provision_cloud_agent() { let _setup = SetupMocks::init(); @@ -103,7 +101,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_messages_update_status() { let _setup = SetupMocks::init(); AgencyMockDecrypted::set_next_decrypted_response(constants::GET_MESSAGES_DECRYPTED_RESPONSE); diff --git a/libvcx_core/src/api_vcx/api_global/ledger.rs b/libvcx_core/src/api_vcx/api_global/ledger.rs index 002fa34d99..592927247f 100644 --- a/libvcx_core/src/api_vcx/api_global/ledger.rs +++ b/libvcx_core/src/api_vcx/api_global/ledger.rs @@ -8,7 +8,9 @@ use aries_vcx::global::settings::CONFIG_INSTITUTION_DID; use diddoc_legacy::aries::service::AriesService; use url::Url; -use crate::api_vcx::api_global::profile::get_main_profile; +use crate::api_vcx::api_global::profile::{ + get_main_indy_ledger_read, get_main_indy_ledger_write, get_main_profile, get_main_wallet, +}; use crate::api_vcx::api_global::settings::get_config_value; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; use crate::errors::mapping_from_ariesvcx::map_ariesvcx_result; @@ -17,27 +19,22 @@ use crate::errors::mapping_from_ariesvcxcore::map_ariesvcx_core_result; pub async fn endorse_transaction(transaction: &str) -> LibvcxResult<()> { let endorser_did = get_config_value(CONFIG_INSTITUTION_DID)?; - let profile = get_main_profile()?; - let ledger = profile.inject_indy_ledger_write(); + let ledger = get_main_indy_ledger_write()?; map_ariesvcx_core_result(ledger.endorse_transaction(&endorser_did, transaction).await) } pub async fn get_ledger_txn(seq_no: i32, submitter_did: Option) -> LibvcxResult { - let profile = get_main_profile()?; - let ledger = profile.inject_indy_ledger_read(); + let ledger = get_main_indy_ledger_read()?; map_ariesvcx_core_result(ledger.get_ledger_txn(seq_no, submitter_did.as_deref()).await) } pub async fn rotate_verkey(did: &str) -> LibvcxResult<()> { - let profile = get_main_profile()?; - map_ariesvcx_result( - aries_vcx::common::keys::rotate_verkey(&profile.inject_wallet(), &profile.inject_indy_ledger_write(), did) - .await, - ) + let result = aries_vcx::common::keys::rotate_verkey(&get_main_wallet()?, &get_main_indy_ledger_write()?, did).await; + map_ariesvcx_result(result) } pub async fn get_verkey_from_ledger(did: &str) -> LibvcxResult { - let indy_ledger = get_main_profile()?.inject_indy_ledger_read(); + let indy_ledger = get_main_indy_ledger_read()?; map_ariesvcx_result(aries_vcx::common::keys::get_verkey_from_ledger(&indy_ledger, did).await) } @@ -54,8 +51,7 @@ pub async fn ledger_write_endpoint_legacy( ) .set_recipient_keys(recipient_keys) .set_routing_keys(routing_keys); - let profile = get_main_profile()?; - write_endpoint_legacy(&profile.inject_indy_ledger_write(), target_did, &service).await?; + write_endpoint_legacy(&get_main_indy_ledger_write()?, target_did, &service).await?; Ok(service) } @@ -74,30 +70,25 @@ pub async fn ledger_write_endpoint( DidSovServiceType::DidCommunication, ])) .set_routing_keys(Some(routing_keys)); - let profile = get_main_profile()?; - write_endpoint(&profile.inject_indy_ledger_write(), target_did, &service).await?; + write_endpoint(&get_main_indy_ledger_write()?, target_did, &service).await?; Ok(service) } pub async fn ledger_get_service(target_did: &str) -> LibvcxResult { let target_did = target_did.to_owned(); - let profile = get_main_profile()?; - map_ariesvcx_result(get_service(&profile.inject_indy_ledger_read(), &target_did).await) + map_ariesvcx_result(get_service(&get_main_indy_ledger_read()?, &target_did).await) } pub async fn ledger_get_attr(target_did: &str, attr: &str) -> LibvcxResult { - let profile = get_main_profile()?; - map_ariesvcx_result(get_attr(&profile.inject_indy_ledger_read(), &target_did, attr).await) + map_ariesvcx_result(get_attr(&get_main_indy_ledger_read()?, &target_did, attr).await) } pub async fn ledger_clear_attr(target_did: &str, attr: &str) -> LibvcxResult { - let profile = get_main_profile()?; - map_ariesvcx_result(clear_attr(&profile.inject_indy_ledger_write(), &target_did, attr).await) + map_ariesvcx_result(clear_attr(&get_main_indy_ledger_write()?, &target_did, attr).await) } pub async fn ledger_get_txn_author_agreement() -> LibvcxResult { - get_main_profile()? - .inject_indy_ledger_read() + get_main_indy_ledger_read()? .get_txn_author_agreement() .await? .ok_or_else(|| { @@ -116,7 +107,7 @@ pub fn ledger_set_txn_author_agreement( time_of_acceptance: u64, ) -> LibvcxResult<()> { map_ariesvcx_result( - aries_vcx::aries_vcx_core::global::author_agreement::set_txn_author_agreement( + aries_vcx::aries_vcx_core::global::author_agreement::set_vdrtools_config_txn_author_agreement( text, version, hash, @@ -131,15 +122,15 @@ pub fn ledger_set_txn_author_agreement( pub mod tests { use crate::api_vcx::api_global::ledger::{ledger_get_txn_author_agreement, ledger_set_txn_author_agreement}; use crate::api_vcx::api_global::settings::get_config_value; - use aries_vcx::global::settings::{set_test_configs, CONFIG_TXN_AUTHOR_AGREEMENT}; + use aries_vcx::aries_vcx_core::global::author_agreement::get_vdrtools_config_txn_author_agreement; + use aries_vcx::global::settings::CONFIG_TXN_AUTHOR_AGREEMENT; use aries_vcx::utils::devsetup::SetupMocks; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_set_active_txn_author_agreement_meta() { let _setup = SetupMocks::init(); - assert!(&get_config_value(CONFIG_TXN_AUTHOR_AGREEMENT).is_err()); + assert!(&get_vdrtools_config_txn_author_agreement().unwrap().is_none()); let text = "text"; let version = "1.0.0"; @@ -154,7 +145,7 @@ pub mod tests { time_of_acceptance, ) .unwrap(); - let auth_agreement = get_config_value(CONFIG_TXN_AUTHOR_AGREEMENT).unwrap(); + let auth_agreement = get_vdrtools_config_txn_author_agreement().unwrap().unwrap(); let expected = json!({ "text": text, @@ -163,16 +154,12 @@ pub mod tests { "timeOfAcceptance": time_of_acceptance, }); - let auth_agreement = serde_json::from_str::<::serde_json::Value>(&auth_agreement).unwrap(); + let auth_agreement = serde_json::to_value(&auth_agreement).unwrap(); assert_eq!(expected, auth_agreement); - - // todo: delete the reset below? - set_test_configs(); } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_get_ledger_author_agreement() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_global/pool.rs b/libvcx_core/src/api_vcx/api_global/pool.rs index 69c61be0fd..21a9f120d2 100644 --- a/libvcx_core/src/api_vcx/api_global/pool.rs +++ b/libvcx_core/src/api_vcx/api_global/pool.rs @@ -1,20 +1,29 @@ -use aries_vcx::aries_vcx_core::indy::ledger::pool::{close, create_pool_ledger_config, open_pool_ledger, PoolConfig}; -use aries_vcx::aries_vcx_core::INVALID_POOL_HANDLE; +use aries_vcx::aries_vcx_core::indy::ledger::pool::{ + create_pool_ledger_config, indy_close_pool, indy_open_pool, PoolConfig, +}; +use aries_vcx::aries_vcx_core::ledger::base_ledger::{ + AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite, +}; +use aries_vcx::aries_vcx_core::{PoolHandle, INVALID_POOL_HANDLE}; use aries_vcx::global::settings::{indy_mocks_enabled, DEFAULT_POOL_NAME}; -use std::sync::RwLock; +use crate::api_vcx::api_global::wallet::get_main_wallet_handle; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; +use aries_vcx::aries_vcx_core::ledger::indy_ledger::{IndySdkLedgerRead, IndySdkLedgerWrite}; +use aries_vcx::core::profile::profile::Profile; +use std::sync::Arc; +use std::sync::RwLock; lazy_static! { static ref POOL_HANDLE: RwLock> = RwLock::new(None); } -pub fn set_main_pool_handle(handle: Option) { +pub fn set_vdrtools_global_pool_handle(handle: Option) { let mut h = POOL_HANDLE.write().expect("Unable to access POOL_HANDLE"); *h = handle; } -pub fn get_main_pool_handle() -> LibvcxResult { +pub fn get_vdrtools_global_pool_handle() -> LibvcxResult { if indy_mocks_enabled() { return Ok(INVALID_POOL_HANDLE); } @@ -30,12 +39,52 @@ pub fn get_main_pool_handle() -> LibvcxResult { )) } +lazy_static! { + pub static ref ledger_anoncreds_read: RwLock>> = RwLock::new(None); + pub static ref ledger_anoncreds_write: RwLock>> = RwLock::new(None); + pub static ref ledger_indy_read: RwLock>> = RwLock::new(None); + pub static ref ledger_indy_write: RwLock>> = RwLock::new(None); +} + pub fn is_main_pool_open() -> bool { - get_main_pool_handle().is_ok() + false + // todo: implement this, based on whether ledger read is Some or None + // global_profile.inject_anoncreds_ledger_read() } -pub fn reset_main_pool_handle() { - set_main_pool_handle(None); +pub fn reset_global_ledger_components() -> LibvcxResult<()> { + setup_ledger_components(None)?; + set_vdrtools_global_pool_handle(None); + Ok(()) +} + +pub fn setup_ledger_components(handle: Option) -> LibvcxResult<()> { + match handle { + None => { + let mut anoncreds_read = ledger_anoncreds_read.write()?; + *anoncreds_read = None; + let mut anoncreds_write = ledger_anoncreds_write.write()?; + *anoncreds_write = None; + let mut indy_read = ledger_indy_read.write()?; + *indy_read = None; + let mut indy_write = ledger_indy_write.write()?; + *indy_write = None; + } + Some(pool_handle) => { + let wallet_handle = get_main_wallet_handle()?; + let ledger_read = Arc::new(IndySdkLedgerRead::new(wallet_handle, pool_handle)); + let ledger_write = Arc::new(IndySdkLedgerWrite::new(wallet_handle, pool_handle)); + let mut anoncreds_read = ledger_anoncreds_read.write()?; + *anoncreds_read = Some(ledger_read.clone() as Arc); + let mut anoncreds_write = ledger_anoncreds_write.write()?; + *anoncreds_write = Some(ledger_write.clone() as Arc); + let mut indy_read = ledger_indy_read.write()?; + *indy_read = Some(ledger_read.clone() as Arc); + let mut indy_write = ledger_indy_write.write()?; + *indy_write = Some(ledger_write.clone() as Arc); + } + } + Ok(()) } pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { @@ -60,11 +109,12 @@ pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { debug!("open_pool >> Pool Config Created Successfully"); - let handle = open_pool_ledger(&pool_name, Some(config.clone())) + let pool_handle = indy_open_pool(&pool_name, config.pool_config.clone()) .await .map_err(|err| err.extend("Can not open Pool Ledger"))?; - set_main_pool_handle(Some(handle)); + set_vdrtools_global_pool_handle(Some(pool_handle)); + setup_ledger_components(Some(pool_handle))?; info!("open_pool >> Pool Opened Successfully"); @@ -73,47 +123,53 @@ pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { pub async fn close_main_pool() -> LibvcxResult<()> { info!("close_main_pool >> Closing main pool"); - close(get_main_pool_handle()?).await?; + indy_close_pool(get_vdrtools_global_pool_handle()?).await?; + // todo: better way to go about this? + set_vdrtools_global_pool_handle(None); + setup_ledger_components(None)?; Ok(()) } #[cfg(test)] pub mod tests { - use crate::api_vcx::api_global::pool::{get_main_pool_handle, open_main_pool, reset_main_pool_handle}; + use crate::api_vcx::api_global::pool::{close_main_pool, open_main_pool, reset_global_ledger_components}; + use crate::api_vcx::api_global::profile::get_main_anoncreds_ledger_read; + use crate::api_vcx::api_global::wallet::test_utils::_create_and_open_wallet; use crate::errors::error::LibvcxErrorKind; - use aries_vcx::aries_vcx_core::indy::ledger::pool::test_utils::{ - create_tmp_genesis_txn_file, delete_named_test_pool, delete_test_pool, - }; - use aries_vcx::aries_vcx_core::indy::ledger::pool::PoolConfig; + use aries_vcx::aries_vcx_core::indy::ledger::pool::test_utils::create_testpool_genesis_txn_file; + use aries_vcx::aries_vcx_core::indy::ledger::pool::{indy_delete_pool, PoolConfig}; use aries_vcx::aries_vcx_core::INVALID_POOL_HANDLE; - use aries_vcx::global::settings::{set_config_value, CONFIG_GENESIS_PATH}; - use aries_vcx::utils::constants::GENESIS_PATH; + use aries_vcx::core::profile::profile::Profile; + use aries_vcx::global::settings::{set_config_value, CONFIG_GENESIS_PATH, DEFAULT_GENESIS_PATH}; + use aries_vcx::utils::constants::POOL1_TXN; use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, TempFile}; + use aries_vcx::utils::get_temp_dir_path; #[tokio::test] - #[cfg(feature = "pool_tests")] + #[ignore] async fn test_open_pool() { let _setup = SetupEmpty::init(); - - let genesis_path = create_tmp_genesis_txn_file(); + _create_and_open_wallet().await.unwrap(); + let genesis_path = get_temp_dir_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); + create_testpool_genesis_txn_file(&genesis_path); let config = PoolConfig { genesis_path, pool_name: None, pool_config: None, }; open_main_pool(&config).await.unwrap(); - delete_test_pool(get_main_pool_handle().unwrap()).await; - reset_main_pool_handle(); + close_main_pool().await.unwrap(); + reset_global_ledger_components().unwrap(); } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_open_pool_fails_if_genesis_file_is_invalid() { let _setup = SetupEmpty::init(); let pool_name = format!("invalidpool_{}", uuid::Uuid::new_v4().to_string()); // Write invalid genesis.txn - let _genesis_transactions = TempFile::create_with_data(GENESIS_PATH, "{ \"invalid\": \"genesis\" }"); + let _genesis_transactions = TempFile::create_with_data(POOL1_TXN, "{ \"invalid\": \"genesis\" }"); set_config_value(CONFIG_GENESIS_PATH, &_genesis_transactions.path).unwrap(); @@ -126,14 +182,17 @@ pub mod tests { open_main_pool(&pool_config).await.unwrap_err().kind(), LibvcxErrorKind::PoolLedgerConnect ); - assert_eq!(get_main_pool_handle().unwrap_err().kind(), LibvcxErrorKind::NoPoolOpen); + assert_eq!( + get_main_anoncreds_ledger_read().unwrap_err().kind(), + LibvcxErrorKind::NotReady + ); - delete_named_test_pool(INVALID_POOL_HANDLE, &pool_name).await; - reset_main_pool_handle(); + indy_delete_pool(&pool_name).await.unwrap(); + reset_global_ledger_components().unwrap(); } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_open_pool_fails_if_genesis_path_is_invalid() { let _setup = SetupDefaults::init(); let pool_name = format!("invalidpool_{}", uuid::Uuid::new_v4().to_string()); @@ -147,6 +206,9 @@ pub mod tests { open_main_pool(&pool_config).await.unwrap_err().kind(), LibvcxErrorKind::InvalidGenesisTxnPath ); - assert_eq!(get_main_pool_handle().unwrap_err().kind(), LibvcxErrorKind::NoPoolOpen); + assert_eq!( + get_main_anoncreds_ledger_read().unwrap_err().kind(), + LibvcxErrorKind::NotReady + ); } } diff --git a/libvcx_core/src/api_vcx/api_global/profile.rs b/libvcx_core/src/api_vcx/api_global/profile.rs index 8a44e20081..b3cfa9ce29 100644 --- a/libvcx_core/src/api_vcx/api_global/profile.rs +++ b/libvcx_core/src/api_vcx/api_global/profile.rs @@ -1,44 +1,203 @@ -use std::sync::Arc; +use std::fmt::{Debug, Formatter}; +use std::sync::{Arc, RwLockReadGuard}; -use crate::errors::error::LibvcxResult; +use crate::api_vcx::api_global::pool::{ + ledger_anoncreds_read, ledger_anoncreds_write, ledger_indy_read, ledger_indy_write, +}; +use crate::api_vcx::api_global::wallet::{base_anoncreds, base_wallet}; +use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; +use aries_vcx::aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; +use aries_vcx::aries_vcx_core::ledger::base_ledger::{ + AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite, TxnAuthrAgrmtOptions, +}; use aries_vcx::aries_vcx_core::{ wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet}, WalletHandle, }; use aries_vcx::core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile}; +use aries_vcx::errors::error::VcxResult; +use aries_vcx::utils::mockdata::profile::mock_anoncreds::MockAnoncreds; +use aries_vcx::utils::mockdata::profile::mock_ledger::MockLedger; +use aries_vcx::utils::mockdata::profile::mock_wallet::MockWallet; use aries_vcx::{global::settings::indy_mocks_enabled, utils::mockdata::profile::mock_profile::MockProfile}; -use super::{pool::get_main_pool_handle, wallet::get_main_wallet_handle}; +pub trait ProfileV2: Send + Sync { + fn inject_indy_ledger_read(&self) -> LibvcxResult>; + + fn inject_indy_ledger_write(&self) -> LibvcxResult>; + + fn inject_anoncreds(&self) -> LibvcxResult>; + + fn inject_anoncreds_ledger_read(&self) -> LibvcxResult>; + + fn inject_anoncreds_ledger_write(&self) -> LibvcxResult>; + + fn inject_wallet(&self) -> LibvcxResult>; -pub fn indy_wallet_handle_to_wallet(wallet_handle: WalletHandle) -> Arc { - Arc::new(IndySdkWallet::new(wallet_handle)) + fn try_inject_wallet(&self) -> LibvcxResult>>; + + fn update_taa_configuration(&self, taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()>; } -pub fn indy_handles_to_profile(wallet_handle: WalletHandle, pool_handle: i32) -> Arc { - Arc::new(VdrtoolsProfile::init(wallet_handle, pool_handle)) +#[derive(Clone)] +struct VcxGlobalsProfile {} + +impl Debug for VcxGlobalsProfile { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "VcxGlobalsProfile") + } +} + +impl ProfileV2 for VcxGlobalsProfile { + fn inject_indy_ledger_read(&self) -> LibvcxResult> { + let ledger = ledger_indy_read.read()?; + match ledger.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Indy ledger read is not initialized", + )), + Some(l) => Ok(Arc::clone(l)), + } + } + + fn inject_indy_ledger_write(&self) -> LibvcxResult> { + let ledger = ledger_indy_write.read()?; + match ledger.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Indy ledger write is not initialized", + )), + Some(l) => Ok(Arc::clone(l)), + } + } + + fn inject_anoncreds(&self) -> LibvcxResult> { + let anoncreds = base_anoncreds.read()?; + match anoncreds.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Anoncreds is not initialized", + )), + Some(a) => Ok(Arc::clone(a)), + } + } + + fn inject_anoncreds_ledger_read(&self) -> LibvcxResult> { + let ledger = ledger_anoncreds_read.read()?; + match ledger.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Anoncreds ledger read is not initialized", + )), + Some(l) => Ok(Arc::clone(l)), + } + } + + fn inject_anoncreds_ledger_write(&self) -> LibvcxResult> { + let ledger = ledger_anoncreds_write.read()?; + match ledger.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Anoncreds ledger write is not initialized", + )), + Some(l) => Ok(Arc::clone(l)), + } + } + + fn inject_wallet(&self) -> LibvcxResult> { + let global_base_wallet = base_wallet.read()?; + match global_base_wallet.as_ref() { + None => Err(LibvcxError::from_msg( + LibvcxErrorKind::NotReady, + "Wallet is not initialized", + )), + Some(w) => Ok(Arc::clone(w)), + } + } + + fn try_inject_wallet(&self) -> LibvcxResult>> { + let global_base_wallet = base_wallet.read()?; + global_base_wallet + .as_ref() + .map(|w| Some(Arc::clone(w))) + .ok_or_else(|| LibvcxError::from_msg(LibvcxErrorKind::NotReady, "Wallet is not initialized")) + } + + fn update_taa_configuration(&self, _taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()> { + todo!() + } } -pub fn get_main_wallet() -> Arc { - indy_wallet_handle_to_wallet(get_main_wallet_handle()) +lazy_static! { + static ref global_profile: VcxGlobalsProfile = VcxGlobalsProfile {}; } -pub fn get_main_profile() -> LibvcxResult> { - if indy_mocks_enabled() { - return Ok(Arc::new(MockProfile {})); +impl ProfileV2 for MockProfile { + fn inject_indy_ledger_read(&self) -> LibvcxResult> { + Ok(Arc::new(MockLedger {})) + } + + fn inject_indy_ledger_write(&self) -> LibvcxResult> { + Ok(Arc::new(MockLedger {})) + } + + fn inject_anoncreds(&self) -> LibvcxResult> { + Ok(Arc::new(MockAnoncreds {})) + } + + fn inject_anoncreds_ledger_read(&self) -> LibvcxResult> { + Ok(Arc::new(MockLedger {})) + } + + fn inject_anoncreds_ledger_write(&self) -> LibvcxResult> { + Ok(Arc::new(MockLedger {})) + } + + fn inject_wallet(&self) -> LibvcxResult> { + Ok(Arc::new(MockWallet {})) + } + + fn try_inject_wallet(&self) -> LibvcxResult>> { + Ok(Some(Arc::new(MockWallet {}))) + } + + fn update_taa_configuration(&self, _taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()> { + error!("update_taa_configuration not implemented for MockProfile"); + Ok(()) } - Ok(indy_handles_to_profile( - get_main_wallet_handle(), - get_main_pool_handle()?, - )) } -// constructs an indy profile under the condition where a pool_handle is NOT required -// - e.g. where only a Wallet is used (no ledger interactions). Should be used sparingly. -pub fn get_main_profile_optional_pool() -> Arc { +pub fn get_main_profile() -> Arc { if indy_mocks_enabled() { return Arc::new(MockProfile {}); } - // attempt to get the pool_handle if possible, else use '-1' - let pool_handle = get_main_pool_handle().ok().map_or(-1, |p| p); - indy_handles_to_profile(get_main_wallet_handle(), pool_handle) + Arc::new(global_profile.clone()) +} + +pub fn try_get_main_wallet() -> LibvcxResult>> { + get_main_profile().try_inject_wallet() +} + +pub fn get_main_wallet() -> LibvcxResult> { + get_main_profile().inject_wallet() +} + +pub fn get_main_anoncreds() -> LibvcxResult> { + get_main_profile().inject_anoncreds() +} + +pub fn get_main_indy_ledger_read() -> LibvcxResult> { + get_main_profile().inject_indy_ledger_read() +} + +pub fn get_main_indy_ledger_write() -> LibvcxResult> { + get_main_profile().inject_indy_ledger_write() +} + +pub fn get_main_anoncreds_ledger_read() -> LibvcxResult> { + get_main_profile().inject_anoncreds_ledger_read() +} + +pub fn get_main_anoncreds_ledger_write() -> LibvcxResult> { + get_main_profile().inject_anoncreds_ledger_write() } diff --git a/libvcx_core/src/api_vcx/api_global/state.rs b/libvcx_core/src/api_vcx/api_global/state.rs index 3ee809101e..3d569c91df 100644 --- a/libvcx_core/src/api_vcx/api_global/state.rs +++ b/libvcx_core/src/api_vcx/api_global/state.rs @@ -1,18 +1,18 @@ use crate::api_vcx::api_global::agency_client::reset_main_agency_client; -use crate::api_vcx::api_global::pool::{close_main_pool, reset_main_pool_handle}; +use crate::api_vcx::api_global::pool::{close_main_pool, reset_global_ledger_components}; use crate::api_vcx::api_global::settings::get_config_value; use crate::api_vcx::api_global::wallet::close_main_wallet; +use crate::errors::error::LibvcxResult; use aries_vcx::aries_vcx_core::indy::ledger::pool; use aries_vcx::aries_vcx_core::indy::wallet::{delete_wallet, WalletConfig}; use aries_vcx::global::settings::{ - reset_config_values, CONFIG_POOL_NAME, CONFIG_WALLET_KEY, CONFIG_WALLET_KEY_DERIVATION, CONFIG_WALLET_NAME, + reset_config_values_ariesvcx, CONFIG_WALLET_KEY, CONFIG_WALLET_KEY_DERIVATION, CONFIG_WALLET_NAME, CONFIG_WALLET_TYPE, DEFAULT_POOL_NAME, DEFAULT_WALLET_NAME, UNINITIALIZED_WALLET_KEY, WALLET_KDF_DEFAULT, }; -pub fn state_vcx_shutdown(delete: bool) { +pub fn state_vcx_shutdown() { info!("vcx_shutdown >>>"); - trace!("vcx_shutdown(delete: {})", delete); if let Ok(()) = futures::executor::block_on(close_main_wallet()) {} if let Ok(()) = futures::executor::block_on(close_main_pool()) {} @@ -25,39 +25,20 @@ pub fn state_vcx_shutdown(delete: bool) { crate::api_vcx::api_handle::disclosed_proof::release_all(); crate::api_vcx::api_handle::credential::release_all(); - if delete { - let pool_name = get_config_value(CONFIG_POOL_NAME).unwrap_or(DEFAULT_POOL_NAME.to_string()); - let wallet_name = get_config_value(CONFIG_WALLET_NAME).unwrap_or(DEFAULT_WALLET_NAME.to_string()); - let wallet_type = get_config_value(CONFIG_WALLET_TYPE).ok(); - let wallet_key = get_config_value(CONFIG_WALLET_KEY).unwrap_or(UNINITIALIZED_WALLET_KEY.into()); - let wallet_key_derivation = get_config_value(CONFIG_WALLET_KEY_DERIVATION).unwrap_or(WALLET_KDF_DEFAULT.into()); - - let _res = futures::executor::block_on(close_main_wallet()); - - let wallet_config = WalletConfig { - wallet_name, - wallet_key, - wallet_key_derivation, - wallet_type, - storage_config: None, - storage_credentials: None, - rekey: None, - rekey_derivation_method: None, - }; - - if let Ok(()) = futures::executor::block_on(delete_wallet(&wallet_config)) {} - if let Ok(()) = futures::executor::block_on(pool::delete(&pool_name)) {} - } - - let _ = reset_config_values(); + let _ = reset_config_values_ariesvcx(); reset_main_agency_client(); - reset_main_pool_handle(); + match reset_global_ledger_components() { + Ok(_) => {} + Err(err) => { + error!("Failed to reset global pool: {}", err); + } + } } #[cfg(test)] pub mod tests { + use crate::api_vcx::api_global::profile::get_main_wallet; use crate::api_vcx::api_global::state::state_vcx_shutdown; - use crate::api_vcx::api_global::wallet::get_main_wallet_handle; use crate::api_vcx::api_handle::credential::credential_create_with_offer; use crate::api_vcx::api_handle::disclosed_proof::create_with_proof_request; use crate::api_vcx::api_handle::schema::create_and_publish_schema; @@ -70,13 +51,12 @@ pub mod tests { use aries_vcx::utils::mockdata::mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_shutdown() { let _setup = SetupMocks::init(); let data = r#"["name","male"]"#; let connection = mediated_connection::test_utils::build_test_connection_inviter_invited().await; - let credentialdef = credential_def::create("SID".to_string(), "id".to_string(), "tag".to_string(), false) + let credential_def = credential_def::create("SID".to_string(), "id".to_string(), "tag".to_string(), false) .await .unwrap(); let issuer_credential = issuer_credential::issuer_credential_create("1".to_string()).unwrap(); @@ -95,14 +75,14 @@ pub mod tests { let disclosed_proof = create_with_proof_request("id", ARIES_PROOF_REQUEST_PRESENTATION).unwrap(); let credential = credential_create_with_offer("name", ARIES_CREDENTIAL_OFFER).unwrap(); - state_vcx_shutdown(true); + state_vcx_shutdown(); assert_eq!(mediated_connection::is_valid_handle(connection), false); assert_eq!(issuer_credential::is_valid_handle(issuer_credential), false); assert_eq!(schema::is_valid_handle(schema), false); assert_eq!(proof::is_valid_handle(proof), false); - assert_eq!(credential_def::is_valid_handle(credentialdef), false); + assert_eq!(credential_def::is_valid_handle(credential_def), false); assert_eq!(credential::is_valid_handle(credential), false); assert_eq!(disclosed_proof::is_valid_handle(disclosed_proof), false); - assert_eq!(get_main_wallet_handle(), INVALID_WALLET_HANDLE); + assert!(get_main_wallet().is_err()); } } diff --git a/libvcx_core/src/api_vcx/api_global/wallet.rs b/libvcx_core/src/api_vcx/api_global/wallet.rs index c8c157ca0f..2347d9212d 100644 --- a/libvcx_core/src/api_vcx/api_global/wallet.rs +++ b/libvcx_core/src/api_vcx/api_global/wallet.rs @@ -1,57 +1,82 @@ +use std::collections::HashMap; +use std::sync::Arc; +use std::sync::RwLock; + +use aries_vcx::aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; +use aries_vcx::aries_vcx_core::anoncreds::indy_anoncreds::IndySdkAnonCreds; use aries_vcx::aries_vcx_core::indy::wallet::{ close_search_wallet, fetch_next_records_wallet, import, open_search_wallet, IssuerConfig, RestoreWalletConfigs, WalletConfig, }; +use aries_vcx::aries_vcx_core::wallet::base_wallet::BaseWallet; +use aries_vcx::aries_vcx_core::wallet::indy_wallet::IndySdkWallet; use aries_vcx::aries_vcx_core::{indy, SearchHandle}; use aries_vcx::aries_vcx_core::{WalletHandle, INVALID_WALLET_HANDLE}; use aries_vcx::common::signing::unpack_message_to_string; use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS; use aries_vcx::protocols::mediated_connection::pairwise_info::PairwiseInfo; -use crate::api_vcx::api_global::profile::{get_main_profile, get_main_wallet, indy_handles_to_profile}; -use crate::errors::error::LibvcxResult; +use crate::api_vcx::api_global::profile::{ + get_main_anoncreds, get_main_indy_ledger_write, get_main_profile, get_main_wallet, try_get_main_wallet, +}; +use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; use crate::errors::mapping_from_ariesvcx::map_ariesvcx_result; use crate::errors::mapping_from_ariesvcxcore::map_ariesvcx_core_result; -use std::collections::HashMap; - -pub static mut WALLET_HANDLE: WalletHandle = INVALID_WALLET_HANDLE; +lazy_static! { + pub static ref base_wallet: RwLock>> = RwLock::new(None); + pub static ref base_anoncreds: RwLock>> = RwLock::new(None); +} -pub fn set_main_wallet_handle(handle: WalletHandle) -> WalletHandle { - trace!("set_wallet_handle >>> handle: {:?}", handle); - unsafe { - WALLET_HANDLE = handle; - } - unsafe { WALLET_HANDLE } +pub fn get_main_wallet_handle() -> LibvcxResult { + get_main_wallet().map(|wallet| WalletHandle(wallet.get_wallet_handle())) } -pub fn get_main_wallet_handle() -> WalletHandle { - unsafe { WALLET_HANDLE } +pub async fn export_main_wallet(path: &str, backup_key: &str) -> LibvcxResult<()> { + let wallet_handle = get_main_wallet_handle()?; + map_ariesvcx_core_result(indy::wallet::export_wallet(wallet_handle, path, backup_key).await) } -pub fn reset_main_wallet_handle() { - set_main_wallet_handle(INVALID_WALLET_HANDLE); +fn setup_global_wallet(handle: WalletHandle) -> LibvcxResult<()> { + // new way + let base_wallet_impl: Arc = Arc::new(IndySdkWallet::new(handle)); + let mut b_wallet = base_wallet.write()?; + *b_wallet = Some(base_wallet_impl); + // anoncreds + let base_anoncreds_impl: Arc = Arc::new(IndySdkAnonCreds::new(handle)); + let mut b_anoncreds = base_anoncreds.write()?; + *b_anoncreds = Some(base_anoncreds_impl); + Ok(()) } -pub async fn export_main_wallet(path: &str, backup_key: &str) -> LibvcxResult<()> { - map_ariesvcx_core_result(indy::wallet::export_wallet(get_main_wallet_handle(), path, backup_key).await) +pub fn setup_wallet(handle: WalletHandle) -> LibvcxResult<()> { + setup_global_wallet(handle) } pub async fn open_as_main_wallet(wallet_config: &WalletConfig) -> LibvcxResult { let handle = indy::wallet::open_wallet(wallet_config).await?; - set_main_wallet_handle(handle); + setup_wallet(handle)?; Ok(handle) } pub async fn create_and_open_as_main_wallet(wallet_config: &WalletConfig) -> LibvcxResult { let handle = indy::wallet::create_and_open_wallet(wallet_config).await?; - set_main_wallet_handle(handle); + setup_wallet(handle)?; Ok(handle) } pub async fn close_main_wallet() -> LibvcxResult<()> { - indy::wallet::close_wallet(get_main_wallet_handle()).await?; - reset_main_wallet_handle(); + let wallet = try_get_main_wallet()?; + match wallet { + None => { + warn!("Skipping wallet close, no global wallet component available.") + } + Some(wallet) => { + indy::wallet::close_wallet(WalletHandle(wallet.get_wallet_handle())).await?; + let mut b_wallet = base_wallet.write()?; + *b_wallet = None; + } + } Ok(()) } @@ -59,11 +84,8 @@ pub async fn create_main_wallet(config: &WalletConfig) -> LibvcxResult<()> { let wallet_handle = create_and_open_as_main_wallet(config).await?; trace!("Created wallet with handle {:?}", wallet_handle); - let profile = indy_handles_to_profile(wallet_handle, -1); - // If MS is already in wallet then just continue - profile - .inject_anoncreds() + get_main_anoncreds()? .prover_create_link_secret(DEFAULT_LINK_SECRET_ALIAS) .await .ok(); @@ -73,89 +95,83 @@ pub async fn create_main_wallet(config: &WalletConfig) -> LibvcxResult<()> { } pub async fn key_for_local_did(did: &str) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.key_for_local_did(did).await) } pub async fn wallet_sign(vk: &str, data_raw: &[u8]) -> LibvcxResult> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.sign(vk, data_raw).await) } pub async fn wallet_verify(vk: &str, msg: &[u8], signature: &[u8]) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.verify(vk, msg, signature).await) } pub async fn replace_did_keys_start(did: &str) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.replace_did_keys_start(did).await) } pub async fn rotate_verkey_apply(did: &str, temp_vk: &str) -> LibvcxResult<()> { - let profile = get_main_profile()?; map_ariesvcx_result( - aries_vcx::common::keys::rotate_verkey_apply( - &profile.inject_wallet(), - &profile.inject_indy_ledger_write(), - did, - temp_vk, - ) - .await, + aries_vcx::common::keys::rotate_verkey_apply(&get_main_wallet()?, &get_main_indy_ledger_write()?, did, temp_vk) + .await, ) } pub async fn wallet_unpack_message_to_string(payload: &[u8]) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_result(unpack_message_to_string(&wallet, payload).await) } pub async fn wallet_create_pairwise_did() -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_result(PairwiseInfo::create(&wallet).await) } pub async fn wallet_configure_issuer(enterprise_seed: &str) -> LibvcxResult { // TODO - future - use profile wallet to stop indy dependency - let wallet = get_main_wallet_handle(); + let wallet = get_main_wallet_handle()?; map_ariesvcx_core_result(indy::wallet::wallet_configure_issuer(wallet, enterprise_seed).await) } pub async fn wallet_add_wallet_record(type_: &str, id: &str, value: &str, option: Option<&str>) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; let tags: Option> = option.map(|tags| serde_json::from_str(tags)).transpose()?; map_ariesvcx_core_result(wallet.add_wallet_record(type_, id, value, tags).await) } pub async fn wallet_update_wallet_record_value(xtype: &str, id: &str, value: &str) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.update_wallet_record_value(xtype, id, value).await) } pub async fn wallet_update_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; let tags: HashMap = serde_json::from_str(tags_json)?; map_ariesvcx_core_result(wallet.update_wallet_record_tags(xtype, id, tags).await) } pub async fn wallet_add_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; let tags: HashMap = serde_json::from_str(tags_json)?; map_ariesvcx_core_result(wallet.add_wallet_record_tags(xtype, id, tags).await) } pub async fn wallet_delete_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.delete_wallet_record_tags(xtype, id, tags_json).await) } pub async fn wallet_get_wallet_record(xtype: &str, id: &str, options: &str) -> LibvcxResult { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.get_wallet_record(xtype, id, options).await) } pub async fn wallet_delete_wallet_record(xtype: &str, id: &str) -> LibvcxResult<()> { - let wallet = get_main_wallet(); + let wallet = get_main_wallet()?; map_ariesvcx_core_result(wallet.delete_wallet_record(xtype, id).await) } @@ -165,7 +181,7 @@ pub async fn wallet_open_search_wallet( options_json: &str, ) -> LibvcxResult { // TODO - future - use profile wallet to stop binding to indy - let wallet_handle = get_main_wallet_handle(); + let wallet_handle = get_main_wallet_handle()?; map_ariesvcx_core_result(open_search_wallet(wallet_handle, xtype, query_json, options_json).await) } @@ -178,7 +194,7 @@ pub async fn wallet_fetch_next_records_wallet( count: usize, ) -> LibvcxResult { // TODO - future - use profile wallet to stop binding to indy - let wallet_handle = get_main_wallet_handle(); + let wallet_handle = get_main_wallet_handle()?; map_ariesvcx_core_result(fetch_next_records_wallet(wallet_handle, wallet_search_handle, count).await) } @@ -186,13 +202,13 @@ pub async fn wallet_import(config: &RestoreWalletConfigs) -> LibvcxResult<()> { map_ariesvcx_core_result(import(config).await) } -#[cfg(feature = "test_utils")] +#[allow(clippy::unwrap_used)] pub mod test_utils { use aries_vcx::aries_vcx_core::indy::wallet::WalletConfig; - use aries_vcx::global::settings::{CONFIG_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW}; + use aries_vcx::global::settings::{DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW}; use aries_vcx::utils::devsetup::TempFile; - use crate::api_vcx::api_global::profile::indy_wallet_handle_to_wallet; + use crate::api_vcx::api_global::profile::get_main_wallet; use crate::api_vcx::api_global::settings::get_config_value; use crate::api_vcx::api_global::wallet::{ close_main_wallet, create_and_open_as_main_wallet, create_main_wallet, export_main_wallet, open_as_main_wallet, @@ -218,13 +234,14 @@ pub mod test_utils { rekey: None, rekey_derivation_method: None, }; - let wallet_handle = create_and_open_as_main_wallet(&wallet_config).await.unwrap(); - let wallet = indy_wallet_handle_to_wallet(wallet_handle); + create_and_open_as_main_wallet(&wallet_config).await.unwrap(); + let wallet = get_main_wallet().unwrap(); wallet.create_and_store_my_did(None, None).await.unwrap(); - let backup_key = get_config_value(CONFIG_WALLET_BACKUP_KEY).unwrap(); let (type_, id, value) = _record(); wallet.add_wallet_record(type_, id, value, None).await.unwrap(); - export_main_wallet(&export_file.path, &backup_key).await.unwrap(); + export_main_wallet(&export_file.path, &DEFAULT_WALLET_BACKUP_KEY) + .await + .unwrap(); close_main_wallet().await.unwrap(); @@ -251,12 +268,9 @@ pub mod test_utils { } #[cfg(test)] -#[cfg(feature = "general_test")] pub mod tests { use aries_vcx::aries_vcx_core::indy::wallet::{delete_wallet, RestoreWalletConfigs, WalletConfig, WalletRecord}; - use aries_vcx::global::settings::{ - CONFIG_WALLET_BACKUP_KEY, DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW, - }; + use aries_vcx::global::settings::{DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW}; use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, TempFile}; use crate::api_vcx::api_global::settings::get_config_value; @@ -269,7 +283,6 @@ pub mod tests { use crate::errors::error::{LibvcxErrorKind, LibvcxResult}; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_create() { let _setup = SetupEmpty::init(); @@ -285,7 +298,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_add_with_tag() { _create_and_open_wallet().await.unwrap(); @@ -301,7 +313,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_add_with_no_tag() { _create_and_open_wallet().await.unwrap(); @@ -314,7 +325,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_add_fails_with_duplication_error() { _create_and_open_wallet().await.unwrap(); @@ -329,7 +339,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_get_fails_if_record_does_not_exist() { _create_and_open_wallet().await.unwrap(); @@ -368,7 +377,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_delete() { _create_and_open_wallet().await.unwrap(); @@ -385,7 +393,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_export_import() { let _setup = SetupDefaults::init(); let wallet_name = uuid::Uuid::new_v4().to_string(); @@ -401,8 +408,8 @@ pub mod tests { rekey_derivation_method: None, }; create_and_open_as_main_wallet(&wallet_config).await.unwrap(); - let backup_key = get_config_value(CONFIG_WALLET_BACKUP_KEY).unwrap(); - export_main_wallet(&export_file.path.to_string(), &backup_key) + let backup_key = DEFAULT_WALLET_BACKUP_KEY; + export_main_wallet(&export_file.path.to_string(), backup_key) .await .unwrap(); close_main_wallet().await.unwrap(); @@ -420,7 +427,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_open_with_incorrect_key_fails() { let _setup = SetupDefaults::init(); let wallet_name = uuid::Uuid::new_v4().to_string(); @@ -443,7 +449,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_open_with_wrong_name_fails() { let _setup = SetupDefaults::init(); @@ -461,7 +466,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_open_of_imported_wallet_succeeds() { let _setup = SetupDefaults::init(); @@ -489,7 +493,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_import_of_opened_wallet_fails() { let _setup = SetupDefaults::init(); @@ -511,7 +514,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_wallet_record_update() { _create_and_open_wallet().await.unwrap(); diff --git a/libvcx_core/src/api_vcx/api_handle/connection.rs b/libvcx_core/src/api_vcx/api_handle/connection.rs index 61c8bd8913..b2d1436e84 100644 --- a/libvcx_core/src/api_vcx/api_handle/connection.rs +++ b/libvcx_core/src/api_vcx/api_handle/connection.rs @@ -14,6 +14,7 @@ use async_trait::async_trait; use rand::Rng; use url::Url; +use crate::api_vcx::api_global::profile::{get_main_indy_ledger_read, get_main_wallet}; use crate::{ api_vcx::api_global::profile::get_main_profile, errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}, @@ -134,22 +135,15 @@ where // ----------------------------- CONSTRUCTORS ------------------------------------ pub async fn create_inviter(pw_info: Option) -> LibvcxResult { trace!("create_inviter >>>"); - let profile = get_main_profile()?; - - let pw_info = pw_info.unwrap_or(PairwiseInfo::create(&profile.inject_wallet()).await?); + let pw_info = pw_info.unwrap_or(PairwiseInfo::create(&get_main_wallet()?).await?); let con = InviterConnection::new_inviter("".to_owned(), pw_info); - add_connection(con) } pub async fn create_invitee(_invitation: &str) -> LibvcxResult { trace!("create_invitee >>>"); - - let profile = get_main_profile()?; - let pairwise_info = PairwiseInfo::create(&profile.inject_wallet()).await?; - + let pairwise_info = PairwiseInfo::create(&get_main_wallet()?).await?; let con = InviteeConnection::new_invitee("".to_owned(), pairwise_info); - add_connection(con) } @@ -237,7 +231,7 @@ pub fn get_invitation(handle: u32) -> LibvcxResult { pub async fn process_invite(handle: u32, invitation: &str) -> LibvcxResult<()> { trace!("process_invite >>>"); - let ledger = get_main_profile()?.inject_indy_ledger_read(); + let ledger = get_main_indy_ledger_read()?; let invitation = deserialize(invitation)?; let con = get_cloned_connection(&handle)? .accept_invitation(&ledger, invitation) @@ -255,7 +249,7 @@ pub async fn process_request( trace!("process_request >>>"); let con = get_cloned_generic_connection(&handle)?; - let wallet = get_main_profile()?.inject_wallet(); + let wallet = get_main_wallet()?; let request: Request = deserialize(request)?; let con = match con.state() { @@ -297,9 +291,8 @@ pub async fn process_response(handle: u32, response: &str) -> LibvcxResult<()> { trace!("process_response >>>"); let con = get_cloned_connection(&handle)?; - let wallet = get_main_profile()?.inject_wallet(); let response = deserialize(response)?; - let con = con.handle_response(&wallet, response, &HttpClient).await?; + let con = con.handle_response(&get_main_wallet()?, response, &HttpClient).await?; insert_connection(handle, con) } @@ -337,8 +330,7 @@ pub async fn send_response(handle: u32) -> LibvcxResult<()> { trace!("send_response >>>"); let con = get_cloned_connection(&handle)?; - let wallet = get_main_profile()?.inject_wallet(); - let con = con.send_response(&wallet, &HttpClient).await?; + let con = con.send_response(&get_main_wallet()?, &HttpClient).await?; insert_connection(handle, con) } @@ -347,10 +339,9 @@ pub async fn send_request(handle: u32, service_endpoint: String, routing_keys: V trace!("send_request >>>"); let con = get_cloned_connection(&handle)?; - let wallet = get_main_profile()?.inject_wallet(); let con = con .send_request( - &wallet, + &get_main_wallet()?, Url::from_str(&service_endpoint) .map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidUrl, err.to_string()))?, routing_keys, @@ -365,8 +356,7 @@ pub async fn send_ack(handle: u32) -> LibvcxResult<()> { trace!("send_ack >>>"); let con = get_cloned_connection(&handle)?; - let wallet = get_main_profile()?.inject_wallet(); - let con = con.send_ack(&wallet, &HttpClient).await?; + let con = con.send_ack(&get_main_wallet()?, &HttpClient).await?; insert_connection(handle, con) } @@ -374,10 +364,9 @@ pub async fn send_ack(handle: u32) -> LibvcxResult<()> { pub async fn send_generic_message(handle: u32, content: String) -> LibvcxResult<()> { trace!("send_generic_message >>>"); - let wallet = get_main_profile()?.inject_wallet(); let message = serde_json::from_str(&content)?; let con = get_cloned_generic_connection(&handle)?; - con.send_message(&wallet, &message, &HttpClient).await?; + con.send_message(&get_main_wallet()?, &message, &HttpClient).await?; Ok(()) } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 60ea866bef..a7cfa64bc7 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -8,7 +8,9 @@ use aries_vcx::handlers::issuance::holder::Holder; use aries_vcx::utils::constants::GET_MESSAGES_DECRYPTED_RESPONSE; use aries_vcx::{global::settings::indy_mocks_enabled, utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_OFFER}; -use crate::api_vcx::api_global::profile::{get_main_profile, get_main_profile_optional_pool}; +use crate::api_vcx::api_global::profile::{ + get_main_anoncreds, get_main_anoncreds_ledger_read, get_main_indy_ledger_read, get_main_profile, +}; use crate::api_vcx::api_handle::mediated_connection; use crate::api_vcx::api_handle::object_cache::ObjectCache; @@ -114,7 +116,7 @@ pub async fn credential_create_with_msgid( pub async fn update_state(credential_handle: u32, message: Option<&str>, connection_handle: u32) -> LibvcxResult { let mut credential = HANDLE_MAP.get_cloned(credential_handle)?; - let profile = get_main_profile()?; + let profile = get_main_profile(); trace!("credential::update_state >>> "); if credential.is_terminal_state() { @@ -131,8 +133,8 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect })?; credential .step( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -142,8 +144,8 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect if let Some((uid, msg)) = credential.find_message_to_handle(messages) { credential .step( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, msg.into(), Some(send_message), ) @@ -194,9 +196,8 @@ pub fn get_rev_reg_id(handle: u32) -> LibvcxResult { pub async fn is_revokable(handle: u32) -> LibvcxResult { let credential = HANDLE_MAP.get_cloned(handle)?; - let profile = get_main_profile()?; credential - .is_revokable(&profile.inject_anoncreds_ledger_read()) + .is_revokable(&get_main_anoncreds_ledger_read()?) .await .map_err(|err| err.into()) } @@ -204,8 +205,7 @@ pub async fn is_revokable(handle: u32) -> LibvcxResult { pub async fn delete_credential(handle: u32) -> LibvcxResult<()> { trace!("Credential::delete_credential >>> credential_handle: {}", handle); let credential = HANDLE_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open - credential.delete_credential(&profile.inject_anoncreds()).await?; + credential.delete_credential(&get_main_anoncreds()?).await?; HANDLE_MAP.release(handle) } @@ -230,11 +230,10 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib let mut credential = HANDLE_MAP.get_cloned(handle)?; let my_pw_did = mediated_connection::get_pw_did(connection_handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let profile = get_main_profile()?; credential .send_request( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, my_pw_did, send_message, ) @@ -362,7 +361,6 @@ pub async fn decline_offer(handle: u32, connection_handle: u32, comment: Option< HANDLE_MAP.insert(handle, credential) } -#[cfg(feature = "test_utils")] pub mod tests_utils { pub const BAD_CREDENTIAL_OFFER: &str = r#"{"version": "0.1","to_did": "LtMgSjtFcyPwenK9SHCyb8","from_did": "LtMgSjtFcyPwenK9SHCyb8","claim": {"account_num": ["8BEaoLf8TBmK4BUyX8WWnA"],"name_on_account": ["Alice"]},"schema_seq_no": 48,"issuer_did": "Pd4fnFtRBcMKRVC2go5w3j","claim_name": "Account Certificate","claim_id": "3675417066","msg_ref_id": "ymy5nth"}"#; } @@ -378,12 +376,12 @@ pub mod tests { ARIES_CREDENTIAL_OFFER, ARIES_CREDENTIAL_OFFER_JSON_FORMAT, ARIES_CREDENTIAL_RESPONSE, CREDENTIAL_SM_FINISHED, }; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::credential::tests_utils::BAD_CREDENTIAL_OFFER; use crate::api_vcx::api_handle::credential::{ credential_create_with_offer, get_attributes, get_credential, send_credential_request, }; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::{ build_test_connection_invitee_completed, build_test_connection_inviter_requested, }; @@ -398,7 +396,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_credential_release() { let _setup = SetupDefaults::init(); let handle = credential_create_with_offer("test_credential_create_with_offer", ARIES_CREDENTIAL_OFFER).unwrap(); @@ -407,7 +404,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_credential_create_with_offer() { let _setup = SetupDefaults::init(); @@ -416,7 +412,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_credential_create_with_offer_with_json_attach() { let _setup = SetupDefaults::init(); @@ -427,7 +422,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_credential_create_with_bad_offer() { let _setup = SetupDefaults::init(); @@ -437,7 +431,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_credential_serialize_deserialize() { let _setup = SetupDefaults::init(); @@ -456,7 +449,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn full_credential_test() { let _setup = SetupMocks::init(); @@ -510,7 +502,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_attributes_json_attach() { let _setup = SetupMocks::init(); @@ -525,7 +516,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_credential_offer() { let _setup = SetupMocks::init(); @@ -540,7 +530,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_credential_and_deserialize() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/credential_def.rs b/libvcx_core/src/api_vcx/api_handle/credential_def.rs index bfaa82a78b..e6e19b8860 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential_def.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential_def.rs @@ -3,7 +3,9 @@ use aries_vcx::common::primitives::credential_definition::CredentialDefConfigBui use aries_vcx::common::primitives::credential_definition::PublicEntityStateType; use aries_vcx::global::settings::CONFIG_INSTITUTION_DID; -use crate::api_vcx::api_global::profile::get_main_profile; +use crate::api_vcx::api_global::profile::{ + get_main_anoncreds, get_main_anoncreds_ledger_read, get_main_anoncreds_ledger_write, get_main_profile, +}; use crate::api_vcx::api_global::settings::get_config_value; use crate::api_vcx::api_handle::object_cache::ObjectCache; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; @@ -26,10 +28,9 @@ pub async fn create(source_id: String, schema_id: String, tag: String, support_r format!("Failed build credential config using provided parameters: {:?}", err), ) })?; - let profile = get_main_profile()?; let cred_def = CredentialDef::create( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, source_id, config, support_revocation, @@ -42,12 +43,9 @@ pub async fn create(source_id: String, schema_id: String, tag: String, support_r pub async fn publish(handle: u32) -> LibvcxResult<()> { let mut cd = CREDENTIALDEF_MAP.get_cloned(handle)?; if !cd.was_published() { - let profile = get_main_profile()?; + let profile = get_main_profile(); cd = cd - .publish_cred_def( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds_ledger_write(), - ) + .publish_cred_def(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds_ledger_write()?) .await?; } else { info!("publish >>> Credential definition was already published") @@ -89,8 +87,8 @@ pub fn release_all() { pub async fn update_state(handle: u32) -> LibvcxResult { let mut cd = CREDENTIALDEF_MAP.get_cloned(handle)?; - let profile = get_main_profile()?; - let res = cd.update_state(&profile.inject_anoncreds_ledger_read()).await?; + let profile = get_main_profile(); + let res = cd.update_state(&get_main_anoncreds_ledger_read()?).await?; CREDENTIALDEF_MAP.insert(handle, cd)?; Ok(res) } @@ -107,31 +105,23 @@ pub fn check_is_published(handle: u32) -> LibvcxResult { pub mod tests { use std::{thread::sleep, time::Duration}; - #[cfg(feature = "pool_tests")] use aries_vcx::common::primitives::credential_definition::RevocationDetailsBuilder; - #[cfg(feature = "pool_tests")] use aries_vcx::common::test_utils::create_and_write_test_schema; use aries_vcx::global::settings::CONFIG_INSTITUTION_DID; - #[cfg(feature = "pool_tests")] use aries_vcx::utils; use aries_vcx::utils::constants::SCHEMA_ID; use aries_vcx::utils::devsetup::SetupMocks; - #[cfg(feature = "pool_tests")] use aries_vcx::utils::get_temp_dir_path; use crate::api_vcx::api_global::settings::get_config_value; - #[cfg(feature = "pool_tests")] use crate::api_vcx::api_handle::revocation_registry; - #[cfg(feature = "pool_tests")] use crate::api_vcx::api_handle::revocation_registry::RevocationRegistryConfig; use crate::api_vcx::api_handle::schema; - #[cfg(feature = "pool_tests")] use crate::api_vcx::utils::devsetup::SetupGlobalsWalletPoolAgency; use super::*; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_credentialdef_release() { let _setup = SetupMocks::init(); let schema_handle = schema::test_utils::create_schema_real().await; @@ -149,7 +139,7 @@ pub mod tests { ) } - #[cfg(feature = "test_utils")] + #[cfg(test)] pub async fn create_and_publish_nonrevocable_creddef() -> (u32, u32) { let schema_handle = schema::test_utils::create_schema_real().await; sleep(Duration::from_secs(1)); @@ -164,22 +154,20 @@ pub mod tests { (schema_handle, cred_def_handle) } - #[cfg(feature = "general_test")] #[tokio::test] async fn test_create_cred_def() { let _setup = SetupMocks::init(); let (_, _) = create_and_publish_nonrevocable_creddef().await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn create_revocable_cred_def_and_check_tails_location() { SetupGlobalsWalletPoolAgency::run(|setup| async move { - let profile = get_main_profile().unwrap(); let (schema_id, _) = create_and_write_test_schema( - &profile.inject_anoncreds(), - &profile.inject_anoncreds_ledger_write(), - &setup.setup.institution_did, + &get_main_anoncreds().unwrap(), + &get_main_anoncreds_ledger_write().unwrap(), + &setup.institution_did, utils::constants::DEFAULT_SCHEMA_ATTRS, ) .await; @@ -214,8 +202,8 @@ pub mod tests { .await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_create_credential_def_real() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let (_, handle) = create_and_publish_nonrevocable_creddef().await; @@ -227,7 +215,6 @@ pub mod tests { .await; } - #[cfg(feature = "general_test")] #[tokio::test] async fn test_to_string_succeeds() { let _setup = SetupMocks::init(); @@ -239,7 +226,6 @@ pub mod tests { assert_eq!(credential_values["version"].clone(), "1.0"); } - #[cfg(feature = "general_test")] #[tokio::test] async fn test_from_string_succeeds() { let _setup = SetupMocks::init(); @@ -260,7 +246,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_all() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/disclosed_proof.rs b/libvcx_core/src/api_vcx/api_handle/disclosed_proof.rs index 4fcd95c46e..7470880b82 100644 --- a/libvcx_core/src/api_vcx/api_handle/disclosed_proof.rs +++ b/libvcx_core/src/api_vcx/api_handle/disclosed_proof.rs @@ -10,7 +10,7 @@ use aries_vcx::{ global::settings::indy_mocks_enabled, utils::mockdata::mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION, }; -use crate::api_vcx::api_global::profile::{get_main_profile, get_main_profile_optional_pool}; +use crate::api_vcx::api_global::profile::{get_main_anoncreds, get_main_anoncreds_ledger_read, get_main_profile}; use crate::api_vcx::api_handle::mediated_connection; use crate::api_vcx::api_handle::object_cache::ObjectCache; @@ -71,7 +71,7 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: return Ok(proof.get_state().into()); } let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let profile = get_main_profile()?; + let profile = get_main_profile(); if let Some(message) = message { let message: AriesMessage = serde_json::from_str(message).map_err(|err| { @@ -86,8 +86,8 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: trace!("disclosed_proof::update_state >>> updating using message {:?}", message); proof .handle_message( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -98,8 +98,8 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: if let Some((uid, message)) = proof.find_message_to_handle(messages) { proof .handle_message( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -186,11 +186,11 @@ pub async fn reject_proof(handle: u32, connection_handle: u32) -> LibvcxResult<( pub async fn generate_proof(handle: u32, credentials: &str, self_attested_attrs: &str) -> LibvcxResult<()> { let mut proof = HANDLE_MAP.get_cloned(handle)?; - let profile = get_main_profile()?; + let profile = get_main_profile(); proof .generate_presentation( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, serde_json::from_str(credentials)?, serde_json::from_str(self_attested_attrs)?, ) @@ -218,8 +218,8 @@ pub async fn decline_presentation_request( pub async fn retrieve_credentials(handle: u32) -> LibvcxResult { let proof = HANDLE_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool not open - let retrieved_creds = proof.retrieve_credentials(&profile.inject_anoncreds()).await?; + let profile = get_main_profile(); // do not throw if pool not open + let retrieved_creds = proof.retrieve_credentials(&get_main_anoncreds()?).await?; Ok(serde_json::to_string(&retrieved_creds)?) } @@ -312,7 +312,7 @@ mod tests { use serde_json::Value; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::{ build_test_connection_invitee_completed, build_test_connection_inviter_requested, }; @@ -338,7 +338,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_disclosed_proof_release() { let _setup = SetupMocks::init(); let handle = create_with_proof_request("TEST_CREDENTIAL", ARIES_PROOF_REQUEST_PRESENTATION).unwrap(); @@ -347,7 +346,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_proof() { let _setup = SetupMocks::init(); @@ -355,7 +353,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_fails() { let _setup = SetupMocks::init(); @@ -366,7 +363,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_cycle() { let _setup = SetupMocks::init(); @@ -398,7 +394,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_update_state_v2() { let _setup = SetupMocks::init(); @@ -434,7 +429,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_reject_cycle() { let _setup = SetupMocks::init(); @@ -456,7 +450,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn get_state_test() { let _setup = SetupMocks::init(); @@ -468,7 +461,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn to_string_test() { let _setup = SetupMocks::init(); @@ -483,7 +475,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_deserialize_fails() { let _setup = SetupDefaults::init(); @@ -491,7 +482,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_proof_request() { let _setup = SetupMocks::init(); @@ -502,7 +492,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_deserialize_succeeds_with_self_attest_allowed() { let _setup = SetupDefaults::init(); @@ -513,7 +502,6 @@ mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_proof_request_attachment() { let _setup = SetupMocks::init(); 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 12c543d59c..e12c5cc301 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -5,7 +5,7 @@ use serde_json; use aries_vcx::handlers::issuance::issuer::Issuer; -use crate::api_vcx::api_global::profile::get_main_profile_optional_pool; +use crate::api_vcx::api_global::profile::{get_main_anoncreds, get_main_wallet}; use crate::api_vcx::api_handle::connection; use crate::api_vcx::api_handle::connection::HttpClient; use crate::api_vcx::api_handle::credential_def; @@ -38,7 +38,6 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: return Ok(credential.get_state().into()); } let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open if let Some(message) = message { let message: AriesMessage = serde_json::from_str(message).map_err(|err| { @@ -48,13 +47,13 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: ) })?; credential - .step(&profile.inject_anoncreds(), message.into(), Some(send_message)) + .step(&get_main_anoncreds()?, message.into(), Some(send_message)) .await?; } else { let messages = mediated_connection::get_messages(connection_handle).await?; if let Some((uid, msg)) = credential.find_message_to_handle(messages) { credential - .step(&profile.inject_anoncreds(), msg.into(), Some(send_message)) + .step(&get_main_anoncreds()?, msg.into(), Some(send_message)) .await?; mediated_connection::update_message_status(connection_handle, &uid).await?; } @@ -76,13 +75,11 @@ pub async fn update_state_with_message_nonmediated( } let con = connection::get_cloned_generic_connection(&connection_handle)?; - let wallet = get_main_profile_optional_pool().inject_wallet(); + let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open - let message: AriesMessage = serde_json::from_str(message).map_err(|err| { LibvcxError::from_msg( LibvcxErrorKind::InvalidOption, @@ -90,7 +87,7 @@ pub async fn update_state_with_message_nonmediated( ) })?; credential - .step(&profile.inject_anoncreds(), message.into(), Some(send_message)) + .step(&get_main_anoncreds()?, message.into(), Some(send_message)) .await?; let res: u32 = credential.get_state().into(); @@ -184,10 +181,9 @@ pub async fn build_credential_offer_msg_v2( tails_file: None, } }; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open credential .build_credential_offer_msg( - &profile.inject_anoncreds(), + &get_main_anoncreds()?, offer_info.clone(), comment.map(|s| s.to_string()), ) @@ -217,7 +213,7 @@ pub async fn send_credential_offer_nonmediated(credential_handle: u32, connectio let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(credential_handle)?; let con = connection::get_cloned_generic_connection(&connection_handle)?; - let wallet = get_main_profile_optional_pool().inject_wallet(); + let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); @@ -229,10 +225,9 @@ pub async fn send_credential_offer_nonmediated(credential_handle: u32, connectio pub async fn send_credential(handle: u32, connection_handle: u32) -> LibvcxResult { let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open credential .send_credential( - &profile.inject_anoncreds(), + &get_main_anoncreds()?, mediated_connection::send_message_closure(connection_handle).await?, ) .await?; @@ -243,17 +238,13 @@ pub async fn send_credential(handle: u32, connection_handle: u32) -> LibvcxResul pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> LibvcxResult { let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open - let con = connection::get_cloned_generic_connection(&connection_handle)?; - let wallet = profile.inject_wallet(); + let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - credential - .send_credential(&profile.inject_anoncreds(), send_message) - .await?; + credential.send_credential(&get_main_anoncreds()?, send_message).await?; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) @@ -261,9 +252,8 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> pub async fn revoke_credential_local(handle: u32) -> LibvcxResult<()> { let credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open credential - .revoke_credential_local(&profile.inject_anoncreds()) + .revoke_credential_local(&get_main_anoncreds()?) .await .map_err(|err| err.into()) } @@ -293,9 +283,9 @@ pub fn get_thread_id(handle: u32) -> LibvcxResult { #[cfg(test)] #[allow(clippy::unwrap_used)] pub mod tests { - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::credential_def::tests::create_and_publish_nonrevocable_creddef; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_requested; use crate::aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; use crate::errors::error; @@ -315,7 +305,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_vcx_issuer_credential_release() { let _setup = SetupMocks::init(); let handle = _issuer_credential_create(); @@ -324,7 +313,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_issuer_credential_create_succeeds() { let _setup = SetupMocks::init(); @@ -333,7 +321,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_to_string_succeeds() { let _setup = SetupMocks::init(); @@ -343,7 +330,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_send_credential_offer() { let _setup = SetupMocks::init(); @@ -362,7 +348,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_from_string_succeeds() { let _setup = SetupMocks::init(); @@ -382,7 +367,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_update_state_with_message() { let _setup = SetupMocks::init(); @@ -407,7 +391,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_update_state_with_bad_message() { let _setup = SetupMocks::init(); @@ -427,7 +410,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_all() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs b/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs index 08213a1526..52bf7268c5 100644 --- a/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs +++ b/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs @@ -17,7 +17,7 @@ use aries_vcx::protocols::SendClosure; use uuid::Uuid; use crate::api_vcx::api_global::agency_client::get_main_agency_client; -use crate::api_vcx::api_global::profile::{get_main_profile, get_main_profile_optional_pool}; +use crate::api_vcx::api_global::profile::{get_main_indy_ledger_read, get_main_profile, get_main_wallet}; use crate::api_vcx::api_global::wallet::{wallet_sign, wallet_verify}; use crate::api_vcx::api_handle::object_cache::ObjectCache; @@ -120,23 +120,18 @@ pub fn store_connection(connection: MediatedConnection) -> LibvcxResult { pub async fn create_connection(source_id: &str) -> LibvcxResult { trace!("create_connection >>> source_id: {}", source_id); - let connection = MediatedConnection::create( - source_id, - &get_main_profile_optional_pool().inject_wallet(), // do not throw if pool is not open - &get_main_agency_client()?, - true, - ) - .await?; + let connection = + MediatedConnection::create(source_id, &get_main_wallet()?, &get_main_agency_client()?, true).await?; store_connection(connection) } pub async fn create_connection_with_invite(source_id: &str, details: &str) -> LibvcxResult { debug!("create connection {} with invite {}", source_id, details); if let Ok(invitation) = serde_json::from_str::(details) { - let ddo = into_did_doc(&get_main_profile()?.inject_indy_ledger_read(), &invitation).await?; + let ddo = into_did_doc(&get_main_indy_ledger_read()?, &invitation).await?; let connection = MediatedConnection::create_with_invite( source_id, - &get_main_profile()?.inject_wallet(), + &get_main_wallet()?, &get_main_agency_client()?, invitation, ddo, @@ -159,27 +154,27 @@ pub async fn create_with_request_v2(request: &str, pw_info: PairwiseInfo) -> Lib format!("Cannot deserialize connection request: {:?}", err), ) })?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open let connection = - MediatedConnection::create_with_request(&profile.inject_wallet(), request, pw_info, &get_main_agency_client()?) + MediatedConnection::create_with_request(&get_main_wallet()?, request, pw_info, &get_main_agency_client()?) .await?; store_connection(connection) } pub async fn send_generic_message(handle: u32, msg: &str) -> LibvcxResult { let connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .send_generic_message(&profile.inject_wallet(), msg) + .send_generic_message(&get_main_wallet()?, msg) .await .map_err(|err| err.into()) } pub async fn send_handshake_reuse(handle: u32, oob_msg: &str) -> LibvcxResult<()> { let connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .send_handshake_reuse(&profile.inject_wallet(), oob_msg) + .send_handshake_reuse(&get_main_wallet()?, oob_msg) .await .map_err(|err| err.into()) } @@ -195,9 +190,9 @@ pub async fn update_state_with_message(handle: u32, message: &str) -> LibvcxResu ), ) })?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .update_state_with_message(profile.inject_wallet(), get_main_agency_client()?, Some(message)) + .update_state_with_message(get_main_wallet()?, get_main_agency_client()?, Some(message)) .await?; let state: u32 = connection.get_state().into(); CONNECTION_MAP.insert(handle, connection)?; @@ -215,8 +210,8 @@ pub async fn handle_message(handle: u32, message: &str) -> LibvcxResult<()> { ), ) })?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open - connection.handle_message(message, &profile.inject_wallet()).await?; + let profile = get_main_profile(); // do not throw if pool is not open + connection.handle_message(message, &get_main_wallet()?).await?; CONNECTION_MAP.insert(handle, connection) } @@ -227,18 +222,18 @@ pub async fn update_state(handle: u32) -> LibvcxResult { "connection::update_state >> connection {} is in final state, trying to respond to messages", handle ); - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .find_and_handle_message(&profile.inject_wallet(), &get_main_agency_client()?) + .find_and_handle_message(&get_main_wallet()?, &get_main_agency_client()?) .await? } else { info!( "connection::update_state >> connection {} is not in final state, trying to update state", handle ); - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .find_message_and_update_state(&profile.inject_wallet(), &get_main_agency_client()?) + .find_message_and_update_state(&get_main_wallet()?, &get_main_agency_client()?) .await? }; let state: u32 = connection.get_state().into(); @@ -254,9 +249,9 @@ pub async fn delete_connection(handle: u32) -> LibvcxResult<()> { pub async fn connect(handle: u32) -> LibvcxResult> { let mut connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .connect(&profile.inject_wallet(), &get_main_agency_client()?, None) + .connect(&get_main_wallet()?, &get_main_agency_client()?, None) .await?; let invitation = connection.get_invite_details().map(|invitation| match invitation { AnyInvitation::Con(Invitation::Pairwise(invitation)) => { @@ -348,31 +343,27 @@ pub async fn send_message(handle: u32, message: AriesMessage) -> LibvcxResult<() pub async fn send_message_closure(handle: u32) -> LibvcxResult { let connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .send_message_closure(profile.inject_wallet()) + .send_message_closure(get_main_wallet()?) .await .map_err(|err| err.into()) } pub async fn send_ping(handle: u32, comment: Option<&str>) -> LibvcxResult<()> { let mut connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .send_ping(profile.inject_wallet(), comment.map(String::from)) + .send_ping(get_main_wallet()?, comment.map(String::from)) .await?; CONNECTION_MAP.insert(handle, connection) } pub async fn send_discovery_features(handle: u32, query: Option<&str>, comment: Option<&str>) -> LibvcxResult<()> { let connection = CONNECTION_MAP.get_cloned(handle)?; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open + let profile = get_main_profile(); // do not throw if pool is not open connection - .send_discovery_query( - &profile.inject_wallet(), - query.map(String::from), - comment.map(String::from), - ) + .send_discovery_query(&get_main_wallet()?, query.map(String::from), comment.map(String::from)) .await?; CONNECTION_MAP.insert(handle, connection) } @@ -458,7 +449,7 @@ pub async fn download_messages( Ok(res) } -#[cfg(feature = "test_utils")] +#[allow(clippy::unwrap_used)] pub mod test_utils { use aries_vcx::utils::mockdata::mockdata_mediated_connection::{ ARIES_CONNECTION_REQUEST, CONNECTION_SM_INVITEE_COMPLETED, @@ -511,7 +502,7 @@ pub mod tests { use diddoc_legacy::aries::diddoc::test_utils::*; use crate::api_vcx::api_handle::mediated_connection; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_invited; use crate::api_vcx::VcxStateType; @@ -526,7 +517,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_connection_release() { let _setup = SetupMocks::init(); let handle = mediated_connection::create_connection(_source_id()).await.unwrap(); @@ -535,7 +525,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_connection_works() { let _setup = SetupMocks::init(); let connection_handle = mediated_connection::create_connection(_source_id()).await.unwrap(); @@ -544,7 +533,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_connection_with_pairwise_invite() { let _setup = SetupMocks::init(); @@ -563,7 +551,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_connection_with_public_invite() { let _setup = SetupMocks::init(); @@ -581,7 +568,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_connection_state_works() { let _setup = SetupMocks::init(); let connection_handle = mediated_connection::create_connection(_source_id()).await.unwrap(); @@ -589,7 +575,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_connection_delete() { let _setup = SetupMocks::init(); warn!(">> test_connection_delete going to create connection"); @@ -602,7 +587,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_connection() { let _setup = SetupMocks::init(); @@ -628,7 +612,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_drop_create() { let _setup = SetupMocks::init(); @@ -651,7 +634,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_state_fails() { let _setup = SetupEmpty::init(); @@ -660,7 +642,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_string_fails() { let _setup = SetupEmpty::init(); @@ -669,7 +650,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_service_endpoint() { let _setup = SetupMocks::init(); @@ -687,7 +667,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_retry_connection() { let _setup = SetupMocks::init(); @@ -700,7 +679,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_all() { let _setup = SetupMocks::init(); @@ -714,7 +692,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_with_valid_invite_details() { let _setup = SetupMocks::init(); @@ -730,7 +707,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_process_acceptance_message() { let _setup = SetupMocks::init(); @@ -752,7 +728,6 @@ pub mod tests { // } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_send_generic_message_fails_with_invalid_connection() { let _setup = SetupMocks::init(); @@ -763,7 +738,6 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_generate_public_invitation() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/object_cache/mod.rs b/libvcx_core/src/api_vcx/api_handle/object_cache/mod.rs index f3b01b4be1..c2867c7943 100644 --- a/libvcx_core/src/api_vcx/api_handle/object_cache/mod.rs +++ b/libvcx_core/src/api_vcx/api_handle/object_cache/mod.rs @@ -272,7 +272,6 @@ mod tests { use crate::api_vcx::api_handle::object_cache::ObjectCache; #[test] - #[cfg(feature = "general_test")] fn create_test() { let _setup = SetupDefaults::init(); @@ -280,7 +279,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn get_closure() { let _setup = SetupDefaults::init(); @@ -291,7 +289,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn to_string_test() { let _setup = SetupDefaults::init(); @@ -303,7 +300,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn mut_object_test() { let _setup = SetupDefaults::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/out_of_band.rs b/libvcx_core/src/api_vcx/api_handle/out_of_band.rs index 8bb9086394..292083062d 100644 --- a/libvcx_core/src/api_vcx/api_handle/out_of_band.rs +++ b/libvcx_core/src/api_vcx/api_handle/out_of_band.rs @@ -10,7 +10,7 @@ use aries_vcx::messages::msg_types::Protocol; use aries_vcx::messages::AriesMessage; use crate::api_vcx::api_global::agency_client::get_main_agency_client; -use crate::api_vcx::api_global::profile::get_main_profile; +use crate::api_vcx::api_global::profile::{get_main_indy_ledger_read, get_main_profile, get_main_wallet}; use crate::api_vcx::api_handle::connection; use crate::api_vcx::api_handle::mediated_connection::CONNECTION_MAP as MEDIATED_CONS_MAP; use crate::api_vcx::api_handle::object_cache::ObjectCache; @@ -160,10 +160,10 @@ pub async fn connection_exists(handle: u32, conn_handles: &Vec) -> LibvcxRe conn_map.insert(*conn_handle, connection); } let connections = conn_map.values().collect(); - let profile = get_main_profile()?; + let profile = get_main_profile(); if let Some(connection) = oob - .connection_exists(&profile.inject_indy_ledger_read(), &connections) + .connection_exists(&get_main_indy_ledger_read()?, &connections) .await? { if let Some((&handle, _)) = conn_map.iter().find(|(_, conn)| *conn == connection) { @@ -186,7 +186,7 @@ pub async fn nonmediated_connection_exists(handle: u32, conn_handles: &[u32]) -> handle, conn_handles ); - let indy_ledger = get_main_profile()?.inject_indy_ledger_read(); + let indy_ledger = get_main_indy_ledger_read()?; let oob = OUT_OF_BAND_RECEIVER_MAP.get_cloned(handle)?; let filter_closure = |h: &u32| connection::get_cloned_generic_connection(h).ok().map(|c| (*h, c)); @@ -205,9 +205,8 @@ pub async fn build_connection(handle: u32) -> LibvcxResult { trace!("build_connection >>> handle: {}", handle); let oob = OUT_OF_BAND_RECEIVER_MAP.get_cloned(handle)?; let invitation = AnyInvitation::Oob(oob.oob.clone()); - let profile = get_main_profile()?; - let ddo = into_did_doc(&profile.inject_indy_ledger_read(), &invitation).await?; - oob.build_connection(&profile.inject_wallet(), &get_main_agency_client()?, ddo, false) + let ddo = into_did_doc(&get_main_indy_ledger_read()?, &invitation).await?; + oob.build_connection(&get_main_wallet()?, &get_main_agency_client()?, ddo, false) .await? .to_string() .map_err(|err| err.into()) @@ -285,19 +284,16 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_build_oob_sender_append_services() { build_and_append_service("V4SGRU86Z58d6TV7PBUe6f").await } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_build_oob_sender_append_services_prefix_did_sov() { build_and_append_service("did:sov:V4SGRU86Z58d6TV7PBUe6f").await } #[test] - #[cfg(feature = "general_test")] fn test_serde_oob_config_handshake_protocols() { let config_str = json!({ "handshake_protocols": vec!["https://didcomm.org/connections/1.0"] }).to_string(); let config_actual: OOBConfig = serde_json::from_str(&config_str).unwrap(); diff --git a/libvcx_core/src/api_vcx/api_handle/proof.rs b/libvcx_core/src/api_vcx/api_handle/proof.rs index 35cb97aa41..b8992ef5ca 100644 --- a/libvcx_core/src/api_vcx/api_handle/proof.rs +++ b/libvcx_core/src/api_vcx/api_handle/proof.rs @@ -6,7 +6,9 @@ use aries_vcx::handlers::proof_presentation::verifier::Verifier; use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; use aries_vcx::protocols::SendClosure; -use crate::api_vcx::api_global::profile::get_main_profile; +use crate::api_vcx::api_global::profile::{ + get_main_anoncreds, get_main_anoncreds_ledger_read, get_main_profile, get_main_wallet, +}; use crate::api_vcx::api_handle::connection::HttpClient; use crate::api_vcx::api_handle::object_cache::ObjectCache; use crate::api_vcx::api_handle::{connection, mediated_connection}; @@ -30,8 +32,8 @@ pub async fn create_proof( revocation_details: String, name: String, ) -> LibvcxResult { - let profile = get_main_profile()?; - let presentation_request = PresentationRequestData::create(&profile.inject_anoncreds(), &name) + let profile = get_main_profile(); + let presentation_request = PresentationRequestData::create(&get_main_anoncreds()?, &name) .await? .set_requested_attributes_as_string(requested_attrs)? .set_requested_predicates_as_string(requested_predicates)? @@ -56,7 +58,7 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: return Ok(proof.get_state().into()); } let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let profile = get_main_profile()?; + let profile = get_main_profile(); if let Some(message) = message { let message: AriesMessage = serde_json::from_str(message).map_err(|err| { @@ -71,8 +73,8 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: trace!("proof::update_state >>> updating using message {:?}", message); proof .handle_message( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -83,8 +85,8 @@ pub async fn update_state(handle: u32, message: Option<&str>, connection_handle: if let Some((uid, message)) = proof.find_message_to_handle(messages) { proof .handle_message( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -109,9 +111,8 @@ pub async fn update_state_nonmediated(handle: u32, connection_handle: u32, messa return Ok(proof.get_state().into()); } - let profile = get_main_profile()?; let con = connection::get_cloned_generic_connection(&connection_handle)?; - let wallet = profile.inject_wallet(); + let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); @@ -127,8 +128,8 @@ pub async fn update_state_nonmediated(handle: u32, connection_handle: u32, messa })?; proof .handle_message( - &profile.inject_anoncreds_ledger_read(), - &profile.inject_anoncreds(), + &get_main_anoncreds_ledger_read()?, + &get_main_anoncreds()?, message.into(), Some(send_message), ) @@ -192,9 +193,9 @@ pub async fn send_proof_request(handle: u32, connection_handle: u32) -> LibvcxRe pub async fn send_proof_request_nonmediated(handle: u32, connection_handle: u32) -> LibvcxResult<()> { let mut proof = PROOF_MAP.get_cloned(handle)?; - let profile = get_main_profile()?; + let profile = get_main_profile(); let con = connection::get_cloned_generic_connection(&connection_handle)?; - let wallet = profile.inject_wallet(); + let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); @@ -286,7 +287,7 @@ pub mod tests { use aries_vcx::utils::mockdata::mock_settings::MockBuilder; use aries_vcx::utils::mockdata::mockdata_proof; - #[cfg(feature = "test_utils")] + #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_requested; use crate::api_vcx::api_handle::proof; use crate::aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; @@ -306,7 +307,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_proof_returns_proof_with_proof_state_invalid() { let _setup = SetupMocks::init(); let handle = create_default_proof().await; @@ -315,14 +315,12 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_proof_succeeds() { let _setup = SetupMocks::init(); create_default_proof().await; } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_revocation_details() { let _setup = SetupMocks::init(); @@ -345,7 +343,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_to_string_succeeds() { let _setup = SetupMocks::init(); @@ -358,7 +355,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_from_string_succeeds() { let _setup = SetupMocks::init(); @@ -370,7 +366,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_proof() { let _setup = SetupMocks::init(); @@ -380,7 +375,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_send_proof_request() { let _setup = SetupMocks::init(); @@ -395,7 +389,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_proof_fails_with_no_proof() { let _setup = SetupMocks::init(); @@ -405,7 +398,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_update_state_v2() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -434,7 +426,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_update_state() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -459,7 +450,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_validation_with_predicate() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -484,7 +474,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_update_state_with_reject_message() { let _setup = SetupMocks::init(); @@ -500,7 +489,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_send_presentation_request() { let _setup = SetupMocks::init(); @@ -515,7 +503,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_proof() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -548,7 +535,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_all() { let _setup = SetupMocks::init(); @@ -586,7 +572,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_send_proof_request_can_be_retried() { let _setup = SetupMocks::init(); @@ -617,7 +602,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_accepted() { let _setup = SetupMocks::init(); let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true)); @@ -638,7 +622,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_proof_errors() { let _setup = SetupMocks::init(); diff --git a/libvcx_core/src/api_vcx/api_handle/revocation_registry.rs b/libvcx_core/src/api_vcx/api_handle/revocation_registry.rs index 55cfd8189d..9141ad14a0 100644 --- a/libvcx_core/src/api_vcx/api_handle/revocation_registry.rs +++ b/libvcx_core/src/api_vcx/api_handle/revocation_registry.rs @@ -2,7 +2,7 @@ use aries_vcx::common::primitives::revocation_registry::RevocationRegistry; use aries_vcx::common::primitives::revocation_registry::RevocationRegistryDefinition; use aries_vcx::global::settings::CONFIG_INSTITUTION_DID; -use crate::api_vcx::api_global::profile::{get_main_profile, get_main_profile_optional_pool}; +use crate::api_vcx::api_global::profile::{get_main_anoncreds, get_main_anoncreds_ledger_write, get_main_profile}; use crate::api_vcx::api_global::settings::get_config_value; use crate::api_vcx::api_handle::object_cache::ObjectCache; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; @@ -28,9 +28,8 @@ pub async fn create(config: RevocationRegistryConfig) -> LibvcxResult { max_creds, tag, } = config; - let profile = get_main_profile_optional_pool(); // do not throw if pool is not open let rev_reg = RevocationRegistry::create( - &profile.inject_anoncreds(), + &get_main_anoncreds()?, &issuer_did, &cred_def_id, &tails_dir, @@ -44,9 +43,8 @@ pub async fn create(config: RevocationRegistryConfig) -> LibvcxResult { pub async fn publish(handle: u32, tails_url: &str) -> LibvcxResult { let mut rev_reg = REV_REG_MAP.get_cloned(handle)?; - let profile = get_main_profile()?; rev_reg - .publish_revocation_primitives(&profile.inject_anoncreds_ledger_write(), tails_url) + .publish_revocation_primitives(&get_main_anoncreds_ledger_write()?, tails_url) .await?; REV_REG_MAP.insert(handle, rev_reg)?; Ok(handle) @@ -54,13 +52,11 @@ pub async fn publish(handle: u32, tails_url: &str) -> LibvcxResult { pub async fn publish_revocations(handle: u32) -> LibvcxResult<()> { let submitter_did = get_config_value(CONFIG_INSTITUTION_DID)?; - let rev_reg = REV_REG_MAP.get_cloned(handle)?; - rev_reg .publish_local_revocations( - &get_main_profile()?.inject_anoncreds(), - &get_main_profile()?.inject_anoncreds_ledger_write(), + &get_main_anoncreds()?, + &get_main_anoncreds_ledger_write()?, &submitter_did, ) .await?; diff --git a/libvcx_core/src/api_vcx/api_handle/schema.rs b/libvcx_core/src/api_vcx/api_handle/schema.rs index 85a7ae3399..39f952a5bc 100644 --- a/libvcx_core/src/api_vcx/api_handle/schema.rs +++ b/libvcx_core/src/api_vcx/api_handle/schema.rs @@ -5,10 +5,11 @@ use serde_json; use aries_vcx::common::primitives::credential_schema::Schema; use aries_vcx::global::settings::CONFIG_INSTITUTION_DID; -use crate::api_vcx::api_global::pool::get_main_pool_handle; -use crate::api_vcx::api_global::profile::{get_main_profile, indy_handles_to_profile}; +use crate::api_vcx::api_global::profile::{ + get_main_anoncreds, get_main_anoncreds_ledger_read, get_main_anoncreds_ledger_write, get_main_indy_ledger_read, + get_main_profile, +}; use crate::api_vcx::api_global::settings::get_config_value; -use crate::api_vcx::api_global::wallet::get_main_wallet_handle; use crate::api_vcx::api_handle::object_cache::ObjectCache; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; @@ -43,18 +44,10 @@ pub async fn create_and_publish_schema( format!("Cannot deserialize schema data to vec: {:?}", err), ) })?; - let profile = get_main_profile()?; - let schema = Schema::create( - &profile.inject_anoncreds(), - source_id, - &issuer_did, - &name, - &version, - &data, - ) - .await? - .publish(&profile.inject_anoncreds_ledger_write(), None) - .await?; + let schema = Schema::create(&get_main_anoncreds()?, source_id, &issuer_did, &name, &version, &data) + .await? + .publish(&get_main_anoncreds_ledger_write()?, None) + .await?; std::thread::sleep(std::time::Duration::from_millis(100)); debug!("created schema on ledger with id: {}", schema.get_schema_id()); @@ -69,9 +62,8 @@ pub async fn get_schema_attrs(source_id: String, schema_id: String) -> LibvcxRes source_id, schema_id ); - let profile = get_main_profile()?; - let schema = - Schema::create_from_ledger_json(&profile.inject_anoncreds_ledger_read(), &source_id, &schema_id).await?; + let profile = get_main_profile(); + let schema = Schema::create_from_ledger_json(&get_main_anoncreds_ledger_read()?, &source_id, &schema_id).await?; let schema_json = schema.to_string_versioned()?; let handle = SCHEMA_MAP @@ -113,11 +105,8 @@ pub fn release_all() { } pub async fn update_state(schema_handle: u32) -> LibvcxResult { - let wallet_handle = get_main_wallet_handle(); - let pool_handle = get_main_pool_handle()?; let mut schema = SCHEMA_MAP.get_cloned(schema_handle)?; - let profile = indy_handles_to_profile(wallet_handle, pool_handle); - let res = schema.update_state(&profile.inject_anoncreds_ledger_read()).await?; + let res = schema.update_state(&get_main_anoncreds_ledger_read()?).await?; SCHEMA_MAP.insert(schema_handle, schema)?; Ok(res) } @@ -126,7 +115,7 @@ pub fn get_state(handle: u32) -> LibvcxResult { SCHEMA_MAP.get(handle, |s| Ok(s.get_state())) } -#[cfg(feature = "test_utils")] +#[allow(clippy::unwrap_used)] pub mod test_utils { use rand::Rng; @@ -156,8 +145,15 @@ pub mod test_utils { pub fn check_schema(schema_handle: u32, schema_json: &str, schema_id: &str, data: &str) { let schema: Schema = Schema::from_string_versioned(schema_json).unwrap(); + info!("schema: {:?}", schema); assert_eq!(schema.schema_id, schema_id.to_string()); - assert_eq!(schema.data.clone().sort(), vec!(data).sort()); + + let mut schema_data = schema.data.clone(); + schema_data.sort(); + let mut vec_data: Vec = serde_json::from_str(data).unwrap(); + vec_data.sort(); + assert_eq!(schema_data, vec_data); + assert!(schema_handle > 0); } @@ -174,24 +170,19 @@ pub mod test_utils { #[cfg(test)] pub mod tests { - #[cfg(feature = "pool_tests")] use aries_vcx::common::test_utils::create_and_write_test_schema; - #[cfg(feature = "pool_tests")] + use aries_vcx::global::settings::{set_config_value, DEFAULT_DID}; use aries_vcx::utils::constants; use aries_vcx::utils::constants::SCHEMA_ID; use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, SetupMocks}; - #[cfg(feature = "pool_tests")] use crate::api_vcx::api_handle::schema; - #[cfg(any(feature = "pool_tests", feature = "general_test"))] use crate::api_vcx::api_handle::schema::test_utils::{check_schema, create_schema_real, prepare_schema_data}; - #[cfg(feature = "pool_tests")] use crate::api_vcx::utils::devsetup::SetupGlobalsWalletPoolAgency; use super::*; #[tokio::test] - #[cfg(feature = "general_test")] async fn test_vcx_schema_release() { let _setup = SetupMocks::init(); @@ -204,33 +195,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] - async fn test_create_schema_to_string() { - let _setup = SetupMocks::init(); - - let (_did, schema_name, schema_version, data) = prepare_schema_data(); - let handle = create_and_publish_schema("test_create_schema_success", schema_name, schema_version, data.clone()) - .await - .unwrap(); - - let schema_id = get_schema_id(handle).unwrap(); - let create_schema_json = to_string(handle).unwrap(); - - let value: serde_json::Value = serde_json::from_str(&create_schema_json).unwrap(); - assert_eq!(value["version"], "1.0"); - assert!(value["data"].is_object()); - - let handle = from_string(&create_schema_json).unwrap(); - - assert_eq!( - get_source_id(handle).unwrap(), - String::from("test_create_schema_success") - ); - check_schema(handle, &create_schema_json, &schema_id, &data); - } - - #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_schema_success() { let _setup = SetupMocks::init(); @@ -241,7 +205,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_get_schema_attrs_success() { let _setup = SetupMocks::init(); @@ -253,26 +216,23 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_create_schema_fails() { let _setup = SetupDefaults::init(); - + set_config_value(CONFIG_INSTITUTION_DID, DEFAULT_DID).unwrap(); let err = create_and_publish_schema("1", "name".to_string(), "1.0".to_string(), "".to_string()) .await .unwrap_err(); assert_eq!(err.kind(), LibvcxErrorKind::SerializationError) } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_get_schema_attrs_from_ledger() { SetupGlobalsWalletPoolAgency::run(|setup| async move { - let profile = get_main_profile().unwrap(); - let (schema_id, _) = create_and_write_test_schema( - &profile.inject_anoncreds(), - &profile.inject_anoncreds_ledger_write(), - &setup.setup.institution_did, + &get_main_anoncreds().unwrap(), + &&get_main_anoncreds_ledger_write().unwrap(), + &setup.institution_did, constants::DEFAULT_SCHEMA_ATTRS, ) .await; @@ -289,8 +249,8 @@ pub mod tests { .await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_create_schema_with_pool() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let handle = create_schema_real().await; @@ -303,7 +263,7 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "pool_tests")] + #[ignore] async fn test_create_duplicate_fails() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let (_did, schema_name, schema_version, data) = prepare_schema_data(); @@ -322,7 +282,6 @@ pub mod tests { } #[tokio::test] - #[cfg(feature = "general_test")] async fn test_release_all() { let _setup = SetupMocks::init(); @@ -346,15 +305,14 @@ pub mod tests { } #[test] - #[cfg(feature = "general_test")] fn test_handle_errors() { let _setup = SetupEmpty::init(); assert_eq!(to_string(13435178).unwrap_err().kind(), LibvcxErrorKind::InvalidHandle); } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_vcx_schema_get_state_with_ledger() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let handle = create_schema_real().await; @@ -363,8 +321,8 @@ pub mod tests { .await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_vcx_create_schema_with_pool() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let (_issuer_did, schema_name, schema_version, schema_data) = prepare_schema_data(); @@ -376,8 +334,8 @@ pub mod tests { .await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_vcx_schema_serialize_contains_version() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let (_issuer_did, schema_name, schema_version, schema_data) = prepare_schema_data(); @@ -395,8 +353,8 @@ pub mod tests { .await; } - #[cfg(feature = "pool_tests")] #[tokio::test] + #[ignore] async fn test_vcx_schema_get_attrs_with_pool() { SetupGlobalsWalletPoolAgency::run(|_setup| async move { let (_issuer_did, schema_name, schema_version, schema_data) = prepare_schema_data(); diff --git a/libvcx_core/src/api_vcx/mod.rs b/libvcx_core/src/api_vcx/mod.rs index 77aa30355e..95bfb41f66 100644 --- a/libvcx_core/src/api_vcx/mod.rs +++ b/libvcx_core/src/api_vcx/mod.rs @@ -120,7 +120,6 @@ mod tests { use self::VcxStateType::*; #[test] - #[cfg(feature = "general_test")] fn test_serialize_vcx_state_type() { let z = VcxStateNone; let y = serde_json::to_string(&z).unwrap(); diff --git a/libvcx_core/src/api_vcx/utils/devsetup.rs b/libvcx_core/src/api_vcx/utils/devsetup.rs index 9f5aca8b3e..21f2e00e73 100644 --- a/libvcx_core/src/api_vcx/utils/devsetup.rs +++ b/libvcx_core/src/api_vcx/utils/devsetup.rs @@ -1,31 +1,65 @@ +use agency_client::agency_client::AgencyClient; +use aries_vcx::aries_vcx_core::global::settings; +use aries_vcx::aries_vcx_core::indy::ledger::pool::test_utils::create_testpool_genesis_txn_file; +use aries_vcx::aries_vcx_core::indy::ledger::pool::{create_pool_ledger_config, indy_close_pool, indy_open_pool}; +use aries_vcx::aries_vcx_core::{PoolHandle, WalletHandle}; +use aries_vcx::global::settings::{ + set_config_value, CONFIG_GENESIS_PATH, CONFIG_INSTITUTION_DID, DEFAULT_DID, DEFAULT_GENESIS_PATH, +}; +use aries_vcx::utils; use std::future::Future; +use uuid::Uuid; -use aries_vcx::utils::devsetup::SetupWalletPoolAgency; +use aries_vcx::utils::devsetup::{init_test_logging, reset_global_state, setup_issuer_wallet_and_agency_client}; +use aries_vcx::utils::get_temp_dir_path; use crate::api_vcx::api_global::agency_client::{reset_main_agency_client, set_main_agency_client}; -use crate::api_vcx::api_global::pool::{reset_main_pool_handle, set_main_pool_handle}; -use crate::api_vcx::api_global::wallet::{reset_main_wallet_handle, set_main_wallet_handle}; +use crate::api_vcx::api_global::pool::{close_main_pool, reset_global_ledger_components, setup_ledger_components}; +use crate::api_vcx::api_global::wallet::{close_main_wallet, setup_wallet}; pub struct SetupGlobalsWalletPoolAgency { - pub setup: SetupWalletPoolAgency, + pub agency_client: AgencyClient, + pub institution_did: String, + pub wallet_handle: WalletHandle, + pub pool_handle: PoolHandle, } impl SetupGlobalsWalletPoolAgency { + pub async fn init() -> SetupGlobalsWalletPoolAgency { + reset_global_state(); + init_test_logging(); + set_config_value(CONFIG_INSTITUTION_DID, DEFAULT_DID).unwrap(); + let (institution_did, wallet_handle, agency_client) = setup_issuer_wallet_and_agency_client().await; + let pool_name = Uuid::new_v4().to_string(); + let genesis_path = get_temp_dir_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); + create_testpool_genesis_txn_file(&genesis_path); + create_pool_ledger_config(&pool_name, &genesis_path).unwrap(); + let pool_handle = indy_open_pool(&pool_name, None).await.unwrap(); + SetupGlobalsWalletPoolAgency { + agency_client, + institution_did, + wallet_handle, + pool_handle, + } + } + pub async fn run(f: impl FnOnce(Self) -> F) where F: Future, { - SetupWalletPoolAgency::run(|setup| async move { - set_main_wallet_handle(setup.wallet_handle); - set_main_agency_client(setup.agency_client.clone()); - set_main_pool_handle(Some(setup.pool_handle)); - - f(SetupGlobalsWalletPoolAgency { setup }).await; - - reset_main_wallet_handle(); - reset_main_agency_client(); - reset_main_pool_handle(); - }) - .await; + let init = Self::init().await; + + let pool_handle = init.pool_handle.clone(); + setup_wallet(init.wallet_handle).unwrap(); + set_main_agency_client(init.agency_client.clone()); + setup_ledger_components(Some(pool_handle)).unwrap(); + + f(init).await; + + close_main_wallet(); + reset_main_agency_client(); + indy_close_pool(pool_handle).await.unwrap(); + + reset_global_state(); } } diff --git a/libvcx_core/src/api_vcx/utils/mod.rs b/libvcx_core/src/api_vcx/utils/mod.rs index 2ce3dce20f..55b916109b 100644 --- a/libvcx_core/src/api_vcx/utils/mod.rs +++ b/libvcx_core/src/api_vcx/utils/mod.rs @@ -1,3 +1,3 @@ -#[cfg(feature = "test_utils")] +#[cfg(test)] pub mod devsetup; pub mod version_constants; diff --git a/libvcx_core/src/errors/mapping_to_u32.rs b/libvcx_core/src/errors/mapping_to_u32.rs index d71c0ea654..8536dda4e1 100644 --- a/libvcx_core/src/errors/mapping_to_u32.rs +++ b/libvcx_core/src/errors/mapping_to_u32.rs @@ -117,7 +117,6 @@ mod tests { use crate::errors::error::LibvcxErrorKind; #[test] - #[cfg(feature = "general_test")] fn it_should_map_error_kinds_to_codes() { assert_eq!(u32::from(LibvcxErrorKind::InvalidState), 1081); assert_eq!(u32::from(LibvcxErrorKind::InvalidConfiguration), 1004); @@ -198,7 +197,6 @@ mod tests { } #[test] - #[cfg(feature = "general_test")] fn it_should_map_error_codes_to_error_kinds() { assert_eq!(LibvcxErrorKind::from(1081), LibvcxErrorKind::InvalidState); assert_eq!(LibvcxErrorKind::from(1004), LibvcxErrorKind::InvalidConfiguration); diff --git a/libvdrtools/src/controllers/pool.rs b/libvdrtools/src/controllers/pool.rs index 72f831a9ff..08bec388ff 100644 --- a/libvdrtools/src/controllers/pool.rs +++ b/libvdrtools/src/controllers/pool.rs @@ -5,7 +5,7 @@ use indy_api_types::{errors::prelude::*, PoolHandle}; use crate::{ domain::{ ledger::request::ProtocolVersion, - pool::{PoolConfig, PoolOpenConfig}, + pool::{PoolConfig, VdrtoolsPoolOpenConfig}, }, services::PoolService, }; @@ -103,7 +103,7 @@ impl PoolController { pub async fn open( &self, name: String, - config: Option, + config: Option, ) -> IndyResult { trace!("open > name {:?} config {:?}", name, config); diff --git a/libvdrtools/src/domain/pool.rs b/libvdrtools/src/domain/pool.rs index 42b70722a1..6aa1cfce24 100644 --- a/libvdrtools/src/domain/pool.rs +++ b/libvdrtools/src/domain/pool.rs @@ -27,26 +27,26 @@ pub enum PoolMode { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct PoolOpenConfig { - #[serde(default = "PoolOpenConfig::default_timeout")] +pub struct VdrtoolsPoolOpenConfig { + #[serde(default = "VdrtoolsPoolOpenConfig::default_timeout")] pub timeout: i64, - #[serde(default = "PoolOpenConfig::default_extended_timeout")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_extended_timeout")] pub extended_timeout: i64, - #[serde(default = "PoolOpenConfig::default_conn_limit")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_conn_limit")] pub conn_limit: usize, - #[serde(default = "PoolOpenConfig::default_conn_active_timeout")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_conn_active_timeout")] pub conn_active_timeout: i64, - #[serde(default = "PoolOpenConfig::default_preordered_nodes")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_preordered_nodes")] pub preordered_nodes: Vec, - #[serde(default = "PoolOpenConfig::default_number_read_nodes")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_number_read_nodes")] pub number_read_nodes: u8, - #[serde(default = "PoolOpenConfig::default_pool_mode")] + #[serde(default = "VdrtoolsPoolOpenConfig::default_pool_mode")] pub pool_mode: PoolMode, #[serde(default)] pub transactions: Option, } -impl Validatable for PoolOpenConfig { +impl Validatable for VdrtoolsPoolOpenConfig { fn validate(&self) -> Result<(), String> { if self.timeout <= 0 { return Err(String::from("`timeout` must be greater than 0")); @@ -72,22 +72,22 @@ impl Validatable for PoolOpenConfig { } } -impl Default for PoolOpenConfig { +impl Default for VdrtoolsPoolOpenConfig { fn default() -> Self { - PoolOpenConfig { - timeout: PoolOpenConfig::default_timeout(), - extended_timeout: PoolOpenConfig::default_extended_timeout(), - conn_limit: PoolOpenConfig::default_conn_limit(), - conn_active_timeout: PoolOpenConfig::default_conn_active_timeout(), - preordered_nodes: PoolOpenConfig::default_preordered_nodes(), - number_read_nodes: PoolOpenConfig::default_number_read_nodes(), - pool_mode: PoolOpenConfig::default_pool_mode(), + VdrtoolsPoolOpenConfig { + timeout: VdrtoolsPoolOpenConfig::default_timeout(), + extended_timeout: VdrtoolsPoolOpenConfig::default_extended_timeout(), + conn_limit: VdrtoolsPoolOpenConfig::default_conn_limit(), + conn_active_timeout: VdrtoolsPoolOpenConfig::default_conn_active_timeout(), + preordered_nodes: VdrtoolsPoolOpenConfig::default_preordered_nodes(), + number_read_nodes: VdrtoolsPoolOpenConfig::default_number_read_nodes(), + pool_mode: VdrtoolsPoolOpenConfig::default_pool_mode(), transactions: None, } } } -impl PoolOpenConfig { +impl VdrtoolsPoolOpenConfig { fn default_timeout() -> i64 { POOL_ACK_TIMEOUT } diff --git a/libvdrtools/src/lib.rs b/libvdrtools/src/lib.rs index 33850f62e0..f3ddcb8b96 100644 --- a/libvdrtools/src/lib.rs +++ b/libvdrtools/src/lib.rs @@ -23,7 +23,7 @@ mod utils; #[macro_use] mod controllers; -mod domain; +pub mod domain; mod services; use std::sync::Arc; diff --git a/libvdrtools/src/services/pool/mod.rs b/libvdrtools/src/services/pool/mod.rs index 313eee04f5..7ff26a7d6a 100644 --- a/libvdrtools/src/services/pool/mod.rs +++ b/libvdrtools/src/services/pool/mod.rs @@ -19,7 +19,7 @@ use zmq::Socket; use crate::{ domain::{ ledger::response::{Message, Reply, ResponseMetadata}, - pool::{PoolConfig, PoolOpenConfig}, + pool::{PoolConfig, VdrtoolsPoolOpenConfig}, }, utils::environment, }; @@ -165,7 +165,7 @@ impl PoolService { pub(crate) async fn open( &self, name: String, - config: Option, + config: Option, handle: Option, ) -> IndyResult<(PoolHandle, String)> { trace!("PoolService::open >>>"); @@ -612,7 +612,7 @@ pub mod tests { ps.open_pools.lock().await.insert( pool_id, Arc::new(ZMQPool::new( - Pool::new("", pool_id, PoolOpenConfig::default()), + Pool::new("", pool_id, VdrtoolsPoolOpenConfig::default()), send_cmd_sock, )), ); @@ -641,7 +641,7 @@ pub mod tests { ps.open_pools.lock().await.insert( pool_id, Arc::new(ZMQPool::new( - Pool::new("", pool_id, PoolOpenConfig::default()), + Pool::new("", pool_id, VdrtoolsPoolOpenConfig::default()), send_cmd_sock, )), ); @@ -688,7 +688,7 @@ pub mod tests { let path: path::PathBuf = environment::pool_path(pool_name); let pool_id = next_pool_handle(); - let pool = Pool::new(pool_name, pool_id, PoolOpenConfig::default()); + let pool = Pool::new(pool_name, pool_id, VdrtoolsPoolOpenConfig::default()); ps.open_pools .lock() .await @@ -710,7 +710,7 @@ pub mod tests { let name = "test"; let (send_cmd_sock, recv_cmd_sock) = pool_create_pair_of_sockets("pool_send_tx_works"); let pool_id = next_pool_handle(); - let pool = Pool::new(name, pool_id, PoolOpenConfig::default()); + let pool = Pool::new(name, pool_id, VdrtoolsPoolOpenConfig::default()); let ps = PoolService::new(); ps.open_pools @@ -750,7 +750,7 @@ pub mod tests { let send_cmd_sock = zmq_ctx.socket(zmq::SocketType::PAIR).unwrap(); let pool_id = next_pool_handle(); - let pool = Pool::new(name, pool_id, PoolOpenConfig::default()); + let pool = Pool::new(name, pool_id, VdrtoolsPoolOpenConfig::default()); let ps = PoolService::new(); ps.open_pools @@ -778,7 +778,11 @@ pub mod tests { pool_create_pair_of_sockets("pool_send_action_works"); let pool_id = next_pool_handle(); - let pool = Pool::new("pool_send_action_works", pool_id, PoolOpenConfig::default()); + let pool = Pool::new( + "pool_send_action_works", + pool_id, + VdrtoolsPoolOpenConfig::default(), + ); let ps = PoolService::new(); ps.open_pools @@ -854,7 +858,7 @@ pub mod tests { file.write_all(gen_txn.as_bytes()).unwrap(); let pool_id = next_pool_handle(); - let mut pool = Pool::new(pool_name, pool_id, PoolOpenConfig::default()); + let mut pool = Pool::new(pool_name, pool_id, VdrtoolsPoolOpenConfig::default()); pool.work(recv_cmd_sock); ps.open_pools diff --git a/libvdrtools/src/services/pool/pool.rs b/libvdrtools/src/services/pool/pool.rs index 39aeb32144..3da82e8af0 100644 --- a/libvdrtools/src/services/pool/pool.rs +++ b/libvdrtools/src/services/pool/pool.rs @@ -11,7 +11,7 @@ use failure::Context; use crate::{ domain::{ ledger::request::ProtocolVersion, - pool::{PoolMode, PoolOpenConfig}, + pool::{PoolMode, VdrtoolsPoolOpenConfig}, }, services::{ ledger::merkletree::merkletree::MerkleTree, @@ -690,7 +690,7 @@ pub struct Pool> { } impl> Pool { - pub fn new(name: &str, id: PoolHandle, config: PoolOpenConfig) -> Self { + pub fn new(name: &str, id: PoolHandle, config: VdrtoolsPoolOpenConfig) -> Self { trace!("Pool::new name {}, id {:?}, config {:?}", name, id, config); Pool { @@ -1147,7 +1147,7 @@ mod tests { let _p: Pool = Pool::new( "pool_new_works", next_pool_handle(), - PoolOpenConfig::default(), + VdrtoolsPoolOpenConfig::default(), ); } @@ -1155,7 +1155,7 @@ mod tests { pub fn pool_get_name_works() { let name = "pool_get_name_works"; let p: Pool = - Pool::new(name, next_pool_handle(), PoolOpenConfig::default()); + Pool::new(name, next_pool_handle(), VdrtoolsPoolOpenConfig::default()); assert_eq!(name, p.get_name()); } @@ -1164,7 +1164,7 @@ mod tests { let name = "pool_get_id_works"; let id = next_pool_handle(); let p: Pool = - Pool::new(name, id, PoolOpenConfig::default()); + Pool::new(name, id, VdrtoolsPoolOpenConfig::default()); assert_eq!(id, p.get_id()); } } diff --git a/uniffi_aries_vcx/core/src/core/profile.rs b/uniffi_aries_vcx/core/src/core/profile.rs index daecd24a8c..5e5b9b495d 100644 --- a/uniffi_aries_vcx/core/src/core/profile.rs +++ b/uniffi_aries_vcx/core/src/core/profile.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use aries_vcx::aries_vcx_core::indy::wallet::{create_and_open_wallet, WalletConfig}; -use aries_vcx::aries_vcx_core::PoolHandle; use aries_vcx::core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile}; use crate::{errors::error::VcxUniFFIResult, runtime::block_on}; diff --git a/wrappers/ios/vcx/VcxAPI.m b/wrappers/ios/vcx/VcxAPI.m index 8c4372ee7d..014d03ab9d 100644 --- a/wrappers/ios/vcx/VcxAPI.m +++ b/wrappers/ios/vcx/VcxAPI.m @@ -1892,10 +1892,6 @@ - (void)deleteCredential:(NSNumber *)credentialHandle }); } -- (int)walletSetHandle:(NSNumber *)handle { - return vcx_wallet_set_handle(handle.integerValue); -} - - (void)exportWallet:(NSString *)exportPath encryptWith:(NSString *)encryptionKey completion:(void (^)(NSError *, NSNumber *))completion { diff --git a/wrappers/ios/vcx/include/libvcx.h b/wrappers/ios/vcx/include/libvcx.h index 596cb11d31..3fb40316b4 100644 --- a/wrappers/ios/vcx/include/libvcx.h +++ b/wrappers/ios/vcx/include/libvcx.h @@ -1104,8 +1104,6 @@ vcx_error_t vcx_delete_credential( * Used for exporting and importing and managing the wallet. */ -vcx_error_t vcx_wallet_set_handle(vcx_i32_t handle); - /** Export the wallet as an encrypted file */ vcx_error_t vcx_wallet_export( vcx_command_handle_t handle, diff --git a/wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java b/wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java index cb11e0171a..8993f2cb1f 100644 --- a/wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java +++ b/wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java @@ -555,9 +555,6 @@ public interface API extends Library { /** Close a search */ public int vcx_wallet_close_search(int command_handle, int search_handle, Callback cb); - /** Set wallet handle manually */ - public int vcx_wallet_set_handle(int handle); - /** * message object * diff --git a/wrappers/java/src/main/java/com/evernym/sdk/vcx/wallet/WalletApi.java b/wrappers/java/src/main/java/com/evernym/sdk/vcx/wallet/WalletApi.java index 3a7ea7f84e..e53c933391 100644 --- a/wrappers/java/src/main/java/com/evernym/sdk/vcx/wallet/WalletApi.java +++ b/wrappers/java/src/main/java/com/evernym/sdk/vcx/wallet/WalletApi.java @@ -537,8 +537,4 @@ public static CompletableFuture closeSearchWallet( return future; } - - public static void setWalletHandle(int handle) { - LibVcx.api.vcx_wallet_set_handle(handle); - } } diff --git a/wrappers/node/test/suite1/ariesvcx-wallet.test.ts b/wrappers/node/test/suite1/ariesvcx-wallet.test.ts index e04874c717..c8a0e3bb4b 100644 --- a/wrappers/node/test/suite1/ariesvcx-wallet.test.ts +++ b/wrappers/node/test/suite1/ariesvcx-wallet.test.ts @@ -41,7 +41,7 @@ describe('Wallet:', () => { Wallet.export('/tmp/foobar.wallet', 'key_for_wallet'), ); assert.equal(error.napiCode, 'GenericFailure'); - assert.equal(error.vcxCode, VCXCode.INVALID_WALLET_HANDLE); + assert.equal(error.vcxCode, VCXCode.NOT_READY); }); }); }); diff --git a/wrappers/vcx-napi-rs/src/api/connection.rs b/wrappers/vcx-napi-rs/src/api/connection.rs index 9c9fbd9f5e..4d2d13d4d5 100644 --- a/wrappers/vcx-napi-rs/src/api/connection.rs +++ b/wrappers/vcx-napi-rs/src/api/connection.rs @@ -4,7 +4,6 @@ use libvcx_core::aries_vcx::messages::msg_fields::protocols::basic_message::{ BasicMessage, BasicMessageContent, BasicMessageDecorators, }; use libvcx_core::aries_vcx::messages::AriesMessage; -use napi::Error; use napi_derive::napi; use libvcx_core::api_vcx::api_handle::connection; diff --git a/wrappers/vcx-napi-rs/src/api/utils.rs b/wrappers/vcx-napi-rs/src/api/utils.rs index 3e40c0808e..0a2dab4633 100644 --- a/wrappers/vcx-napi-rs/src/api/utils.rs +++ b/wrappers/vcx-napi-rs/src/api/utils.rs @@ -4,8 +4,8 @@ use libvcx_core::api_vcx::api_global::state::state_vcx_shutdown; use libvcx_core::api_vcx::api_global::VERSION_STRING; #[napi] -pub fn shutdown(delete_all: Option) -> ::napi::Result<()> { - state_vcx_shutdown(delete_all.unwrap_or(false)); +pub fn shutdown(_delete_all: Option) -> ::napi::Result<()> { + state_vcx_shutdown(); Ok(()) }