diff --git a/tests/test_opening.py b/tests/test_opening.py index cdf069cb6eca..f528eb6801a5 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -1571,12 +1571,24 @@ def censoring_sendrawtx(r): # Make a 3rd inflight that won't make it into the mempool signed_psbt = run_retry() - last = len(l1.daemon.logs) + # Snapshot the logs only after catching up: len(logs) does not read + # new output, so a stale snapshot would match the *2nd* inflight's + # "sendrawtx exit 0" and we'd unmock before the 3rd is broadcast. + l1.daemon.logs_catchup() + l2.daemon.logs_catchup() + last1 = len(l1.daemon.logs) + last2 = len(l2.daemon.logs) l1.rpc.openchannel_signed(chan_id, signed_psbt) - wait_for(lambda: l1.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last)) + # Both nodes broadcast the (censored) funding tx, and either request + # may still be in flight, so wait for both before unmocking: otherwise + # the still-mocked attempt would be forwarded for real and replace the + # 2nd inflight in the mempool. + wait_for(lambda: l1.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last1)) + wait_for(lambda: l2.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last2)) import time - time.sleep(.05) + + time.sleep(0.05) l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', None) l2.daemon.rpcproxy.mock_rpc('sendrawtransaction', None) @@ -1686,11 +1698,22 @@ def censoring_sendrawtx(r): # Make a 3rd inflight that won't make it into the mempool signed_psbt = run_retry() - last = len(l1.daemon.logs) + # Snapshot the logs only after catching up: len(logs) does not read + # new output, so a stale snapshot would match the *2nd* inflight's + # "sendrawtx exit 0" and we'd unmock before the 3rd is broadcast. + l1.daemon.logs_catchup() + l2.daemon.logs_catchup() + last1 = len(l1.daemon.logs) + last2 = len(l2.daemon.logs) l1.rpc.openchannel_signed(chan_id, signed_psbt) - wait_for(lambda: l1.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last)) - time.sleep(.05) + # Both nodes broadcast the (censored) funding tx, and either request + # may still be in flight, so wait for both before unmocking: otherwise + # the still-mocked attempt would be forwarded for real and replace the + # 2nd inflight in the mempool. + wait_for(lambda: l1.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last1)) + wait_for(lambda: l2.daemon.is_in_log("plugin-bcli: sendrawtx exit 0", start=last2)) + time.sleep(0.05) l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', None) l2.daemon.rpcproxy.mock_rpc('sendrawtransaction', None)