From dffbf289192b1cc949f3d61dca705b4640335a7c Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Tue, 24 Jan 2023 15:24:38 +0200 Subject: [PATCH] Added dummy, not functional tests, as a mere representation of the transitions between states for the typestate Connection Signed-off-by: Bogdan Mircea --- .../src/protocols/connection/invitee/mod.rs | 15 +++++++- .../src/protocols/connection/inviter/mod.rs | 2 +- aries_vcx/src/protocols/connection/mod.rs | 36 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/aries_vcx/src/protocols/connection/invitee/mod.rs b/aries_vcx/src/protocols/connection/invitee/mod.rs index 424496499a..55b95a85f0 100644 --- a/aries_vcx/src/protocols/connection/invitee/mod.rs +++ b/aries_vcx/src/protocols/connection/invitee/mod.rs @@ -9,7 +9,7 @@ use messages::{ }, }; -use crate::errors::error::VcxResult; +use crate::{core::profile::profile::Profile, errors::error::VcxResult}; use self::states::{ complete::CompleteState, initial::InitialState, invited::InvitedState, requested::RequestedState, @@ -173,6 +173,19 @@ impl InviteeConnection { transport_type, }) } + + pub async fn send_request( + self, + profile: &Arc, + service_endpoint: String, + routing_keys: Vec, + send_message: Option, + ) -> VcxResult> { + trace!("Connection::send_request"); + let send_message = send_message.unwrap_or(self.send_message_closure_connection(profile)); + self.send_connection_request(routing_keys, service_endpoint, send_message) + .await + } } impl InviteeConnection { diff --git a/aries_vcx/src/protocols/connection/inviter/mod.rs b/aries_vcx/src/protocols/connection/inviter/mod.rs index e48c1b29d4..3cbfec5d90 100644 --- a/aries_vcx/src/protocols/connection/inviter/mod.rs +++ b/aries_vcx/src/protocols/connection/inviter/mod.rs @@ -74,7 +74,7 @@ impl InviterConnection { } } - pub async fn create_invite( + pub fn create_invite( self, service_endpoint: String, routing_keys: Vec, diff --git a/aries_vcx/src/protocols/connection/mod.rs b/aries_vcx/src/protocols/connection/mod.rs index 48c7c890b9..051d39fe4b 100644 --- a/aries_vcx/src/protocols/connection/mod.rs +++ b/aries_vcx/src/protocols/connection/mod.rs @@ -110,3 +110,39 @@ where })) } } + +#[cfg(test)] +/// Only present to illustrate the transition between states for the typestate Connection. +/// Methods are only available to given states (encoded as types) and thus the Connection is guaranteed +/// at compile time not to get into an invalid state. +mod dummy_tests { + use super::*; + + async fn invitee() { + let con = Connection::new_invitee(source_id, pairwise_info, did_doc, transport_type) + .process_invite(invitation) + .unwrap() + .send_request(profile, service_endpoint, routing_keys, None) + .await + .unwrap() + .handle_connection_response(wallet, response, send_message) + .await + .unwrap() + .handle_send_ack(send_message) + .await + .unwrap(); + } + + async fn inviter() { + let con = Connection::new_inviter(source_id, pairwise_info, transport_type) + .create_invite(service_endpoint, routing_keys) + .process_request(profile, request, service_endpoint, routing_keys, send_message) + .await + .unwrap() + .handle_send_response(send_message) + .await + .unwrap() + .handle_confirmation_message(msg) + .unwrap(); + } +}