forked from bitcoinafterlife/bal-electrum-plugin
Bump plugin version to 0.3.4 (manifest, __init__, plugin_base, VERSION). GROUP A - A1: remove block-height locktimes; the plugin now uses UNIX timestamps only. The NLOCKTIME_BLOCKHEIGHT_MAX guard is kept on purpose (it forces every locktime to be a timestamp). chk_locktime is now 2-arg; int_locktime and anticipate_locktime no longer accept blocks; RAW input only accepts d/y. Two now-dormant configs (LOCKTIME_BLOCKS, LOCKTIMEDELTA_BLOCKS) are kept with comments to avoid touching persisted keys. - A2: rename PENDING -> MEMPOOL everywhere (label 'Mempool', yellow #ffce30); add new UPDATED status; ANTICIPATED & UPDATED keep VALID; documented set_status rules; backward-compat migration (old PENDING -> MEMPOOL). - A3: clarify that anticipating to a future date only rebuilds (never invalidates), while only a past locktime invalidates (WillExpired). Code was already correct; only the comment and docs were fixed. Colour follow-up: UPDATED lightened from #800080 to #b266b2 (more readable), updated in theme.py, docs and the theme test. GROUP B - B1: verified the 'Create your will' button already opens the guided wizard (no code change needed). - B2: new persisted AUTO_SIGN setting (default ON) with an 'Auto-sign on Check' checkbox in the settings dialog. When enabled, Check signs and broadcasts automatically; the wallet password is requested only for encrypted wallets. B2 follow-up (fixes reported after testing): - Remove the duplicate sign/broadcast cycle in lists.check(); build_will_task() already signs and broadcasts. - Suppress the manual 'press Sign/Broadcast' hint and its popup when AUTO_SIGN is ON (kept when OFF). - Make broadcast one-shot: removed the retry flag and the Exception('retry'); failed will-executors stay PUSH_FAIL and are skipped (no endless retry). PUSHED transactions are already excluded from re-collection. Docs: inheritance-options.md/.html and inheritance-flow.svg updated to v0.3.4. Tests: 206 passing (new test_anticipate_manual_locktime, test_anticipate_past_locktime, test_group_b_auto_sign; updated core/util, core/will_extra, gui/theme, gui/widgets). CHANGELOG.md added with one numbered entry per task.
261 lines
8.0 KiB
Python
261 lines
8.0 KiB
Python
"""
|
|
Tests for ``bal.gui.qt.widgets``.
|
|
|
|
Covers testable widgets without requiring a running Electrum wallet:
|
|
- ClickableLabel
|
|
- BalLineEdit, BalTextEdit, BalCheckBox
|
|
- _LockTimeEditor (static/class methods)
|
|
- LockTimeRawEdit (numbify, checkbdy, replace_str)
|
|
- PercAmountEdit
|
|
|
|
Run:
|
|
QT_QPA_PLATFORM=offscreen python3 tests/test_gui_widgets.py
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, __file__.rsplit("/", 2)[0])
|
|
|
|
from PyQt6.QtCore import QTimer
|
|
from PyQt6.QtWidgets import QApplication, QWidget
|
|
|
|
from electrum.util import DECIMAL_POINT, decimal_point_to_base_unit_name
|
|
|
|
_app = QApplication.instance() or QApplication(sys.argv)
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# ClickableLabel
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_clickable_label_creation():
|
|
from bal.gui.qt.widgets import ClickableLabel
|
|
lbl = ClickableLabel("test")
|
|
assert lbl.text() == "test"
|
|
assert hasattr(lbl, "doubleClicked")
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# BalLineEdit
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_bal_line_edit():
|
|
from bal.gui.qt.common import shown_cv
|
|
from bal.gui.qt.widgets import BalLineEdit
|
|
cv = shown_cv("initial")
|
|
edit = BalLineEdit(cv)
|
|
assert edit.text() == "initial"
|
|
cv.set("updated")
|
|
assert cv.get() == "updated"
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# BalTextEdit
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_bal_text_edit():
|
|
from bal.gui.qt.common import shown_cv
|
|
from bal.gui.qt.widgets import BalTextEdit
|
|
cv = shown_cv("multi\nline")
|
|
edit = BalTextEdit(cv)
|
|
assert edit.toPlainText() == "multi\nline"
|
|
cv.set("changed")
|
|
assert cv.get() == "changed"
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# BalCheckBox
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_bal_check_box():
|
|
from bal.gui.qt.common import shown_cv
|
|
from bal.gui.qt.widgets import BalCheckBox
|
|
cv = shown_cv(True)
|
|
cb = BalCheckBox(cv)
|
|
assert cb.isChecked() is True
|
|
cv.set(False)
|
|
assert cv.get() is False
|
|
|
|
|
|
def test_bal_check_box_on_click():
|
|
from bal.gui.qt.common import shown_cv
|
|
from bal.gui.qt.widgets import BalCheckBox
|
|
calls = []
|
|
def handler():
|
|
calls.append(1)
|
|
cv = shown_cv(True)
|
|
cb = BalCheckBox(cv, on_click=handler)
|
|
cb.click()
|
|
assert len(calls) == 1
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# _LockTimeEditor
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_locktime_editor_is_acceptable():
|
|
from bal.gui.qt.widgets import _LockTimeEditor
|
|
assert _LockTimeEditor.is_acceptable_locktime(100) is True
|
|
assert _LockTimeEditor.is_acceptable_locktime(0) is True
|
|
assert _LockTimeEditor.is_acceptable_locktime(-1) is False
|
|
assert _LockTimeEditor.is_acceptable_locktime(None) is True
|
|
|
|
|
|
def test_locktime_editor_is_acceptable_string():
|
|
from bal.gui.qt.widgets import _LockTimeEditor
|
|
assert _LockTimeEditor.is_acceptable_locktime("100") is True
|
|
assert _LockTimeEditor.is_acceptable_locktime("abc") is False
|
|
assert _LockTimeEditor.is_acceptable_locktime("") is True
|
|
|
|
|
|
def test_locktime_editor_min_max():
|
|
from bal.gui.qt.widgets import _LockTimeEditor
|
|
assert _LockTimeEditor.min_allowed_value >= 0
|
|
assert _LockTimeEditor.max_allowed_value > _LockTimeEditor.min_allowed_value
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# LockTimeRawEdit
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_locktime_raw_edit_replace_str():
|
|
# replace_str only strips the day ("d") and year ("y") suffixes. The
|
|
# block-height suffix ("b") was removed (A1), so "b" is NOT stripped
|
|
# anymore (locktimes are always UNIX timestamps now).
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
assert LockTimeRawEdit.replace_str("123d") == "123"
|
|
assert LockTimeRawEdit.replace_str("456y") == "456"
|
|
# "b" is left untouched (no longer a recognised suffix)
|
|
assert LockTimeRawEdit.replace_str("789b") == "789b"
|
|
# only d/y are stripped; a stray "b" remains
|
|
assert LockTimeRawEdit.replace_str("12d34y56b") == "123456b"
|
|
|
|
|
|
def test_locktime_raw_edit_checkbdy():
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
# character at expected position matches appendix
|
|
pos, s = LockTimeRawEdit.checkbdy(None, "123d", 4, "d")
|
|
assert s == "123d"
|
|
# character at expected position does not match
|
|
pos, s = LockTimeRawEdit.checkbdy(None, "123x", 4, "d")
|
|
assert s == "123x"
|
|
|
|
|
|
def test_locktime_raw_edit_numbify_empty():
|
|
parent = QWidget()
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
edit = LockTimeRawEdit(parent)
|
|
edit.setText("")
|
|
edit.numbify()
|
|
assert edit.text() == ""
|
|
|
|
|
|
def test_locktime_raw_edit_numbify_days():
|
|
parent = QWidget()
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
edit = LockTimeRawEdit(parent)
|
|
# Use setText + numbify to simulate user typing
|
|
edit.blockSignals(True)
|
|
edit.setText("30d")
|
|
edit.blockSignals(False)
|
|
edit.numbify()
|
|
# Should be "30d" with isdays=True
|
|
assert edit.text() == "30d"
|
|
|
|
|
|
def test_locktime_raw_edit_numbify_years():
|
|
parent = QWidget()
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
edit = LockTimeRawEdit(parent)
|
|
edit.blockSignals(True)
|
|
edit.setText("2y")
|
|
edit.blockSignals(False)
|
|
edit.numbify()
|
|
assert edit.text() == "2y"
|
|
|
|
|
|
def test_locktime_raw_edit_get_set_value():
|
|
parent = QWidget()
|
|
from bal.gui.qt.widgets import LockTimeRawEdit
|
|
edit = LockTimeRawEdit(parent)
|
|
edit.set_value("90d")
|
|
val = edit.get_value()
|
|
assert val is not None
|
|
assert "d" in val
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# PercAmountEdit
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_perc_amount_edit_numbify_percent():
|
|
from bal.gui.qt.widgets import PercAmountEdit
|
|
parent = QWidget()
|
|
edit = PercAmountEdit(8, parent=parent)
|
|
edit.blockSignals(True)
|
|
edit.setText("50%")
|
|
edit.blockSignals(False)
|
|
edit.numbify()
|
|
assert edit.is_perc is True
|
|
# After numbify: "50%" -> strip % -> add back -> "50%"
|
|
assert edit.text() == "50%"
|
|
|
|
|
|
def test_perc_amount_edit_numbify_no_percent():
|
|
from bal.gui.qt.widgets import PercAmountEdit
|
|
parent = QWidget()
|
|
edit = PercAmountEdit(8, parent=parent)
|
|
edit.blockSignals(True)
|
|
edit.setText("123")
|
|
edit.blockSignals(False)
|
|
edit.numbify()
|
|
assert edit.is_perc is False
|
|
assert edit.text() == "123"
|
|
|
|
|
|
def test_perc_amount_get_amount_from_text():
|
|
from bal.gui.qt.widgets import PercAmountEdit
|
|
parent = QWidget()
|
|
edit = PercAmountEdit(8, parent=parent)
|
|
# With percent
|
|
result = edit._get_amount_from_text("50%")
|
|
assert result is not None
|
|
# Without percent
|
|
result = edit._get_amount_from_text("123.45")
|
|
assert result is not None
|
|
# Invalid
|
|
result = edit._get_amount_from_text("abc")
|
|
assert result is None
|
|
|
|
|
|
def test_perc_amount_get_text_from_amount():
|
|
from bal.gui.qt.widgets import PercAmountEdit
|
|
parent = QWidget()
|
|
edit = PercAmountEdit(lambda: 8, parent=parent)
|
|
edit.numbify() # sets is_perc
|
|
text = edit._get_text_from_amount(100)
|
|
assert isinstance(text, str)
|
|
|
|
|
|
def test_perc_amount_get_text_from_amount_perc():
|
|
from bal.gui.qt.widgets import PercAmountEdit
|
|
parent = QWidget()
|
|
edit = PercAmountEdit(lambda: 8, parent=parent)
|
|
edit.blockSignals(True)
|
|
edit.setText("50%")
|
|
edit.blockSignals(False)
|
|
edit.numbify() # sets is_perc = True
|
|
text = edit._get_text_from_amount(100)
|
|
assert "%" in text
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Main
|
|
# ------------------------------------------------------------------ #
|
|
|
|
if __name__ == "__main__":
|
|
for name in sorted(dir()):
|
|
if name.startswith("test_"):
|
|
globals()[name]()
|
|
print(f" [OK] {name}")
|
|
print("[OK] All widget tests passed")
|