1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

fixup! test(core/ui): fix bitcoin signtx for T3T1

This commit is contained in:
Martin Milata 2024-05-22 16:55:14 +02:00
parent d359f81af3
commit 62b40fbca8
12 changed files with 204 additions and 150 deletions

View File

@ -339,4 +339,4 @@ def swipe_till_the_end(debug: "DebugLink", br: messages.ButtonRequest) -> None:
def is_core(client: "Client") -> bool:
return client.model in (models.T2T1, models.T2B1, models.T3T1)
return client.model is not models.T1B1

View File

@ -23,6 +23,8 @@ from trezorlib.messages import SafetyCheckLevel
from trezorlib.tools import parse_path
from ... import bip32
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
def getmultisig(chain, nr, xpubs):
@ -202,26 +204,30 @@ def test_multisig(client: Client):
xpubs.append(node.xpub)
for nr in range(1, 4):
assert (
btc.get_address(
client,
"Bitcoin",
parse_path(f"m/44h/0h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
client,
"Bitcoin",
parse_path(f"m/44h/0h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
)
== "3Pdz86KtfJBuHLcSv4DysJo4aQfanTqCzG"
)
== "3Pdz86KtfJBuHLcSv4DysJo4aQfanTqCzG"
)
assert (
btc.get_address(
client,
"Bitcoin",
parse_path(f"m/44h/0h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
assert (
btc.get_address(
client,
"Bitcoin",
parse_path(f"m/44h/0h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
)
== "36gP3KVx1ooStZ9quZDXbAF3GCr42b2zzd"
)
== "36gP3KVx1ooStZ9quZDXbAF3GCr42b2zzd"
)
@pytest.mark.multisig
@ -254,7 +260,10 @@ def test_multisig_missing(client: Client, show_display):
)
for multisig in (multisig1, multisig2):
with pytest.raises(TrezorFailure):
with client, pytest.raises(TrezorFailure):
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.get_address(
client,
"Bitcoin",
@ -275,26 +284,30 @@ def test_bch_multisig(client: Client):
xpubs.append(node.xpub)
for nr in range(1, 4):
assert (
btc.get_address(
client,
"Bcash",
parse_path(f"m/44h/145h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
client,
"Bcash",
parse_path(f"m/44h/145h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
)
== "bitcoincash:pqguz4nqq64jhr5v3kvpq4dsjrkda75hwy86gq0qzw"
)
== "bitcoincash:pqguz4nqq64jhr5v3kvpq4dsjrkda75hwy86gq0qzw"
)
assert (
btc.get_address(
client,
"Bcash",
parse_path(f"m/44h/145h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
assert (
btc.get_address(
client,
"Bcash",
parse_path(f"m/44h/145h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
)
== "bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a"
)
== "bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a"
)
def test_public_ckd(client: Client):
@ -342,6 +355,9 @@ def test_unknown_path(client: Client):
messages.Address,
]
)
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
# try again with a warning
btc.get_address(client, "Bitcoin", UNKNOWN_PATH, show_display=True)

View File

@ -21,6 +21,9 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
def test_show_segwit(client: Client):
assert (
@ -71,61 +74,65 @@ def test_show_segwit(client: Client):
@pytest.mark.altcoin
def test_show_segwit_altcoin(client: Client):
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7"
)
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7"
)
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e"
)
== "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e"
)
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N6UeBoqYEEnybg4cReFYDammpsyDzLXvCT"
)
== "2N6UeBoqYEEnybg4cReFYDammpsyDzLXvCT"
)
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
)
== "mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y"
)
== "mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y"
)
assert (
btc.get_address(
client,
"Elements",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
assert (
btc.get_address(
client,
"Elements",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z"
)
== "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z"
)
@pytest.mark.multisig

View File

@ -20,7 +20,9 @@ from trezorlib import btc, messages, tools
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import Cancelled, TrezorFailure
from ...common import is_core
from ...input_flows import (
InputFlowConfirmAllWarnings,
InputFlowShowAddressQRCode,
InputFlowShowAddressQRCodeCancel,
InputFlowShowMultisigXPUBs,
@ -148,17 +150,21 @@ def test_show_multisig_3(client: Client):
)
for i in [1, 2, 3]:
assert (
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,
)
== "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD"
)
== "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD"
)
VECTORS_MULTISIG = ( # script_type, bip48_type, address, xpubs, ignore_xpub_magic
@ -289,14 +295,18 @@ def test_show_multisig_15(client: Client):
)
for i in range(15):
assert (
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,
)
== "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ"
)
== "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ"
)

View File

