Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Feb 22, 2023
1 parent 07a1b29 commit 8401829
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 73 deletions.
2 changes: 1 addition & 1 deletion libvcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
8 changes: 4 additions & 4 deletions libvcx/src/api_c/ledger/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
11 changes: 7 additions & 4 deletions libvcx/src/api_c/protocols/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(
Expand All @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down
11 changes: 6 additions & 5 deletions libvcx/src/api_c/protocols/disclosed_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions libvcx/src/api_c/protocols/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions libvcx/src/api_c/protocols/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions libvcx_core/src/api_vcx/api_handle/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
65 changes: 38 additions & 27 deletions libvcx_core/src/api_vcx/api_handle/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down
60 changes: 37 additions & 23 deletions libvcx_core/src/api_vcx/api_handle/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,39 +165,18 @@ pub fn get_state(handle: u32) -> LibvcxResult<u32> {
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<String> {
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();
Expand Down Expand Up @@ -225,6 +204,41 @@ pub mod tests {
assert!(schema_handle > 0);
}

fn data() -> Vec<String> {
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() {
Expand Down

0 comments on commit 8401829

Please sign in to comment.