Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup test assertions #519

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions payjoin-cli/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ mod e2e {
let temp_dir = env::temp_dir();
let receiver_db_path = temp_dir.join("receiver_db");
let sender_db_path = temp_dir.join("sender_db");
let result: Result<()> = tokio::select! {
let result = tokio::select! {
res = services.take_ohttp_relay_handle() => Err(format!("Ohttp relay is long running: {:?}", res).into()),
res = services.take_directory_handle() => Err(format!("Directory server is long running: {:?}", res).into()),
res = send_receive_cli_async(&services, receiver_db_path.clone(), sender_db_path.clone()) => res.map_err(|e| format!("send_receive failed: {:?}", e).into()),
res = send_receive_cli_async(&services, receiver_db_path.clone(), sender_db_path.clone()) => res,
};

cleanup_temp_file(&receiver_db_path).await;
cleanup_temp_file(&sender_db_path).await;
assert!(result.is_ok(), "{}", result.unwrap_err());
assert!(result.is_ok(), "send_receive failed: {:#?}", result.unwrap_err());

async fn send_receive_cli_async(
services: &TestServices,
Expand Down
38 changes: 22 additions & 16 deletions payjoin/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ mod integration {
OhttpKeys::from_str("OH1QYPM5JXYNS754Y4R45QWE336QFX6ZR8DQGVQCULVZTV20TFVEYDMFQC")
.expect("Invalid OhttpKeys");
let mut services = TestServices::initialize().await?;
tokio::select!(
let result = tokio::select!(
err = services.take_directory_handle() => panic!("Directory server exited early: {:?}", err),
res = try_request_with_bad_keys(&services, bad_ohttp_keys) => {
assert_eq!(
res?.headers().get("content-type").expect("content type should be present"),
"application/problem+json"
);
}
res = try_request_with_bad_keys(&services, bad_ohttp_keys) => res
);

assert_eq!(
result?.headers().get("content-type").expect("content type should be present"),
"application/problem+json"
);

async fn try_request_with_bad_keys(
Expand All @@ -220,12 +220,14 @@ mod integration {
async fn test_session_expiration() -> Result<(), BoxSendSyncError> {
init_tracing();
let mut services = TestServices::initialize().await?;
tokio::select!(
let result = tokio::select!(
err = services.take_ohttp_relay_handle() => panic!("Ohttp relay exited early: {:?}", err),
err = services.take_directory_handle() => panic!("Directory server exited early: {:?}", err),
res = do_expiration_tests(&services) => assert!(res.is_ok(), "v2 send receive failed: {:#?}", res)
res = do_expiration_tests(&services) => res
);

assert!(result.is_ok(), "v2 send receive failed: {:#?}", result.unwrap_err());

async fn do_expiration_tests(services: &TestServices) -> Result<(), BoxError> {
let (_bitcoind, sender, receiver) = init_bitcoind_sender_receiver(None, None)?;
services.wait_for_services_ready().await?;
Expand Down Expand Up @@ -269,12 +271,14 @@ mod integration {
async fn v2_to_v2() -> Result<(), BoxSendSyncError> {
init_tracing();
let mut services = TestServices::initialize().await?;
tokio::select!(
let result = tokio::select!(
err = services.take_ohttp_relay_handle() => panic!("Ohttp relay exited early: {:?}", err),
err = services.take_directory_handle() => panic!("Directory server exited early: {:?}", err),
res = do_v2_send_receive(&services) => assert!(res.is_ok(), "v2 send receive failed: {:#?}", res)
res = do_v2_send_receive(&services) => res
);

assert!(result.is_ok(), "v2 send receive failed: {:#?}", result.unwrap_err());

async fn do_v2_send_receive(services: &TestServices) -> Result<(), BoxError> {
let (_bitcoind, sender, receiver) = init_bitcoind_sender_receiver(None, None)?;
let agent = services.http_agent();
Expand All @@ -293,7 +297,7 @@ mod integration {
let mock_ohttp_relay = directory.clone();
let (req, ctx) = session.extract_req(&mock_ohttp_relay)?;
let response = agent.post(req.url).body(req.body).send().await?;
assert!(response.status().is_success());
assert!(response.status().is_success(), "error response: {}", response.status());
let response_body =
session.process_res(response.bytes().await?.to_vec().as_slice(), ctx)?;
// No proposal yet since sender has not responded
Expand All @@ -319,7 +323,7 @@ mod integration {
.send()
.await?;
log::info!("Response: {:#?}", &response);
assert!(response.status().is_success());
assert!(response.status().is_success(), "error response: {}", response.status());
let send_ctx = send_ctx.process_response(&response.bytes().await?)?;
// POST Original PSBT

Expand Down Expand Up @@ -432,12 +436,14 @@ mod integration {
async fn v1_to_v2() -> Result<(), BoxSendSyncError> {
init_tracing();
let mut services = TestServices::initialize().await?;
tokio::select!(
let result = tokio::select!(
err = services.take_ohttp_relay_handle() => panic!("Ohttp relay exited early: {:?}", err),
err = services.take_directory_handle() => panic!("Directory server exited early: {:?}", err),
res = do_v1_to_v2(&services) => assert!(res.is_ok(), "v2 send receive failed: {:#?}", res)
res = do_v1_to_v2(&services) => res
);

assert!(result.is_ok(), "v2 send receive failed: {:#?}", result.unwrap_err());

async fn do_v1_to_v2(services: &TestServices) -> Result<(), BoxError> {
let (_bitcoind, sender, receiver) = init_bitcoind_sender_receiver(None, None)?;
let agent = services.http_agent();
Expand Down Expand Up @@ -523,7 +529,7 @@ mod integration {
let response =
agent.post(url).header("Content-Type", content_type).body(body).send().await?;
log::info!("Response: {:#?}", &response);
assert!(response.status().is_success());
assert!(response.status().is_success(), "error response: {}", response.status());

let res = response.bytes().await?.to_vec();
let checked_payjoin_proposal_psbt =
Expand Down