Skip to content

Commit

Permalink
Deduplicate exchange_proof_and_verify
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee committed Sep 6, 2023
1 parent c1c11dc commit d536b81
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
32 changes: 24 additions & 8 deletions aries_vcx/tests/test_creds_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ mod tests {
)
.await;

exchange_proof_and_verify(&mut verifier, &mut consumer1, &schema_id, &cred_def_id, Some("request1")).await;
exchange_proof_and_verify(&mut verifier, &mut consumer2, &schema_id, &cred_def_id, Some("request2")).await;
exchange_proof_and_verify(&mut verifier, &mut consumer1, &schema_id, &cred_def_id, Some("request1"), PresentationVerificationStatus::Valid).await;
exchange_proof_and_verify(&mut verifier, &mut consumer2, &schema_id, &cred_def_id, Some("request2"), PresentationVerificationStatus::Valid).await;
}).await;
}

Expand All @@ -832,8 +832,24 @@ mod tests {
#[cfg(feature = "migration")]
issuer.migrate().await;

exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, Some("request1")).await;
exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, Some("request2")).await;
exchange_proof_and_verify(
&mut verifier,
&mut consumer,
&schema_id,
&cred_def_id,
Some("request1"),
PresentationVerificationStatus::Valid,
)
.await;
exchange_proof_and_verify(
&mut verifier,
&mut consumer,
&schema_id,
&cred_def_id,
Some("request2"),
PresentationVerificationStatus::Valid,
)
.await;
})
.await;
}
Expand All @@ -859,8 +875,8 @@ mod tests {
)
.await;

exchange_proof_and_verify(&mut institution, &mut consumer, &schema_id, &cred_def_id, Some("request1")).await;
exchange_proof_and_verify(&mut institution, &mut consumer, &schema_id, &cred_def_id, Some("request2")).await;
exchange_proof_and_verify(&mut institution, &mut consumer, &schema_id, &cred_def_id, Some("request1"), PresentationVerificationStatus::Valid).await;
exchange_proof_and_verify(&mut institution, &mut consumer, &schema_id, &cred_def_id, Some("request2"), PresentationVerificationStatus::Valid).await;
}).await;
}

Expand Down Expand Up @@ -992,8 +1008,8 @@ mod tests {
#[cfg(feature = "migration")]
verifier.migrate().await;

exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, req1).await;
exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, req2).await;
exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, req1, PresentationVerificationStatus::Valid).await;
exchange_proof_and_verify(&mut verifier, &mut consumer, &schema_id, &cred_def_id, req2, PresentationVerificationStatus::Valid).await;
}).await;
}

