Skip to content

Commit

Permalink
Fix Endpoint Test
Browse files Browse the repository at this point in the history
Signed-off-by: lli <[email protected]>
  • Loading branch information
lukewli-anonyome committed Aug 6, 2024
1 parent 65b4f1f commit e82e629
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
66 changes: 41 additions & 25 deletions did_core/did_methods/did_resolver_sov/src/resolution/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,47 @@ pub(super) async fn ledger_response_to_ddo(
log::info!("ledger_response_to_ddo >> did: {did}, verkey: {verkey}, resp: {resp}");
let (service_id, ddo_id) = prepare_ids(did)?;

let service_data = get_data_from_response(resp)?;
log::info!("ledger_response_to_ddo >> service_data: {service_data:?}");
let endpoint: EndpointDidSov = serde_json::from_value(service_data["endpoint"].clone())?;

let txn_time = get_txn_time_from_response(resp)?;
let datetime = unix_to_datetime(txn_time);

let service_types: Vec<ServiceType> = endpoint
.types
.into_iter()
.map(|t| match t {
DidSovServiceType::Endpoint => ServiceType::AIP1,
DidSovServiceType::DidCommunication => ServiceType::DIDCommV1,
DidSovServiceType::DIDComm => ServiceType::DIDCommV2,
DidSovServiceType::Unknown => ServiceType::Other("Unknown".to_string()),
})
.collect();
let service = Service::new(
service_id,
endpoint.endpoint,
OneOrList::List(service_types),
Default::default(),
);
let service_data = match get_data_from_response(resp) {
Ok(data) => data,
Err(_) => serde_json::Value::Null,
};

let mut ddo = DidDocument::new(ddo_id.clone());

let mut services = Vec::new();

if !service_data.is_null() {
let endpoint: EndpointDidSov = serde_json::from_value(service_data["endpoint"].clone())?;

let service_types: Vec<ServiceType> = endpoint
.types
.into_iter()
.map(|t| match t {
DidSovServiceType::Endpoint => ServiceType::AIP1,
DidSovServiceType::DidCommunication => ServiceType::DIDCommV1,
DidSovServiceType::DIDComm => ServiceType::DIDCommV2,
DidSovServiceType::Unknown => ServiceType::Other("Unknown".to_string()),
})
.collect();
let service = Service::new(
service_id,
endpoint.endpoint,
OneOrList::List(service_types),
Default::default(),
);
services.push(service);
}

ddo.set_service(services);

let txn_time_result = get_txn_time_from_response(resp);
let datetime = match txn_time_result {
Ok(txn_time) => unix_to_datetime(txn_time),
Err(e) => {
log::warn!("Failed to parse txnTime: {}", e);
None
}
};

let expanded_verkey = expand_abbreviated_verkey(ddo_id.id(), &verkey)?;

Expand All @@ -127,8 +145,6 @@ pub(super) async fn ledger_response_to_ddo(
})
.build();

let mut ddo = DidDocument::new(ddo_id);
ddo.add_service(service);
ddo.add_verification_method(verification_method);
ddo.add_key_agreement_ref(DidUrl::parse("#1".to_string())?);

Expand Down
20 changes: 3 additions & 17 deletions did_core/did_methods/did_resolver_sov/tests/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,18 @@ async fn test_error_handling_during_resolution() {
#[tokio::test]
async fn write_new_nym_and_get_did_doc() {
let profile = build_setup_profile().await;

write_test_endpoint(
&profile.wallet,
&profile.ledger_write,
&profile.institution_did,
)
.await;

let did_data: aries_vcx_wallet::wallet::base_wallet::did_data::DidData = profile
let did_data = profile
.wallet
.create_and_store_my_did(None, None)
.await
.unwrap();

let parsed_did = Did::parse(did_data.did().to_string())
.map_err(|e| {
eprintln!("Failed to parse DID: {}", e);
})
.unwrap();

profile
.ledger_write
.publish_nym(
&profile.wallet,
&profile.institution_did,
&parsed_did,
&did_data.did().parse().unwrap(),
Some(did_data.verkey()),
None,
None,
Expand All @@ -96,7 +82,7 @@ async fn write_new_nym_and_get_did_doc() {
.unwrap();

let resolver = DidSovResolver::new(profile.ledger_read);
let did = format!("did:sov:{}", profile.institution_did);
let did = format!("did:sov:{}", did_data.did());

let DidResolutionOutput { did_document, .. } = resolver
.resolve(&Did::parse(did.clone()).unwrap(), &())
Expand Down

0 comments on commit e82e629

Please sign in to comment.