From e4032572bedd2496c75e4679cd997cde4fe127b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Thu, 14 Nov 2024 18:43:59 +0100 Subject: [PATCH] refactor(tests): use same path in per-node specification --- tests/device_tests/bitcoin/test_getaddress.py | 11 +- .../bitcoin/test_getaddress_segwit.py | 10 +- .../bitcoin/test_getaddress_segwit_native.py | 10 +- .../bitcoin/test_getaddress_show.py | 109 +++++++++++------- 4 files changed, 74 insertions(+), 66 deletions(-) diff --git a/tests/device_tests/bitcoin/test_getaddress.py b/tests/device_tests/bitcoin/test_getaddress.py index 9977b5598d..ecdcb58613 100644 --- a/tests/device_tests/bitcoin/test_getaddress.py +++ b/tests/device_tests/bitcoin/test_getaddress.py @@ -300,27 +300,22 @@ def test_multisig(client: Client): @pytest.mark.multisig @pytest.mark.parametrize("show_display", (True, False)) def test_multisig_missing(client: Client, show_display): - # Multisig with global suffix specification. # Use account numbers 1, 2 and 3 to create a valid multisig, # but not containing the keys from account 0 used below. nodes = [ btc.get_public_node(client, parse_path(f"m/44h/0h/{i}h")).node for i in range(1, 4) ] + + # Multisig with global suffix specification. multisig1 = messages.MultisigRedeemScriptType( nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 ) # Multisig with per-node suffix specification. - node = btc.get_public_node( - client, parse_path("m/44h/0h/0h/0"), coin_name="Bitcoin" - ).node - multisig2 = messages.MultisigRedeemScriptType( pubkeys=[ - messages.HDNodePathType(node=node, address_n=[1]), - messages.HDNodePathType(node=node, address_n=[2]), - messages.HDNodePathType(node=node, address_n=[3]), + messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes ], signatures=[b"", b"", b""], m=2, diff --git a/tests/device_tests/bitcoin/test_getaddress_segwit.py b/tests/device_tests/bitcoin/test_getaddress_segwit.py index 0958facda2..848097a8cb 100644 --- a/tests/device_tests/bitcoin/test_getaddress_segwit.py +++ b/tests/device_tests/bitcoin/test_getaddress_segwit.py @@ -169,26 +169,22 @@ def test_show_multisig_3(client: Client): @pytest.mark.multisig @pytest.mark.parametrize("show_display", (True, False)) def test_multisig_missing(client: Client, show_display): - # Multisig with global suffix specification. # Use account numbers 1, 2 and 3 to create a valid multisig, # but not containing the keys from account 0 used below. nodes = [ btc.get_public_node(client, parse_path(f"m/49h/0h/{i}h")).node for i in range(1, 4) ] + + # Multisig with global suffix specification. multisig1 = messages.MultisigRedeemScriptType( nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 ) # Multisig with per-node suffix specification. - node = btc.get_public_node( - client, parse_path("m/49h/0h/0h/0"), coin_name="Bitcoin" - ).node multisig2 = messages.MultisigRedeemScriptType( pubkeys=[ - messages.HDNodePathType(node=node, address_n=[1]), - messages.HDNodePathType(node=node, address_n=[2]), - messages.HDNodePathType(node=node, address_n=[3]), + messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes ], signatures=[b"", b"", b""], m=2, diff --git a/tests/device_tests/bitcoin/test_getaddress_segwit_native.py b/tests/device_tests/bitcoin/test_getaddress_segwit_native.py index f141630053..55b0fbfdb5 100644 --- a/tests/device_tests/bitcoin/test_getaddress_segwit_native.py +++ b/tests/device_tests/bitcoin/test_getaddress_segwit_native.py @@ -222,26 +222,22 @@ def test_show_multisig_3(client: Client): @pytest.mark.multisig @pytest.mark.parametrize("show_display", (True, False)) def test_multisig_missing(client: Client, show_display: bool): - # Multisig with global suffix specification. # Use account numbers 1, 2 and 3 to create a valid multisig, # but not containing the keys from account 0 used below. nodes = [ btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node for i in range(1, 4) ] + + # Multisig with global suffix specification. multisig1 = messages.MultisigRedeemScriptType( nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 ) # Multisig with per-node suffix specification. - node = btc.get_public_node( - client, parse_path("m/84h/0h/0h/0"), coin_name="Bitcoin" - ).node multisig2 = messages.MultisigRedeemScriptType( pubkeys=[ - messages.HDNodePathType(node=node, address_n=[1]), - messages.HDNodePathType(node=node, address_n=[2]), - messages.HDNodePathType(node=node, address_n=[3]), + messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes ], signatures=[b"", b"", b""], m=2, diff --git a/tests/device_tests/bitcoin/test_getaddress_show.py b/tests/device_tests/bitcoin/test_getaddress_show.py index ef143ff362..8770176d42 100644 --- a/tests/device_tests/bitcoin/test_getaddress_show.py +++ b/tests/device_tests/bitcoin/test_getaddress_show.py @@ -134,35 +134,44 @@ def test_show_unrecognized_path(client: Client): @pytest.mark.multisig def test_show_multisig_3(client: Client): - node = btc.get_public_node( - client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin" - ).node - multisig = messages.MultisigRedeemScriptType( + nodes = [ + btc.get_public_node( + client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin" + ).node + for i in [1, 2, 3] + ] + + # Multisig with global suffix specification. + multisig1 = messages.MultisigRedeemScriptType( + nodes=nodes, signatures=[b"", b"", b""], m=2, address_n=[0, 0] + ) + + # Multisig with per-node suffix specification. + multisig2 = messages.MultisigRedeemScriptType( pubkeys=[ - messages.HDNodePathType(node=node, address_n=[1]), - messages.HDNodePathType(node=node, address_n=[2]), - messages.HDNodePathType(node=node, address_n=[3]), + messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes ], signatures=[b"", b"", b""], m=2, ) - for i in [1, 2, 3]: - 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, + for multisig in (multisig1, multisig2): + for i in [1, 2, 3]: + 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/{i}/0/0"), + show_display=True, + multisig=multisig, + script_type=messages.InputScriptType.SPENDMULTISIG, + ) + == "3FQJAFhGpgryDeYh5trpFJTCvN3H5aX2Cg" ) - == "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD" - ) VECTORS_MULTISIG = ( # script_type, bip48_type, address, xpubs, ignore_xpub_magic @@ -282,29 +291,41 @@ def test_show_multisig_xpubs( @pytest.mark.multisig def test_show_multisig_15(client: Client): - node = btc.get_public_node( - client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin" - ).node + nodes = [ + btc.get_public_node( + client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin" + ).node + for i in range(15) + ] - pubs = [messages.HDNodePathType(node=node, address_n=[x]) for x in range(15)] - - multisig = messages.MultisigRedeemScriptType( - pubkeys=pubs, signatures=[b""] * 15, m=15 + # Multisig with global suffix specification. + multisig1 = messages.MultisigRedeemScriptType( + nodes=nodes, signatures=[b"", b"", b""], m=2, address_n=[0, 0] ) - for i in range(15): - 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, + # Multisig with per-node suffix specification. + multisig2 = messages.MultisigRedeemScriptType( + pubkeys=[ + messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes + ], + signatures=[b"", b"", b""], + m=2, + ) + + for multisig in [multisig1, multisig2]: + for i in range(15): + 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/{i}/0/0"), + show_display=True, + multisig=multisig, + script_type=messages.InputScriptType.SPENDMULTISIG, + ) + == "3A8zs8W98A7n1zCWSvVzodiBsaHBYzAhzb" ) - == "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ" - )