From bab58af71098be7911ac77c08bd97678372da4ab Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Wed, 14 May 2025 10:14:08 +0200 Subject: [PATCH] UX story fix; improve warning tests --- shared/psbt.py | 4 ++-- testing/test_ephemeral.py | 16 ++++++++-------- testing/test_sign.py | 29 ++++++++++++++++++++++++----- testing/test_teleport.py | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/shared/psbt.py b/shared/psbt.py index 0ff2806d..a59652c3 100644 --- a/shared/psbt.py +++ b/shared/psbt.py @@ -1549,9 +1549,9 @@ class psbtObject(psbtProxy): if (num_op_return > 1) or num_op_return_size: mm = "" if num_op_return > 1: - mm += " Multiple OP_RETURN outputs: %d" % num_op_return + mm += "\nMultiple OP_RETURN outputs: %d" % num_op_return if num_op_return_size: - mm += " OP_RETURN size > 80 bytes." + mm += "\nOP_RETURN > 80 bytes" self.warnings.append( ("OP_RETURN", "TX may not be relayed by some nodes.%s" % mm)) diff --git a/testing/test_ephemeral.py b/testing/test_ephemeral.py index 5f4001a8..8384494d 100644 --- a/testing/test_ephemeral.py +++ b/testing/test_ephemeral.py @@ -20,15 +20,15 @@ WORDLISTS = { } SEEDVAULT_TEST_DATA = [ - ("47649253", "344f9dc08e88b8a46d4b8f46c4e6bb6c", - "crowd language ice brown merit fall release impose egg cheese put suit"), - ("CC7BB706", "88f53ed897cc371ffe4b715c267206f3286ed2f655ba9d68", - "material prepare renew convince sell morning weird hotel found crime like town manage harvest sun resemble output dolphin"), - ("AC39935C", "956f484cc2136178fd1ad45faeb54972c829f65aad0d74eb2541b11984655893", - "nice kid basket loud current round virtual fold garden interest false tortoise little will height payment insane float expire giraffe obscure crawl girl glare"), - ('939B32C4', + ["47649253", "344f9dc08e88b8a46d4b8f46c4e6bb6c", + "crowd language ice brown merit fall release impose egg cheese put suit"], + ["CC7BB706", "88f53ed897cc371ffe4b715c267206f3286ed2f655ba9d68", + "material prepare renew convince sell morning weird hotel found crime like town manage harvest sun resemble output dolphin"], + ["AC39935C", "956f484cc2136178fd1ad45faeb54972c829f65aad0d74eb2541b11984655893", + "nice kid basket loud current round virtual fold garden interest false tortoise little will height payment insane float expire giraffe obscure crawl girl glare"], + ['939B32C4', '017caa3142d48791f837b42fcd7a98662f9fb4101a15ae87cdbc1fecc96f33c11ffcefd8121daaba0625c918a335a0712b8c35c2da60e6fc6eef78b7028f4be02a', - None), # BIP-85 -> BIP-32 -> #23 + None], # BIP-85 -> BIP-32 -> #23 ] @pytest.fixture diff --git a/testing/test_sign.py b/testing/test_sign.py index 2c374228..44e6195e 100644 --- a/testing/test_sign.py +++ b/testing/test_sign.py @@ -1790,11 +1790,14 @@ def test_op_return_signing(op_return_data, dev, fake_txn, bitcoind_d_sim_watch, assert title == "OK TO SEND?" # in older implementations, one would see a warning for OP_RETURN --> not now if len(op_return_data) > 80: - assert "warning" in story + assert "(1 warning below)" in story # looking for warning at the top + assert "OP_RETURN > 80 bytes" in story else: assert "warning" not in story assert "OP_RETURN" in story + assert "Multiple OP_RETURN outputs:" not in story # always just one - core restriction + try: assert len(op_return_data) <= 200 expect = op_return_data.decode("ascii") @@ -2180,6 +2183,7 @@ def test_send2taproot_addresss(fake_txn , start_sign, end_sign, cap_story, use_t title, story = cap_story() assert title == "OK TO SEND?" # we do not understand change in taproot (taproot not supported) + assert "warning" not in story # no warning for taproot, just not change assert "Consolidating" not in story assert "Change back" not in story # but we should show address @@ -2195,13 +2199,18 @@ def test_sign_taproot_input(fake_txn, start_sign, end_sign, cap_story): assert title == "Failure" assert "Install EDGE firmware" in story -def test_send2unknown_script(fake_txn , start_sign, end_sign, cap_story, use_testnet): +@pytest.mark.parametrize("num_unknown", [1,3]) +def test_send2unknown_script(fake_txn , start_sign, end_sign, cap_story, use_testnet, num_unknown): use_testnet() - psbt = fake_txn(2, 2, segwit_in=True, change_outputs=[0], outstyles=["p2tr", "unknown"]) + unknowns = ["unknown"] * num_unknown + num_out = 2 if num_unknown == 1 else 4 + psbt = fake_txn(2, num_out, segwit_in=True, change_outputs=[0], outstyles=["p2tr"]+unknowns) start_sign(psbt) title, story = cap_story() assert title == "OK TO SEND?" # we do not understand change in taproot (taproot not supported) + assert "(1 warning below)" in story # unknown script + assert ("Sending to %d not well understood script(s)" % num_unknown) in story assert "Consolidating" not in story assert "Change back" not in story assert "to script" in story @@ -3028,7 +3037,7 @@ def test_txout_explorer(chain, data, fake_txn, start_sign, settings_set, txout_e @pytest.mark.parametrize("finalize", [True, False]) @pytest.mark.parametrize("data", [ [(1, b"Coinkite"), (0, b"Mk1 Mk2 Mk3 Mk4 Q"), (100, b"binarywatch.org"), (100, b"a" * 75)], - [(0, b"a" * 300), (10, b"x" * 1000)] + [(0, b"a" * 300), (10, b"x" * 1000), (0, b"anchor output")], ]) def test_txout_explorer_op_return(finalize, data, fake_txn, start_sign, cap_story, is_q1, need_keypress, press_cancel, press_select, end_sign): @@ -3037,7 +3046,17 @@ def test_txout_explorer_op_return(finalize, data, fake_txn, start_sign, cap_stor time.sleep(.1) title, story = cap_story() assert title == 'OK TO SEND?' - assert "warning" in story + assert "(1 warning below)" in story + if len(data) > 1: + assert ("Multiple OP_RETURN outputs: %d" % len(data)) in story + else: + assert "Multiple OP_RETURN outputs" not in story + + if sum(int(len(x[1]) > 80) for x in data): + assert "OP_RETURN > 80 bytes" in story + else: + assert "OP_RETURN > 80 bytes" not in story + assert "Press (2) to explore txn" in story need_keypress("2") time.sleep(.1) diff --git a/testing/test_teleport.py b/testing/test_teleport.py index 17c56f1e..cf03f8e2 100644 --- a/testing/test_teleport.py +++ b/testing/test_teleport.py @@ -327,7 +327,7 @@ def test_tx_seedvault(data, rx_start, tx_start, cap_menu, enter_complex, pick_me else: stored_secret = entropy_bytes - pkg = (xfp, stored_secret.hex(), f"[{xfp}]", "from testing") + pkg = [xfp, stored_secret.hex(), f"[{xfp}]", "from testing"] settings_set("seedvault", True) settings_set("seeds", [pkg])