Skip to content

Commit

Permalink
Added dummy, not functional tests, as a mere representation of the tr…
Browse files Browse the repository at this point in the history
…ansitions between states for the typestate Connection

Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur committed Jan 24, 2023
1 parent 9a7cab9 commit dffbf28
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
15 changes: 14 additions & 1 deletion aries_vcx/src/protocols/connection/invitee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -173,6 +173,19 @@ impl<T> InviteeConnection<T, InvitedState> {
transport_type,
})
}

pub async fn send_request(
self,
profile: &Arc<dyn Profile>,
service_endpoint: String,
routing_keys: Vec<String>,
send_message: Option<SendClosureConnection>,
) -> VcxResult<InviteeConnection<T, RequestedState>> {
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<T> InviteeConnection<T, RequestedState> {
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/protocols/connection/inviter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<T> InviterConnection<T, InitialState> {
}
}

pub async fn create_invite(
pub fn create_invite(
self,
service_endpoint: String,
routing_keys: Vec<String>,
Expand Down
36 changes: 36 additions & 0 deletions aries_vcx/src/protocols/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit dffbf28

Please sign in to comment.