Expand Down
20 changes: 11 additions & 9 deletions aries_vcx/tests/test_creds_proofs_revocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod integration_tests {
use crate::utils::migration::Migratable;
use crate::utils::scenarios::test_utils::{
_create_address_schema_creddef_revreg, _exchange_credential, attr_names, create_proof_request_data,
create_verifier_from_request_data, exchange_proof_and_verify, exchange_proof_and_verify_invalid,
issue_address_credential, prover_select_credentials_and_send_proof, publish_revocation, requested_attrs,
create_verifier_from_request_data, exchange_proof_and_verify, issue_address_credential,
prover_select_credentials_and_send_proof, publish_revocation, requested_attrs,
revoke_credential_and_publish_accumulator, revoke_credential_local, rotate_rev_reg,
verifier_create_proof_and_send_request,
};
Expand Down Expand Up @@ -193,6 +193,7 @@ mod integration_tests {
&schema_id,
&cred_def_id,
Some("request1"),
PresentationVerificationStatus::Valid,
)
.await;

Expand All @@ -203,12 +204,13 @@ mod integration_tests {

publish_revocation(&mut institution, &rev_reg).await;

exchange_proof_and_verify_invalid(
exchange_proof_and_verify(
&mut institution,
&mut consumer,
&schema_id,
&cred_def_id,
Some("request2"),
PresentationVerificationStatus::Invalid,
)
.await;

Expand Down Expand Up @@ -279,9 +281,9 @@ mod integration_tests {
assert!(!issuer_credential3.is_revoked(&institution.profile.inject_anoncreds_ledger_read()).await.unwrap());

// Revoke two locally and verify their are all still valid
exchange_proof_and_verify(&mut institution, &mut consumer1, &schema_id, &cred_def_id, Some("request1")).await;
exchange_proof_and_verify(&mut institution, &mut consumer2, &schema_id, &cred_def_id, Some("request2")).await;
exchange_proof_and_verify(&mut institution, &mut consumer3, &schema_id, &cred_def_id, Some("request3")).await;
exchange_proof_and_verify(&mut institution, &mut consumer1, &schema_id, &cred_def_id, Some("request1"), PresentationVerificationStatus::Valid).await;
exchange_proof_and_verify(&mut institution, &mut consumer2, &schema_id, &cred_def_id, Some("request2"), PresentationVerificationStatus::Valid).await;
exchange_proof_and_verify(&mut institution, &mut consumer3, &schema_id, &cred_def_id, Some("request3"), PresentationVerificationStatus::Valid).await;

// Publish revocations and verify the two are invalid, third still valid
publish_revocation(&mut institution, &rev_reg).await;
Expand All @@ -291,9 +293,9 @@ mod integration_tests {
assert!(issuer_credential2.is_revoked(&institution.profile.inject_anoncreds_ledger_read()).await.unwrap());
assert!(!issuer_credential3.is_revoked(&institution.profile.inject_anoncreds_ledger_read()).await.unwrap());

exchange_proof_and_verify_invalid(&mut institution, &mut consumer1, &schema_id, &cred_def_id, Some("request1")).await;
exchange_proof_and_verify_invalid(&mut institution, &mut consumer2, &schema_id, &cred_def_id, Some("request2")).await;
exchange_proof_and_verify(&mut institution, &mut consumer3, &schema_id, &cred_def_id, Some("request3")).await;
exchange_proof_and_verify(&mut institution, &mut consumer1, &schema_id, &cred_def_id, Some("request1"), PresentationVerificationStatus::Invalid).await;
exchange_proof_and_verify(&mut institution, &mut consumer2, &schema_id, &cred_def_id, Some("request2"), PresentationVerificationStatus::Invalid).await;
exchange_proof_and_verify(&mut institution, &mut consumer3, &schema_id, &cred_def_id, Some("request3"), PresentationVerificationStatus::Valid).await;
})
.await;
}
Expand Down
34 changes: 6 additions & 28 deletions aries_vcx/tests/utils/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,38 +1067,19 @@ pub mod test_utils {
schema_id: &str,
cred_def_id: &str,
request_name: Option<&str>,
expected_result: PresentationVerificationStatus,
) {
let mut verifier =
verifier_create_proof_and_send_request(institution, &schema_id, &cred_def_id, request_name).await;

#[cfg(feature = "migration")]
consumer.migrate().await;

let presentation =
prover_select_credentials_and_send_proof(consumer, verifier.get_presentation_request_msg().unwrap(), None)
.await;
verifier
.verify_presentation(
&institution.profile.inject_anoncreds_ledger_read(),
&institution.profile.inject_anoncreds(),
presentation,
)
.await
.unwrap();
assert_eq!(
verifier.get_verification_status(),
PresentationVerificationStatus::Valid
);
let verifier = exchange_proof(institution, consumer, schema_id, cred_def_id, request_name).await;
assert_eq!(verifier.get_verification_status(), expected_result);
}

// TODO: Deduplicate
pub async fn exchange_proof_and_verify_invalid(
async fn exchange_proof(
institution: &mut Faber,
consumer: &mut Alice,
schema_id: &str,
cred_def_id: &str,
request_name: Option<&str>,
) {
) -> Verifier {
let mut verifier =
verifier_create_proof_and_send_request(institution, &schema_id, &cred_def_id, request_name).await;

Expand All @@ -1116,9 +1097,6 @@ pub mod test_utils {
)
.await
.unwrap();
assert_eq!(
verifier.get_verification_status(),
PresentationVerificationStatus::Invalid
);
verifier
}
}

0 comments on commit d536b81

Please sign in to comment.