Skip to content
Draft
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
41 changes: 35 additions & 6 deletions payjoin-cli/src/app/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,32 @@ impl AppTrait for App {

let mut interrupt = self.interrupt.clone();
tokio::select! {
_ = async {
all_completed = async {
let mut all_completed = true;
for task in tasks {
let _ = task.await;
let result = task.await;
match result {
Ok(inner) => {
match inner {
Ok(_) => {},
Err(e) => {
all_completed = false;
println!("{e}")
}
}
},
Err(e) => {
all_completed = false;
println!("{e}")
}

}
}
all_completed
} => {
println!("All resumed sessions completed.");
if all_completed {
println!("All resumed sessions completed.");
}
}
_ = interrupt.changed() => {
println!("Resumed sessions were interrupted.");
Expand Down Expand Up @@ -859,9 +879,18 @@ impl App {
.save(persister);

match check_result {
Ok(_) => {
println!("Payjoin transaction detected in the mempool!");
return Ok(());
Ok(outcome) => {
match outcome {
OptionalTransitionOutcome::Progress(_) => {
println!("Payjoin transaction detected in the mempool!");
return Ok(());
}
OptionalTransitionOutcome::Stasis(_) => {
// keep polling

continue;
}
}
}
Err(_) => {
// keep polling
Expand Down
41 changes: 40 additions & 1 deletion payjoin-cli/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ mod e2e {
.expect("Failed to execute payjoin-cli");
respond_with_payjoin(cli_receive_resumer).await?;

// Resume the receiver to ensure it stays active before receiving payment
let cli_receive_resumer = Command::new(payjoin_cli)
.arg("--root-certificate")
.arg(cert_path)
.arg("--rpchost")
.arg(&receiver_rpchost)
.arg("--cookie-file")
.arg(cookie_file)
.arg("--db-path")
.arg(&receiver_db_path)
.arg("--ohttp-relays")
.arg(ohttp_relay)
.arg("resume")
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to execute payjoin-cli");
check_resume_not_completed(cli_receive_resumer).await?;

// Resume the sender to process and broadcast payjoin
let cli_send_resumer = Command::new(payjoin_cli)
.arg("--root-certificate")
.arg(cert_path)
Expand Down Expand Up @@ -360,8 +380,8 @@ mod e2e {
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to execute payjoin-cli");

check_resume_completed(cli_receive_resumer).await?;

// Check that neither the sender or the receiver have sessions to resume
let cli_receive_resumer = Command::new(payjoin_cli)
.arg("--root-certificate")
Expand Down Expand Up @@ -397,6 +417,7 @@ mod e2e {
.spawn()
.expect("Failed to execute payjoin-cli");
check_resume_has_no_sessions(cli_send_resumer).await?;

Ok(())
}

Expand Down Expand Up @@ -461,6 +482,24 @@ mod e2e {
assert!(res.is_some(), "Expected all resumed sessions completed");
Ok(())
}

async fn check_resume_not_completed(mut cli_resumer: Child) -> Result<()> {
let mut stdout =
cli_resumer.stdout.take().expect("Failed to take stdout of child process");
let timeout = tokio::time::Duration::from_secs(10);
let res = tokio::time::timeout(
timeout,
wait_for_stdout_match(&mut stdout, |line| {
line.contains("All resumed sessions completed.")
|| line.contains("No sessions to resume.")
}),
)
.await?;

terminate(cli_resumer).await.expect("Failed to kill payjoin-cli");
assert!(res.is_none(), "Expected resumed sessions not yet completed",);
Ok(())
}
Ok(())
}

Expand Down
Loading