Skip to content

Commit

Permalink
Commented libvcx_core tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur committed Oct 3, 2023
1 parent b0a8b3e commit ed9e3eb
Show file tree
Hide file tree
Showing 10 changed files with 1,261 additions and 1,310 deletions.
33 changes: 15 additions & 18 deletions libvcx_core/src/api_vcx/api_global/agency_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub async fn provision_cloud_agent(

#[cfg(test)]
pub mod tests {
use agency_client::configuration::AgentProvisionConfig;
use aries_vcx::{
agency_client::{
messages::update_message::UIDsByConn, testing::mocking::AgencyMockDecrypted,
Expand All @@ -100,30 +99,28 @@ pub mod tests {
utils::{constants, devsetup::SetupMocks},
};

use crate::api_vcx::api_global::agency_client::{
agency_update_messages, provision_cloud_agent, update_webhook_url,
};
use crate::api_vcx::api_global::agency_client::{agency_update_messages, update_webhook_url};

#[tokio::test]
async fn test_update_institution_webhook() {
let _setup = SetupMocks::init();
update_webhook_url("https://example.com").await.unwrap();
}

#[tokio::test]
async fn test_provision_cloud_agent() {
let _setup = SetupMocks::init();

let config = AgentProvisionConfig {
agency_did: "Ab8TvZa3Q19VNkQVzAWVL7".into(),
agency_verkey: "5LXaR43B1aQyeh94VBP8LG1Sgvjk7aNfqiksBCSjwqbf".into(),
agency_endpoint: "https://enym-eagency.pdev.evernym.com"
.parse()
.expect("valid url"),
agent_seed: None,
};
provision_cloud_agent(&config).await.unwrap();
}
// #[tokio::test]
// async fn test_provision_cloud_agent() {
// let _setup = SetupMocks::init();

// let config = AgentProvisionConfig {
// agency_did: "Ab8TvZa3Q19VNkQVzAWVL7".into(),
// agency_verkey: "5LXaR43B1aQyeh94VBP8LG1Sgvjk7aNfqiksBCSjwqbf".into(),
// agency_endpoint: "https://enym-eagency.pdev.evernym.com"
// .parse()
// .expect("valid url"),
// agent_seed: None,
// };
// provision_cloud_agent(&config).await.unwrap();
// }

#[tokio::test]
async fn test_messages_update_status() {
Expand Down
22 changes: 11 additions & 11 deletions libvcx_core/src/api_vcx/api_global/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub mod tests {
get_txns_sovrin_testnet,
},
global::settings::DEFAULT_GENESIS_PATH,
utils::devsetup::{SetupEmpty, SetupMocks},
utils::devsetup::SetupEmpty,
};

use crate::api_vcx::api_global::{
Expand Down Expand Up @@ -226,14 +226,14 @@ pub mod tests {
assert_eq!(expected, auth_agreement);
}

#[tokio::test]
async fn test_vcx_get_ledger_author_agreement() {
let _setup = SetupMocks::init();

let agreement = ledger_get_txn_author_agreement().await.unwrap();
assert_eq!(
aries_vcx::utils::constants::DEFAULT_AUTHOR_AGREEMENT,
agreement
);
}
// #[tokio::test]
// async fn test_vcx_get_ledger_author_agreement() {
// let _setup = SetupMocks::init();

// let agreement = ledger_get_txn_author_agreement().await.unwrap();
// assert_eq!(
// aries_vcx::utils::constants::DEFAULT_AUTHOR_AGREEMENT,
// agreement
// );
// }
}
130 changes: 65 additions & 65 deletions libvcx_core/src/api_vcx/api_global/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,73 +29,73 @@ pub fn state_vcx_shutdown() {

#[cfg(test)]
pub mod tests {
use aries_vcx::{
global::settings::DEFAULT_DID,
utils::{
devsetup::SetupMocks,
mockdata::{
mockdata_credex::ARIES_CREDENTIAL_OFFER,
mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION,
},
},
};
// use aries_vcx::{
// global::settings::DEFAULT_DID,
// utils::{
// devsetup::SetupMocks,
// mockdata::{
// mockdata_credex::ARIES_CREDENTIAL_OFFER,
// mockdata_proof::ARIES_PROOF_REQUEST_PRESENTATION,
// },
// },
// };

use crate::api_vcx::{
api_global::state::state_vcx_shutdown,
api_handle::{
credential, credential::credential_create_with_offer, credential_def, disclosed_proof,
disclosed_proof::create_with_proof_request, issuer_credential, mediated_connection,
proof, schema, schema::create_and_publish_schema,
},
};
// use crate::api_vcx::{
// api_global::state::state_vcx_shutdown,
// api_handle::{
// credential, credential::credential_create_with_offer, credential_def, disclosed_proof,
// disclosed_proof::create_with_proof_request, issuer_credential, mediated_connection,
// proof, schema, schema::create_and_publish_schema,
// },
// };

#[tokio::test]
async fn test_shutdown() {
let _setup = SetupMocks::init();
// #[tokio::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 credential_def = credential_def::create(
DEFAULT_DID.to_owned(),
"SID".to_string(),
"id".to_string(),
"tag".to_string(),
false,
)
.await
.unwrap();
let issuer_credential =
issuer_credential::issuer_credential_create("1".to_string()).unwrap();
let proof = proof::create_proof(
"1".to_string(),
"[]".to_string(),
"[]".to_string(),
r#"{"support_revocation":false}"#.to_string(),
"Optional".to_owned(),
)
.await
.unwrap();
let schema = create_and_publish_schema(
DEFAULT_DID,
"5",
"name".to_string(),
"0.1".to_string(),
data.to_string(),
)
.await
.unwrap();
let disclosed_proof =
create_with_proof_request("id", ARIES_PROOF_REQUEST_PRESENTATION).unwrap();
let credential = credential_create_with_offer("name", ARIES_CREDENTIAL_OFFER).unwrap();
// let data = r#"["name","male"]"#;
// let connection =
// mediated_connection::test_utils::build_test_connection_inviter_invited().await;
// let credential_def = credential_def::create(
// DEFAULT_DID.to_owned(),
// "SID".to_string(),
// "id".to_string(),
// "tag".to_string(),
// false,
// )
// .await
// .unwrap();
// let issuer_credential =
// issuer_credential::issuer_credential_create("1".to_string()).unwrap();
// let proof = proof::create_proof(
// "1".to_string(),
// "[]".to_string(),
// "[]".to_string(),
// r#"{"support_revocation":false}"#.to_string(),
// "Optional".to_owned(),
// )
// .await
// .unwrap();
// let schema = create_and_publish_schema(
// DEFAULT_DID,
// "5",
// "name".to_string(),
// "0.1".to_string(),
// data.to_string(),
// )
// .await
// .unwrap();
// 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();
assert!(!mediated_connection::is_valid_handle(connection));
assert!(!issuer_credential::is_valid_handle(issuer_credential));
assert!(!schema::is_valid_handle(schema));
assert!(!proof::is_valid_handle(proof));
assert!(!credential_def::is_valid_handle(credential_def));
assert!(!credential::is_valid_handle(credential));
assert!(!disclosed_proof::is_valid_handle(disclosed_proof));
}
// state_vcx_shutdown();
// assert!(!mediated_connection::is_valid_handle(connection));
// assert!(!issuer_credential::is_valid_handle(issuer_credential));
// assert!(!schema::is_valid_handle(schema));
// assert!(!proof::is_valid_handle(proof));
// assert!(!credential_def::is_valid_handle(credential_def));
// assert!(!credential::is_valid_handle(credential));
// assert!(!disclosed_proof::is_valid_handle(disclosed_proof));
// }
}
148 changes: 73 additions & 75 deletions libvcx_core/src/api_vcx/api_handle/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub mod tests {
mockdata_credex,
mockdata_credex::{
ARIES_CREDENTIAL_OFFER, ARIES_CREDENTIAL_OFFER_JSON_FORMAT,
ARIES_CREDENTIAL_RESPONSE, CREDENTIAL_SM_FINISHED,
CREDENTIAL_SM_FINISHED,
},
},
},
Expand All @@ -427,12 +427,10 @@ pub mod tests {
#[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,
credential_create_with_offer, get_attributes, get_credential,
};
#[cfg(test)]
use crate::api_vcx::api_handle::mediated_connection::test_utils::{
build_test_connection_invitee_completed, build_test_connection_inviter_requested,
};
use crate::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_invitee_completed;

async fn _get_offer(handle: u32) -> String {
let offers = get_credential_offer_messages_with_conn_handle(handle)
Expand Down Expand Up @@ -514,76 +512,76 @@ pub mod tests {
assert_eq!(cred_original_serialized, cred_restored_serialized);
}

#[tokio::test]
async fn full_credential_test() {
let _setup = SetupMocks::init();

info!("full_credential_test:: going to build_test_connection");
let handle_conn = build_test_connection_inviter_requested().await;

info!("full_credential_test:: going to _get_offer");
let offer = _get_offer(handle_conn).await;

info!("full_credential_test:: going to credential_create_with_offer");
let handle_cred = credential_create_with_offer("TEST_CREDENTIAL", &offer).unwrap();
assert_eq!(
HolderState::OfferReceived as u32,
get_state(handle_cred).unwrap()
);

info!("full_credential_test:: going get offered attributes from offer received state");
let offer_attrs: String = get_attributes(handle_cred).unwrap();
info!(
"full_credential_test:: obtained offered attributes: {}",
offer_attrs
);
let offer_attrs: serde_json::Value = serde_json::from_str(&offer_attrs).unwrap();
let offer_attrs_expected: serde_json::Value =
serde_json::from_str(mockdata_credex::OFFERED_ATTRIBUTES).unwrap();
assert_eq!(offer_attrs, offer_attrs_expected);

info!("full_credential_test:: going to send_credential_request");
send_credential_request(handle_cred, handle_conn)
.await
.unwrap();
assert_eq!(
HolderState::RequestSet as u32,
get_state(handle_cred).unwrap()
);

AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE);
AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_RESPONSE);

info!("full_credential_test:: going to update_state, should receive credential");
update_state(handle_cred, None, handle_conn).await.unwrap();
assert_eq!(
get_state(handle_cred).unwrap(),
HolderState::Finished as u32
);

info!("full_credential_test:: going to get_credential");
let msg = get_credential(handle_cred).unwrap();
info!("full_credential_test:: get_credential returned {}", msg);
let msg_value: serde_json::Value = serde_json::from_str(&msg).unwrap();

info!(
"full_credential_test:: going to deserialize credential: {:?}",
msg_value
);
let _credential_struct: IssueCredentialV1 =
serde_json::from_str(msg_value.to_string().as_str()).unwrap();

info!("full_credential_test:: going get offered attributes from final state");
let offer_attrs: String = get_attributes(handle_cred).unwrap();
info!(
"full_credential_test:: obtained offered attributes: {}",
offer_attrs
);
let offer_attrs: serde_json::Value = serde_json::from_str(&offer_attrs).unwrap();
let offer_attrs_expected: serde_json::Value =
serde_json::from_str(mockdata_credex::OFFERED_ATTRIBUTES).unwrap();
assert_eq!(offer_attrs, offer_attrs_expected);
}
// #[tokio::test]
// async fn full_credential_test() {
// let _setup = SetupMocks::init();

// info!("full_credential_test:: going to build_test_connection");
// let handle_conn = build_test_connection_inviter_requested().await;

// info!("full_credential_test:: going to _get_offer");
// let offer = _get_offer(handle_conn).await;

// info!("full_credential_test:: going to credential_create_with_offer");
// let handle_cred = credential_create_with_offer("TEST_CREDENTIAL", &offer).unwrap();
// assert_eq!(
// HolderState::OfferReceived as u32,
// get_state(handle_cred).unwrap()
// );

// info!("full_credential_test:: going get offered attributes from offer received state");
// let offer_attrs: String = get_attributes(handle_cred).unwrap();
// info!(
// "full_credential_test:: obtained offered attributes: {}",
// offer_attrs
// );
// let offer_attrs: serde_json::Value = serde_json::from_str(&offer_attrs).unwrap();
// let offer_attrs_expected: serde_json::Value =
// serde_json::from_str(mockdata_credex::OFFERED_ATTRIBUTES).unwrap();
// assert_eq!(offer_attrs, offer_attrs_expected);

// info!("full_credential_test:: going to send_credential_request");
// send_credential_request(handle_cred, handle_conn)
// .await
// .unwrap();
// assert_eq!(
// HolderState::RequestSet as u32,
// get_state(handle_cred).unwrap()
// );

// AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE);
// AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_RESPONSE);

// info!("full_credential_test:: going to update_state, should receive credential");
// update_state(handle_cred, None, handle_conn).await.unwrap();
// assert_eq!(
// get_state(handle_cred).unwrap(),
// HolderState::Finished as u32
// );

// info!("full_credential_test:: going to get_credential");
// let msg = get_credential(handle_cred).unwrap();
// info!("full_credential_test:: get_credential returned {}", msg);
// let msg_value: serde_json::Value = serde_json::from_str(&msg).unwrap();

// info!(
// "full_credential_test:: going to deserialize credential: {:?}",
// msg_value
// );
// let _credential_struct: IssueCredentialV1 =
// serde_json::from_str(msg_value.to_string().as_str()).unwrap();

// info!("full_credential_test:: going get offered attributes from final state");
// let offer_attrs: String = get_attributes(handle_cred).unwrap();
// info!(
// "full_credential_test:: obtained offered attributes: {}",
// offer_attrs
// );
// let offer_attrs: serde_json::Value = serde_json::from_str(&offer_attrs).unwrap();
// let offer_attrs_expected: serde_json::Value =
// serde_json::from_str(mockdata_credex::OFFERED_ATTRIBUTES).unwrap();
// assert_eq!(offer_attrs, offer_attrs_expected);
// }

#[tokio::test]
async fn test_get_attributes_json_attach() {
Expand Down
Loading

0 comments on commit ed9e3eb

Please sign in to comment.