Skip to content

Commit

Permalink
fixup! tests: udpdate with ragger client
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Mar 8, 2024
1 parent 5cd975e commit 4f86668
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 97 deletions.
68 changes: 13 additions & 55 deletions tests/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,60 +101,6 @@ def register_wallet_instruction_approve(model: Firmware) -> Instructions:
return instructions


def register_wallet_instruction_approve_16(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
instructions.new_request("Approve", save_screenshot=False)
else:
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
return instructions


def register_wallet_instruction_approve_long(model: Firmware) -> Instructions:
instructions = Instructions(model)

Expand Down Expand Up @@ -387,7 +333,19 @@ def sign_psbt_instruction_approve_10(model: Firmware) -> Instructions:
return instructions


def tapscript_instruction(model: Firmware) -> Instructions:
def e2e_register_wallet_instruction(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
for _ in range(23):
instructions.new_request("Approve", save_screenshot=False)
else:
for _ in range(23):
instructions.choice_confirm(save_screenshot=False)
return instructions


def e2e_sign_psbt_instruction(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
Expand Down
25 changes: 13 additions & 12 deletions tests/test_e2e_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from test_utils import SpeculosGlobals, get_internal_xpub, count_internal_keys

from ragger_bitcoin import RaggerClient
from ragger_bitcoin.instructions import Instructions
from ragger.navigator import Navigator, NavInsID
from ragger.firmware import Firmware
from ragger.error import ExceptionRAPDU

from .instructions import Instructions, register_wallet_instruction_approve_16, tapscript_instruction
from .instructions import e2e_register_wallet_instruction, e2e_sign_psbt_instruction

from .conftest import create_new_wallet, generate_blocks, get_unique_wallet_name, get_wallet_rpc, testnet_to_regtest_addr as T
from .conftest import AuthServiceProxy
Expand Down Expand Up @@ -160,7 +161,7 @@ def test_e2e_miniscript_one_of_two_1(navigator: Navigator, firmware: Firmware, c
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_one_of_two_2(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand All @@ -180,7 +181,7 @@ def test_e2e_miniscript_one_of_two_2(navigator: Navigator, firmware: Firmware, c
])

run_test_e2e(navigator, client, wallet_policy, [_], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_2fa(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand All @@ -200,7 +201,7 @@ def test_e2e_miniscript_2fa(navigator: Navigator, firmware: Firmware, client: Ra
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_decaying_3of3(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -222,7 +223,7 @@ def test_e2e_miniscript_decaying_3of3(navigator: Navigator, firmware: Firmware,
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name1, core_wallet_name2], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_bolt3_offered_htlc(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -245,7 +246,7 @@ def test_e2e_miniscript_bolt3_offered_htlc(navigator: Navigator, firmware: Firmw
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name1, core_wallet_name2], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_bolt3_received_htlc(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -268,7 +269,7 @@ def test_e2e_miniscript_bolt3_received_htlc(navigator: Navigator, firmware: Firm
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name1, core_wallet_name2], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_me_or_3of5(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -295,7 +296,7 @@ def test_e2e_miniscript_me_or_3of5(navigator: Navigator, firmware: Firmware, cli
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_me_large_vault(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -327,7 +328,7 @@ def test_e2e_miniscript_me_large_vault(navigator: Navigator, firmware: Firmware,
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_me_and_bob_or_me_and_carl_1(navigator: Navigator, firmware: Firmware,
Expand Down Expand Up @@ -356,7 +357,7 @@ def test_e2e_miniscript_me_and_bob_or_me_and_carl_1(navigator: Navigator, firmwa
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name1], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_nanos_large_policy(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -390,7 +391,7 @@ def test_e2e_miniscript_nanos_large_policy(navigator: Navigator, firmware: Firmw

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name1, core_wallet_name2,
core_wallet_name3], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_policy_with_a(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -420,7 +421,7 @@ def test_e2e_miniscript_policy_with_a(navigator: Navigator, firmware: Firmware,
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name3], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_invalid_miniscript(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand Down
15 changes: 8 additions & 7 deletions tests/test_e2e_multisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
from speculos.client import SpeculosClient

from ragger_bitcoin import RaggerClient
from ragger_bitcoin.instructions import Instructions
from ragger.navigator import Navigator, NavInsID
from ragger.firmware import Firmware

from .instructions import Instructions, register_wallet_instruction_approve_16, tapscript_instruction
from .instructions import e2e_register_wallet_instruction, e2e_sign_psbt_instruction

from .conftest import create_new_wallet, generate_blocks, get_unique_wallet_name, get_wallet_rpc, testnet_to_regtest_addr as T
from .conftest import AuthServiceProxy
Expand Down Expand Up @@ -150,8 +151,8 @@ def test_e2e_multisig_2_of_2(navigator: Navigator, firmware: Firmware, client: R
)

run_test(navigator, client, wallet_policy, [core_wallet_name], rpc, rpc_test_wallet,
speculos_globals, register_wallet_instruction_approve_16(firmware),
tapscript_instruction(firmware), test_name)
speculos_globals, e2e_register_wallet_instruction(firmware),
e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_multisig_multiple_internal_keys(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -183,8 +184,8 @@ def test_e2e_multisig_multiple_internal_keys(navigator: Navigator, firmware: Fir

run_test(navigator, client, wallet_policy, [core_wallet_name_3],
rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware),
tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware),
e2e_sign_psbt_instruction(firmware), test_name)


@pytest.mark.timeout(0) # disable timeout
Expand Down Expand Up @@ -215,5 +216,5 @@ def test_e2e_multisig_16_of_16(navigator: Navigator, firmware: Firmware, client:
)

run_test(navigator, client, wallet_policy, core_wallet_names, rpc, rpc_test_wallet,
speculos_globals. register_wallet_instruction_approve_16(firmware),
tapscript_instruction(firmware), test_name)
speculos_globals. e2e_register_wallet_instruction(firmware),
e2e_sign_psbt_instruction(firmware), test_name)
26 changes: 13 additions & 13 deletions tests/test_e2e_tapscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
from test_utils import SpeculosGlobals, get_internal_xpub, count_internal_keys

from ragger_bitcoin import RaggerClient
from ragger_bitcoin.instructions import Instructions
from ragger.navigator import Navigator, NavInsID
from ragger.firmware import Firmware
from ragger.error import ExceptionRAPDU

from .instructions import Instructions, register_wallet_instruction_approve_16, tapscript_instruction

from .conftest import create_new_wallet, generate_blocks, get_unique_wallet_name, get_wallet_rpc, testnet_to_regtest_addr as T
from .instructions import e2e_register_wallet_instruction, e2e_sign_psbt_instruction
from .conftest import AuthServiceProxy
from .conftest import create_new_wallet, generate_blocks, get_unique_wallet_name, get_wallet_rpc, testnet_to_regtest_addr as T


def run_test_e2e(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPolicy,
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_e2e_tapscript_one_of_two_keypath(navigator: Navigator, firmware: Firmwa
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapscript_one_of_two_scriptpath(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -191,7 +191,7 @@ def test_e2e_tapscript_one_of_two_scriptpath(navigator: Navigator, firmware: Fir
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapscript_one_of_three_keypath(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -213,7 +213,7 @@ def test_e2e_tapscript_one_of_three_keypath(navigator: Navigator, firmware: Firm
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_register_wallet_instruction(firmware), test_name)


def test_e2e_tapscript_one_of_three_scriptpath(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -235,7 +235,7 @@ def test_e2e_tapscript_one_of_three_scriptpath(navigator: Navigator, firmware: F
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapscript_multi_a_2of2(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -256,7 +256,7 @@ def test_e2e_tapscript_multi_a_2of2(navigator: Navigator, firmware: Firmware, cl
])

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name2], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapscript_maxdepth(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_e2e_tapscript_maxdepth(navigator: Navigator, firmware: Firmware, client
keys_info=keys_info)

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapscript_large(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_e2e_tapscript_large(navigator: Navigator, firmware: Firmware, client: R
keys_info=keys_info)

run_test_e2e(navigator, client, wallet_policy, [core_wallet_name], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapminiscript_keypath_or_decaying_3of3(navigator: Navigator, firmware: Firmware,
Expand All @@ -345,7 +345,7 @@ def test_e2e_tapminiscript_keypath_or_decaying_3of3(navigator: Navigator, firmwa
])

run_test_e2e(navigator, client, wallet_policy, [core_name_2, core_name_3], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapminiscript_with_hash256(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -367,7 +367,7 @@ def test_e2e_tapminiscript_with_hash256(navigator: Navigator, firmware: Firmware
])

run_test_e2e(navigator, client, wallet_policy, [core_name_3], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_tapminiscript_mixed_leaves(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -392,7 +392,7 @@ def test_e2e_tapminiscript_mixed_leaves(navigator: Navigator, firmware: Firmware
])

run_test_e2e(navigator, client, wallet_policy, [], rpc, rpc_test_wallet, speculos_globals,
register_wallet_instruction_approve_16(firmware), tapscript_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)


def test_invalid_tapminiscript(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_extended_pubkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ def test_get_extended_pubkey_non_standard_reject(navigator: Navigator, firmware:
instructions=pubkey_reject(firmware),
testname=test_name,
)
assert e.value.status == 0x6985
assert DeviceException.exc.get(e.value.status) == DenyError
assert len(e.value.data) == 0
6 changes: 4 additions & 2 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from ledger_bitcoin.client_base import ApduException
from ledger_bitcoin.command_builder import BitcoinCommandBuilder, BitcoinInsType, CURRENT_PROTOCOL_VERSION
from ledger_bitcoin.exception.errors import WrongP1P2Error
from ledger_bitcoin.exception.device_exception import DeviceException

from ragger.error import ExceptionRAPDU
from ragger_bitcoin import RaggerClient

Expand Down Expand Up @@ -32,5 +34,5 @@ def test_p2_too_high(client: RaggerClient):
p2=CURRENT_PROTOCOL_VERSION + 1,
data=b''
)
assert e.value.status == 0x6a86
assert DeviceException.exc.get(e.value.status) == WrongP1P2Error
assert len(e.value.data) == 0
Loading

0 comments on commit 4f86668

Please sign in to comment.