Skip to content

Commit

Permalink
Delete dead code, simplify testing
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Sep 26, 2023
1 parent ecc2047 commit a5acdcb
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 208 deletions.
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 @@ -43,7 +43,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.inject_anoncreds_ledger_write(), None)
.publish(&self.profile.inject_anoncreds_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 @@ -12,8 +12,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 @@ -130,7 +130,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.inject_anoncreds(),
&setup.profile.inject_anoncreds_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 @@ -57,8 +57,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 @@ -83,7 +83,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.inject_anoncreds(),
&setup.profile.inject_anoncreds_ledger_write(),
&setup.institution_did,
Expand Down Expand Up @@ -138,7 +138,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.inject_anoncreds(),
&setup.profile.inject_anoncreds_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: &Arc<dyn AnoncredsLedgerWrite>,
endorser_did: Option<String>,
) -> VcxResult<Self> {
pub async fn publish(self, ledger: &Arc<dyn 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
34 changes: 17 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,22 @@ 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(),
&attr_list
.split(',')
.map(|slice| slice.to_string())
.collect(),
)
.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 +77,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: &Arc<dyn BaseAnonCreds>,
ledger_write: &Arc<dyn 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 @@ -24,13 +24,13 @@ 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,
},
},
errors::error::AriesVcxErrorKind,
utils::{
constants::DEFAULT_SCHEMA_ATTRS,
constants::{DEFAULT_SCHEMA_ATTRS, TEST_TAILS_URL},
devsetup::{SetupPoolDirectory, SetupProfile},
},
};
Expand Down Expand Up @@ -100,15 +100,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 @@ -541,6 +541,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 = Arc::clone(&setup.profile).inject_anoncreds_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 @@ -9,8 +9,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 @@ -55,7 +55,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.inject_anoncreds(),
&setup.profile.inject_anoncreds_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(
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
49 changes: 1 addition & 48 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,14 @@ 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_handle::schema,
utils::devsetup::SetupGlobalsWalletPoolAgency,
};

Expand Down Expand Up @@ -177,50 +174,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

0 comments on commit a5acdcb

Please sign in to comment.