1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-28 02:18:20 +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.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,

View File

@ -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,

View File

@ -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,

View File

@ -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"
)