Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/test #995

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agents/rust/aries-vcx-agent/src/services/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ServiceSchemas {

pub async fn publish_schema(&self, thread_id: &str) -> AgentResult<()> {
let schema = self.schemas.get(thread_id)?;
let schema = schema.publish(self.profile.ledger_write(), None).await?;
let schema = schema.publish(self.profile.ledger_write()).await?;
self.schemas.insert(thread_id, schema)?;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/src/common/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub mod integration_tests {
common::{
credentials::get_cred_rev_id,
test_utils::{
create_and_write_credential, create_and_write_test_cred_def,
create_and_write_test_rev_reg, create_and_write_test_schema,
create_and_publish_test_rev_reg, create_and_write_credential,
create_and_write_test_cred_def, create_and_write_test_schema,
},
},
utils::devsetup::SetupProfile,
Expand Down Expand Up @@ -129,7 +129,7 @@ pub mod integration_tests {
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
setup.profile.anoncreds(),
setup.profile.ledger_write(),
&setup.institution_did,
Expand Down
8 changes: 4 additions & 4 deletions aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ mod integration_tests {
use super::*;
use crate::{
common::test_utils::{
create_and_write_credential, create_and_write_test_cred_def,
create_and_write_test_rev_reg, create_and_write_test_schema,
create_and_publish_test_rev_reg, create_and_write_credential,
create_and_write_test_cred_def, create_and_write_test_schema,
},
utils::devsetup::SetupProfile,
};
Expand All @@ -80,7 +80,7 @@ mod integration_tests {
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
setup.profile.anoncreds(),
setup.profile.ledger_write(),
&setup.institution_did,
Expand Down Expand Up @@ -135,7 +135,7 @@ mod integration_tests {
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
setup.profile.anoncreds(),
setup.profile.ledger_write(),
&setup.institution_did,
Expand Down
32 changes: 4 additions & 28 deletions aries_vcx/src/common/primitives/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,11 @@ impl Schema {
})
}

pub fn create_from_ledger_json(
schema_json: &str,
source_id: &str,
schema_id: &str,
) -> VcxResult<Self> {
let schema_data: SchemaData = serde_json::from_str(schema_json).map_err(|err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
format!("Cannot deserialize schema: {}", err),
)
})?;

Ok(Self {
source_id: source_id.to_string(),
schema_id: schema_id.to_string(),
schema_json: schema_json.to_string(),
name: schema_data.name,
version: schema_data.version,
data: schema_data.attr_names,
submitter_did: "".to_string(),
state: PublicEntityStateType::Published,
})
pub async fn submitter_did(&self) -> String {
self.submitter_did.clone()
}

pub async fn publish(
self,
ledger: &impl AnoncredsLedgerWrite,
endorser_did: Option<String>,
) -> VcxResult<Self> {
pub async fn publish(self, ledger: &impl AnoncredsLedgerWrite) -> VcxResult<Self> {
trace!("Schema::publish >>>");

if settings::indy_mocks_enabled() {
Expand All @@ -130,7 +106,7 @@ impl Schema {
}

ledger
.publish_schema(&self.schema_json, &self.submitter_did, endorser_did)
.publish_schema(&self.schema_json, &self.submitter_did, None)
.await?;

Ok(Self {
Expand Down
31 changes: 14 additions & 17 deletions aries_vcx/src/common/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,19 @@ pub async fn create_and_write_test_schema(
submitter_did: &str,
attr_list: &str,
) -> Schema {
let (schema_id, schema_json) = anoncreds
.issuer_create_schema(
submitter_did,
&generate_random_schema_name(),
&generate_random_schema_version(),
attr_list,
)
.await
.unwrap();

ledger_write
.publish_schema(&schema_json, submitter_did, None)
.await
.unwrap();
tokio::time::sleep(Duration::from_millis(1000)).await;
Schema::create_from_ledger_json(&schema_json, "", &schema_id).unwrap()
let schema = Schema::create(
anoncreds,
"source_id",
submitter_did,
&generate_random_schema_name(),
&generate_random_schema_version(),
&serde_json::from_str::<Vec<String>>(attr_list).unwrap(),
)
.await
.unwrap();
let schema = schema.publish(ledger_write).await.unwrap();
std::thread::sleep(Duration::from_millis(500));
schema
}

pub async fn create_and_write_test_cred_def(
Expand Down Expand Up @@ -77,7 +74,7 @@ pub async fn create_and_write_test_cred_def(
.unwrap()
}

pub async fn create_and_write_test_rev_reg(
pub async fn create_and_publish_test_rev_reg(
anoncreds: &impl BaseAnonCreds,
ledger_write: &impl AnoncredsLedgerWrite,
issuer_did: &str,
Expand Down
12 changes: 8 additions & 4 deletions aries_vcx/tests/test_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use aries_vcx::{
revocation_registry_delta::RevocationRegistryDelta,
},
test_utils::{
create_and_write_test_cred_def, create_and_write_test_rev_reg,
create_and_publish_test_rev_reg, create_and_write_test_cred_def,
create_and_write_test_schema,
},
},
core::profile::profile::Profile,
errors::error::AriesVcxErrorKind,
run_setup,
utils::{
constants::DEFAULT_SCHEMA_ATTRS,
constants::{DEFAULT_SCHEMA_ATTRS, TEST_TAILS_URL},
devsetup::{SetupPoolDirectory, SetupProfile},
},
};
Expand Down Expand Up @@ -103,15 +103,15 @@ async fn create_and_store_revocable_credential_def(
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
anoncreds,
ledger_write,
issuer_did,
&cred_def.get_cred_def_id(),
)
.await;

tokio::time::sleep(Duration::from_millis(1000)).await;

(schema, cred_def, rev_reg)
}

Expand Down Expand Up @@ -514,6 +514,10 @@ async fn test_pool_get_rev_reg() {
&attrs,
)
.await;
assert_eq!(
TEST_TAILS_URL,
rev_reg.get_rev_reg_def().value.tails_location
);

let ledger = setup.profile.ledger_read();
let (id, _rev_reg, _timestamp) = ledger
Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/tests/test_proof_presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use aries_vcx::{
common::{
proofs::proof_request::PresentationRequestData,
test_utils::{
create_and_write_credential, create_and_write_test_cred_def,
create_and_write_test_rev_reg, create_and_write_test_schema,
create_and_publish_test_rev_reg, create_and_write_credential,
create_and_write_test_cred_def, create_and_write_test_schema,
},
},
handlers::proof_presentation::{prover::Prover, verifier::Verifier},
Expand Down Expand Up @@ -58,7 +58,7 @@ async fn test_agency_pool_generate_proof_with_predicates() {
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
setup.profile.anoncreds(),
setup.profile.ledger_write(),
&setup.institution_did,
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/tests/utils/scenarios/credential_issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aries_vcx::{
revocation_registry::RevocationRegistry,
},
test_utils::{
create_and_write_test_cred_def, create_and_write_test_rev_reg,
create_and_publish_test_rev_reg, create_and_write_test_cred_def,
create_and_write_test_schema,
},
},
Expand Down Expand Up @@ -58,7 +58,7 @@ pub async fn create_address_schema_creddef_revreg<P: Profile>(
true,
)
.await;
let rev_reg = create_and_write_test_rev_reg(
let rev_reg = create_and_publish_test_rev_reg(
anoncreds,
ledger_write,
institution_did,
Expand Down
50 changes: 1 addition & 49 deletions libvcx_core/src/api_vcx/api_handle/credential_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,13 @@ pub mod tests {
use std::{thread::sleep, time::Duration};

use aries_vcx::{
aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path,
common::test_utils::create_and_write_test_schema,
global::settings::CONFIG_INSTITUTION_DID,
utils,
utils::{constants::SCHEMA_ID, devsetup::SetupMocks},
};

use super::*;
use crate::api_vcx::{
api_global::settings::get_config_value,
api_handle::{revocation_registry, revocation_registry::RevocationRegistryConfig, schema},
api_global::settings::get_config_value, api_handle::schema,
utils::devsetup::SetupGlobalsWalletPoolAgency,
};

Expand Down Expand Up @@ -177,50 +173,6 @@ pub mod tests {
let (_, _) = create_and_publish_nonrevocable_creddef().await;
}

#[tokio::test]
#[ignore]
async fn create_revocable_cred_def_and_check_tails_location() {
SetupGlobalsWalletPoolAgency::run(|setup| async move {
let schema = create_and_write_test_schema(
&get_main_anoncreds().unwrap(),
&get_main_anoncreds_ledger_write().unwrap(),
&setup.institution_did,
utils::constants::DEFAULT_SCHEMA_ATTRS,
)
.await;
let issuer_did = get_config_value(CONFIG_INSTITUTION_DID).unwrap();

let path = get_temp_dir_path();

let handle_cred_def = create(
"1".to_string(),
schema.schema_id.clone(),
"tag1".to_string(),
true,
)
.await
.unwrap();
publish(handle_cred_def).await.unwrap();

let rev_reg_config = RevocationRegistryConfig {
issuer_did,
cred_def_id: get_cred_def_id(handle_cred_def).unwrap(),
tag: 1,
tails_dir: String::from(path.to_str().unwrap()),
max_creds: 2,
};
let handle_rev_reg = revocation_registry::create(rev_reg_config).await.unwrap();
let tails_url = utils::constants::TEST_TAILS_URL;

revocation_registry::publish(handle_rev_reg, tails_url)
.await
.unwrap();
let rev_reg_def = revocation_registry::get_rev_reg_def(handle_rev_reg).unwrap();
assert_eq!(rev_reg_def.value.tails_location, tails_url);
})
.await;
}

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