diff --git a/aries_vcx/tests/test_anoncreds.rs b/aries_vcx/tests/test_anoncreds.rs index f3730b3413..f5ff822d1d 100644 --- a/aries_vcx/tests/test_anoncreds.rs +++ b/aries_vcx/tests/test_anoncreds.rs @@ -1,4 +1,4 @@ -pub mod utils; +use std::error::Error; use aries_vcx::common::credentials::get_cred_rev_id; use aries_vcx_core::{ @@ -7,191 +7,180 @@ use aries_vcx_core::{ ledger::{base_ledger::AnoncredsLedgerRead, indy::pool::test_utils::get_temp_dir_path}, }; use serde_json::json; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, run_setup_test}; +use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile}; use crate::utils::{ create_and_publish_test_rev_reg, create_and_write_credential, create_and_write_test_cred_def, create_and_write_test_schema, }; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_pool_returns_error_if_proof_request_is_malformed() { - run_setup_test!(|setup| async move { - let proof_req = "{"; - let anoncreds = setup.anoncreds; - let result = anoncreds - .prover_get_credentials_for_proof_req(&setup.wallet, proof_req) - .await; - assert_eq!( - result.unwrap_err().kind(), - AriesVcxCoreErrorKind::InvalidProofRequest - ); - }) - .await; +async fn test_pool_returns_error_if_proof_request_is_malformed() -> Result<(), Box> { + let setup = build_setup_profile().await; + let proof_req = "{"; + let anoncreds = setup.anoncreds; + let result = anoncreds + .prover_get_credentials_for_proof_req(&setup.wallet, proof_req) + .await; + assert_eq!( + result.unwrap_err().kind(), + AriesVcxCoreErrorKind::InvalidProofRequest + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_prover_get_credentials() { - run_setup_test!(|setup| async move { - let proof_req = json!({ - "nonce":"123432421212", - "name":"proof_req_1", - "version":"0.1", - "requested_attributes": json!({ - "address1_1": json!({ - "name":"address1", - }), - "zip_2": json!({ - "name":"zip", - }), +async fn test_pool_prover_get_credentials() -> Result<(), Box> { + let setup = build_setup_profile().await; + let proof_req = json!({ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attributes": json!({ + "address1_1": json!({ + "name":"address1", }), - "requested_predicates": json!({}), - }) - .to_string(); - - let anoncreds = setup.anoncreds; - let _result = anoncreds - .prover_get_credentials_for_proof_req(&setup.wallet, &proof_req) - .await - .unwrap(); - - let result_malformed_json = anoncreds - .prover_get_credentials_for_proof_req(&setup.wallet, "{}") - .await - .unwrap_err(); - assert_eq!( - result_malformed_json.kind(), - AriesVcxCoreErrorKind::InvalidAttributesStructure - ); + "zip_2": json!({ + "name":"zip", + }), + }), + "requested_predicates": json!({}), }) - .await; + .to_string(); + + let anoncreds = setup.anoncreds; + let _result = anoncreds + .prover_get_credentials_for_proof_req(&setup.wallet, &proof_req) + .await?; + + let result_malformed_json = anoncreds + .prover_get_credentials_for_proof_req(&setup.wallet, "{}") + .await + .unwrap_err(); + assert_eq!( + result_malformed_json.kind(), + AriesVcxCoreErrorKind::InvalidAttributesStructure + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_proof_req_attribute_names() { - run_setup_test!(|setup| async move { - let proof_req = json!({ - "nonce":"123432421212", - "name":"proof_req_1", - "version":"0.1", - "requested_attributes": json!({ - "multiple_attrs": { - "names": ["name_1", "name_2"] - }, - "address1_1": json!({ - "name":"address1", - "restrictions": [json!({ "issuer_did": "some_did" })] - }), - "self_attest_3": json!({ - "name":"self_attest", - }), +async fn test_pool_proof_req_attribute_names() -> Result<(), Box> { + let setup = build_setup_profile().await; + let proof_req = json!({ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attributes": json!({ + "multiple_attrs": { + "names": ["name_1", "name_2"] + }, + "address1_1": json!({ + "name":"address1", + "restrictions": [json!({ "issuer_did": "some_did" })] }), - "requested_predicates": json!({ - "zip_3": {"name":"zip", "p_type":">=", "p_value":18} + "self_attest_3": json!({ + "name":"self_attest", }), - }) - .to_string(); - - let anoncreds = setup.anoncreds; - let _result = anoncreds - .prover_get_credentials_for_proof_req(&setup.wallet, &proof_req) - .await - .unwrap(); + }), + "requested_predicates": json!({ + "zip_3": {"name":"zip", "p_type":">=", "p_value":18} + }), }) - .await; + .to_string(); + + let anoncreds = setup.anoncreds; + anoncreds + .prover_get_credentials_for_proof_req(&setup.wallet, &proof_req) + .await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_revoke_credential() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let cred_def = create_and_write_test_cred_def( +async fn test_pool_revoke_credential() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def = create_and_write_test_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &schema.schema_id, + true, + ) + .await; + let rev_reg = create_and_publish_test_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + &cred_def.get_cred_def_id(), + ) + .await; + let cred_id = create_and_write_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.institution_did, + &cred_def, + Some(&rev_reg), + ) + .await; + let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id).await?; + + let ledger = setup.ledger_read; + + let (_, first_rev_reg_delta, first_timestamp) = ledger + .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) + .await?; + + let (_, test_same_delta, test_same_timestamp) = ledger + .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) + .await?; + + assert_eq!(first_rev_reg_delta, test_same_delta); + assert_eq!(first_timestamp, test_same_timestamp); + + let anoncreds = &setup.anoncreds; + + anoncreds + .revoke_credential_local( &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &schema.schema_id, - true, + get_temp_dir_path().to_str().unwrap(), + &rev_reg.rev_reg_id, + &cred_rev_id, ) - .await; - let rev_reg = create_and_publish_test_rev_reg( + .await?; + + rev_reg + .publish_local_revocations( &setup.wallet, &setup.anoncreds, &setup.ledger_write, &setup.institution_did, - &cred_def.get_cred_def_id(), ) - .await; - let cred_id = create_and_write_credential( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.institution_did, - &cred_def, - Some(&rev_reg), - ) - .await; - let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id) - .await - .unwrap(); - - let ledger = setup.ledger_read; - - let (_, first_rev_reg_delta, first_timestamp) = ledger - .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) - .await - .unwrap(); - - let (_, test_same_delta, test_same_timestamp) = ledger - .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) - .await - .unwrap(); - - assert_eq!(first_rev_reg_delta, test_same_delta); - assert_eq!(first_timestamp, test_same_timestamp); - - let anoncreds = &setup.anoncreds; - - anoncreds - .revoke_credential_local( - &setup.wallet, - get_temp_dir_path().to_str().unwrap(), - &rev_reg.rev_reg_id, - &cred_rev_id, - ) - .await - .unwrap(); - - rev_reg - .publish_local_revocations( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - ) - .await - .unwrap(); - - // Delta should change after revocation - let (_, second_rev_reg_delta, _) = ledger - .get_rev_reg_delta_json(&rev_reg.rev_reg_id, Some(first_timestamp + 1), None) - .await - .unwrap(); - - assert_ne!(first_rev_reg_delta, second_rev_reg_delta); - }) - .await; + .await?; + + // Delta should change after revocation + let (_, second_rev_reg_delta, _) = ledger + .get_rev_reg_delta_json(&rev_reg.rev_reg_id, Some(first_timestamp + 1), None) + .await?; + + assert_ne!(first_rev_reg_delta, second_rev_reg_delta); + Ok(()) } diff --git a/aries_vcx/tests/test_connection.rs b/aries_vcx/tests/test_connection.rs index edc5890a65..83b9c8c400 100644 --- a/aries_vcx/tests/test_connection.rs +++ b/aries_vcx/tests/test_connection.rs @@ -1,4 +1,4 @@ -pub mod utils; +use std::error::Error; use aries_vcx::{ common::ledger::transactions::write_endpoint_legacy, @@ -33,6 +33,8 @@ use crate::utils::{ test_agent::{create_test_agent, create_test_agent_trustee}, }; +pub mod utils; + fn build_basic_message(content: String) -> BasicMessage { let now = Utc::now(); @@ -120,86 +122,83 @@ async fn create_service( #[tokio::test] #[ignore] -async fn test_agency_pool_establish_connection_via_public_invite() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - create_service(&institution).await; - - let (consumer_to_institution, institution_to_consumer) = - create_connections_via_public_invite(&mut consumer, &mut institution).await; - - let basic_message = build_basic_message("Hello TestAgent".to_string()); - if let AriesMessage::BasicMessage(message) = send_and_receive_message( - &consumer, - &institution, - &institution_to_consumer, - &consumer_to_institution, - &basic_message.clone().into(), - ) - .await - { - assert_eq!(message.content.content, basic_message.content.content); - } else { - panic!("Unexpected message type"); - } - }) - .await; +async fn test_agency_pool_establish_connection_via_public_invite() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + create_service(&institution).await; + + let (consumer_to_institution, institution_to_consumer) = + create_connections_via_public_invite(&mut consumer, &mut institution).await; + + let basic_message = build_basic_message("Hello TestAgent".to_string()); + if let AriesMessage::BasicMessage(message) = send_and_receive_message( + &consumer, + &institution, + &institution_to_consumer, + &consumer_to_institution, + &basic_message.clone().into(), + ) + .await + { + assert_eq!(message.content.content, basic_message.content.content); + } else { + panic!("Unexpected message type"); + } + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_establish_connection_via_pairwise_invite() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (consumer_to_institution, institution_to_consumer) = - create_connections_via_pairwise_invite(&mut consumer, &mut institution).await; - - let basic_message = build_basic_message("Hello TestAgent".to_string()); - if let AriesMessage::BasicMessage(message) = send_and_receive_message( - &consumer, - &institution, - &institution_to_consumer, - &consumer_to_institution, - &basic_message.clone().into(), - ) - .await - { - assert_eq!(message.content.content, basic_message.content.content); - } else { - panic!("Unexpected message type"); - } - }) - .await; +async fn test_agency_pool_establish_connection_via_pairwise_invite() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (consumer_to_institution, institution_to_consumer) = + create_connections_via_pairwise_invite(&mut consumer, &mut institution).await; + + let basic_message = build_basic_message("Hello TestAgent".to_string()); + if let AriesMessage::BasicMessage(message) = send_and_receive_message( + &consumer, + &institution, + &institution_to_consumer, + &consumer_to_institution, + &basic_message.clone().into(), + ) + .await + { + assert_eq!(message.content.content, basic_message.content.content); + } else { + panic!("Unexpected message type"); + } + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_establish_connection_via_out_of_band() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - create_service(&institution).await; - - let (consumer_to_institution, institution_to_consumer) = - create_connections_via_oob_invite(&mut consumer, &mut institution).await; - - let basic_message = build_basic_message("Hello TestAgent".to_string()); - if let AriesMessage::BasicMessage(message) = send_and_receive_message( - &consumer, - &institution, - &institution_to_consumer, - &consumer_to_institution, - &basic_message.clone().into(), - ) - .await - { - assert_eq!(message.content.content, basic_message.content.content); - } else { - panic!("Unexpected message type"); - } - }) - .await; +async fn test_agency_pool_establish_connection_via_out_of_band() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + create_service(&institution).await; + + let (consumer_to_institution, institution_to_consumer) = + create_connections_via_oob_invite(&mut consumer, &mut institution).await; + + let basic_message = build_basic_message("Hello TestAgent".to_string()); + if let AriesMessage::BasicMessage(message) = send_and_receive_message( + &consumer, + &institution, + &institution_to_consumer, + &consumer_to_institution, + &basic_message.clone().into(), + ) + .await + { + assert_eq!(message.content.content, basic_message.content.content); + } else { + panic!("Unexpected message type"); + } + Ok(()) } diff --git a/aries_vcx/tests/test_credential_issuance.rs b/aries_vcx/tests/test_credential_issuance.rs index 9640679ecb..c29c87cc5f 100644 --- a/aries_vcx/tests/test_credential_issuance.rs +++ b/aries_vcx/tests/test_credential_issuance.rs @@ -1,4 +1,4 @@ -pub mod utils; +use std::error::Error; use aries_vcx::protocols::{ issuance::issuer::state_machine::IssuerState, @@ -16,244 +16,239 @@ use crate::utils::{ test_agent::{create_test_agent, create_test_agent_trustee}, }; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_agency_pool_double_issuance_issuer_is_verifier() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - let _credential_handle = exchange_credential( - &mut consumer, - &mut institution, - credential_data_address_1().to_string(), - &cred_def, - &rev_reg, - None, - ) - .await; - - let verifier = exchange_proof( - &mut institution, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); +async fn test_agency_pool_double_issuance_issuer_is_verifier() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; + let _credential_handle = exchange_credential( + &mut consumer, + &mut institution, + credential_data_address_1().to_string(), + &cred_def, + &rev_reg, + None, + ) + .await; - let verifier = exchange_proof( - &mut institution, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - }) + let verifier = exchange_proof( + &mut institution, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + let verifier = exchange_proof( + &mut institution, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) .await; + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_two_creds_one_rev_reg() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let _credential_handle1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let _credential_handle2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data_address_1().to_string(), - &cred_def, - &rev_reg, - Some("request2"), - ) - .await; +async fn test_agency_pool_two_creds_one_rev_reg() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let _credential_handle1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; - let verifier_handler = exchange_proof( - &mut verifier, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); + let _credential_handle2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data_address_1().to_string(), + &cred_def, + &rev_reg, + Some("request2"), + ) + .await; - let verifier_handler = exchange_proof( - &mut verifier, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); - }) + let verifier_handler = exchange_proof( + &mut verifier, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + let verifier_handler = exchange_proof( + &mut verifier, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_credential_exchange_via_proposal() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; +async fn test_agency_pool_credential_exchange_via_proposal() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; - exchange_credential_with_proposal( - &mut consumer, - &mut institution, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some(rev_reg.rev_reg_id.clone()), - Some(rev_reg.get_tails_dir()), - "comment", - ) - .await; - }) + exchange_credential_with_proposal( + &mut consumer, + &mut institution, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some(rev_reg.rev_reg_id.clone()), + Some(rev_reg.get_tails_dir()), + "comment", + ) .await; + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_credential_exchange_via_proposal_failed() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - - let cred_proposal = - create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); - let mut holder = create_holder_from_proposal(cred_proposal.clone()); - let mut issuer = create_issuer_from_proposal(cred_proposal.clone()); +async fn test_agency_pool_credential_exchange_via_proposal_failed() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; - let cred_offer = accept_credential_proposal( - &mut institution, - &mut issuer, - cred_proposal, - Some(rev_reg.rev_reg_id.clone()), - Some(rev_reg.get_tails_dir()), - ) - .await; - let problem_report = decline_offer(&mut consumer, cred_offer, &mut holder).await; - assert_eq!(IssuerState::OfferSet, issuer.get_state()); - issuer - .process_aries_msg(problem_report.into()) - .await - .unwrap(); - assert_eq!(IssuerState::Failed, issuer.get_state()); - }) + let cred_proposal = + create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); + let mut holder = create_holder_from_proposal(cred_proposal.clone()); + let mut issuer = create_issuer_from_proposal(cred_proposal.clone()); + + let cred_offer = accept_credential_proposal( + &mut institution, + &mut issuer, + cred_proposal, + Some(rev_reg.rev_reg_id.clone()), + Some(rev_reg.get_tails_dir()), + ) .await; + let problem_report = decline_offer(&mut consumer, cred_offer, &mut holder).await; + assert_eq!(IssuerState::OfferSet, issuer.get_state()); + issuer.process_aries_msg(problem_report.into()).await?; + assert_eq!(IssuerState::Failed, issuer.get_state()); + Ok(()) } // TODO: Maybe duplicates test_agency_pool_credential_exchange_via_proposal #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_credential_exchange_via_proposal_with_negotiation() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - - let cred_proposal = - create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); - let mut holder = create_holder_from_proposal(cred_proposal.clone()); - let mut issuer = create_issuer_from_proposal(cred_proposal.clone()); +async fn test_agency_pool_credential_exchange_via_proposal_with_negotiation( +) -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; - let cred_proposal_1 = - create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); - let cred_offer_1 = accept_credential_proposal( - &mut institution, - &mut issuer, - cred_proposal_1, - Some(rev_reg.rev_reg_id.clone()), - Some(rev_reg.get_tails_dir()), - ) - .await; + let cred_proposal = + create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); + let mut holder = create_holder_from_proposal(cred_proposal.clone()); + let mut issuer = create_issuer_from_proposal(cred_proposal.clone()); + + let cred_proposal_1 = + create_credential_proposal(&schema.schema_id, &cred_def.get_cred_def_id(), "comment"); + let cred_offer_1 = accept_credential_proposal( + &mut institution, + &mut issuer, + cred_proposal_1, + Some(rev_reg.rev_reg_id.clone()), + Some(rev_reg.get_tails_dir()), + ) + .await; - let cred_request = accept_offer(&mut consumer, cred_offer_1, &mut holder).await; + let cred_request = accept_offer(&mut consumer, cred_offer_1, &mut holder).await; - send_credential( - &mut consumer, - &mut institution, - &mut issuer, - &mut holder, - cred_request, - true, - ) - .await; - }) + send_credential( + &mut consumer, + &mut institution, + &mut issuer, + &mut holder, + cred_request, + true, + ) .await; + Ok(()) } diff --git a/aries_vcx/tests/test_credential_retrieval.rs b/aries_vcx/tests/test_credential_retrieval.rs index 13c3a8af1c..86504647bb 100644 --- a/aries_vcx/tests/test_credential_retrieval.rs +++ b/aries_vcx/tests/test_credential_retrieval.rs @@ -1,7 +1,5 @@ #![allow(clippy::diverging_sub_expression)] -pub mod utils; - use std::{collections::HashMap, error::Error}; use aries_vcx::{ @@ -20,308 +18,250 @@ use messages::{ }, }; use serde_json::json; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile, run_setup_test}; +use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile}; use crate::utils::{ create_and_write_credential, create_and_write_test_cred_def, create_and_write_test_schema, }; +pub mod utils; + #[tokio::test] #[ignore] // TODO: This should be a unit test async fn test_agency_pool_retrieve_credentials_empty() -> Result<(), Box> { - build_setup_profile() - .await - .run2(|setup| async move { - let pres_req_data = PresentationRequestData { - nonce: "123432421212".into(), - name: "proof_req_1".into(), - data_version: "0.1".into(), - requested_attributes: serde_json::from_value(json!({}))?, - requested_predicates: serde_json::from_value(json!({}))?, - non_revoked: None, - }; - - let attach_type = AttachmentType::Base64( - general_purpose::STANDARD.encode(json!(pres_req_data).to_string()), - ); - let attach_data = AttachmentData::builder().content(attach_type).build(); - let attach = Attachment::builder() - .data(attach_data) - .id(AttachmentId::PresentationRequest.as_ref().to_owned()) - .mime_type(MimeType::Json) - .build(); - - let content = RequestPresentationV1Content::builder() - .request_presentations_attach(vec![attach]) - .build(); - - // test retrieving credentials for empty proof request returns "{}" - let id = "test_id".to_owned(); - let proof_req = RequestPresentationV1::builder() - .id(id) - .content(content) - .build(); - let proof: Prover = Prover::create_from_request("1", proof_req)?; - - let retrieved_creds = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await?; - assert_eq!(serde_json::to_string(&retrieved_creds)?, "{}".to_string()); - assert!(retrieved_creds.credentials_by_referent.is_empty()); - - // populate proof request with a single attribute referent request - let pres_req_data = PresentationRequestData { - nonce: "123432421212".into(), - name: "proof_req_1".into(), - data_version: "0.1".into(), - requested_attributes: serde_json::from_value( - json!({ "address1_1": {"name": "address1"} }), - )?, - requested_predicates: serde_json::from_value(json!({}))?, - non_revoked: None, - }; - - let attach_type = AttachmentType::Base64( - general_purpose::STANDARD.encode(json!(pres_req_data).to_string()), - ); - let attach_data = AttachmentData::builder().content(attach_type).build(); - let attach = Attachment::builder() - .data(attach_data) - .id(AttachmentId::PresentationRequest.as_ref().to_owned()) - .mime_type(MimeType::Json) - .build(); - - let content = RequestPresentationV1Content::builder() - .request_presentations_attach(vec![attach]) - .build(); + let setup = build_setup_profile().await; + let pres_req_data = PresentationRequestData { + nonce: "123432421212".into(), + name: "proof_req_1".into(), + data_version: "0.1".into(), + requested_attributes: serde_json::from_value(json!({}))?, + requested_predicates: serde_json::from_value(json!({}))?, + non_revoked: None, + }; - // test retrieving credentials for the proof request returns the referent with no cred - // matches - let id = "test_id".to_owned(); - let proof_req = RequestPresentationV1::builder() - .id(id) - .content(content) - .build(); - let proof: Prover = Prover::create_from_request("2", proof_req)?; + let attach_type = + AttachmentType::Base64(general_purpose::STANDARD.encode(json!(pres_req_data).to_string())); + let attach_data = AttachmentData::builder().content(attach_type).build(); + let attach = Attachment::builder() + .data(attach_data) + .id(AttachmentId::PresentationRequest.as_ref().to_owned()) + .mime_type(MimeType::Json) + .build(); + + let content = RequestPresentationV1Content::builder() + .request_presentations_attach(vec![attach]) + .build(); + + // test retrieving credentials for empty proof request returns "{}" + let id = "test_id".to_owned(); + let proof_req = RequestPresentationV1::builder() + .id(id) + .content(content) + .build(); + let proof: Prover = Prover::create_from_request("1", proof_req)?; + + let retrieved_creds = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + assert_eq!(serde_json::to_string(&retrieved_creds)?, "{}".to_string()); + assert!(retrieved_creds.credentials_by_referent.is_empty()); + + // populate proof request with a single attribute referent request + let pres_req_data = PresentationRequestData { + nonce: "123432421212".into(), + name: "proof_req_1".into(), + data_version: "0.1".into(), + requested_attributes: serde_json::from_value( + json!({ "address1_1": {"name": "address1"} }), + )?, + requested_predicates: serde_json::from_value(json!({}))?, + non_revoked: None, + }; - let retrieved_creds = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await?; - assert_eq!( - serde_json::to_string(&retrieved_creds)?, - json!({"attrs":{"address1_1":[]}}).to_string() - ); - assert_eq!( - retrieved_creds, - RetrievedCredentials { - credentials_by_referent: HashMap::from([("address1_1".to_string(), vec![])]) - } - ); - Ok(()) - }) - .await + let attach_type = + AttachmentType::Base64(general_purpose::STANDARD.encode(json!(pres_req_data).to_string())); + let attach_data = AttachmentData::builder().content(attach_type).build(); + let attach = Attachment::builder() + .data(attach_data) + .id(AttachmentId::PresentationRequest.as_ref().to_owned()) + .mime_type(MimeType::Json) + .build(); + + let content = RequestPresentationV1Content::builder() + .request_presentations_attach(vec![attach]) + .build(); + + // test retrieving credentials for the proof request returns the referent with no cred + // matches + let id = "test_id".to_owned(); + let proof_req = RequestPresentationV1::builder() + .id(id) + .content(content) + .build(); + let proof: Prover = Prover::create_from_request("2", proof_req)?; + + let retrieved_creds = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + assert_eq!( + serde_json::to_string(&retrieved_creds)?, + json!({"attrs":{"address1_1":[]}}).to_string() + ); + assert_eq!( + retrieved_creds, + RetrievedCredentials { + credentials_by_referent: HashMap::from([("address1_1".to_string(), vec![])]) + } + ); + Ok(()) } #[tokio::test] #[ignore] // TODO: This should be a unit test -async fn test_agency_pool_case_for_proof_req_doesnt_matter_for_retrieve_creds() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let cred_def = create_and_write_test_cred_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &schema.schema_id, - true, - ) - .await; - create_and_write_credential( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.institution_did, - &cred_def, - None, - ) - .await; - - let mut req = json!({ - "nonce":"123432421212", - "name":"proof_req_1", - "version":"0.1", - "requested_attributes": json!({ - "zip_1": json!({ - "name":"zip", - "restrictions": [json!({ "issuer_did": setup.institution_did })] - }) - }), - "requested_predicates": json!({}), - }); - - let pres_req_data: PresentationRequestData = - serde_json::from_str(&req.to_string()).unwrap(); - let id = "test_id".to_owned(); - - let attach_type = AttachmentType::Base64( - general_purpose::STANDARD.encode(json!(pres_req_data).to_string()), - ); - let attach_data = AttachmentData::builder().content(attach_type).build(); - let attach = Attachment::builder() - .data(attach_data) - .id(AttachmentId::PresentationRequest.as_ref().to_owned()) - .mime_type(MimeType::Json) - .build(); - - let content = RequestPresentationV1Content::builder() - .request_presentations_attach(vec![attach]) - .build(); - - let proof_req = RequestPresentationV1::builder() - .id(id) - .content(content) - .build(); - let proof: Prover = Prover::create_from_request("1", proof_req).unwrap(); - - // All lower case - let retrieved_creds = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await - .unwrap(); - assert_eq!( - retrieved_creds.credentials_by_referent["zip_1"][0] - .cred_info - .attributes["zip"], - "84000" - ); - - // First letter upper - req["requested_attributes"]["zip_1"]["name"] = json!("Zip"); - let pres_req_data: PresentationRequestData = - serde_json::from_str(&req.to_string()).unwrap(); - let id = "test_id".to_owned(); - - let attach_type = AttachmentType::Base64( - general_purpose::STANDARD.encode(json!(pres_req_data).to_string()), - ); - let attach_data = AttachmentData::builder().content(attach_type).build(); - let attach = Attachment::builder() - .data(attach_data) - .id(AttachmentId::PresentationRequest.as_ref().to_owned()) - .mime_type(MimeType::Json) - .build(); - - let content = RequestPresentationV1Content::builder() - .request_presentations_attach(vec![attach]) - .build(); - - let proof_req = RequestPresentationV1::builder() - .id(id) - .content(content) - .build(); - let proof: Prover = Prover::create_from_request("2", proof_req).unwrap(); - let retrieved_creds2 = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await - .unwrap(); - assert_eq!( - retrieved_creds2.credentials_by_referent["zip_1"][0] - .cred_info - .attributes["zip"], - "84000" - ); - - // Entire word upper - req["requested_attributes"]["zip_1"]["name"] = json!("ZIP"); - let pres_req_data: PresentationRequestData = - serde_json::from_str(&req.to_string()).unwrap(); - let id = "test_id".to_owned(); - - let attach_type = AttachmentType::Base64( - general_purpose::STANDARD.encode(json!(pres_req_data).to_string()), - ); - let attach_data = AttachmentData::builder().content(attach_type).build(); - let attach = Attachment::builder() - .data(attach_data) - .id(AttachmentId::PresentationRequest.as_ref().to_owned()) - .mime_type(MimeType::Json) - .build(); - - let content = RequestPresentationV1Content::builder() - .request_presentations_attach(vec![attach]) - .build(); - - let proof_req = RequestPresentationV1::builder() - .id(id) - .content(content) - .build(); - let proof: Prover = Prover::create_from_request("1", proof_req).unwrap(); - let retrieved_creds3 = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await - .unwrap(); - assert_eq!( - retrieved_creds3.credentials_by_referent["zip_1"][0] - .cred_info - .attributes["zip"], - "84000" - ); - }) +async fn test_agency_pool_case_for_proof_req_doesnt_matter_for_retrieve_creds( +) -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) .await; -} - -// todo: credx implementation does not support checking credential value in respect to predicate -#[cfg(not(feature = "credx"))] -#[tokio::test] -#[ignore] -#[allow(unused_mut)] -async fn test_agency_pool_it_should_fail_to_select_credentials_for_predicate() { - use test_utils::devsetup::SetupPoolDirectory; - use utils::{ - scenarios::prover_select_credentials, - test_agent::{create_test_agent, create_test_agent_trustee}, - }; - - use crate::utils::scenarios::{ - create_proof_request_data, create_prover_from_request, create_verifier_from_request_data, - issue_address_credential, - }; - - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - issue_address_credential(&mut consumer, &mut institution).await; - - let requested_preds_string = serde_json::to_string(&json!([{ - "name": "zip", - "p_type": ">=", - "p_value": 85000 - }])) - .unwrap(); - - let presentation_request_data = - create_proof_request_data(&mut institution, "[]", &requested_preds_string, "{}", None) - .await; - let mut verifier = create_verifier_from_request_data(presentation_request_data).await; - - let presentation_request = verifier.get_presentation_request_msg().unwrap(); - let mut prover = create_prover_from_request(presentation_request.clone()).await; - let selected_credentials = - prover_select_credentials(&mut prover, &mut consumer, presentation_request, None).await; - - assert!(selected_credentials.credential_for_referent.is_empty()); - }) + let cred_def = create_and_write_test_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &schema.schema_id, + true, + ) .await; + create_and_write_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.institution_did, + &cred_def, + None, + ) + .await; + + let mut req = json!({ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attributes": json!({ + "zip_1": json!({ + "name":"zip", + "restrictions": [json!({ "issuer_did": setup.institution_did })] + }) + }), + "requested_predicates": json!({}), + }); + + let pres_req_data: PresentationRequestData = serde_json::from_str(&req.to_string())?; + let id = "test_id".to_owned(); + + let attach_type = + AttachmentType::Base64(general_purpose::STANDARD.encode(json!(pres_req_data).to_string())); + let attach_data = AttachmentData::builder().content(attach_type).build(); + let attach = Attachment::builder() + .data(attach_data) + .id(AttachmentId::PresentationRequest.as_ref().to_owned()) + .mime_type(MimeType::Json) + .build(); + + let content = RequestPresentationV1Content::builder() + .request_presentations_attach(vec![attach]) + .build(); + + let proof_req = RequestPresentationV1::builder() + .id(id) + .content(content) + .build(); + let proof: Prover = Prover::create_from_request("1", proof_req)?; + + // All lower case + let retrieved_creds = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + assert_eq!( + retrieved_creds.credentials_by_referent["zip_1"][0] + .cred_info + .attributes["zip"], + "84000" + ); + + // First letter upper + req["requested_attributes"]["zip_1"]["name"] = json!("Zip"); + let pres_req_data: PresentationRequestData = serde_json::from_str(&req.to_string())?; + let id = "test_id".to_owned(); + + let attach_type = + AttachmentType::Base64(general_purpose::STANDARD.encode(json!(pres_req_data).to_string())); + let attach_data = AttachmentData::builder().content(attach_type).build(); + let attach = Attachment::builder() + .data(attach_data) + .id(AttachmentId::PresentationRequest.as_ref().to_owned()) + .mime_type(MimeType::Json) + .build(); + + let content = RequestPresentationV1Content::builder() + .request_presentations_attach(vec![attach]) + .build(); + + let proof_req = RequestPresentationV1::builder() + .id(id) + .content(content) + .build(); + let proof: Prover = Prover::create_from_request("2", proof_req)?; + let retrieved_creds2 = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + assert_eq!( + retrieved_creds2.credentials_by_referent["zip_1"][0] + .cred_info + .attributes["zip"], + "84000" + ); + + // Entire word upper + req["requested_attributes"]["zip_1"]["name"] = json!("ZIP"); + let pres_req_data: PresentationRequestData = serde_json::from_str(&req.to_string())?; + let id = "test_id".to_owned(); + + let attach_type = + AttachmentType::Base64(general_purpose::STANDARD.encode(json!(pres_req_data).to_string())); + let attach_data = AttachmentData::builder().content(attach_type).build(); + let attach = Attachment::builder() + .data(attach_data) + .id(AttachmentId::PresentationRequest.as_ref().to_owned()) + .mime_type(MimeType::Json) + .build(); + + let content = RequestPresentationV1Content::builder() + .request_presentations_attach(vec![attach]) + .build(); + + let proof_req = RequestPresentationV1::builder() + .id(id) + .content(content) + .build(); + let proof: Prover = Prover::create_from_request("1", proof_req)?; + let retrieved_creds3 = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + assert_eq!( + retrieved_creds3.credentials_by_referent["zip_1"][0] + .cred_info + .attributes["zip"], + "84000" + ); + Ok(()) } diff --git a/aries_vcx/tests/test_credentials.rs b/aries_vcx/tests/test_credentials.rs index 3b4560b557..82c8e5ac9b 100644 --- a/aries_vcx/tests/test_credentials.rs +++ b/aries_vcx/tests/test_credentials.rs @@ -1,150 +1,135 @@ -pub mod utils; +use std::error::Error; use aries_vcx::common::credentials::{get_cred_rev_id, is_cred_revoked, ProverCredential}; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, run_setup_test}; +use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile}; use crate::utils::{ create_and_publish_test_rev_reg, create_and_write_credential, create_and_write_test_cred_def, create_and_write_test_schema, }; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_pool_prover_get_credential() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let cred_def = create_and_write_test_cred_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &schema.schema_id, - true, - ) - .await; - let rev_reg = create_and_publish_test_rev_reg( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - &cred_def.get_cred_def_id(), - ) - .await; - let cred_id = create_and_write_credential( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.institution_did, - &cred_def, - Some(&rev_reg), - ) - .await; - let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id) - .await - .unwrap(); +async fn test_pool_prover_get_credential() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def = create_and_write_test_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &schema.schema_id, + true, + ) + .await; + let rev_reg = create_and_publish_test_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + &cred_def.get_cred_def_id(), + ) + .await; + let cred_id = create_and_write_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.institution_did, + &cred_def, + Some(&rev_reg), + ) + .await; + let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id).await?; - let cred_json = setup - .anoncreds - .prover_get_credential(&setup.wallet, &cred_id) - .await - .unwrap(); - let prover_cred = serde_json::from_str::(&cred_json).unwrap(); + let cred_json = setup + .anoncreds + .prover_get_credential(&setup.wallet, &cred_id) + .await?; + let prover_cred = serde_json::from_str::(&cred_json)?; - assert_eq!(prover_cred.schema_id, schema.schema_id); - assert_eq!(prover_cred.cred_def_id, cred_def.get_cred_def_id()); - assert_eq!(prover_cred.cred_rev_id.unwrap(), cred_rev_id); - assert_eq!(prover_cred.rev_reg_id.unwrap(), rev_reg.rev_reg_id); - }) - .await; + assert_eq!(prover_cred.schema_id, schema.schema_id); + assert_eq!(prover_cred.cred_def_id, cred_def.get_cred_def_id()); + assert_eq!(prover_cred.cred_rev_id.unwrap(), cred_rev_id); + assert_eq!(prover_cred.rev_reg_id.unwrap(), rev_reg.rev_reg_id); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_is_cred_revoked() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let cred_def = create_and_write_test_cred_def( +async fn test_pool_is_cred_revoked() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def = create_and_write_test_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &schema.schema_id, + true, + ) + .await; + let rev_reg = create_and_publish_test_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + &cred_def.get_cred_def_id(), + ) + .await; + let cred_id = create_and_write_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.institution_did, + &cred_def, + Some(&rev_reg), + ) + .await; + let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id).await?; + + assert!(!is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id).await?); + + setup + .anoncreds + .revoke_credential_local( &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &schema.schema_id, - true, + &rev_reg.get_tails_dir(), + &rev_reg.rev_reg_id, + &cred_rev_id, ) - .await; - let rev_reg = create_and_publish_test_rev_reg( + .await?; + rev_reg + .publish_local_revocations( &setup.wallet, &setup.anoncreds, &setup.ledger_write, &setup.institution_did, - &cred_def.get_cred_def_id(), ) - .await; - let cred_id = create_and_write_credential( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.institution_did, - &cred_def, - Some(&rev_reg), - ) - .await; - let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id) - .await - .unwrap(); + .await?; - assert!( - !is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id) - .await - .unwrap() - ); + std::thread::sleep(std::time::Duration::from_millis(500)); - setup - .anoncreds - .revoke_credential_local( - &setup.wallet, - &rev_reg.get_tails_dir(), - &rev_reg.rev_reg_id, - &cred_rev_id, - ) - .await - .unwrap(); - rev_reg - .publish_local_revocations( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - ) - .await - .unwrap(); - - std::thread::sleep(std::time::Duration::from_millis(500)); - - assert!( - is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id) - .await - .unwrap() - ); - }) - .await; + assert!(is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id).await?); + Ok(()) } diff --git a/aries_vcx/tests/test_mysql_wallet.rs b/aries_vcx/tests/test_mysql_wallet.rs index d4eb47feec..f54ac90de9 100644 --- a/aries_vcx/tests/test_mysql_wallet.rs +++ b/aries_vcx/tests/test_mysql_wallet.rs @@ -3,6 +3,8 @@ extern crate serde_json; #[cfg(test)] mod dbtests { + use std::error::Error; + use aries_vcx::global::settings; use aries_vcx_core::wallet::{ base_wallet::BaseWallet, @@ -15,7 +17,7 @@ mod dbtests { #[tokio::test] #[ignore] - async fn test_mysql_init_issuer_with_mysql_wallet() { + async fn test_mysql_init_issuer_with_mysql_wallet() -> Result<(), Box> { LibvcxDefaultLogger::init_testing_logger(); let db_name = format!("mysqltest_{}", uuid::Uuid::new_v4()).replace('-', "_"); let storage_config = json!({ @@ -39,18 +41,15 @@ mod dbtests { .wallet_type("mysql") .storage_config(storage_config) .storage_credentials(storage_credentials) - .build() - .unwrap(); + .build()?; - let wallet_handle = create_and_open_wallet(&config_wallet).await.unwrap(); - let _config_issuer = wallet_configure_issuer(wallet_handle, enterprise_seed) - .await - .unwrap(); + let wallet_handle = create_and_open_wallet(&config_wallet).await?; + let _config_issuer = wallet_configure_issuer(wallet_handle, enterprise_seed).await?; let (_, _) = IndySdkWallet::new(wallet_handle) .create_and_store_my_did(None, None) - .await - .unwrap(); - close_wallet(wallet_handle).await.unwrap(); + .await?; + close_wallet(wallet_handle).await?; + Ok(()) } } diff --git a/aries_vcx/tests/test_pool.rs b/aries_vcx/tests/test_pool.rs index d5bcbeff3c..64858e401b 100644 --- a/aries_vcx/tests/test_pool.rs +++ b/aries_vcx/tests/test_pool.rs @@ -1,7 +1,6 @@ #![allow(clippy::diverging_sub_expression)] -pub mod utils; -use std::{thread, time::Duration}; +use std::{error::Error, thread, time::Duration}; use aries_vcx::{ common::{ @@ -34,8 +33,7 @@ use diddoc_legacy::aries::service::AriesService; use serde_json::json; use test_utils::{ constants::{DEFAULT_SCHEMA_ATTRS, TEST_TAILS_URL}, - devsetup::SetupPoolDirectory, - run_setup_test, + devsetup::{build_setup_profile, SetupPoolDirectory}, }; use crate::utils::{ @@ -44,6 +42,8 @@ use crate::utils::{ test_agent::{create_test_agent, create_test_agent_trustee}, }; +pub mod utils; + // TODO: Deduplicate with create_and_store_revocable_credential_def async fn create_and_store_nonrevocable_credential_def( wallet: &impl BaseWallet, @@ -52,7 +52,7 @@ async fn create_and_store_nonrevocable_credential_def( ledger_write: &impl AnoncredsLedgerWrite, issuer_did: &str, attr_list: &str, -) -> (String, String, String, String, CredentialDef) { +) -> Result<(String, String, String, String, CredentialDef), Box> { let schema = create_and_write_test_schema(wallet, anoncreds, ledger_write, issuer_did, attr_list).await; let cred_def = create_and_write_test_cred_def( @@ -68,14 +68,14 @@ async fn create_and_store_nonrevocable_credential_def( tokio::time::sleep(Duration::from_millis(1000)).await; let cred_def_id = cred_def.get_cred_def_id(); - let cred_def_json = ledger_read.get_cred_def(&cred_def_id, None).await.unwrap(); - ( + let cred_def_json = ledger_read.get_cred_def(&cred_def_id, None).await?; + Ok(( schema.schema_id, schema.schema_json, cred_def_id, cred_def_json, cred_def, - ) + )) } // TODO: Deduplicate with create_and_store_nonrevocable_credential_def @@ -86,7 +86,7 @@ async fn create_and_store_revocable_credential_def( ledger_write: &impl AnoncredsLedgerWrite, issuer_did: &str, attr_list: &str, -) -> (Schema, CredentialDef, RevocationRegistry) { +) -> Result<(Schema, CredentialDef, RevocationRegistry), Box> { let schema = create_and_write_test_schema(wallet, anoncreds, ledger_write, issuer_did, attr_list).await; let cred_def = create_and_write_test_cred_def( @@ -108,471 +108,407 @@ async fn create_and_store_revocable_credential_def( ) .await; tokio::time::sleep(Duration::from_millis(1000)).await; - - (schema, cred_def, rev_reg) + Ok((schema, cred_def, rev_reg)) } #[tokio::test] #[ignore] -async fn test_pool_rotate_verkey() { - run_setup_test!(|setup| async move { - let (did, verkey) = add_new_did( - &setup.wallet, - &setup.ledger_write, - &setup.institution_did, - None, - ) - .await - .unwrap(); - rotate_verkey(&setup.wallet, &setup.ledger_write, &did) - .await - .unwrap(); - tokio::time::sleep(Duration::from_millis(1000)).await; - let local_verkey = setup.wallet.key_for_local_did(&did).await.unwrap(); - - let ledger_verkey = get_verkey_from_ledger(&setup.ledger_read, &did) - .await - .unwrap(); - assert_ne!(verkey, ledger_verkey); - assert_eq!(local_verkey, ledger_verkey); - }) - .await; +async fn test_pool_rotate_verkey() -> Result<(), Box> { + let setup = build_setup_profile().await; + let (did, verkey) = add_new_did( + &setup.wallet, + &setup.ledger_write, + &setup.institution_did, + None, + ) + .await?; + rotate_verkey(&setup.wallet, &setup.ledger_write, &did).await?; + tokio::time::sleep(Duration::from_millis(1000)).await; + let local_verkey = setup.wallet.key_for_local_did(&did).await?; + + let ledger_verkey = get_verkey_from_ledger(&setup.ledger_read, &did).await?; + assert_ne!(verkey, ledger_verkey); + assert_eq!(local_verkey, ledger_verkey); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_add_get_service() { - run_setup_test!(|setup| async move { - let did = setup.institution_did.clone(); - let expect_service = AriesService::default(); - write_endpoint_legacy(&setup.wallet, &setup.ledger_write, &did, &expect_service) - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - assert_eq!(expect_service, service); - - // clean up written legacy service - clear_attr( - &setup.wallet, - &setup.ledger_write, - &setup.institution_did, - "service", - ) - .await - .unwrap(); - }) - .await; +async fn test_pool_add_get_service() -> Result<(), Box> { + let setup = build_setup_profile().await; + let did = setup.institution_did.clone(); + let expect_service = AriesService::default(); + write_endpoint_legacy(&setup.wallet, &setup.ledger_write, &did, &expect_service).await?; + thread::sleep(Duration::from_millis(50)); + let service = get_service(&setup.ledger_read, &did).await?; + assert_eq!(expect_service, service); + + // clean up written legacy service + clear_attr( + &setup.wallet, + &setup.ledger_write, + &setup.institution_did, + "service", + ) + .await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_write_new_endorser_did() { - SetupPoolDirectory::run(|setup| async move { - let faber = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let acme = create_test_agent(setup.genesis_file_path.clone()).await; - let acme_vk = - get_verkey_from_wallet(acme.wallet.get_wallet_handle(), &acme.institution_did) - .await - .unwrap(); - - let attrib_json = json!({ "attrib_name": "foo"}).to_string(); - assert!(add_attr( - &acme.wallet, - &acme.ledger_write, - &acme.institution_did, - &attrib_json - ) - .await - .is_err()); - write_endorser_did( - &faber.wallet, - &faber.ledger_write, - &faber.institution_did, - &acme.institution_did, - &acme_vk, - None, - ) - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - add_attr( - &acme.wallet, - &acme.ledger_write, - &acme.institution_did, - &attrib_json, - ) - .await - .unwrap(); - }) - .await; +async fn test_pool_write_new_endorser_did() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let faber = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let acme = create_test_agent(setup.genesis_file_path.clone()).await; + let acme_vk = + get_verkey_from_wallet(acme.wallet.get_wallet_handle(), &acme.institution_did).await?; + + let attrib_json = json!({ "attrib_name": "foo"}).to_string(); + assert!(add_attr( + &acme.wallet, + &acme.ledger_write, + &acme.institution_did, + &attrib_json, + ) + .await + .is_err()); + write_endorser_did( + &faber.wallet, + &faber.ledger_write, + &faber.institution_did, + &acme.institution_did, + &acme_vk, + None, + ) + .await?; + thread::sleep(Duration::from_millis(50)); + add_attr( + &acme.wallet, + &acme.ledger_write, + &acme.institution_did, + &attrib_json, + ) + .await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_add_get_service_public() { - run_setup_test!(|setup| async move { - let did = setup.institution_did.clone(); - let create_service = EndpointDidSov::create() - .set_service_endpoint("https://example.org".parse().unwrap()) - .set_routing_keys(Some(vec!["did:sov:456".into()])); - write_endpoint(&setup.wallet, &setup.ledger_write, &did, &create_service) - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - let expect_recipient_key = - get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did) - .await - .unwrap(); - let expect_service = AriesService::default() - .set_service_endpoint("https://example.org".parse().unwrap()) - .set_recipient_keys(vec![expect_recipient_key]) - .set_routing_keys(vec!["did:sov:456".into()]); - assert_eq!(expect_service, service); - - // clean up written endpoint - clear_attr( - &setup.wallet, - &setup.ledger_write, - &setup.institution_did, - "endpoint", - ) - .await - .unwrap(); - }) - .await; +async fn test_pool_add_get_service_public() -> Result<(), Box> { + let setup = build_setup_profile().await; + let did = setup.institution_did.clone(); + let create_service = EndpointDidSov::create() + .set_service_endpoint("https://example.org".parse()?) + .set_routing_keys(Some(vec!["did:sov:456".into()])); + write_endpoint(&setup.wallet, &setup.ledger_write, &did, &create_service).await?; + thread::sleep(Duration::from_millis(50)); + let service = get_service(&setup.ledger_read, &did).await?; + let expect_recipient_key = + get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did).await?; + let expect_service = AriesService::default() + .set_service_endpoint("https://example.org".parse()?) + .set_recipient_keys(vec![expect_recipient_key]) + .set_routing_keys(vec!["did:sov:456".into()]); + assert_eq!(expect_service, service); + + // clean up written endpoint + clear_attr( + &setup.wallet, + &setup.ledger_write, + &setup.institution_did, + "endpoint", + ) + .await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_add_get_service_public_none_routing_keys() { - run_setup_test!(|setup| async move { - let did = setup.institution_did.clone(); - let create_service = EndpointDidSov::create() - .set_service_endpoint("https://example.org".parse().unwrap()) - .set_routing_keys(None); - write_endpoint(&setup.wallet, &setup.ledger_write, &did, &create_service) - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - let expect_recipient_key = - get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did) - .await - .unwrap(); - let expect_service = AriesService::default() - .set_service_endpoint("https://example.org".parse().unwrap()) - .set_recipient_keys(vec![expect_recipient_key]) - .set_routing_keys(vec![]); - assert_eq!(expect_service, service); - - // clean up written endpoint - clear_attr( - &setup.wallet, - &setup.ledger_write, - &setup.institution_did, - "endpoint", - ) - .await - .unwrap(); - }) - .await; +async fn test_pool_add_get_service_public_none_routing_keys() -> Result<(), Box> { + let setup = build_setup_profile().await; + let did = setup.institution_did.clone(); + let create_service = EndpointDidSov::create() + .set_service_endpoint("https://example.org".parse()?) + .set_routing_keys(None); + write_endpoint(&setup.wallet, &setup.ledger_write, &did, &create_service).await?; + thread::sleep(Duration::from_millis(50)); + let service = get_service(&setup.ledger_read, &did).await?; + let expect_recipient_key = + get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did).await?; + let expect_service = AriesService::default() + .set_service_endpoint("https://example.org".parse()?) + .set_recipient_keys(vec![expect_recipient_key]) + .set_routing_keys(vec![]); + assert_eq!(expect_service, service); + + // clean up written endpoint + clear_attr( + &setup.wallet, + &setup.ledger_write, + &setup.institution_did, + "endpoint", + ) + .await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_multiple_service_formats() { - run_setup_test!(|setup| async move { - let did = setup.institution_did.clone(); - - // Write legacy service format - let service_1 = AriesService::create() - .set_service_endpoint("https://example1.org".parse().unwrap()) - .set_recipient_keys(vec!["did:sov:123".into()]) - .set_routing_keys(vec!["did:sov:456".into()]); - write_endpoint_legacy(&setup.wallet, &setup.ledger_write, &did, &service_1) - .await - .unwrap(); - - // Get service and verify it is in the old format - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - assert_eq!(service_1, service); - - // Write new service format - let endpoint_url_2 = "https://example2.org"; - let routing_keys_2 = vec![]; - let service_2 = EndpointDidSov::create() - .set_service_endpoint(endpoint_url_2.parse().unwrap()) - .set_routing_keys(Some(routing_keys_2.clone())); - write_endpoint(&setup.wallet, &setup.ledger_write, &did, &service_2) - .await - .unwrap(); - - thread::sleep(Duration::from_millis(50)); - - // Get service and verify it is in the new format - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - let expect_recipient_key = - get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did) - .await - .unwrap(); - let expect_service = AriesService::default() - .set_service_endpoint(endpoint_url_2.parse().unwrap()) - .set_recipient_keys(vec![expect_recipient_key]) - .set_routing_keys(routing_keys_2); - assert_eq!(expect_service, service); - - // Clear up written endpoint - clear_attr( - &setup.wallet, - &setup.ledger_write, - &setup.institution_did, - "endpoint", - ) - .await - .unwrap(); +async fn test_pool_multiple_service_formats() -> Result<(), Box> { + let setup = build_setup_profile().await; + let did = setup.institution_did.clone(); + + // Write legacy service format + let service_1 = AriesService::create() + .set_service_endpoint("https://example1.org".parse()?) + .set_recipient_keys(vec!["did:sov:123".into()]) + .set_routing_keys(vec!["did:sov:456".into()]); + write_endpoint_legacy(&setup.wallet, &setup.ledger_write, &did, &service_1).await?; + + // Get service and verify it is in the old format + let service = get_service(&setup.ledger_read, &did).await?; + assert_eq!(service_1, service); + + // Write new service format + let endpoint_url_2 = "https://example2.org"; + let routing_keys_2 = vec![]; + let service_2 = EndpointDidSov::create() + .set_service_endpoint(endpoint_url_2.parse()?) + .set_routing_keys(Some(routing_keys_2.clone())); + write_endpoint(&setup.wallet, &setup.ledger_write, &did, &service_2).await?; + + thread::sleep(Duration::from_millis(50)); + + // Get service and verify it is in the new format + let service = get_service(&setup.ledger_read, &did).await?; + let expect_recipient_key = + get_verkey_from_ledger(&setup.ledger_read, &setup.institution_did).await?; + let expect_service = AriesService::default() + .set_service_endpoint(endpoint_url_2.parse()?) + .set_recipient_keys(vec![expect_recipient_key]) + .set_routing_keys(routing_keys_2); + assert_eq!(expect_service, service); + + // Clear up written endpoint + clear_attr( + &setup.wallet, + &setup.ledger_write, + &setup.institution_did, + "endpoint", + ) + .await?; - thread::sleep(Duration::from_millis(50)); + thread::sleep(Duration::from_millis(50)); - // Get service and verify it is in the old format - let service = get_service(&setup.ledger_read, &did).await.unwrap(); - assert_eq!(service_1, service); - }) - .await; + // Get service and verify it is in the old format + let service = get_service(&setup.ledger_read, &did).await?; + assert_eq!(service_1, service); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_add_get_attr() { - run_setup_test!(|setup| async move { - let did = setup.institution_did.clone(); - let attr_json = json!({ - "attr_json": { - "attr_key_1": "attr_value_1", - "attr_key_2": "attr_value_2", - } - }); - add_attr( - &setup.wallet, - &setup.ledger_write, - &did, - &attr_json.to_string(), - ) - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - let attr = get_attr(&setup.ledger_read, &did, "attr_json") - .await - .unwrap(); - assert_eq!(attr, attr_json["attr_json"].to_string()); - - clear_attr(&setup.wallet, &setup.ledger_write, &did, "attr_json") - .await - .unwrap(); - thread::sleep(Duration::from_millis(50)); - let attr = get_attr(&setup.ledger_read, &did, "attr_json") - .await - .unwrap(); - assert_eq!(attr, ""); - - let attr = get_attr(&setup.ledger_read, &did, "nonexistent") - .await - .unwrap(); - assert_eq!(attr, ""); - }) - .await; +async fn test_pool_add_get_attr() -> Result<(), Box> { + let setup = build_setup_profile().await; + let did = setup.institution_did.clone(); + let attr_json = json!({ + "attr_json": { + "attr_key_1": "attr_value_1", + "attr_key_2": "attr_value_2", + } + }); + add_attr( + &setup.wallet, + &setup.ledger_write, + &did, + &attr_json.to_string(), + ) + .await?; + thread::sleep(Duration::from_millis(50)); + let attr = get_attr(&setup.ledger_read, &did, "attr_json").await?; + assert_eq!(attr, attr_json["attr_json"].to_string()); + + clear_attr(&setup.wallet, &setup.ledger_write, &did, "attr_json").await?; + thread::sleep(Duration::from_millis(50)); + let attr = get_attr(&setup.ledger_read, &did, "attr_json").await?; + assert_eq!(attr, ""); + + let attr = get_attr(&setup.ledger_read, &did, "nonexistent").await?; + assert_eq!(attr, ""); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_get_credential_def() { - run_setup_test!(|setup| async move { - let (_, _, cred_def_id, cred_def_json, _) = create_and_store_nonrevocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; +async fn test_agency_pool_get_credential_def() -> Result<(), Box> { + let setup = build_setup_profile().await; + let (_, _, cred_def_id, cred_def_json, _) = create_and_store_nonrevocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await?; - let ledger = &setup.ledger_read; - let r_cred_def_json = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); + let ledger = &setup.ledger_read; + let r_cred_def_json = ledger.get_cred_def(&cred_def_id, None).await?; - let def1: serde_json::Value = serde_json::from_str(&cred_def_json).unwrap(); - let def2: serde_json::Value = serde_json::from_str(&r_cred_def_json).unwrap(); - assert_eq!(def1, def2); - }) - .await; + let def1: serde_json::Value = serde_json::from_str(&cred_def_json)?; + let def2: serde_json::Value = serde_json::from_str(&r_cred_def_json)?; + assert_eq!(def1, def2); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_rev_reg_def_fails_for_cred_def_created_without_revocation() { - run_setup_test!(|setup| async move { - // Cred def is created with support_revocation=false, - // revoc_reg_def will fail in libindy because cred_Def doesn't have revocation keys - let (_, _, cred_def_id, _, _) = create_and_store_nonrevocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - - let rc = generate_rev_reg( - &setup.wallet, - &setup.anoncreds, - &setup.institution_did, - &cred_def_id, - get_temp_file_path("path.txt").to_str().unwrap(), - 2, - "tag1", - ) - .await; - - #[cfg(feature = "credx")] - assert_eq!(rc.unwrap_err().kind(), AriesVcxErrorKind::InvalidState); - #[cfg(not(feature = "credx"))] - assert_eq!(rc.unwrap_err().kind(), AriesVcxErrorKind::InvalidInput); - }) +async fn test_pool_rev_reg_def_fails_for_cred_def_created_without_revocation( +) -> Result<(), Box> { + let setup = build_setup_profile().await; + // Cred def is created with support_revocation=false, + // revoc_reg_def will fail in libindy because cred_Def doesn't have revocation keys + let (_, _, cred_def_id, _, _) = create_and_store_nonrevocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await?; + + let rc = generate_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.institution_did, + &cred_def_id, + get_temp_file_path("path.txt").to_str().unwrap(), + 2, + "tag1", + ) .await; + + #[cfg(feature = "credx")] + assert_eq!(rc.unwrap_err().kind(), AriesVcxErrorKind::InvalidState); + #[cfg(not(feature = "credx"))] + assert_eq!(rc.unwrap_err().kind(), AriesVcxErrorKind::InvalidInput); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_get_rev_reg_def_json() { - run_setup_test!(|setup| async move { - let attrs = format!("{:?}", attr_names_address_list()); - let (_, _, rev_reg) = create_and_store_revocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &attrs, - ) - .await; - - let ledger = &setup.ledger_read; - let _json = ledger - .get_rev_reg_def_json(&rev_reg.rev_reg_id) - .await - .unwrap(); - }) - .await; +async fn test_pool_get_rev_reg_def_json() -> Result<(), Box> { + let setup = build_setup_profile().await; + let attrs = format!("{:?}", attr_names_address_list()); + let (_, _, rev_reg) = create_and_store_revocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &attrs, + ) + .await?; + + let ledger = &setup.ledger_read; + let _json = ledger.get_rev_reg_def_json(&rev_reg.rev_reg_id).await?; + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_get_rev_reg_delta_json() { - run_setup_test!(|setup| async move { - let attrs = format!("{:?}", attr_names_address_list()); - let (_, _, rev_reg) = create_and_store_revocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &attrs, - ) - .await; +async fn test_pool_get_rev_reg_delta_json() -> Result<(), Box> { + let setup = build_setup_profile().await; + let attrs = format!("{:?}", attr_names_address_list()); + let (_, _, rev_reg) = create_and_store_revocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &attrs, + ) + .await?; - let ledger = &setup.ledger_read; - let (id, _delta, _timestamp) = ledger - .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) - .await - .unwrap(); + let ledger = &setup.ledger_read; + let (id, _delta, _timestamp) = ledger + .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) + .await?; - assert_eq!(id, rev_reg.rev_reg_id); - }) - .await; + assert_eq!(id, rev_reg.rev_reg_id); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_get_rev_reg() { - run_setup_test!(|setup| async move { - let attrs = format!("{:?}", attr_names_address_list()); - let (_, _, rev_reg) = create_and_store_revocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &attrs, +async fn test_pool_get_rev_reg() -> Result<(), Box> { + let setup = build_setup_profile().await; + let attrs = format!("{:?}", attr_names_address_list()); + let (_, _, rev_reg) = create_and_store_revocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &attrs, + ) + .await?; + assert_eq!( + TEST_TAILS_URL, + rev_reg.get_rev_reg_def().value.tails_location + ); + + let ledger = &setup.ledger_read; + let (id, _rev_reg, _timestamp) = ledger + .get_rev_reg( + &rev_reg.rev_reg_id, + time::OffsetDateTime::now_utc().unix_timestamp() as u64, ) - .await; - assert_eq!( - TEST_TAILS_URL, - rev_reg.get_rev_reg_def().value.tails_location - ); - - let ledger = &setup.ledger_read; - let (id, _rev_reg, _timestamp) = ledger - .get_rev_reg( - &rev_reg.rev_reg_id, - time::OffsetDateTime::now_utc().unix_timestamp() as u64, - ) - .await - .unwrap(); - - assert_eq!(id, rev_reg.rev_reg_id); - }) - .await; + .await?; + + assert_eq!(id, rev_reg.rev_reg_id); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_create_and_get_schema() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - - let ledger = &setup.ledger_read; - let rc = ledger.get_schema(&schema.schema_id, None).await; - - let retrieved_schema = rc.unwrap(); - assert!(retrieved_schema.contains(&schema.schema_id)); - }) +async fn test_pool_create_and_get_schema() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) .await; + + let ledger = &setup.ledger_read; + let retrieved_schema = ledger.get_schema(&schema.schema_id, None).await?; + assert!(retrieved_schema.contains(&schema.schema_id)); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_create_rev_reg_delta_from_ledger() { - run_setup_test!(|setup| async move { - let attrs = format!("{:?}", attr_names_address_list()); - let (_, _, rev_reg) = create_and_store_revocable_credential_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &attrs, - ) - .await; - - let (_, rev_reg_delta_json, _) = setup - .ledger_read - .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) - .await - .unwrap(); - assert!( - RevocationRegistryDelta::create_from_ledger(&rev_reg_delta_json) - .await - .is_ok() - ); - }) - .await; +async fn test_pool_create_rev_reg_delta_from_ledger() -> Result<(), Box> { + let setup = build_setup_profile().await; + let attrs = format!("{:?}", attr_names_address_list()); + let (_, _, rev_reg) = create_and_store_revocable_credential_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &attrs, + ) + .await?; + + let (_, rev_reg_delta_json, _) = setup + .ledger_read + .get_rev_reg_delta_json(&rev_reg.rev_reg_id, None, None) + .await?; + RevocationRegistryDelta::create_from_ledger(&rev_reg_delta_json).await?; + Ok(()) } diff --git a/aries_vcx/tests/test_primitives.rs b/aries_vcx/tests/test_primitives.rs index 848cfa80be..0af7da3b2c 100644 --- a/aries_vcx/tests/test_primitives.rs +++ b/aries_vcx/tests/test_primitives.rs @@ -1,4 +1,4 @@ -pub mod utils; +use std::error::Error; use aries_vcx::common::primitives::{ credential_definition::generate_cred_def, revocation_registry::generate_rev_reg, @@ -8,125 +8,111 @@ use aries_vcx_core::ledger::{ indy::pool::test_utils::get_temp_dir_path, }; use serde_json::json; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, run_setup_test}; +use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile}; use crate::utils::create_and_write_test_schema; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_pool_create_cred_def_real() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; +async fn test_pool_create_cred_def_real() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; - let ledger_read = setup.ledger_read; - let ledger_write = &setup.ledger_write; - let schema_json = ledger_read - .get_schema(&schema.schema_id, None) - .await - .unwrap(); + let ledger_read = setup.ledger_read; + let ledger_write = &setup.ledger_write; + let schema_json = ledger_read.get_schema(&schema.schema_id, None).await?; - let (cred_def_id, cred_def_json_local) = generate_cred_def( - &setup.wallet, - &setup.anoncreds, - &setup.institution_did, - &schema_json, - "tag_1", - None, - Some(true), - ) - .await - .unwrap(); + let (cred_def_id, cred_def_json_local) = generate_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.institution_did, + &schema_json, + "tag_1", + None, + Some(true), + ) + .await?; - ledger_write - .publish_cred_def(&setup.wallet, &cred_def_json_local, &setup.institution_did) - .await - .unwrap(); + ledger_write + .publish_cred_def(&setup.wallet, &cred_def_json_local, &setup.institution_did) + .await?; - std::thread::sleep(std::time::Duration::from_secs(2)); + std::thread::sleep(std::time::Duration::from_secs(2)); - let cred_def_json_ledger = ledger_read - .get_cred_def(&cred_def_id, Some(&setup.institution_did)) - .await - .unwrap(); + let cred_def_json_ledger = ledger_read + .get_cred_def(&cred_def_id, Some(&setup.institution_did)) + .await?; - assert!(cred_def_json_local.contains(&cred_def_id)); - assert!(cred_def_json_ledger.contains(&cred_def_id)); - }) - .await; + assert!(cred_def_json_local.contains(&cred_def_id)); + assert!(cred_def_json_ledger.contains(&cred_def_id)); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_create_rev_reg_def() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let ledger_read = &setup.ledger_read; - let ledger_write = &setup.ledger_write; - let schema_json = ledger_read - .get_schema(&schema.schema_id, None) - .await - .unwrap(); +async fn test_pool_create_rev_reg_def() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let ledger_read = &setup.ledger_read; + let ledger_write = &setup.ledger_write; + let schema_json = ledger_read.get_schema(&schema.schema_id, None).await?; - let (cred_def_id, cred_def_json) = generate_cred_def( + let (cred_def_id, cred_def_json) = generate_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.institution_did, + &schema_json, + "tag_1", + None, + Some(true), + ) + .await?; + ledger_write + .publish_cred_def(&setup.wallet, &cred_def_json, &setup.institution_did) + .await?; + + let path = get_temp_dir_path(); + + let (rev_reg_def_id, rev_reg_def_json, rev_reg_entry_json) = generate_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.institution_did, + &cred_def_id, + path.to_str().unwrap(), + 2, + "tag1", + ) + .await?; + ledger_write + .publish_rev_reg_def( &setup.wallet, - &setup.anoncreds, + &json!(rev_reg_def_json).to_string(), &setup.institution_did, - &schema_json, - "tag_1", - None, - Some(true), ) - .await - .unwrap(); - ledger_write - .publish_cred_def(&setup.wallet, &cred_def_json, &setup.institution_did) - .await - .unwrap(); - - let path = get_temp_dir_path(); - - let (rev_reg_def_id, rev_reg_def_json, rev_reg_entry_json) = generate_rev_reg( + .await?; + ledger_write + .publish_rev_reg_delta( &setup.wallet, - &setup.anoncreds, + &rev_reg_def_id, + &rev_reg_entry_json, &setup.institution_did, - &cred_def_id, - path.to_str().unwrap(), - 2, - "tag1", ) - .await - .unwrap(); - ledger_write - .publish_rev_reg_def( - &setup.wallet, - &json!(rev_reg_def_json).to_string(), - &setup.institution_did, - ) - .await - .unwrap(); - ledger_write - .publish_rev_reg_delta( - &setup.wallet, - &rev_reg_def_id, - &rev_reg_entry_json, - &setup.institution_did, - ) - .await - .unwrap(); - }) - .await; + .await?; + Ok(()) } diff --git a/aries_vcx/tests/test_proof_presentation.rs b/aries_vcx/tests/test_proof_presentation.rs index f9798441dd..5feff04810 100644 --- a/aries_vcx/tests/test_proof_presentation.rs +++ b/aries_vcx/tests/test_proof_presentation.rs @@ -1,5 +1,6 @@ #![allow(clippy::diverging_sub_expression)] -pub mod utils; + +use std::error::Error; use aries_vcx::{ common::proofs::proof_request::PresentationRequestData, @@ -16,7 +17,10 @@ use messages::{ AriesMessage, }; use serde_json::json; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::SetupPoolDirectory, run_setup_test}; +use test_utils::{ + constants::DEFAULT_SCHEMA_ATTRS, + devsetup::{build_setup_profile, SetupPoolDirectory}, +}; use crate::utils::{ create_and_publish_test_rev_reg, create_and_write_credential, create_and_write_test_cred_def, @@ -29,49 +33,51 @@ use crate::utils::{ test_agent::{create_test_agent, create_test_agent_trustee}, }; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_agency_pool_generate_proof_with_predicates() { - run_setup_test!(|setup| async move { - let schema = create_and_write_test_schema( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, - ) - .await; - let cred_def = create_and_write_test_cred_def( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - &schema.schema_id, - true, - ) - .await; - let rev_reg = create_and_publish_test_rev_reg( - &setup.wallet, - &setup.anoncreds, - &setup.ledger_write, - &setup.institution_did, - &cred_def.get_cred_def_id(), - ) - .await; - let _cred_id = create_and_write_credential( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.institution_did, - &cred_def, - Some(&rev_reg), - ) - .await; +async fn test_agency_pool_generate_proof_with_predicates() -> Result<(), Box> { + let setup = build_setup_profile().await; + let schema = create_and_write_test_schema( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def = create_and_write_test_cred_def( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + &schema.schema_id, + true, + ) + .await; + let rev_reg = create_and_publish_test_rev_reg( + &setup.wallet, + &setup.anoncreds, + &setup.ledger_write, + &setup.institution_did, + &cred_def.get_cred_def_id(), + ) + .await; + let _cred_id = create_and_write_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.institution_did, + &cred_def, + Some(&rev_reg), + ) + .await; - let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64; - let indy_proof_req = json!({ + let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64; + let indy_proof_req = json!({ "nonce": "123432421212", "name": "proof_req_1", "version": "0.1", @@ -100,195 +106,190 @@ async fn test_agency_pool_generate_proof_with_predicates() { }) .to_string(); - let pres_req_data: PresentationRequestData = serde_json::from_str(&indy_proof_req).unwrap(); - let mut verifier = Verifier::create_from_request("1".to_string(), &pres_req_data).unwrap(); - let proof_req = verifier.get_presentation_request_msg().unwrap(); - verifier.mark_presentation_request_sent().unwrap(); + let pres_req_data: PresentationRequestData = serde_json::from_str(&indy_proof_req)?; + let mut verifier = Verifier::create_from_request("1".to_string(), &pres_req_data)?; + let proof_req = verifier.get_presentation_request_msg()?; + verifier.mark_presentation_request_sent()?; - let mut proof: Prover = Prover::create_from_request("1", proof_req).unwrap(); + let mut proof: Prover = Prover::create_from_request("1", proof_req)?; - let all_creds = proof - .retrieve_credentials(&setup.wallet, &setup.anoncreds) - .await - .unwrap(); - let selected_credentials: serde_json::Value = json!({ - "attrs":{ - "address1_1": { - "credential": all_creds.credentials_by_referent["address1_1"][0], - "tails_dir": rev_reg.get_tails_dir() - }, - "state_2": { - "credential": all_creds.credentials_by_referent["state_2"][0], - "tails_dir": rev_reg.get_tails_dir() - }, - "zip_3": { - "credential": all_creds.credentials_by_referent["zip_3"][0], - "tails_dir": rev_reg.get_tails_dir() - }, - }, - }); - let self_attested: serde_json::Value = json!({ - "zip_self_attested_3":"attested_val" - }); - proof - .generate_presentation( - &setup.wallet, - &setup.ledger_read, - &setup.anoncreds, - serde_json::from_value(selected_credentials).unwrap(), - serde_json::from_value(self_attested).unwrap(), - ) - .await - .unwrap(); - assert!(matches!(proof.get_state(), ProverState::PresentationPrepared)); + let all_creds = proof + .retrieve_credentials(&setup.wallet, &setup.anoncreds) + .await?; + let selected_credentials: serde_json::Value = json!({ + "attrs":{ + "address1_1": { + "credential": all_creds.credentials_by_referent["address1_1"][0], + "tails_dir": rev_reg.get_tails_dir() + }, + "state_2": { + "credential": all_creds.credentials_by_referent["state_2"][0], + "tails_dir": rev_reg.get_tails_dir() + }, + "zip_3": { + "credential": all_creds.credentials_by_referent["zip_3"][0], + "tails_dir": rev_reg.get_tails_dir() + }, + }, + }); + let self_attested: serde_json::Value = json!({ + "zip_self_attested_3":"attested_val" + }); + proof + .generate_presentation( + &setup.wallet, + &setup.ledger_read, + &setup.anoncreds, + serde_json::from_value(selected_credentials)?, + serde_json::from_value(self_attested)?, + ) + .await?; + assert!(matches!( + proof.get_state(), + ProverState::PresentationPrepared + )); - let final_message = verifier - .verify_presentation( - &setup.ledger_read, - &setup.anoncreds, - proof.get_presentation_msg().unwrap(), - ) - .await - .unwrap(); + let final_message = verifier + .verify_presentation( + &setup.ledger_read, + &setup.anoncreds, + proof.get_presentation_msg()?, + ) + .await?; - if let AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::Ack(_))) = final_message { - assert_eq!(verifier.get_state(), VerifierState::Finished); - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - } else { - panic!("Unexpected message type {:?}", final_message); - } - }) - .await; + if let AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::Ack(_))) = final_message { + assert_eq!(verifier.get_state(), VerifierState::Finished); + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + } else { + panic!("Unexpected message type {:?}", final_message); + } + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_presentation_via_proposal() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - let tails_dir = rev_reg.get_tails_dir(); +async fn test_agency_pool_presentation_via_proposal() -> Result<(), Box> { + let setup = build_setup_profile().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - exchange_credential_with_proposal( - &mut consumer, - &mut institution, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some(rev_reg.rev_reg_id), - Some(tails_dir), - "comment", - ) - .await; - let mut prover = Prover::create("1").unwrap(); - let mut verifier = Verifier::create("1").unwrap(); - let presentation_proposal = - create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; - let presentation_request = - accept_proof_proposal(&mut institution, &mut verifier, presentation_proposal).await; + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; + let tails_dir = rev_reg.get_tails_dir(); - let selected_credentials = - prover_select_credentials(&mut prover, &mut consumer, presentation_request, None).await; - let presentation = - generate_and_send_proof(&mut consumer, &mut prover, selected_credentials) - .await - .unwrap(); - verify_proof(&mut institution, &mut verifier, presentation).await; - }) + exchange_credential_with_proposal( + &mut consumer, + &mut institution, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some(rev_reg.rev_reg_id), + Some(tails_dir), + "comment", + ) .await; + let mut prover = Prover::create("1")?; + let mut verifier = Verifier::create("1")?; + let presentation_proposal = + create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; + let presentation_request = + accept_proof_proposal(&mut institution, &mut verifier, presentation_proposal).await; + + let selected_credentials = + prover_select_credentials(&mut prover, &mut consumer, presentation_request, None).await; + let presentation = generate_and_send_proof(&mut consumer, &mut prover, selected_credentials) + .await + .unwrap(); + verify_proof(&mut institution, &mut verifier, presentation).await; + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_presentation_via_proposal_with_rejection() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; +async fn test_agency_pool_presentation_via_proposal_with_rejection() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - let tails_dir = rev_reg.get_tails_dir(); + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; + let tails_dir = rev_reg.get_tails_dir(); - exchange_credential_with_proposal( - &mut consumer, - &mut institution, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some(rev_reg.rev_reg_id), - Some(tails_dir), - "comment", - ) - .await; - let mut prover = Prover::create("1").unwrap(); - let presentation_proposal = - create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; - let rejection = reject_proof_proposal(&presentation_proposal).await; - receive_proof_proposal_rejection(&mut prover, rejection).await; - }) + exchange_credential_with_proposal( + &mut consumer, + &mut institution, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some(rev_reg.rev_reg_id), + Some(tails_dir), + "comment", + ) .await; + let mut prover = Prover::create("1")?; + let presentation_proposal = + create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; + let rejection = reject_proof_proposal(&presentation_proposal).await; + receive_proof_proposal_rejection(&mut prover, rejection).await; + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_presentation_via_proposal_with_negotiation() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; +async fn test_agency_pool_presentation_via_proposal_with_negotiation() -> Result<(), Box> +{ + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - let tails_dir = rev_reg.get_tails_dir(); - - exchange_credential_with_proposal( - &mut consumer, - &mut institution, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some(rev_reg.rev_reg_id), - Some(tails_dir), - "comment", - ) - .await; - let mut prover = Prover::create("1").unwrap(); - let mut verifier = Verifier::create("1").unwrap(); + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .await; + let tails_dir = rev_reg.get_tails_dir(); - let presentation_proposal = - create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; - let presentation_request = - accept_proof_proposal(&mut institution, &mut verifier, presentation_proposal).await; - let selected_credentials = - prover_select_credentials(&mut prover, &mut consumer, presentation_request, None).await; - let presentation = - generate_and_send_proof(&mut consumer, &mut prover, selected_credentials) - .await - .unwrap(); - verify_proof(&mut institution, &mut verifier, presentation).await; - }) + exchange_credential_with_proposal( + &mut consumer, + &mut institution, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some(rev_reg.rev_reg_id), + Some(tails_dir), + "comment", + ) .await; + let mut prover = Prover::create("1")?; + let mut verifier = Verifier::create("1")?; + + let presentation_proposal = + create_proof_proposal(&mut prover, &cred_def.get_cred_def_id()).await; + let presentation_request = + accept_proof_proposal(&mut institution, &mut verifier, presentation_proposal).await; + let selected_credentials = + prover_select_credentials(&mut prover, &mut consumer, presentation_request, None).await; + let presentation = generate_and_send_proof(&mut consumer, &mut prover, selected_credentials) + .await + .unwrap(); + verify_proof(&mut institution, &mut verifier, presentation).await; + Ok(()) } diff --git a/aries_vcx/tests/test_revocations.rs b/aries_vcx/tests/test_revocations.rs index 833925f734..e649740f60 100644 --- a/aries_vcx/tests/test_revocations.rs +++ b/aries_vcx/tests/test_revocations.rs @@ -1,6 +1,4 @@ -pub mod utils; - -use std::{thread, time::Duration}; +use std::{error::Error, thread, time::Duration}; use aries_vcx::protocols::proof_presentation::verifier::{ state_machine::VerifierState, verification_status::PresentationVerificationStatus, @@ -20,948 +18,864 @@ use crate::utils::{ test_agent::{create_test_agent, create_test_agent_trustee}, }; +pub mod utils; + #[tokio::test] #[ignore] -async fn test_agency_pool_basic_revocation() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg, issuer) = - issue_address_credential(&mut consumer, &mut institution).await; - - assert!(!issuer.is_revoked(&institution.ledger_read).await.unwrap()); - - let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; - revoke_credential_and_publish_accumulator(&mut institution, &issuer, &rev_reg).await; - - tokio::time::sleep(Duration::from_millis(1000)).await; - let time_after_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; - - assert!(issuer.is_revoked(&institution.ledger_read).await.unwrap()); - - let requested_attrs = requested_attrs_address( - &institution.institution_did, - &schema.schema_id, - &cred_def.get_cred_def_id(), - None, - Some(time_after_revocation), - ); - - let presentation_request_data = create_proof_request_data( - &mut institution, - &requested_attrs.to_string(), - "[]", - &json!({"from": time_before_revocation - 100, "to": time_after_revocation}).to_string(), - None, - ) - .await; +async fn test_agency_pool_basic_revocation() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg, issuer) = + issue_address_credential(&mut consumer, &mut institution).await; + + assert!(!issuer.is_revoked(&institution.ledger_read).await?); + + let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; + revoke_credential_and_publish_accumulator(&mut institution, &issuer, &rev_reg).await; + + tokio::time::sleep(Duration::from_millis(1000)).await; + let time_after_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; + + assert!(issuer.is_revoked(&institution.ledger_read).await?); + + let requested_attrs = requested_attrs_address( + &institution.institution_did, + &schema.schema_id, + &cred_def.get_cred_def_id(), + None, + Some(time_after_revocation), + ); + + let presentation_request_data = create_proof_request_data( + &mut institution, + &requested_attrs.to_string(), + "[]", + &json!({"from": time_before_revocation - 100, "to": time_after_revocation}).to_string(), + None, + ) + .await; - let mut verifier = create_verifier_from_request_data(presentation_request_data).await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - verifier.get_presentation_request_msg().unwrap(), - None, - ) - .await; - - verifier - .verify_presentation( - &institution.ledger_read, - &institution.anoncreds, - presentation, - ) - .await - .unwrap(); - assert_eq!(verifier.get_state(), VerifierState::Finished); - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - }) + let mut verifier = create_verifier_from_request_data(presentation_request_data).await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + verifier.get_presentation_request_msg()?, + None, + ) .await; + + verifier + .verify_presentation( + &institution.ledger_read, + &institution.anoncreds, + presentation, + ) + .await?; + assert_eq!(verifier.get_state(), VerifierState::Finished); + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_revoked_credential_might_still_work() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg, issuer) = - issue_address_credential(&mut consumer, &mut institution).await; - - assert!(!issuer.is_revoked(&institution.ledger_read).await.unwrap()); - - tokio::time::sleep(Duration::from_millis(1000)).await; - let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; - tokio::time::sleep(Duration::from_millis(1000)).await; - - revoke_credential_and_publish_accumulator(&mut institution, &issuer, &rev_reg).await; - tokio::time::sleep(Duration::from_millis(1000)).await; - - let from = time_before_revocation - 100; - let to = time_before_revocation; - let requested_attrs = requested_attrs_address( - &institution.institution_did, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some(from), - Some(to), - ); - - let presentation_request_data = create_proof_request_data( - &mut institution, - &requested_attrs.to_string(), - "[]", - &json!({"from": from, "to": to}).to_string(), - None, - ) - .await; +async fn test_agency_pool_revoked_credential_might_still_work() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg, issuer) = + issue_address_credential(&mut consumer, &mut institution).await; + + assert!(!issuer.is_revoked(&institution.ledger_read).await?); + + tokio::time::sleep(Duration::from_millis(1000)).await; + let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; + tokio::time::sleep(Duration::from_millis(1000)).await; + + revoke_credential_and_publish_accumulator(&mut institution, &issuer, &rev_reg).await; + tokio::time::sleep(Duration::from_millis(1000)).await; + + let from = time_before_revocation - 100; + let to = time_before_revocation; + let requested_attrs = requested_attrs_address( + &institution.institution_did, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some(from), + Some(to), + ); + + let presentation_request_data = create_proof_request_data( + &mut institution, + &requested_attrs.to_string(), + "[]", + &json!({"from": from, "to": to}).to_string(), + None, + ) + .await; - let mut verifier = create_verifier_from_request_data(presentation_request_data).await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - verifier.get_presentation_request_msg().unwrap(), - None, - ) - .await; - - verifier - .verify_presentation( - &institution.ledger_read, - &institution.anoncreds, - presentation, - ) - .await - .unwrap(); - assert_eq!(verifier.get_state(), VerifierState::Finished); - assert_eq!( - verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - }) + let mut verifier = create_verifier_from_request_data(presentation_request_data).await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + verifier.get_presentation_request_msg()?, + None, + ) .await; + + verifier + .verify_presentation( + &institution.ledger_read, + &institution.anoncreds, + presentation, + ) + .await?; + assert_eq!(verifier.get_state(), VerifierState::Finished); + assert_eq!( + verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_local_revocation() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg, issuer) = - issue_address_credential(&mut consumer, &mut institution).await; - - revoke_credential_local(&mut institution, &issuer, &rev_reg.rev_reg_id).await; - assert!(!issuer.is_revoked(&institution.ledger_read).await.unwrap()); - - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - assert!(!issuer.is_revoked(&institution.ledger_read).await.unwrap()); - - publish_revocation(&mut institution, &rev_reg).await; - - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - - assert!(issuer.is_revoked(&institution.ledger_read).await.unwrap()); - }) +async fn test_agency_pool_local_revocation() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg, issuer) = + issue_address_credential(&mut consumer, &mut institution).await; + + revoke_credential_local(&mut institution, &issuer, &rev_reg.rev_reg_id).await; + assert!(!issuer.is_revoked(&institution.ledger_read).await?); + + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + assert!(!issuer.is_revoked(&institution.ledger_read).await?); + + publish_revocation(&mut institution, &rev_reg).await; + + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + + assert!(issuer.is_revoked(&institution.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_batch_revocation() { - SetupPoolDirectory::run(|setup| async move { - let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer1 = create_test_agent(setup.genesis_file_path.clone()).await; - let mut consumer2 = create_test_agent(setup.genesis_file_path.clone()).await; - let mut consumer3 = create_test_agent(setup.genesis_file_path).await; - - // Issue and send three credentials of the same schema - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &institution.wallet, - &institution.ledger_read, - &institution.ledger_write, - &institution.anoncreds, - &institution.institution_did, - ) - .await; - - let issuer_credential1 = exchange_credential( - &mut consumer1, - &mut institution, - credential_data_address_1().to_string(), - &cred_def, - &rev_reg, - None, - ) - .await; - - let issuer_credential2 = exchange_credential( - &mut consumer2, - &mut institution, - credential_data_address_2().to_string(), - &cred_def, - &rev_reg, - None, - ) - .await; - - let issuer_credential3 = exchange_credential( - &mut consumer3, - &mut institution, - credential_data_address_3().to_string(), - &cred_def, - &rev_reg, - None, - ) - .await; +async fn test_agency_batch_revocation() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut institution = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer1 = create_test_agent(setup.genesis_file_path.clone()).await; + let mut consumer2 = create_test_agent(setup.genesis_file_path.clone()).await; + let mut consumer3 = create_test_agent(setup.genesis_file_path).await; + + // Issue and send three credentials of the same schema + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &institution.wallet, + &institution.ledger_read, + &institution.ledger_write, + &institution.anoncreds, + &institution.institution_did, + ) + .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; - assert!(!issuer_credential1 + let issuer_credential1 = exchange_credential( + &mut consumer1, + &mut institution, + credential_data_address_1().to_string(), + &cred_def, + &rev_reg, + None, + ) + .await; + + let issuer_credential2 = exchange_credential( + &mut consumer2, + &mut institution, + credential_data_address_2().to_string(), + &cred_def, + &rev_reg, + None, + ) + .await; + + let issuer_credential3 = exchange_credential( + &mut consumer3, + &mut institution, + credential_data_address_3().to_string(), + &cred_def, + &rev_reg, + 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; + assert!( + !issuer_credential1 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 + .await? + ); + assert!( + !issuer_credential2 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential3 + .await? + ); + assert!( + !issuer_credential3 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - - // Revoke two locally and verify their are all still valid - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer1, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer2, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer3, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request3"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); + .await? + ); + + // Revoke two locally and verify their are all still valid + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer1, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer2, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer3, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request3"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); - // Publish revocations and verify the two are invalid, third still valid - publish_revocation(&mut institution, &rev_reg).await; - tokio::time::sleep(Duration::from_millis(1000)).await; + // Publish revocations and verify the two are invalid, third still valid + publish_revocation(&mut institution, &rev_reg).await; + tokio::time::sleep(Duration::from_millis(1000)).await; - assert!(issuer_credential1 + assert!( + issuer_credential1 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - assert!(issuer_credential2 + .await? + ); + assert!( + issuer_credential2 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential3 + .await? + ); + assert!( + !issuer_credential3 .is_revoked(&institution.ledger_read) - .await - .unwrap()); - - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer1, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer2, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - let verifier_handler = exchange_proof( - &mut institution, - &mut consumer3, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request3"), - ) - .await; - assert_eq!( - verifier_handler.get_verification_status(), - PresentationVerificationStatus::Valid - ); - }) + .await? + ); + + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer1, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer2, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + let verifier_handler = exchange_proof( + &mut institution, + &mut consumer3, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request3"), + ) + .await; + assert_eq!( + verifier_handler.get_verification_status(), + PresentationVerificationStatus::Valid + ); + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_two_creds_one_rev_reg_revoke_first() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let credential_data2 = credential_data_address_2().to_string(); - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg, - Some("request2"), - ) - .await; - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - - revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential1, &rev_reg).await; - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - let presentation_request = proof_verifier.get_presentation_request_msg().unwrap(); - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - presentation_request, - Some(&credential_data1), - ) - .await; - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - let presentation_request = proof_verifier.get_presentation_request_msg().unwrap(); - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - presentation_request, - Some(&credential_data2), - ) - .await; - - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - assert!(issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) +async fn test_agency_pool_two_creds_one_rev_reg_revoke_first() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; + + let credential_data2 = credential_data_address_2().to_string(); + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg, + Some("request2"), + ) .await; + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + + revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential1, &rev_reg).await; + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + let presentation_request = proof_verifier.get_presentation_request_msg()?; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + presentation_request, + Some(&credential_data1), + ) + .await; + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + let presentation_request = proof_verifier.get_presentation_request_msg()?; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + presentation_request, + Some(&credential_data2), + ) + .await; + + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + assert!(issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_two_creds_one_rev_reg_revoke_second() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let credential_data2 = credential_data_address_2().to_string(); - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg, - Some("request2"), - ) - .await; - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - - revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential2, &rev_reg).await; - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data1), - ) - .await; - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data2), - ) - .await; - - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) +async fn test_agency_pool_two_creds_one_rev_reg_revoke_second() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; + + let credential_data2 = credential_data_address_2().to_string(); + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg, + Some("request2"), + ) .await; + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + + revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential2, &rev_reg).await; + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data1), + ) + .await; + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data2), + ) + .await; + + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(issuer_credential2.is_revoked(&issuer.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_two_creds_two_rev_reg_id() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = credential_data_address_2().to_string(); - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - Some("request2"), - ) - .await; +async fn test_agency_pool_two_creds_two_rev_reg_id() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data1), - ) - .await; - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = credential_data_address_2().to_string(); + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + Some("request2"), + ) + .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data2), - ) - .await; - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data1), + ) .await; + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data2), + ) + .await; + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] #[allow(unused_mut)] -async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_first() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = credential_data_address_2().to_string(); - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - Some("request2"), - ) - .await; - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - - revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential1, &rev_reg).await; - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data1), - ) - .await; - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data2), - ) - .await; - - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - assert!(issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) +async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_first() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; + + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = credential_data_address_2().to_string(); + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + Some("request2"), + ) + .await; + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + + revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential1, &rev_reg).await; + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data1), + ) .await; + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data2), + ) + .await; + + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + assert!(issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_second() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path).await; - - let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - let credential_data1 = credential_data_address_1().to_string(); - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data1.clone(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; - let credential_data2 = credential_data_address_2().to_string(); - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data2.clone(), - &cred_def, - &rev_reg_2, - Some("request2"), - ) - .await; - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - - revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential2, &rev_reg_2) - .await; - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request1"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data1), - ) - .await; - - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Valid - ); - - let mut proof_verifier = verifier_create_proof_and_send_request( - &mut verifier, - &schema.schema_id, - &cred_def.get_cred_def_id(), - Some("request2"), - ) - .await; - let presentation = prover_select_credentials_and_send_proof( - &mut consumer, - proof_verifier.get_presentation_request_msg().unwrap(), - Some(&credential_data2), - ) - .await; - - proof_verifier - .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) - .await - .unwrap(); - assert_eq!(proof_verifier.get_state(), VerifierState::Finished); - assert_eq!( - proof_verifier.get_verification_status(), - PresentationVerificationStatus::Invalid - ); - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) +async fn test_agency_pool_two_creds_two_rev_reg_id_revoke_second() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut verifier = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path).await; + + let (schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + let credential_data1 = credential_data_address_1().to_string(); + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data1.clone(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; + + let rev_reg_2 = rotate_rev_reg(&mut issuer, &cred_def, &rev_reg).await; + let credential_data2 = credential_data_address_2().to_string(); + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data2.clone(), + &cred_def, + &rev_reg_2, + Some("request2"), + ) + .await; + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + + revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential2, &rev_reg_2).await; + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request1"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data1), + ) .await; + + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Valid + ); + + let mut proof_verifier = verifier_create_proof_and_send_request( + &mut verifier, + &schema.schema_id, + &cred_def.get_cred_def_id(), + Some("request2"), + ) + .await; + let presentation = prover_select_credentials_and_send_proof( + &mut consumer, + proof_verifier.get_presentation_request_msg()?, + Some(&credential_data2), + ) + .await; + + proof_verifier + .verify_presentation(&verifier.ledger_read, &verifier.anoncreds, presentation) + .await?; + assert_eq!(proof_verifier.get_state(), VerifierState::Finished); + assert_eq!( + proof_verifier.get_verification_status(), + PresentationVerificationStatus::Invalid + ); + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(issuer_credential2.is_revoked(&issuer.ledger_read).await?); + Ok(()) } #[tokio::test] #[ignore] -async fn test_agency_pool_three_creds_one_rev_reg_revoke_all() { - SetupPoolDirectory::run(|setup| async move { - let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; - let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; - - let (_schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( - &issuer.wallet, - &issuer.ledger_read, - &issuer.ledger_write, - &issuer.anoncreds, - &issuer.institution_did, - ) - .await; - - let issuer_credential1 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data_address_1().to_string(), - &cred_def, - &rev_reg, - Some("request1"), - ) - .await; - - assert!(!issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - revoke_credential_local(&mut issuer, &issuer_credential1, &rev_reg.rev_reg_id).await; - - let issuer_credential2 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data_address_2().to_string(), - &cred_def, - &rev_reg, - Some("request2"), - ) - .await; - - assert!(!issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - - revoke_credential_local(&mut issuer, &issuer_credential2, &rev_reg.rev_reg_id).await; - - let issuer_credential3 = exchange_credential( - &mut consumer, - &mut issuer, - credential_data_address_3().to_string(), - &cred_def, - &rev_reg, - Some("request3"), - ) - .await; - - revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential3, &rev_reg).await; - thread::sleep(Duration::from_millis(100)); - - assert!(issuer_credential1 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(issuer_credential2 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - assert!(issuer_credential3 - .is_revoked(&issuer.ledger_read) - .await - .unwrap()); - }) +async fn test_agency_pool_three_creds_one_rev_reg_revoke_all() -> Result<(), Box> { + let setup = SetupPoolDirectory::init().await; + let mut issuer = create_test_agent_trustee(setup.genesis_file_path.clone()).await; + let mut consumer = create_test_agent(setup.genesis_file_path.clone()).await; + + let (_schema, cred_def, rev_reg) = create_address_schema_creddef_revreg( + &issuer.wallet, + &issuer.ledger_read, + &issuer.ledger_write, + &issuer.anoncreds, + &issuer.institution_did, + ) + .await; + + let issuer_credential1 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data_address_1().to_string(), + &cred_def, + &rev_reg, + Some("request1"), + ) + .await; + + assert!(!issuer_credential1.is_revoked(&issuer.ledger_read).await?); + revoke_credential_local(&mut issuer, &issuer_credential1, &rev_reg.rev_reg_id).await; + + let issuer_credential2 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data_address_2().to_string(), + &cred_def, + &rev_reg, + Some("request2"), + ) .await; + + assert!(!issuer_credential2.is_revoked(&issuer.ledger_read).await?); + + revoke_credential_local(&mut issuer, &issuer_credential2, &rev_reg.rev_reg_id).await; + + let issuer_credential3 = exchange_credential( + &mut consumer, + &mut issuer, + credential_data_address_3().to_string(), + &cred_def, + &rev_reg, + Some("request3"), + ) + .await; + + revoke_credential_and_publish_accumulator(&mut issuer, &issuer_credential3, &rev_reg).await; + thread::sleep(Duration::from_millis(100)); + + assert!(issuer_credential1.is_revoked(&issuer.ledger_read).await?); + assert!(issuer_credential2.is_revoked(&issuer.ledger_read).await?); + assert!(issuer_credential3.is_revoked(&issuer.ledger_read).await?); + Ok(()) } diff --git a/aries_vcx/tests/test_verifier.rs b/aries_vcx/tests/test_verifier.rs index 52c0756068..a2e0e83dd7 100644 --- a/aries_vcx/tests/test_verifier.rs +++ b/aries_vcx/tests/test_verifier.rs @@ -1,6 +1,4 @@ -pub mod utils; - -use std::time::Duration; +use std::{error::Error, time::Duration}; use aries_vcx::{ common::{ @@ -15,12 +13,14 @@ use aries_vcx_core::{ wallet::base_wallet::BaseWallet, }; use serde_json::json; -use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, run_setup_test}; +use test_utils::{constants::DEFAULT_SCHEMA_ATTRS, devsetup::build_setup_profile}; use crate::utils::{ create_and_write_credential, create_and_write_test_cred_def, create_and_write_test_schema, }; +pub mod utils; + // FUTURE - issuer and holder seperation only needed whilst modular deps not fully implemented async fn create_indy_proof( wallet_issuer: &impl BaseWallet, @@ -30,7 +30,7 @@ async fn create_indy_proof( ledger_read: &impl AnoncredsLedgerRead, ledger_write: &impl AnoncredsLedgerWrite, did: &str, -) -> (String, String, String, String) { +) -> Result<(String, String, String, String), Box> { let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( wallet_issuer, wallet_holder, @@ -75,14 +75,13 @@ async fn create_indy_proof( .to_string(); let schema_id = schema.schema_id.clone(); - let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); + let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json)?; let schemas = json!({ schema_id: schema_json, }) .to_string(); - let cred_def_json: serde_json::Value = - serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); + let cred_def_json: serde_json::Value = serde_json::from_str(cred_def.get_cred_def_json())?; let cred_defs = json!({ cred_def.get_cred_def_id(): cred_def_json, }) @@ -90,8 +89,7 @@ async fn create_indy_proof( anoncreds_holder .prover_get_credentials_for_proof_req(wallet_holder, &proof_req) - .await - .unwrap(); + .await?; let proof = anoncreds_holder .prover_create_proof( @@ -103,9 +101,8 @@ async fn create_indy_proof( &cred_defs, None, ) - .await - .unwrap(); - (schemas, cred_defs, proof_req, proof) + .await?; + Ok((schemas, cred_defs, proof_req, proof)) } #[allow(clippy::too_many_arguments)] @@ -118,7 +115,7 @@ async fn create_proof_with_predicate( ledger_write: &impl AnoncredsLedgerWrite, did: &str, include_predicate_cred: bool, -) -> (String, String, String, String) { +) -> Result<(String, String, String, String), Box> { let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( wallet_issuer, wallet_holder, @@ -177,14 +174,13 @@ async fn create_proof_with_predicate( .to_string() }; - let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); + let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json)?; let schemas = json!({ schema.schema_id: schema_json, }) .to_string(); - let cred_def_json: serde_json::Value = - serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); + let cred_def_json: serde_json::Value = serde_json::from_str(cred_def.get_cred_def_json())?; let cred_defs = json!({ cred_def.get_cred_def_id(): cred_def_json, }) @@ -192,8 +188,7 @@ async fn create_proof_with_predicate( anoncreds_holder .prover_get_credentials_for_proof_req(wallet_holder, &proof_req) - .await - .unwrap(); + .await?; let proof = anoncreds_holder .prover_create_proof( @@ -205,9 +200,8 @@ async fn create_proof_with_predicate( &cred_defs, None, ) - .await - .unwrap(); - (schemas, cred_defs, proof_req, proof) + .await?; + Ok((schemas, cred_defs, proof_req, proof)) } #[allow(clippy::too_many_arguments)] @@ -257,364 +251,342 @@ async fn create_and_store_nonrevocable_credential( #[tokio::test] #[ignore] -async fn test_pool_proof_self_attested_proof_validation() { - run_setup_test!(|setup| async move { - let requested_attrs = json!([ - json!({ - "name":"address1", - "self_attest_allowed": true, - }), - json!({ - "name":"zip", - "self_attest_allowed": true, - }), - ]) - .to_string(); - let requested_predicates = json!([]).to_string(); - let revocation_details = r#"{"support_revocation":false}"#.to_string(); - let name = "Optional".to_owned(); - - let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) - .await - .unwrap() - .set_requested_attributes_as_string(requested_attrs) - .unwrap() - .set_requested_predicates_as_string(requested_predicates) - .unwrap() - .set_not_revoked_interval(revocation_details) - .unwrap(); - - let proof_req_json = serde_json::to_string(&proof_req_json).unwrap(); - - let anoncreds = &setup.anoncreds; - let prover_proof_json = anoncreds - .prover_create_proof( - &setup.wallet, - &proof_req_json, - &json!({ - "self_attested_attributes":{ - "attribute_0": "my_self_attested_address", - "attribute_1": "my_self_attested_zip" - }, - "requested_attributes":{}, - "requested_predicates":{} - }) - .to_string(), - "main", - &json!({}).to_string(), - &json!({}).to_string(), - None, - ) - .await - .unwrap(); +async fn test_pool_proof_self_attested_proof_validation() -> Result<(), Box> { + let setup = build_setup_profile().await; + let requested_attrs = json!([ + json!({ + "name":"address1", + "self_attest_allowed": true, + }), + json!({ + "name":"zip", + "self_attest_allowed": true, + }), + ]) + .to_string(); + let requested_predicates = json!([]).to_string(); + let revocation_details = r#"{"support_revocation":false}"#.to_string(); + let name = "Optional".to_owned(); - assert!(validate_indy_proof( + let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) + .await? + .set_requested_attributes_as_string(requested_attrs)? + .set_requested_predicates_as_string(requested_predicates)? + .set_not_revoked_interval(revocation_details)?; + + let proof_req_json = serde_json::to_string(&proof_req_json)?; + + let anoncreds = &setup.anoncreds; + let prover_proof_json = anoncreds + .prover_create_proof( + &setup.wallet, + &proof_req_json, + &json!({ + "self_attested_attributes":{ + "attribute_0": "my_self_attested_address", + "attribute_1": "my_self_attested_zip" + }, + "requested_attributes":{}, + "requested_predicates":{} + }) + .to_string(), + "main", + &json!({}).to_string(), + &json!({}).to_string(), + None, + ) + .await?; + + assert!( + validate_indy_proof( &setup.ledger_read, &setup.anoncreds, &prover_proof_json, - &proof_req_json + &proof_req_json, ) - .await - .unwrap()); - }) - .await; + .await? + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_proof_restrictions() { - run_setup_test!(|setup| async move { - let requested_attrs = json!([ - json!({ - "name":"address1", - "restrictions": [{ "issuer_did": "Not Here" }], - }), - json!({ - "name":"zip", - }), - json!({ - "name":"self_attest", - "self_attest_allowed": true, - }), - ]) - .to_string(); - let requested_predicates = json!([]).to_string(); - let revocation_details = r#"{"support_revocation":true}"#.to_string(); - let name = "Optional".to_owned(); - - let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) - .await - .unwrap() - .set_requested_attributes_as_string(requested_attrs) - .unwrap() - .set_requested_predicates_as_string(requested_predicates) - .unwrap() - .set_not_revoked_interval(revocation_details) - .unwrap(); +async fn test_pool_proof_restrictions() -> Result<(), Box> { + let setup = build_setup_profile().await; + let requested_attrs = json!([ + json!({ + "name":"address1", + "restrictions": [{ "issuer_did": "Not Here" }], + }), + json!({ + "name":"zip", + }), + json!({ + "name":"self_attest", + "self_attest_allowed": true, + }), + ]) + .to_string(); + let requested_predicates = json!([]).to_string(); + let revocation_details = r#"{"support_revocation":true}"#.to_string(); + let name = "Optional".to_owned(); - let proof_req_json = serde_json::to_string(&proof_req_json).unwrap(); + let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) + .await? + .set_requested_attributes_as_string(requested_attrs)? + .set_requested_predicates_as_string(requested_predicates)? + .set_not_revoked_interval(revocation_details)?; - let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( - &setup.wallet, + let proof_req_json = serde_json::to_string(&proof_req_json)?; + + let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def_json: serde_json::Value = serde_json::from_str(cred_def.get_cred_def_json())?; + let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json)?; + + let anoncreds = &setup.anoncreds; + let prover_proof_json = anoncreds + .prover_create_proof( &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, + &proof_req_json, + &json!({ + "self_attested_attributes":{ + "attribute_2": "my_self_attested_val" + }, + "requested_attributes":{ + "attribute_0": {"cred_id": cred_id, "revealed": true}, + "attribute_1": {"cred_id": cred_id, "revealed": true} + }, + "requested_predicates":{} + }) + .to_string(), + "main", + &json!({ schema.schema_id: schema_json }).to_string(), + &json!({ cred_def.get_cred_def_id(): cred_def_json }).to_string(), + None, ) - .await; - let cred_def_json: serde_json::Value = - serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); - let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); - - let anoncreds = &setup.anoncreds; - let prover_proof_json = anoncreds - .prover_create_proof( - &setup.wallet, - &proof_req_json, - &json!({ - "self_attested_attributes":{ - "attribute_2": "my_self_attested_val" - }, - "requested_attributes":{ - "attribute_0": {"cred_id": cred_id, "revealed": true}, - "attribute_1": {"cred_id": cred_id, "revealed": true} - }, - "requested_predicates":{} - }) - .to_string(), - "main", - &json!({ schema.schema_id: schema_json }).to_string(), - &json!({ cred_def.get_cred_def_id(): cred_def_json }).to_string(), - None, - ) - .await - .unwrap(); - assert_eq!( - validate_indy_proof( - &setup.ledger_read, - &setup.anoncreds, - &prover_proof_json, - &proof_req_json - ) - .await - .unwrap_err() - .kind(), - AriesVcxErrorKind::ProofRejected - ); - - let mut proof_req_json: serde_json::Value = serde_json::from_str(&proof_req_json).unwrap(); - proof_req_json["requested_attributes"]["attribute_0"]["restrictions"] = json!({}); - assert!(validate_indy_proof( + .await?; + assert_eq!( + validate_indy_proof( &setup.ledger_read, &setup.anoncreds, &prover_proof_json, - &proof_req_json.to_string() + &proof_req_json, ) .await - .unwrap()); - }) - .await; + .unwrap_err() + .kind(), + AriesVcxErrorKind::ProofRejected + ); + + let mut proof_req_json: serde_json::Value = serde_json::from_str(&proof_req_json)?; + proof_req_json["requested_attributes"]["attribute_0"]["restrictions"] = json!({}); + assert!( + validate_indy_proof( + &setup.ledger_read, + &setup.anoncreds, + &prover_proof_json, + &proof_req_json.to_string(), + ) + .await? + ); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_proof_validate_attribute() { - run_setup_test!(|setup| async move { - let requested_attrs = json!([ - json!({ - "name":"address1", - "restrictions": [json!({ "issuer_did": setup.institution_did })] - }), - json!({ - "name":"zip", - "restrictions": [json!({ "issuer_did": setup.institution_did })] - }), - json!({ - "name":"self_attest", - "self_attest_allowed": true, - }), - ]) - .to_string(); - let requested_predicates = json!([]).to_string(); - let revocation_details = r#"{"support_revocation":true}"#.to_string(); - let name = "Optional".to_owned(); - - let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) - .await - .unwrap() - .set_requested_attributes_as_string(requested_attrs) - .unwrap() - .set_requested_predicates_as_string(requested_predicates) - .unwrap() - .set_not_revoked_interval(revocation_details) - .unwrap(); +async fn test_pool_proof_validate_attribute() -> Result<(), Box> { + let setup = build_setup_profile().await; + let requested_attrs = json!([ + json!({ + "name":"address1", + "restrictions": [json!({ "issuer_did": setup.institution_did })] + }), + json!({ + "name":"zip", + "restrictions": [json!({ "issuer_did": setup.institution_did })] + }), + json!({ + "name":"self_attest", + "self_attest_allowed": true, + }), + ]) + .to_string(); + let requested_predicates = json!([]).to_string(); + let revocation_details = r#"{"support_revocation":true}"#.to_string(); + let name = "Optional".to_owned(); - let proof_req_json = serde_json::to_string(&proof_req_json).unwrap(); + let proof_req_json = ProofRequestData::create(&setup.anoncreds, &name) + .await? + .set_requested_attributes_as_string(requested_attrs)? + .set_requested_predicates_as_string(requested_predicates)? + .set_not_revoked_interval(revocation_details)?; - let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( - &setup.wallet, + let proof_req_json = serde_json::to_string(&proof_req_json)?; + + let (schema, cred_def, cred_id) = create_and_store_nonrevocable_credential( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + DEFAULT_SCHEMA_ATTRS, + ) + .await; + let cred_def_json: serde_json::Value = serde_json::from_str(cred_def.get_cred_def_json())?; + let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json)?; + + let anoncreds = &setup.anoncreds; + let prover_proof_json = anoncreds + .prover_create_proof( &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - DEFAULT_SCHEMA_ATTRS, + &proof_req_json, + &json!({ + "self_attested_attributes":{ + "attribute_2": "my_self_attested_val" + }, + "requested_attributes":{ + "attribute_0": {"cred_id": cred_id, "revealed": true}, + "attribute_1": {"cred_id": cred_id, "revealed": true} + }, + "requested_predicates":{} + }) + .to_string(), + "main", + &json!({ schema.schema_id: schema_json }).to_string(), + &json!({ cred_def.get_cred_def_id(): cred_def_json }).to_string(), + None, ) - .await; - let cred_def_json: serde_json::Value = - serde_json::from_str(cred_def.get_cred_def_json()).unwrap(); - let schema_json: serde_json::Value = serde_json::from_str(&schema.schema_json).unwrap(); - - let anoncreds = &setup.anoncreds; - let prover_proof_json = anoncreds - .prover_create_proof( - &setup.wallet, - &proof_req_json, - &json!({ - "self_attested_attributes":{ - "attribute_2": "my_self_attested_val" - }, - "requested_attributes":{ - "attribute_0": {"cred_id": cred_id, "revealed": true}, - "attribute_1": {"cred_id": cred_id, "revealed": true} - }, - "requested_predicates":{} - }) - .to_string(), - "main", - &json!({ schema.schema_id: schema_json }).to_string(), - &json!({ cred_def.get_cred_def_id(): cred_def_json }).to_string(), - None, - ) - .await - .unwrap(); - assert!(validate_indy_proof( + .await?; + assert!( + validate_indy_proof( &setup.ledger_read, &setup.anoncreds, &prover_proof_json, - &proof_req_json + &proof_req_json, ) - .await - .unwrap()); - - let mut proof_obj: serde_json::Value = serde_json::from_str(&prover_proof_json).unwrap(); - { - proof_obj["requested_proof"]["revealed_attrs"]["address1_1"]["raw"] = - json!("Other Value"); - let prover_proof_json = serde_json::to_string(&proof_obj).unwrap(); - - assert_eq!( - validate_indy_proof( - &setup.ledger_read, - &setup.anoncreds, - &prover_proof_json, - &proof_req_json - ) - .await - .unwrap_err() - .kind(), - AriesVcxErrorKind::InvalidProof - ); - } - { - proof_obj["requested_proof"]["revealed_attrs"]["address1_1"]["encoded"] = - json!("1111111111111111111111111111111111111111111111111111111111"); - let prover_proof_json = serde_json::to_string(&proof_obj).unwrap(); - - assert_eq!( - validate_indy_proof( - &setup.ledger_read, - &setup.anoncreds, - &prover_proof_json, - &proof_req_json - ) - .await - .unwrap_err() - .kind(), - AriesVcxErrorKind::InvalidProof - ); - } - }) - .await; + .await? + ); + + let mut proof_obj: serde_json::Value = serde_json::from_str(&prover_proof_json)?; + { + proof_obj["requested_proof"]["revealed_attrs"]["address1_1"]["raw"] = json!("Other Value"); + let prover_proof_json = serde_json::to_string(&proof_obj)?; + + assert_eq!( + validate_indy_proof( + &setup.ledger_read, + &setup.anoncreds, + &prover_proof_json, + &proof_req_json, + ) + .await + .unwrap_err() + .kind(), + AriesVcxErrorKind::InvalidProof + ); + } + { + proof_obj["requested_proof"]["revealed_attrs"]["address1_1"]["encoded"] = + json!("1111111111111111111111111111111111111111111111111111111111"); + let prover_proof_json = serde_json::to_string(&proof_obj).unwrap(); + + assert_eq!( + validate_indy_proof( + &setup.ledger_read, + &setup.anoncreds, + &prover_proof_json, + &proof_req_json, + ) + .await + .unwrap_err() + .kind(), + AriesVcxErrorKind::InvalidProof + ); + } + Ok(()) } + #[tokio::test] #[ignore] -async fn test_pool_prover_verify_proof() { - run_setup_test!(|setup| async move { - let (schemas, cred_defs, proof_req, proof) = create_indy_proof( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - ) - .await; +async fn test_pool_prover_verify_proof() -> Result<(), Box> { + let setup = build_setup_profile().await; + let (schemas, cred_defs, proof_req, proof) = create_indy_proof( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + ) + .await?; - let anoncreds = &setup.anoncreds; - let proof_validation = anoncreds - .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") - .await - .unwrap(); + let anoncreds = &setup.anoncreds; + let proof_validation = anoncreds + .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") + .await?; - assert!(proof_validation); - }) - .await; + assert!(proof_validation); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_prover_verify_proof_with_predicate_success_case() { - run_setup_test!(|setup| async move { - let (schemas, cred_defs, proof_req, proof) = create_proof_with_predicate( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - true, - ) - .await; +async fn test_pool_prover_verify_proof_with_predicate_success_case() -> Result<(), Box> { + let setup = build_setup_profile().await; + let (schemas, cred_defs, proof_req, proof) = create_proof_with_predicate( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + true, + ) + .await?; - let anoncreds = &setup.anoncreds; - let proof_validation = anoncreds - .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") - .await - .unwrap(); + let anoncreds = &setup.anoncreds; + let proof_validation = anoncreds + .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") + .await?; - assert!(proof_validation); - }) - .await; + assert!(proof_validation); + Ok(()) } #[tokio::test] #[ignore] -async fn test_pool_prover_verify_proof_with_predicate_fail_case() { - run_setup_test!(|setup| async move { - let (schemas, cred_defs, proof_req, proof) = create_proof_with_predicate( - &setup.wallet, - &setup.wallet, - &setup.anoncreds, - &setup.anoncreds, - &setup.ledger_read, - &setup.ledger_write, - &setup.institution_did, - false, - ) - .await; +async fn test_pool_prover_verify_proof_with_predicate_fail_case() -> Result<(), Box> { + let setup = build_setup_profile().await; + let (schemas, cred_defs, proof_req, proof) = create_proof_with_predicate( + &setup.wallet, + &setup.wallet, + &setup.anoncreds, + &setup.anoncreds, + &setup.ledger_read, + &setup.ledger_write, + &setup.institution_did, + false, + ) + .await?; - let anoncreds = &setup.anoncreds; - anoncreds - .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") - .await - .unwrap_err(); - }) - .await; + let anoncreds = &setup.anoncreds; + anoncreds + .verifier_verify_proof(&proof_req, &proof, &schemas, &cred_defs, "{}", "{}") + .await + .unwrap_err(); + Ok(()) } diff --git a/tools/test_utils/src/devsetup.rs b/tools/test_utils/src/devsetup.rs index bd4ab0fb2f..446db27f86 100644 --- a/tools/test_utils/src/devsetup.rs +++ b/tools/test_utils/src/devsetup.rs @@ -351,17 +351,10 @@ where { f(self).await; } - - pub async fn run2(self, f: impl FnOnce(Self) -> F) -> Result<(), Box> - where - F: Future>>, - { - f(self).await - } } impl SetupPoolDirectory { - async fn init() -> SetupPoolDirectory { + pub async fn init() -> SetupPoolDirectory { debug!("SetupPoolDirectory init >> going to setup agency environment"); init_test_logging();