Skip to content

Commit e1834aa

Browse files
committed
add validation tests
1 parent 077e7c7 commit e1834aa

File tree

3 files changed

+210
-142
lines changed

3 files changed

+210
-142
lines changed

electrum/gui/qt/transaction_dialog.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
from electrum.i18n import _
4646
from electrum.plugin import run_hook
4747
from electrum import simple_config
48-
from electrum.transaction import SerializationError, Transaction, PartialTransaction, PartialTxInput, PayjoinTransaction
48+
from electrum.transaction import (SerializationError, Transaction, PartialTransaction, PartialTxInput, PayjoinTransaction,
49+
PayJoinProposalValidationException, PayJoinExchangeException)
4950
from electrum.logging import get_logger
5051

5152
from .util import (MessageBoxMixin, read_QIcon, Buttons, icon_path,
@@ -107,7 +108,7 @@ def __init__(self, *, parent: 'ElectrumWindow', desc, prompt_if_unsaved, finaliz
107108
self.prompt_if_unsaved = prompt_if_unsaved
108109

109110
self.payjoin = PayjoinTransaction(payjoin)
110-
print(self.payjoin)#
111+
self.payjoin_finished = False
111112

112113
self.saved = False
113114
self.desc = desc
@@ -211,7 +212,6 @@ def set_tx(self, tx: 'Transaction'):
211212
# e.g. the FX plugin. If this happens during or after a long
212213
# sign operation the signatures are lost.
213214
self.tx = tx = copy.deepcopy(tx)
214-
print('tx-diaog: set_tx', self.tx)#
215215
try:
216216
self.tx.deserialize()
217217
except BaseException as e:
@@ -222,36 +222,51 @@ def set_tx(self, tx: 'Transaction'):
222222
# note: this might fetch prev txs over the network.
223223
tx.add_info_from_wallet(self.wallet)
224224

225+
def do_payjoin(self) -> None:
226+
def sign_done(success):
227+
self.payjoin_finished = True
228+
if self.tx.get_fee_rate() < self.payjoin._minfeerate:
229+
self.set_tx(original_tx)
230+
_logger.warning("The receiver used a too low fee rate.")
231+
self.show_error(
232+
_("Error creating a payjoin") + ":\n" +
233+
_("The receiver used a too low fee rate") + "\n" +
234+
_("Sending the original transaction"))
235+
self.update()
236+
self.main_window.pop_top_level_window(self)
237+
self.do_broadcast()
225238

226-
227-
def do_broadcast(self):
228239
self.main_window.push_top_level_window(self)
229-
230-
if self.payjoin_cb.isChecked():
240+
original_tx = copy.deepcopy(self.tx)
241+
_logger.info(f"Starting Payjoin Session")
242+
try:
231243
self.payjoin.set_tx(self.tx)
232-
tx = self.payjoin.do_payjoin()
233-
if tx is not None:
234-
#self.set_tx(tx)
235-
self.tx = copy.deepcopy(tx)
236-
print('broadcast1: ', self.tx.to_json())#
237-
print('broadcast1: ', self.tx.serialize_as_base64())#
238-
self.sign()
239-
print('external keyspairs', self.external_keypairs)
240-
print('broadcast2: ', self.tx.to_json())#
241-
print('broadcast2: ', self.tx.serialize_as_base64())#
242-
print('broadcast2: ', self.tx._serialize_as_base64()) #
243-
print('broadcast2: ', self.tx.is_complete()) #
244-
"""
244+
self.payjoin.do_payjoin()
245+
self.payjoin.payjoin_proposal.add_info_from_wallet(self.wallet)
246+
self.payjoin.validate_payjoin_proposal()
247+
except (PayJoinProposalValidationException, PayJoinExchangeException) as e:
248+
_logger.warning(repr(e))
249+
self.payjoin_cb.setChecked(False)
250+
self.show_error(_("Error creating a payjoin") + ":\n" + str(e) + "\n" +
251+
_("Sending the original transaction"))
252+
self.do_broadcast()
253+
return
254+
tx = self.payjoin.payjoin_proposal
255+
self.set_tx(tx)
256+
self.main_window.sign_tx(self.tx, callback=sign_done, external_keypairs=self.external_keypairs)
257+
258+
def do_broadcast(self) -> None:
259+
if self.payjoin_cb.isChecked() and self.payjoin.is_available() and not self.payjoin_finished:
260+
self.do_payjoin()
261+
return
262+
self.main_window.push_top_level_window(self)
245263
try:
246264
self.main_window.broadcast_transaction(self.tx)
247265
finally:
248266
self.main_window.pop_top_level_window(self)
249-
"""
250267
self.saved = True
251268
self.update()
252269

253-
254-
255270
def closeEvent(self, event):
256271
if (self.prompt_if_unsaved and not self.saved
257272
and not self.question(_('This transaction is not saved. Close anyway?'), title=_("Warning"))):
@@ -686,7 +701,6 @@ def add_tx_stats(self, vbox):
686701
self.rbf_label.setVisible(self.finalized)
687702
self.rbf_cb.setVisible(not self.finalized)
688703
self.payjoin_cb.setVisible(self.payjoin.is_available())
689-
print('pj_available in dialog:', self.payjoin.is_available())#
690704
self.locktime_final_label.setVisible(self.finalized)
691705
self.locktime_setter_widget.setVisible(not self.finalized)
692706

electrum/tests/test_payjoin.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)