@ -22,6 +22,7 @@ from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
from ...common import MNEMONIC12, is_core
from ...input_flows import InputFlowConfirmAllWarnings
from ...tx_cache import TxCache
from .signtx import (
assert_tx_matches,
@ -304,6 +305,9 @@ def test_attack_change_input(client: Client):
# Transaction can be signed without the attack processor
with client:
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_tx(
client,
"Testnet",

View File

@ -22,6 +22,7 @@ from trezorlib.tools import H_, parse_path
from ... import bip32
from ...common import MNEMONIC12, is_core
from ...input_flows import InputFlowConfirmAllWarnings
from ...tx_cache import TxCache
from .signtx import request_finished, request_input, request_meta, request_output
@ -243,6 +244,9 @@ def test_external_internal(client: Client):
client.set_expected_responses(
_responses(client, INP1, INP2, change=2, foreign=True)
)
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
_, serialized_tx = btc.sign_tx(
client,
"Bitcoin",
@ -276,6 +280,9 @@ def test_internal_external(client: Client):
client.set_expected_responses(
_responses(client, INP1, INP2, change=1, foreign=True)
)
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
_, serialized_tx = btc.sign_tx(
client,
"Bitcoin",

View File

@ -20,6 +20,7 @@ from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
from .signtx import forge_prevtx
@ -115,8 +116,9 @@ def test_getaddress(
):
for script_type in script_types:
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
res = btc.get_address(
client,
"Bitcoin",
@ -135,8 +137,9 @@ def test_signmessage(
):
for script_type in script_types:
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
sig = btc.sign_message(
client,
@ -173,8 +176,9 @@ def test_signtx(
)
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
_, serialized_tx = btc.sign_tx(
client, "Bitcoin", [inp1], [out1], prev_txes={prevhash: prevtx}
)
@ -199,8 +203,9 @@ def test_getaddress_multisig(
multisig = messages.MultisigRedeemScriptType(pubkeys=pubs, m=2)
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
address = btc.get_address(
client,
"Bitcoin",
@ -257,8 +262,9 @@ def test_signtx_multisig(client: Client, paths: list[str], address_index: list[i
)
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
sig, _ = btc.sign_tx(
client, "Bitcoin", [inp1], [out1], prev_txes={prevhash: prevtx}
)

View File

@ -24,6 +24,7 @@ from trezorlib.debuglink import message_filters
from trezorlib.exceptions import Cancelled
from trezorlib.tools import parse_path
from ...common import is_core
from ...input_flows import (
InputFlowConfirmAllWarnings,
InputFlowSignMessageInfo,
@ -413,8 +414,9 @@ def test_signmessage_path_warning(client: Client):
messages.MessageSignature,
]
)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_message(
client,
coin_name="Bitcoin",

View File

@ -21,6 +21,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
from .signtx import forge_prevtx, request_input
@ -80,8 +81,9 @@ def test_invalid_path_prompt(client: Client):
)
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_tx(client, "Litecoin", [inp1], [out1], prev_txes=PREV_TXES)
@ -105,8 +107,9 @@ def test_invalid_path_pass_forkid(client: Client):
)
with client:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_tx(client, "Bcash", [inp1], [out1], prev_txes=PREV_TXES)

View File

@ -8,6 +8,7 @@ from trezorlib import btc, messages, models, tools
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
from .signtx import forge_prevtx
@ -131,8 +132,9 @@ def test_invalid_prev_hash_attack(client: Client, prev_hash):
with client, pytest.raises(TrezorFailure) as e:
client.set_filter(messages.TxAck, attack_filter)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=PREV_TXES)
# check that injection was performed
@ -167,7 +169,8 @@ def test_invalid_prev_hash_in_prevtx(client: Client, prev_hash):
inp0.prev_hash = tx_hash
with client, pytest.raises(TrezorFailure) as e:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if client.model is not models.T1B1:
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
btc.sign_tx(client, "Bitcoin", [inp0], [out1], prev_txes={tx_hash: prev_tx})
_check_error_message(prev_hash, client.model, e.value.message)

View File

@ -613,8 +613,9 @@ def test_send_multisig_3_change(client: Client):
with client:
client.set_expected_responses(expected_responses)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
signatures, _ = btc.sign_tx(
client, "Testnet", [inp1], [out1], prev_txes=TX_API_TESTNET
)
@ -627,8 +628,9 @@ def test_send_multisig_3_change(client: Client):
with client:
client.set_expected_responses(expected_responses)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
_, serialized_tx = btc.sign_tx(
client, "Testnet", [inp1], [out1], prev_txes=TX_API_TESTNET
)
@ -703,8 +705,9 @@ def test_send_multisig_4_change(client: Client):
with client:
client.set_expected_responses(expected_responses)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
signatures, _ = btc.sign_tx(
client, "Testnet", [inp1], [out1], prev_txes=TX_API_TESTNET
)
@ -717,8 +720,9 @@ def test_send_multisig_4_change(client: Client):
with client:
client.set_expected_responses(expected_responses)
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
if is_core(client):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
_, serialized_tx = btc.sign_tx(
client, "Testnet", [inp1], [out1], prev_txes=TX_API_TESTNET
)

View File

@ -2142,9 +2142,9 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
def input_flow_tt(self) -> BRGeneratorType:
br = yield
# wait for homescreen to go away
self.debug.wait_layout()
while True:
# wait for homescreen to go away
self.debug.wait_layout()
self.client.ui._default_input_flow(br)
br = yield
@ -2153,10 +2153,10 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
br = yield
# wait for homescreen to go away
# probably won't be needed after https://github.com/trezor/trezor-firmware/pull/3686
self.debug.wait_layout()
while True:
# wait for homescreen to go away
# probably won't be needed after https://github.com/trezor/trezor-firmware/pull/3686
self.debug.wait_layout()
# Paginating (going as further as possible) and pressing Yes
if br.pages is not None:
for _ in range(br.pages - 1):
@ -2164,18 +2164,10 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
layout = self.debug.read_layout()
text = layout.text_content().lower()
# hi priority warning
if (
("wrong derivation path" in text)
or ("to a multisig" in text)
or ("multiple accounts" in text)
):
if ("wrong derivation path" in text) or ("to a multisig" in text):
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[1])
elif "receive address" in layout.title().lower():
self.debug.swipe_up()
self.debug.synchronize_at("PromptScreen")
self.debug.press_yes()
elif "swipe up" in layout.footer().lower():
self.debug.swipe_up()
else: