diff --git a/crates/interledger-ildcp/src/server.rs b/crates/interledger-ildcp/src/server.rs index 273993457..da2684eba 100644 --- a/crates/interledger-ildcp/src/server.rs +++ b/crates/interledger-ildcp/src/server.rs @@ -49,3 +49,66 @@ where } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::get_ildcp_info; + use lazy_static::lazy_static; + use std::str::FromStr; + use uuid::Uuid; + + lazy_static! { + pub static ref ALICE: Username = Username::from_str("alice").unwrap(); + pub static ref EXAMPLE_ADDRESS: Address = Address::from_str("example.alice").unwrap(); + } + + #[derive(Clone, Debug, Copy)] + struct TestAccount; + + impl Account for TestAccount { + fn id(&self) -> Uuid { + Uuid::new_v4() + } + + fn username(&self) -> &Username { + &ALICE + } + + fn asset_scale(&self) -> u8 { + 9 + } + + fn asset_code(&self) -> &str { + "XYZ" + } + + fn ilp_address(&self) -> &Address { + &EXAMPLE_ADDRESS + } + } + + #[tokio::test] + async fn handles_request() { + let from = TestAccount; + let prepare = IldcpRequest {}.to_prepare(); + let req = IncomingRequest { from, prepare }; + let mut service = IldcpService::new(incoming_service_fn(|_| { + Err(RejectBuilder { + code: ErrorCode::F02_UNREACHABLE, + message: b"No other incoming handler!", + data: &[], + triggered_by: None, + } + .build()) + })); + + let result = service.handle_request(req).await.unwrap(); + assert_eq!(result.data().len(), 19); + + let ildpc_info = get_ildcp_info(&mut service, from).await.unwrap(); + assert_eq!(ildpc_info.ilp_address(), EXAMPLE_ADDRESS.clone()); + assert_eq!(ildpc_info.asset_code(), b"XYZ"); + assert_eq!(ildpc_info.asset_scale(), 9); + } +}