Skip to content

Commit

Permalink
refactor: update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Naian <[email protected]>
  • Loading branch information
nain-F49FF806 committed Nov 15, 2023
1 parent c8ad419 commit f600b98
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 260 deletions.
117 changes: 0 additions & 117 deletions aries/agents/rust/mediator/mediation/src/didcomm_types.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ use aries_vcx::{
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use diddoc_legacy::aries::diddoc::AriesDidDoc;
use mediation::{
didcomm_types::mediator_coord_structs::{MediateGrantData, MediatorCoordMsgEnum},
storage::MediatorPersistence,
};
use mediation::storage::MediatorPersistence;
use mediator::{
aries_agent::{
client::transports::{AriesReqwest, AriesTransport},
utils::oob2did,
Agent,
},
utils::{structs::VerKey, GenericStringError},
};
use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation;
use messages::{
msg_fields::protocols::{
coordinate_mediation::{
keylist_update::{KeylistUpdateItem, KeylistUpdateItemAction},
CoordinateMediation, KeylistUpdate, KeylistUpdateContent, MediateGrantContent,
MediateRequest, MediateRequestContent,
},
out_of_band::invitation::Invitation as OOBInvitation,
},
AriesMessage,
};
use reqwest::header::ACCEPT;

use super::prelude::*;
Expand Down Expand Up @@ -91,15 +99,62 @@ pub async fn send_message_and_pop_response_message(
.unwrap();
Ok(unpacked_response.message)
}
/// Register recipient keys with mediator
pub async fn gen_and_register_recipient_key(
agent: &mut Agent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent_aries_transport: &mut impl AriesTransport,
agent_verkey: &VerKey,
mediator_diddoc: &AriesDidDoc,
) -> Result<(VerKey, AriesDidDoc)> {
let agent_invite: OOBInvitation = agent
.get_oob_invite()
.map_err(|e| GenericStringError { msg: e.to_string() })?;
let agent_diddoc = oob2did(agent_invite);
let agent_recipient_key = agent_diddoc
.recipient_keys()
.unwrap()
.first()
.unwrap()
.clone();
// register recipient key with mediator
let key_update = KeylistUpdate::builder()
.content(
KeylistUpdateContent::builder()
.updates(vec![KeylistUpdateItem {
recipient_key: agent_recipient_key.clone(),
action: KeylistUpdateItemAction::Add,
}])
.build(),
)
.id("register-key-with-mediator".to_owned())
.build();
let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate(key_update));
info!("Sending {:?}", serde_json::to_string(&message).unwrap());
let message_bytes = serde_json::to_vec(&message)?;
let _response_message = send_message_and_pop_response_message(
&message_bytes,
agent,
agent_aries_transport,
agent_verkey,
mediator_diddoc,
)
.await?;
Ok((agent_recipient_key, agent_diddoc))
}

pub async fn get_mediator_grant_data(
agent: &Agent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent_aries_transport: &mut impl AriesTransport,
agent_verkey: &VerKey,
mediator_diddoc: &AriesDidDoc,
) -> MediateGrantData {
) -> MediateGrantContent {
// prepare request message
let message = MediatorCoordMsgEnum::MediateRequest;
let message = AriesMessage::CoordinateMediation(CoordinateMediation::MediateRequest(
MediateRequest::builder()
.content(MediateRequestContent::default())
.id("mediate-requets".to_owned())
.build(),
));
let message_bytes = serde_json::to_vec(&message).unwrap();
// send message and get response
let response_message = send_message_and_pop_response_message(
Expand All @@ -112,11 +167,11 @@ pub async fn get_mediator_grant_data(
.await
.unwrap();
// extract routing parameters
if let MediatorCoordMsgEnum::MediateGrant(grant_data) =
if let AriesMessage::CoordinateMediation(CoordinateMediation::MediateGrant(grant_data)) =
serde_json::from_str(&response_message).unwrap()
{
info!("Grant Data {:?}", grant_data);
grant_data
grant_data.content
} else {
panic!(
"Should get response that is of type Mediator Grant. Found {:?}",
Expand Down
Loading

0 comments on commit f600b98

Please sign in to comment.