Skip to content

Commit

Permalink
Update tests and ragger instructions for new UX wording
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Apr 5, 2024
1 parent 1d48c10 commit 70ac277
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 74 deletions.
82 changes: 40 additions & 42 deletions tests/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def sign_psbt_instruction_approve(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.navigate_end_of_flow()
instructions.confirm_transaction()
Expand All @@ -166,8 +166,8 @@ def sign_psbt_instruction_approve_2(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Sign")
else:
instructions.navigate_end_of_flow()
instructions.navigate_end_of_flow()
Expand All @@ -179,9 +179,9 @@ def sign_psbt_instruction_approve_3(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Continue")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.navigate_end_of_flow()
instructions.navigate_end_of_flow()
Expand All @@ -195,8 +195,8 @@ def sign_psbt_instruction_approve_4(model: Firmware) -> Instructions:

if model.name.startswith("nano"):
instructions.new_request("Continue")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.warning_accept()
instructions.navigate_end_of_flow()
Expand All @@ -208,9 +208,7 @@ def sign_psbt_instruction_approve_5(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Accept")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Sign")
else:
instructions.navigate_end_of_flow()
instructions.confirm_transaction()
Expand All @@ -221,9 +219,9 @@ def sign_psbt_instruction_approve_6(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Sign")
else:
instructions.confirm_wallet()
instructions.navigate_end_of_flow()
Expand All @@ -236,9 +234,9 @@ def sign_psbt_instruction_approve_7(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.confirm_wallet()
instructions.navigate_end_of_flow()
Expand All @@ -250,10 +248,10 @@ def sign_psbt_instruction_approve_8(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Continue")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.confirm_wallet()
instructions.warning_accept()
Expand All @@ -266,9 +264,9 @@ def sign_psbt_instruction_approve_9(model: Firmware) -> Instructions:
instructions = Instructions(model)

if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.navigate_end_of_flow()
instructions.navigate_end_of_flow()
Expand All @@ -281,12 +279,12 @@ def sign_psbt_instruction_approve_external_inputs(model: Firmware) -> Instructio

if model.name.startswith("nano"):
instructions.new_request("Continue")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.warning_accept()
instructions.navigate_end_of_flow()
Expand All @@ -303,11 +301,11 @@ def sign_psbt_instruction_approve_external_inputs_2(model: Firmware) -> Instruct

if model.name.startswith("nano"):
instructions.new_request("Continue")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.new_request("Approve")
instructions.same_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.warning_accept()
instructions.navigate_end_of_flow()
Expand All @@ -323,8 +321,8 @@ def sign_psbt_instruction_approve_10(model: Firmware) -> Instructions:

if model.name.startswith("nano"):
instructions.new_request("Continue")
instructions.new_request("Approve")
instructions.new_request("Accept")
instructions.new_request("Continue")
instructions.new_request("Sign")
else:
instructions.warning_accept()
instructions.navigate_end_of_flow()
Expand All @@ -333,14 +331,14 @@ def sign_psbt_instruction_approve_10(model: Firmware) -> Instructions:
return instructions


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

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

Expand All @@ -349,9 +347,9 @@ def e2e_sign_psbt_instruction(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("Accept", save_screenshot=False)
instructions.new_request("Continue", save_screenshot=False)
instructions.new_request("Continue", save_screenshot=False)
instructions.new_request("Sign", save_screenshot=False)
else:
instructions.confirm_wallet(save_screenshot=False)
instructions.navigate_end_of_flow(save_screenshot=False)
Expand Down
22 changes: 11 additions & 11 deletions tests/test_e2e_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_one_of_two_2(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand All @@ -181,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_2fa(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand All @@ -201,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_decaying_3of3(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -223,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_bolt3_offered_htlc(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -246,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_bolt3_received_htlc(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -269,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_me_or_3of5(navigator: Navigator, firmware: Firmware, client:
Expand All @@ -296,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_me_large_vault(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -328,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), 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 @@ -357,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_nanos_large_policy(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -391,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_e2e_miniscript_policy_with_a(navigator: Navigator, firmware: Firmware, client:
Expand Down Expand Up @@ -421,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,
e2e_register_wallet_instruction(firmware), e2e_sign_psbt_instruction(firmware), test_name)
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys), e2e_sign_psbt_instruction(firmware), test_name)


def test_invalid_miniscript(navigator: Navigator, firmware: Firmware, client: RaggerClient,
Expand Down
29 changes: 19 additions & 10 deletions tests/test_e2e_multisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def run_test(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPo
assert wallet_id == wallet_policy.id

assert hmac.compare_digest(
hmac.new(speculos_globals.wallet_registration_key, wallet_id, sha256).digest(),
hmac.new(speculos_globals.wallet_registration_key,
wallet_id, sha256).digest(),
wallet_hmac,
)

address_hww = client.get_wallet_address(wallet_policy, wallet_hmac, 0, 3, False)
address_hww = client.get_wallet_address(
wallet_policy, wallet_hmac, 0, 3, False)

# ==> verify the address matches what bitcoin-core computes
receive_descriptor = wallet_policy.get_descriptor(change=False)
Expand Down Expand Up @@ -94,7 +96,8 @@ def run_test(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPo
out_address: Decimal("0.01")
},
options={
"changePosition": 1 # We need a fixed position to be able to know how to navigate in the flows
# We need a fixed position to be able to know how to navigate in the flows
"changePosition": 1
}
)

Expand All @@ -109,8 +112,10 @@ def run_test(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPo
instructions=instructions_sign_psbt,
testname=f"{test_name}_sign")

n_internal_keys = count_internal_keys(speculos_globals.seed, "test", wallet_policy)
assert len(hww_sigs) == n_internal_keys * len(psbt.inputs) # should be true as long as all inputs are internal
n_internal_keys = count_internal_keys(
speculos_globals.seed, "test", wallet_policy)
# should be true as long as all inputs are internal
assert len(hww_sigs) == n_internal_keys * len(psbt.inputs)

for i, part_sig in hww_sigs:
psbt.inputs[i].partial_sigs[part_sig.pubkey] = part_sig.signature
Expand All @@ -121,7 +126,8 @@ def run_test(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPo
partial_psbts = [signed_psbt_hww_b64]

for core_wallet_name in core_wallet_names:
partial_psbts.append(get_wallet_rpc(core_wallet_name).walletprocesspsbt(psbt_b64)["psbt"])
partial_psbts.append(get_wallet_rpc(
core_wallet_name).walletprocesspsbt(psbt_b64)["psbt"])

# ==> finalize the psbt, extract tx and broadcast
combined_psbt = rpc.combinepsbt(partial_psbts)
Expand Down Expand Up @@ -151,7 +157,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, e2e_register_wallet_instruction(firmware),
speculos_globals, e2e_register_wallet_instruction(
firmware, wallet_policy.n_keys),
e2e_sign_psbt_instruction(firmware), test_name)


Expand Down Expand Up @@ -184,7 +191,7 @@ 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,
e2e_register_wallet_instruction(firmware),
e2e_register_wallet_instruction(firmware, wallet_policy.n_keys),
e2e_sign_psbt_instruction(firmware), test_name)


Expand Down Expand Up @@ -212,9 +219,11 @@ def test_e2e_multisig_16_of_16(navigator: Navigator, firmware: Firmware, client:
address_type=AddressType.WIT,
threshold=2,
sorted=True,
keys_info=core_xpub_origs + [f"[{speculos_globals.master_key_fingerprint.hex()}/{path}]{internal_xpub}"],
keys_info=core_xpub_origs +
[f"[{speculos_globals.master_key_fingerprint.hex()}/{path}]{internal_xpub}"],
)

run_test(navigator, client, wallet_policy, core_wallet_names, rpc, rpc_test_wallet,
speculos_globals. e2e_register_wallet_instruction(firmware),
speculos_globals. e2e_register_wallet_instruction(
firmware, wallet_policy.n_keys),
e2e_sign_psbt_instruction(firmware), test_name)
Loading

0 comments on commit 70ac277

Please sign in to comment.