1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-01 03:48:18 +00:00

refactor(tests): use same path in per-node specification

This commit is contained in:
Ondřej Vejpustek 2024-11-14 18:43:59 +01:00
parent a67c7cdf5a
commit e8c64a539c
4 changed files with 74 additions and 66 deletions

View File

@ -300,27 +300,22 @@ def test_multisig(client: Client):
@pytest.mark.multisig @pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False)) @pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client: Client, show_display): 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, # Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below. # but not containing the keys from account 0 used below.
nodes = [ nodes = [
btc.get_public_node(client, parse_path(f"m/44h/0h/{i}h")).node btc.get_public_node(client, parse_path(f"m/44h/0h/{i}h")).node
for i in range(1, 4) for i in range(1, 4)
] ]
# Multisig with global suffix specification.
multisig1 = messages.MultisigRedeemScriptType( multisig1 = messages.MultisigRedeemScriptType(
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
) )
# Multisig with per-node suffix specification. # 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( multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[ pubkeys=[
messages.HDNodePathType(node=node, address_n=[1]), messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
messages.HDNodePathType(node=node, address_n=[2]),
messages.HDNodePathType(node=node, address_n=[3]),
], ],
signatures=[b"", b"", b""], signatures=[b"", b"", b""],
m=2, m=2,

View File

@ -169,26 +169,22 @@ def test_show_multisig_3(client: Client):
@pytest.mark.multisig @pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False)) @pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client: Client, show_display): 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, # Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below. # but not containing the keys from account 0 used below.
nodes = [ nodes = [
btc.get_public_node(client, parse_path(f"m/49h/0h/{i}h")).node btc.get_public_node(client, parse_path(f"m/49h/0h/{i}h")).node
for i in range(1, 4) for i in range(1, 4)
] ]
# Multisig with global suffix specification.
multisig1 = messages.MultisigRedeemScriptType( multisig1 = messages.MultisigRedeemScriptType(
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
) )
# Multisig with per-node suffix specification. # 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( multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[ pubkeys=[
messages.HDNodePathType(node=node, address_n=[1]), messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
messages.HDNodePathType(node=node, address_n=[2]),
messages.HDNodePathType(node=node, address_n=[3]),
], ],
signatures=[b"", b"", b""], signatures=[b"", b"", b""],
m=2, m=2,

View File

@ -222,26 +222,22 @@ def test_show_multisig_3(client: Client):
@pytest.mark.multisig @pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False)) @pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client: Client, show_display: bool): 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, # Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below. # but not containing the keys from account 0 used below.
nodes = [ nodes = [
btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node
for i in range(1, 4) for i in range(1, 4)
] ]
# Multisig with global suffix specification.
multisig1 = messages.MultisigRedeemScriptType( multisig1 = messages.MultisigRedeemScriptType(
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
) )
# Multisig with per-node suffix specification. # 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( multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[ pubkeys=[
messages.HDNodePathType(node=node, address_n=[1]), messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
messages.HDNodePathType(node=node, address_n=[2]),
messages.HDNodePathType(node=node, address_n=[3]),
], ],
signatures=[b"", b"", b""], signatures=[b"", b"", b""],
m=2, m=2,

View File

@ -134,19 +134,28 @@ def test_show_unrecognized_path(client: Client):
@pytest.mark.multisig @pytest.mark.multisig
def test_show_multisig_3(client: Client): def test_show_multisig_3(client: Client):
node = btc.get_public_node( nodes = [
client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin" btc.get_public_node(
client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin"
).node ).node
multisig = messages.MultisigRedeemScriptType( 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=[ pubkeys=[
messages.HDNodePathType(node=node, address_n=[1]), messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
messages.HDNodePathType(node=node, address_n=[2]),
messages.HDNodePathType(node=node, address_n=[3]),
], ],
signatures=[b"", b"", b""], signatures=[b"", b"", b""],
m=2, m=2,
) )
for multisig in (multisig1, multisig2):
for i in [1, 2, 3]: for i in [1, 2, 3]:
with client: with client:
if is_core(client): if is_core(client):
@ -156,12 +165,12 @@ def test_show_multisig_3(client: Client):
btc.get_address( btc.get_address(
client, client,
"Bitcoin", "Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"), tools.parse_path(f"m/45h/{i}/0/0"),
show_display=True, show_display=True,
multisig=multisig, multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG, script_type=messages.InputScriptType.SPENDMULTISIG,
) )
== "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD" == "3FQJAFhGpgryDeYh5trpFJTCvN3H5aX2Cg"
) )
@ -282,16 +291,28 @@ def test_show_multisig_xpubs(
@pytest.mark.multisig @pytest.mark.multisig
def test_show_multisig_15(client: Client): def test_show_multisig_15(client: Client):
node = btc.get_public_node( nodes = [
client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin" btc.get_public_node(
client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin"
).node ).node
for i in range(15)
]
pubs = [messages.HDNodePathType(node=node, address_n=[x]) for x in range(15)] # Multisig with global suffix specification.
multisig1 = messages.MultisigRedeemScriptType(
multisig = messages.MultisigRedeemScriptType( nodes=nodes, signatures=[b"", b"", b""], m=2, address_n=[0, 0]
pubkeys=pubs, signatures=[b""] * 15, m=15
) )
# 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): for i in range(15):
with client: with client:
if is_core(client): if is_core(client):
@ -301,10 +322,10 @@ def test_show_multisig_15(client: Client):
btc.get_address( btc.get_address(
client, client,
"Bitcoin", "Bitcoin",
tools.parse_path(f"m/45h/0/0/{i}"), tools.parse_path(f"m/45h/{i}/0/0"),
show_display=True, show_display=True,
multisig=multisig, multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG, script_type=messages.InputScriptType.SPENDMULTISIG,
) )
== "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ" == "3A8zs8W98A7n1zCWSvVzodiBsaHBYzAhzb"
) )