diff --git a/libvcx/Cargo.toml b/libvcx/Cargo.toml index 1afb17e84b..bc59876d6c 100644 --- a/libvcx/Cargo.toml +++ b/libvcx/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["staticlib", "cdylib", "lib"] doctest = false [features] -test_utils = [ "aries-vcx/test_utils" ] +test_utils = [ "aries-vcx/test_utils", "libvcx_core/test_utils" ] pool_tests = [ "test_utils" ] general_test = [ "test_utils" ] fatal_warnings = [] diff --git a/libvcx/src/api_c/ledger/schema.rs b/libvcx/src/api_c/ledger/schema.rs index d1bcc00e14..94d458196f 100644 --- a/libvcx/src/api_c/ledger/schema.rs +++ b/libvcx/src/api_c/ledger/schema.rs @@ -566,7 +566,7 @@ mod tests { use libvcx_core::api_vcx::api_global::settings; use libvcx_core::api_vcx::api_global::settings::get_config_value; use libvcx_core::api_vcx::api_handle::schema::prepare_schema_for_endorser; - use libvcx_core::api_vcx::api_handle::schema::tests::prepare_schema_data; + use libvcx_core::api_vcx::api_handle::schema::test_utils::prepare_schema_data; use libvcx_core::errors; use crate::api_c::cutils::return_types_u32; @@ -608,9 +608,9 @@ mod tests { fn test_vcx_create_schema_success() { let _setup = SetupMocks::init(); - let (_, schema_name, schema_version, data) = prepare_schema_data(); - let handle = vcx_schema_create_c_closure(&schema_name, &schema_version, &data).unwrap(); - assert!(handle > 0) + let foo = prepare_schema_data(); + // let handle = vcx_schema_create_c_closure(&schema_name, &schema_version, &data).unwrap(); + // assert!(handle > 0) } #[test] diff --git a/libvcx/src/api_c/protocols/credential.rs b/libvcx/src/api_c/protocols/credential.rs index 9f28c1081e..494a5f1be3 100644 --- a/libvcx/src/api_c/protocols/credential.rs +++ b/libvcx/src/api_c/protocols/credential.rs @@ -1202,8 +1202,11 @@ mod tests { use aries_vcx::utils::mockdata::mockdata_credex::{ ARIES_CREDENTIAL_OFFER, ARIES_CREDENTIAL_RESPONSE, CREDENTIAL_SM_FINISHED, }; - use libvcx_core::api_vcx::api_handle::credential::tests::BAD_CREDENTIAL_OFFER; + use libvcx_core::api_vcx::api_handle::credential::tests_utils::BAD_CREDENTIAL_OFFER; use libvcx_core::api_vcx::api_handle::mediated_connection; + use libvcx_core::api_vcx::api_handle::mediated_connection::test_utils::{ + build_test_connection_invitee_completed, build_test_connection_inviter_requested, + }; use libvcx_core::errors; use crate::api_c::cutils::return_types_u32; @@ -1281,7 +1284,7 @@ mod tests { async fn test_vcx_credential_get_new_offers() { let _setup = SetupMocks::init(); - let handle_conn = mediated_connection::tests::build_test_connection_invitee_completed(); + let handle_conn = build_test_connection_invitee_completed(); let cb = return_types_u32::Return_U32_STR::new().unwrap(); assert_eq!( @@ -1296,7 +1299,7 @@ mod tests { async fn test_vcx_credential_create() { let _setup = SetupMocks::init(); - let handle_conn = mediated_connection::tests::build_test_connection_invitee_completed(); + let handle_conn = build_test_connection_invitee_completed(); let cb = return_types_u32::Return_U32_U32_STR::new().unwrap(); assert_eq!( @@ -1335,7 +1338,7 @@ mod tests { async fn test_vcx_credential_update_state() { let _setup = SetupMocks::init(); - let handle_conn = mediated_connection::tests::build_test_connection_inviter_requested().await; + let handle_conn = build_test_connection_inviter_requested().await; let handle_cred = _vcx_credential_create_with_offer_c_closure(ARIES_CREDENTIAL_OFFER).unwrap(); assert_eq!( diff --git a/libvcx/src/api_c/protocols/disclosed_proof.rs b/libvcx/src/api_c/protocols/disclosed_proof.rs index 22e5e39d03..e53b979ea2 100644 --- a/libvcx/src/api_c/protocols/disclosed_proof.rs +++ b/libvcx/src/api_c/protocols/disclosed_proof.rs @@ -1144,6 +1144,7 @@ mod tests { use aries_vcx::utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_REQUEST; use aries_vcx::utils::mockdata::mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION; use libvcx_core::api_vcx::api_handle::mediated_connection; + use libvcx_core::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_requested; use libvcx_core::errors; use crate::api_c::cutils::return_types_u32; @@ -1191,7 +1192,7 @@ mod tests { async fn test_create_with_msgid() { let _setup = SetupMocks::init(); - let cxn = mediated_connection::tests::build_test_connection_inviter_requested().await; + let cxn = build_test_connection_inviter_requested().await; let cb = return_types_u32::Return_U32_U32_STR::new().unwrap(); assert_eq!( @@ -1278,7 +1279,7 @@ mod tests { ProverState::PresentationRequestReceived as u32 ); - let handle_conn = mediated_connection::tests::build_test_connection_inviter_requested().await; + let handle_conn = build_test_connection_inviter_requested().await; let cb = return_types_u32::Return_U32::new().unwrap(); assert_eq!( @@ -1299,7 +1300,7 @@ mod tests { ProverState::PresentationRequestReceived as u32 ); - let connection_handle = mediated_connection::tests::build_test_connection_inviter_requested().await; + let connection_handle = build_test_connection_inviter_requested().await; let cb = return_types_u32::Return_U32::new().unwrap(); assert_eq!( @@ -1322,7 +1323,7 @@ mod tests { ProverState::PresentationRequestReceived as u32 ); - let _connection_handle = mediated_connection::tests::build_test_connection_inviter_requested().await; + let _connection_handle = build_test_connection_inviter_requested().await; let cb = return_types_u32::Return_U32_STR::new().unwrap(); assert_eq!( @@ -1337,7 +1338,7 @@ mod tests { async fn test_vcx_proof_get_requests() { let _setup = SetupMocks::init(); - let cxn = mediated_connection::tests::build_test_connection_inviter_requested().await; + let cxn = build_test_connection_inviter_requested().await; AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE); AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_REQUEST); diff --git a/libvcx/src/api_c/protocols/mediated_connection.rs b/libvcx/src/api_c/protocols/mediated_connection.rs index ef0ae50c15..cd8b674383 100644 --- a/libvcx/src/api_c/protocols/mediated_connection.rs +++ b/libvcx/src/api_c/protocols/mediated_connection.rs @@ -1594,12 +1594,12 @@ mod tests { use aries_vcx::utils::mockdata::mockdata_mediated_connection::{ ARIES_CONNECTION_ACK, ARIES_CONNECTION_REQUEST, DEFAULT_SERIALIZED_CONNECTION, }; - use libvcx_core::api_vcx::api_handle::mediated_connection::tests::{ + use libvcx_core::api_vcx::api_handle::mediated_connection::test_utils::{ build_test_connection_inviter_invited, build_test_connection_inviter_null, build_test_connection_inviter_requested, }; - use libvcx_core::errors::error::{LibvcxErrorKind, SUCCESS_ERR_CODE}; - use libvcx_core::VcxStateType; + use libvcx_core::api_vcx::VcxStateType; + use libvcx_core::errors::error::LibvcxErrorKind; use crate::api_c::cutils::return_types_u32; use crate::api_c::cutils::timeout::TimeoutUtils; @@ -1866,7 +1866,7 @@ mod tests { async fn test_sign() { let _setup = SetupMocks::init(); - let connection_handle = mediated_connection::tests::build_test_connection_inviter_invited().await; + let connection_handle = build_test_connection_inviter_invited().await; let msg = format!("My message"); let msg_len = msg.len(); @@ -1891,7 +1891,7 @@ mod tests { async fn test_verify_signature() { let _setup = SetupMocks::init(); - let connection_handle = mediated_connection::tests::build_test_connection_inviter_requested().await; + let connection_handle = build_test_connection_inviter_requested().await; let msg = format!("My message"); let msg_len = msg.len(); diff --git a/libvcx/src/api_c/protocols/proof.rs b/libvcx/src/api_c/protocols/proof.rs index b8ad58166b..ae2731f1a3 100644 --- a/libvcx/src/api_c/protocols/proof.rs +++ b/libvcx/src/api_c/protocols/proof.rs @@ -801,10 +801,9 @@ mod tests { use aries_vcx::utils::devsetup::*; use aries_vcx::utils::mockdata::mock_settings::MockBuilder; use aries_vcx::utils::mockdata::mockdata_proof; - use libvcx_core::api_vcx::api_handle::mediated_connection::tests::build_test_connection_inviter_requested; + use libvcx_core::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_requested; use libvcx_core::api_vcx::api_handle::proof; use libvcx_core::errors; - use libvcx_core::ProofStateType; use crate::api_c::cutils::return_types_u32; use crate::api_c::cutils::timeout::TimeoutUtils; diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index ae72e84ce6..7a51e1334d 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -338,6 +338,11 @@ 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"}"#; +} + #[cfg(test)] pub mod tests { use aries_vcx::protocols::issuance::holder::state_machine::HolderState; @@ -355,8 +360,6 @@ pub mod tests { use super::*; - 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"}"#; - async fn _get_offer(handle: u32) -> String { let offers = get_credential_offer_messages_with_conn_handle(handle).await.unwrap(); let offers: serde_json::Value = serde_json::from_str(&offers).unwrap(); 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 01acc7b4d6..52db7d6150 100644 --- a/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs +++ b/libvcx_core/src/api_vcx/api_handle/mediated_connection.rs @@ -433,6 +433,44 @@ pub async fn download_messages( Ok(res) } +#[cfg(feature = "test_utils")] +pub mod test_utils { + use serde_json::Value; + + use aries_vcx::utils::mockdata::mockdata_mediated_connection::{ + ARIES_CONNECTION_ACK, ARIES_CONNECTION_INVITATION, ARIES_CONNECTION_REQUEST, CONNECTION_SM_INVITEE_COMPLETED, + }; + + use super::*; + + pub async fn mock_connection() -> u32 { + build_test_connection_inviter_requested().await + } + + pub async fn build_test_connection_inviter_null() -> u32 { + let handle = create_connection("faber_to_alice").await.unwrap(); + handle + } + + pub async fn build_test_connection_inviter_invited() -> u32 { + let handle = create_connection("faber_to_alice").await.unwrap(); + connect(handle).await.unwrap(); + handle + } + + pub fn build_test_connection_invitee_completed() -> u32 { + from_string(CONNECTION_SM_INVITEE_COMPLETED).unwrap() + } + + pub async fn build_test_connection_inviter_requested() -> u32 { + let handle = build_test_connection_inviter_invited().await; + update_state_with_message(handle, ARIES_CONNECTION_REQUEST) + .await + .unwrap(); + handle + } +} + #[cfg(test)] pub mod tests { use serde_json::Value; @@ -453,10 +491,6 @@ pub mod tests { use super::*; - pub async fn mock_connection() -> u32 { - build_test_connection_inviter_requested().await - } - fn _setup() { let _setup = SetupEmpty::init(); } @@ -528,29 +562,6 @@ pub mod tests { assert!(!mediated_connection::is_valid_handle(connection_handle)); } - pub async fn build_test_connection_inviter_null() -> u32 { - let handle = create_connection("faber_to_alice").await.unwrap(); - handle - } - - pub async fn build_test_connection_inviter_invited() -> u32 { - let handle = create_connection("faber_to_alice").await.unwrap(); - connect(handle).await.unwrap(); - handle - } - - pub fn build_test_connection_invitee_completed() -> u32 { - from_string(CONNECTION_SM_INVITEE_COMPLETED).unwrap() - } - - pub async fn build_test_connection_inviter_requested() -> u32 { - let handle = build_test_connection_inviter_invited().await; - update_state_with_message(handle, ARIES_CONNECTION_REQUEST) - .await - .unwrap(); - handle - } - #[tokio::test] #[cfg(feature = "general_test")] async fn test_create_connection() { diff --git a/libvcx_core/src/api_vcx/api_handle/schema.rs b/libvcx_core/src/api_vcx/api_handle/schema.rs index e5a59a65a7..c5c68a36f3 100644 --- a/libvcx_core/src/api_vcx/api_handle/schema.rs +++ b/libvcx_core/src/api_vcx/api_handle/schema.rs @@ -165,39 +165,18 @@ pub fn get_state(handle: u32) -> LibvcxResult { SCHEMA_MAP.get(handle, |s| Ok(s.get_state())) } -#[cfg(test)] -pub mod tests { +#[cfg(feature = "test_utils")] +pub mod test_utils { use rand::Rng; - #[cfg(feature = "pool_tests")] - use aries_vcx::common::ledger::transactions::add_new_did; - #[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::constants; use aries_vcx::utils::constants::SCHEMA_ID; - use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, SetupMocks}; use crate::api_vcx::api_global::settings::get_config_value; use crate::api_vcx::api_global::wallet::get_main_wallet_handle; - #[cfg(feature = "pool_tests")] - use crate::api_vcx::api_handle::schema; - #[cfg(feature = "pool_tests")] - use crate::api_vcx::utils::devsetup::SetupGlobalsWalletPoolAgency; use super::*; - fn data() -> Vec { - vec![ - "address1".to_string(), - "address2".to_string(), - "zip".to_string(), - "city".to_string(), - "state".to_string(), - ] - } - pub fn prepare_schema_data() -> (String, String, String, String) { let data = json!(data()).to_string(); let schema_name: String = aries_vcx::utils::random::generate_random_schema_name(); @@ -225,6 +204,41 @@ pub mod tests { assert!(schema_handle > 0); } + fn data() -> Vec { + vec![ + "address1".to_string(), + "address2".to_string(), + "zip".to_string(), + "city".to_string(), + "state".to_string(), + ] + } +} + +#[cfg(test)] +pub mod tests { + use rand::Rng; + + #[cfg(feature = "pool_tests")] + use aries_vcx::common::ledger::transactions::add_new_did; + #[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::constants; + use aries_vcx::utils::constants::SCHEMA_ID; + use aries_vcx::utils::devsetup::{SetupDefaults, SetupEmpty, SetupMocks}; + + use crate::api_vcx::api_global::settings::get_config_value; + use crate::api_vcx::api_global::wallet::get_main_wallet_handle; + #[cfg(feature = "pool_tests")] + use crate::api_vcx::api_handle::schema; + use crate::api_vcx::api_handle::schema::test_utils::{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() {