diff --git a/agents/rust/aries-vcx-agent/src/services/schema.rs b/agents/rust/aries-vcx-agent/src/services/schema.rs index 54b4fb20d0..402d934c21 100644 --- a/agents/rust/aries-vcx-agent/src/services/schema.rs +++ b/agents/rust/aries-vcx-agent/src/services/schema.rs @@ -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(()) } diff --git a/aries_vcx/src/common/anoncreds.rs b/aries_vcx/src/common/anoncreds.rs index 87e132ea98..265774083e 100644 --- a/aries_vcx/src/common/anoncreds.rs +++ b/aries_vcx/src/common/anoncreds.rs @@ -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, @@ -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, diff --git a/aries_vcx/src/common/credentials/mod.rs b/aries_vcx/src/common/credentials/mod.rs index 5d934e27ff..89a987b08a 100644 --- a/aries_vcx/src/common/credentials/mod.rs +++ b/aries_vcx/src/common/credentials/mod.rs @@ -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, }; @@ -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, @@ -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, diff --git a/aries_vcx/src/common/primitives/credential_schema.rs b/aries_vcx/src/common/primitives/credential_schema.rs index 84f2d18172..adf15f9563 100644 --- a/aries_vcx/src/common/primitives/credential_schema.rs +++ b/aries_vcx/src/common/primitives/credential_schema.rs @@ -91,35 +91,11 @@ impl Schema { }) } - pub fn create_from_ledger_json( - schema_json: &str, - source_id: &str, - schema_id: &str, - ) -> VcxResult { - 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, - ) -> VcxResult { + pub async fn publish(self, ledger: &impl AnoncredsLedgerWrite) -> VcxResult { trace!("Schema::publish >>>"); if settings::indy_mocks_enabled() { @@ -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 { diff --git a/aries_vcx/src/common/test_utils.rs b/aries_vcx/src/common/test_utils.rs index 83aa9c5df3..f3e5f1a5fa 100644 --- a/aries_vcx/src/common/test_utils.rs +++ b/aries_vcx/src/common/test_utils.rs @@ -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::>(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( @@ -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, diff --git a/aries_vcx/tests/test_pool.rs b/aries_vcx/tests/test_pool.rs index 98853911ed..235ee9b020 100644 --- a/aries_vcx/tests/test_pool.rs +++ b/aries_vcx/tests/test_pool.rs @@ -25,7 +25,7 @@ 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, }, }, @@ -33,7 +33,7 @@ use aries_vcx::{ errors::error::AriesVcxErrorKind, run_setup, utils::{ - constants::DEFAULT_SCHEMA_ATTRS, + constants::{DEFAULT_SCHEMA_ATTRS, TEST_TAILS_URL}, devsetup::{SetupPoolDirectory, SetupProfile}, }, }; @@ -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) } @@ -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 diff --git a/aries_vcx/tests/test_proof_presentation.rs b/aries_vcx/tests/test_proof_presentation.rs index de46090a41..0bb2426f0c 100644 --- a/aries_vcx/tests/test_proof_presentation.rs +++ b/aries_vcx/tests/test_proof_presentation.rs @@ -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}, @@ -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, diff --git a/aries_vcx/tests/utils/scenarios/credential_issuance.rs b/aries_vcx/tests/utils/scenarios/credential_issuance.rs index d6b3f09bea..a0aef3420f 100644 --- a/aries_vcx/tests/utils/scenarios/credential_issuance.rs +++ b/aries_vcx/tests/utils/scenarios/credential_issuance.rs @@ -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, }, }, @@ -58,7 +58,7 @@ pub async fn create_address_schema_creddef_revreg( 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, diff --git a/libvcx_core/src/api_vcx/api_handle/credential_def.rs b/libvcx_core/src/api_vcx/api_handle/credential_def.rs index 9dd67bf1e5..b8ef158e6c 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential_def.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential_def.rs @@ -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, }; @@ -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() { diff --git a/libvcx_core/src/api_vcx/api_handle/schema.rs b/libvcx_core/src/api_vcx/api_handle/schema.rs index 0e45dac00f..84eecfa5d3 100644 --- a/libvcx_core/src/api_vcx/api_handle/schema.rs +++ b/libvcx_core/src/api_vcx/api_handle/schema.rs @@ -58,7 +58,7 @@ pub async fn create_and_publish_schema( &data, ) .await? - .publish(&get_main_anoncreds_ledger_write()?, None) + .publish(&get_main_anoncreds_ledger_write()?) .await?; std::thread::sleep(std::time::Duration::from_millis(100)); debug!( @@ -71,25 +71,6 @@ pub async fn create_and_publish_schema( .map_err(|e| LibvcxError::from_msg(LibvcxErrorKind::CreateSchema, e.to_string())) } -pub async fn get_schema_attrs(source_id: String, schema_id: String) -> LibvcxResult<(u32, String)> { - trace!( - "get_schema_attrs >>> source_id: {}, schema_id: {}", - source_id, - schema_id - ); - let schema_ledger_data_json = get_main_anoncreds_ledger_read()? - .get_schema(&schema_id, None) - .await?; - let schema = Schema::create_from_ledger_json(&schema_ledger_data_json, &source_id, &schema_id)?; - let schema_json = schema.to_string_versioned()?; - - let handle = SCHEMA_MAP - .add(schema) - .map_err(|e| LibvcxError::from_msg(LibvcxErrorKind::CreateSchema, e.to_string()))?; - - Ok((handle, schema_json)) -} - pub fn is_valid_handle(handle: u32) -> bool { SCHEMA_MAP.has_handle(handle) } @@ -192,20 +173,15 @@ pub mod test_utils { #[cfg(test)] pub mod tests { use aries_vcx::{ - common::test_utils::create_and_write_test_schema, global::settings::{set_config_value, DEFAULT_DID}, - utils::{ - constants, - constants::SCHEMA_ID, - devsetup::{SetupDefaults, SetupEmpty, SetupMocks}, - }, + utils::devsetup::{SetupDefaults, SetupEmpty, SetupMocks}, }; use super::*; use crate::api_vcx::{ api_handle::{ schema, - schema::test_utils::{check_schema, create_schema_real, prepare_schema_data}, + schema::test_utils::{create_schema_real, prepare_schema_data}, }, utils::devsetup::SetupGlobalsWalletPoolAgency, }; @@ -245,23 +221,6 @@ pub mod tests { .unwrap(); } - #[tokio::test] - async fn test_get_schema_attrs_success() { - let _setup = SetupMocks::init(); - - let (handle, schema_json) = - get_schema_attrs("Check For Success".to_string(), SCHEMA_ID.to_string()) - .await - .unwrap(); - - check_schema( - handle, - &schema_json, - SCHEMA_ID, - r#"["name","age","height","sex"]"#, - ); - } - #[tokio::test] async fn test_create_schema_fails() { let _setup = SetupDefaults::init(); @@ -273,33 +232,6 @@ pub mod tests { assert_eq!(err.kind(), LibvcxErrorKind::SerializationError) } - #[tokio::test] - #[ignore] - async fn test_get_schema_attrs_from_ledger() { - 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, - constants::DEFAULT_SCHEMA_ATTRS, - ) - .await; - - let (schema_handle, schema_attrs) = - get_schema_attrs("id".to_string(), schema.schema_id.clone()) - .await - .unwrap(); - - check_schema( - schema_handle, - &schema_attrs, - &schema.schema_id, - constants::DEFAULT_SCHEMA_ATTRS, - ); - }) - .await; - } - #[tokio::test] #[ignore] async fn test_create_schema_with_pool() { @@ -421,31 +353,4 @@ pub mod tests { }) .await; } - - #[tokio::test] - #[ignore] - async fn test_vcx_schema_get_attrs_with_pool() { - SetupGlobalsWalletPoolAgency::run(|_setup| async move { - let (_issuer_did, schema_name, schema_version, schema_data) = prepare_schema_data(); - let schema_handle = schema::create_and_publish_schema( - "source_id", - schema_name, - schema_version, - schema_data, - ) - .await - .unwrap(); - let _schema_json_1 = schema::to_string(schema_handle).unwrap(); - let schema_id = schema::get_schema_id(schema_handle).unwrap(); - - let (_schema_handle, schema_json_2) = - schema::get_schema_attrs("source_id".into(), schema_id) - .await - .unwrap(); - let j: serde_json::Value = serde_json::from_str(&schema_json_2).unwrap(); - let _schema: Schema = serde_json::from_value(j["data"].clone()).unwrap(); - assert_eq!(j["version"], "1.0"); - }) - .await; - } }