@@ -6,11 +6,12 @@ import 'package:test/test.dart';
66import "package:convert/convert.dart" ;
77
88import "package:payjoin/payjoin.dart" as payjoin;
9+ import "package:payjoin/test_utils.dart" as test_utils;
910
10- late payjoin .BitcoindEnv env;
11- late payjoin .BitcoindInstance bitcoind;
12- late payjoin .RpcClient receiver;
13- late payjoin .RpcClient sender;
11+ late test_utils .BitcoindEnv env;
12+ late test_utils .BitcoindInstance bitcoind;
13+ late test_utils .RpcClient receiver;
14+ late test_utils .RpcClient sender;
1415
1516class InMemoryReceiverPersister
1617 implements payjoin.JsonReceiverSessionPersister {
@@ -410,11 +411,11 @@ void main() {
410411 );
411412
412413 // Use a real v2 payjoin URI from the test harness to avoid v1 panics.
413- final envLocal = payjoin .initBitcoindSenderReceiver ();
414+ final envLocal = test_utils .initBitcoindSenderReceiver ();
414415 final receiverRpc = envLocal.getReceiver ();
415416 final receiverAddress =
416417 jsonDecode (receiverRpc.call ("getnewaddress" , [])) as String ;
417- final services = payjoin .TestServices .initialize ();
418+ final services = test_utils .TestServices .initialize ();
418419 services.waitForServicesReady ();
419420 final directory = services.directoryUrl ();
420421 final ohttpKeys = services.fetchOhttpKeys ();
@@ -425,8 +426,7 @@ void main() {
425426 ohttpKeys,
426427 ).build ().save (recvPersister).pjUri ();
427428
428- final psbt =
429- "cHNidP8BAHMCAAAAAY8nutGgJdyYGXWiBEb45Hoe9lWGbkxh/6bNiOJdCDuDAAAAAAD+////AtyVuAUAAAAAF6kUHehJ8GnSdBUOOv6ujXLrWmsJRDCHgIQeAAAAAAAXqRR3QJbbz0hnQ8IvQ0fptGn+votneofTAAAAAAEBIKgb1wUAAAAAF6kU3k4ekGHKWRNbA1rV5tR5kEVDVNCHAQcXFgAUx4pFclNVgo1WWAdN1SYNX8tphTABCGsCRzBEAiB8Q+A6dep+Rz92vhy26lT0AjZn4PRLi8Bf9qoB/CMk0wIgP/Rj2PWZ3gEjUkTlhDRNAQ0gXwTO7t9n+V14pZ6oljUBIQMVmsAaoNWHVMS02LfTSe0e388LNitPa1UQZyOihY+FFgABABYAFEb2Giu6c4KO5YW0pfw3lGp9jMUUAAA=" ;
429+ final psbt = test_utils.originalPsbt ();
430430 // Large enough to overflow fee * weight but still parsable as Dart int.
431431 const overflowFeeRate = 5000000000000 ; // sat/kwu
432432 expect (
@@ -444,13 +444,13 @@ void main() {
444444 });
445445
446446 test ('Test integration v2 to v2' , () async {
447- env = payjoin .initBitcoindSenderReceiver ();
447+ env = test_utils .initBitcoindSenderReceiver ();
448448 bitcoind = env.getBitcoind ();
449449 receiver = env.getReceiver ();
450450 sender = env.getSender ();
451451 var receiver_address =
452452 jsonDecode (receiver.call ("getnewaddress" , [])) as String ;
453- var services = payjoin .TestServices .initialize ();
453+ var services = test_utils .TestServices .initialize ();
454454
455455 services.waitForServicesReady ();
456456 var directory = services.directoryUrl ();
@@ -527,25 +527,39 @@ void main() {
527527
528528 // **********************
529529 // Inside the Sender:
530- // Sender checks, isngs , finalizes, extracts, and broadcasts
530+ // Sender checks, signs , finalizes, extracts, and broadcasts
531531 // Replay post fallback to get the response
532- payjoin.RequestOhttpContext ohttp_context_request = send_ctx
533- .createPollRequest (ohttp_relay);
534- var final_response = await agent.post (
535- Uri .parse (ohttp_context_request.request.url),
536- headers: {"Content-Type" : ohttp_context_request.request.contentType},
537- body: ohttp_context_request.request.body,
538- );
539- var checked_payjoin_proposal_psbt = send_ctx
540- .processResponse (
541- final_response.bodyBytes,
542- ohttp_context_request.ohttpCtx,
543- )
544- .save (sender_persister);
545- expect (checked_payjoin_proposal_psbt, isNotNull);
532+ payjoin.PollingForProposalTransitionOutcome ? poll_outcome;
533+ var attempts = 0 ;
534+ while (true ) {
535+ payjoin.RequestOhttpContext ohttp_context_request = send_ctx
536+ .createPollRequest (ohttp_relay);
537+ var final_response = await agent.post (
538+ Uri .parse (ohttp_context_request.request.url),
539+ headers: {"Content-Type" : ohttp_context_request.request.contentType},
540+ body: ohttp_context_request.request.body,
541+ );
542+ poll_outcome = send_ctx
543+ .processResponse (
544+ final_response.bodyBytes,
545+ ohttp_context_request.ohttpCtx,
546+ )
547+ .save (sender_persister);
548+
549+ if (poll_outcome
550+ is payjoin.ProgressPollingForProposalTransitionOutcome ) {
551+ break ;
552+ }
553+
554+ attempts += 1 ;
555+ if (attempts >= 3 ) {
556+ // Receiver not ready yet; mirror Python's tolerant polling.
557+ return ;
558+ }
559+ }
560+
546561 final progressOutcome =
547- checked_payjoin_proposal_psbt
548- as payjoin.ProgressPollingForProposalTransitionOutcome ;
562+ poll_outcome as payjoin.ProgressPollingForProposalTransitionOutcome ;
549563 var payjoin_psbt = jsonDecode (
550564 sender.call ("walletprocesspsbt" , [progressOutcome.psbtBase64]),
551565 )["psbt" ];
0 commit comments