Skip to content

Commit

Permalink
Additional cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas authored and gmulhearn committed Nov 6, 2023
1 parent b4ebb2e commit c8b8a6e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 96 deletions.
75 changes: 39 additions & 36 deletions aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,47 +276,50 @@ pub fn build_requested_credentials_json(

#[cfg(test)]
pub mod pool_tests {
use std::error::Error;

use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;
use test_utils::{
constants::{CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, SCHEMA_ID},
run_setup_test,
devsetup::build_setup_profile,
};

use crate::common::proofs::prover::prover_internal::{build_rev_states_json, CredInfoProver};

#[tokio::test]
#[ignore]
async fn test_pool_build_rev_states_json_empty() {
run_setup_test!(|setup| async move {
// empty vector
assert_eq!(
build_rev_states_json(&setup.ledger_read, &setup.anoncreds, Vec::new().as_mut())
.await
.unwrap(),
"{}".to_string()
);

// no rev_reg_id
let cred1 = CredInfoProver {
referent: "height_1".to_string(),
credential_referent: LICENCE_CRED_ID.to_string(),
schema_id: SCHEMA_ID.to_string(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: None,
cred_rev_id: Some(CRED_REV_ID.to_string()),
tails_dir: Some(get_temp_dir_path().to_str().unwrap().to_string()),
revocation_interval: None,
timestamp: None,
revealed: None,
};
assert_eq!(
build_rev_states_json(&setup.ledger_read, &setup.anoncreds, vec![cred1].as_mut())
.await
.unwrap(),
"{}".to_string()
);
})
.await;
async fn test_pool_build_rev_states_json_empty() -> Result<(), Box<dyn Error>> {
let setup = build_setup_profile().await;
let mut empty_credential_identifiers = Vec::new();
assert_eq!(
build_rev_states_json(
&setup.ledger_read,
&setup.anoncreds,
empty_credential_identifiers.as_mut()
)
.await?,
"{}".to_string()
);

// no rev_reg_id
let cred1 = CredInfoProver {
referent: "height_1".to_string(),
credential_referent: LICENCE_CRED_ID.to_string(),
schema_id: SCHEMA_ID.to_string(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: None,
cred_rev_id: Some(CRED_REV_ID.to_string()),
tails_dir: Some(get_temp_dir_path().to_str().unwrap().to_string()),
revocation_interval: None,
timestamp: None,
revealed: None,
};
assert_eq!(
build_rev_states_json(&setup.ledger_read, &setup.anoncreds, vec![cred1].as_mut())
.await?,
"{}".to_string()
);
Ok(())
}
}

Expand Down Expand Up @@ -546,15 +549,15 @@ pub mod unit_tests {
assert_eq!(
credential_def_identifiers(
&serde_json::from_str("{}").unwrap(),
&proof_req_no_interval()
&proof_req_no_interval(),
)
.unwrap(),
Vec::new()
);
assert_eq!(
credential_def_identifiers(
&serde_json::from_str(r#"{"attrs":{}}"#).unwrap(),
&proof_req_no_interval()
&proof_req_no_interval(),
)
.unwrap(),
Vec::new()
Expand Down Expand Up @@ -598,7 +601,7 @@ pub mod unit_tests {
assert_eq!(
&credential_def_identifiers(
&serde_json::from_value(selected_credentials.clone()).unwrap(),
&proof_req_no_interval()
&proof_req_no_interval(),
)
.unwrap(),
&creds
Expand All @@ -610,7 +613,7 @@ pub mod unit_tests {
assert_eq!(
&credential_def_identifiers(
&serde_json::from_value(selected_credentials).unwrap(),
&proof_req_no_interval()
&proof_req_no_interval(),
)
.unwrap(),
&creds
Expand Down
56 changes: 29 additions & 27 deletions did_resolver_sov/tests/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use did_resolver::{
traits::resolvable::{resolution_options::DidResolutionOptions, DidResolvable},
};
use did_resolver_sov::resolution::DidSovResolver;
use test_utils::run_setup_test;
use test_utils::devsetup::build_setup_profile;

async fn write_test_endpoint(
wallet: &impl BaseWallet,
Expand All @@ -29,37 +29,39 @@ async fn write_test_endpoint(

#[tokio::test]
async fn write_service_on_ledger_and_resolve_did_doc() {
run_setup_test!(|init| async move {
let did = format!("did:sov:{}", init.institution_did);
write_test_endpoint(&init.wallet, &init.ledger_write, &init.institution_did).await;
let resolver = DidSovResolver::new(&init.ledger_read);
let did_doc = resolver
.resolve(
&Did::parse(did.clone()).unwrap(),
&DidResolutionOptions::default(),
)
.await
.unwrap();
assert_eq!(did_doc.did_document().id().to_string(), did);
})
let profile = build_setup_profile().await;
write_test_endpoint(
&profile.wallet,
&profile.ledger_write,
&profile.institution_did,
)
.await;
let resolver = DidSovResolver::new(&profile.ledger_read);
let did = format!("did:sov:{}", profile.institution_did);

let did_doc = resolver
.resolve(
&Did::parse(did.clone()).unwrap(),
&DidResolutionOptions::default(),
)
.await
.unwrap();

assert_eq!(did_doc.did_document().id().to_string(), did);
}

#[tokio::test]
async fn test_error_handling_during_resolution() {
run_setup_test!(|init| async move {
let did = format!("did:unknownmethod:{}", init.institution_did);

let resolver = DidSovResolver::new(&init.ledger_read);
let profile = build_setup_profile().await;
let resolver = DidSovResolver::new(&profile.ledger_read);
let did = format!("did:unknownmethod:{}", profile.institution_did);

let result = resolver
.resolve(
&Did::parse(did.clone()).unwrap(),
&DidResolutionOptions::default(),
)
.await;
let result = resolver
.resolve(
&Did::parse(did.clone()).unwrap(),
&DidResolutionOptions::default(),
)
.await;

assert!(result.is_err());
})
.await;
assert!(result.is_err());
}
33 changes: 0 additions & 33 deletions tools/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,6 @@ pub async fn dev_build_featured_wallet(key_seed: &str) -> (String, impl BaseWall
return (INSTITUTION_DID.to_owned(), MockWallet);
}

#[macro_export]
macro_rules! run_setup_test {
($func:expr) => {{
$crate::devsetup::build_setup_profile().await.run($func)
}};
}

pub async fn build_setup_profile() -> SetupProfile<
impl IndyLedgerRead + AnoncredsLedgerRead,
impl IndyLedgerWrite + AnoncredsLedgerWrite,
Expand Down Expand Up @@ -338,21 +331,6 @@ pub async fn build_setup_profile() -> SetupProfile<
}
}

impl<LR, LW, A, W> SetupProfile<LR, LW, A, W>
where
LR: IndyLedgerRead + AnoncredsLedgerRead,
LW: IndyLedgerWrite + AnoncredsLedgerWrite,
A: BaseAnonCreds,
W: BaseWallet,
{
pub async fn run<F>(self, f: impl FnOnce(Self) -> F)
where
F: Future<Output = ()>,
{
f(self).await;
}
}

impl SetupPoolDirectory {
pub async fn init() -> SetupPoolDirectory {
debug!("SetupPoolDirectory init >> going to setup agency environment");
Expand All @@ -364,17 +342,6 @@ impl SetupPoolDirectory {
debug!("SetupPoolDirectory init >> completed");
SetupPoolDirectory { genesis_file_path }
}

pub async fn run<F>(f: impl FnOnce(Self) -> F)
where
F: Future<Output = ()>,
{
let init = Self::init().await;

f(init).await;

reset_global_state();
}
}

pub struct TempFile {
Expand Down

0 comments on commit c8b8a6e

Please sign in to comment.