Skip to content

Commit

Permalink
Cleanup some tests; remove debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Nov 29, 2024
1 parent 4a2a3c5 commit 08a2ac0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 60 deletions.
1 change: 1 addition & 0 deletions test_utils/taproot_sighash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# Copyright (c) 2015-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.


import struct
Expand Down
39 changes: 2 additions & 37 deletions tests/test_e2e_musig2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from typing import Dict, List, Tuple
from typing import List, Tuple

import hmac
from hashlib import sha256
Expand All @@ -13,8 +13,7 @@
from ledger_bitcoin.wallet import WalletPolicy
from ledger_bitcoin import MusigPubNonce, MusigPartialSignature, PartialSignature, SignPsbtYieldedObject

from test_utils import SpeculosGlobals, bip0327, get_internal_xpub, count_internal_key_placeholders
from test_utils.musig2 import PsbtMusig2Cosigner
from test_utils import SpeculosGlobals, get_internal_xpub, count_internal_key_placeholders

from ragger_bitcoin import RaggerClient
from ragger_bitcoin.ragger_instructions import Instructions
Expand Down Expand Up @@ -44,12 +43,6 @@ def strip_non_musig2_derivations(psbt: PSBT) -> PSBT:
def run_test_e2e_musig2(navigator: Navigator, client: RaggerClient, wallet_policy: WalletPolicy, core_wallet_names: List[str], rpc: AuthServiceProxy, rpc_test_wallet: AuthServiceProxy, speculos_globals: SpeculosGlobals,
instructions_register_wallet: Instructions,
instructions_sign_psbt: Instructions, test_name: str):
# TODO: delete
def printb(*args):
print('\033[94m', end='')
print(*args)
print('\033[0m', end='')

wallet_id, wallet_hmac = client.register_wallet(wallet_policy, navigator,
instructions=instructions_register_wallet, testname=f"{test_name}_register")

Expand Down Expand Up @@ -78,9 +71,6 @@ def printb(*args):
change_descriptor_info = rpc.getdescriptorinfo(change_descriptor)
change_descriptor_chk: str = change_descriptor_info["descriptor"]

printb("Receive descriptor:", receive_descriptor_chk) # TODO: remove
printb("Change descriptor:", change_descriptor_chk) # TODO: remove

# ==> import wallet in bitcoin-core

new_core_wallet_name = get_unique_wallet_name()
Expand Down Expand Up @@ -131,9 +121,6 @@ def printb(*args):

psbt_b64 = result["psbt"]

printb("PSBT before the first round:")
printb(psbt_b64)

# Round 1: get nonces

# ==> get nonce from the hww
Expand All @@ -149,12 +136,8 @@ def printb(*args):
instructions=instructions_sign_psbt,
testname=f"{test_name}_sign")

printb("SignPsbt yielded:", hww_yielded)
for (input_index, yielded) in hww_yielded:
if isinstance(yielded, MusigPubNonce):
printb(f"Yielded MusigPubNonce for input {input_index}:")
printb(yielded.participant_pubkey.hex(), yielded.aggregate_pubkey.hex(
), None if yielded.tapleaf_hash is None else yielded.tapleaf_hash.hex())
psbt_key = (
yielded.participant_pubkey,
yielded.aggregate_pubkey,
Expand All @@ -177,32 +160,20 @@ def printb(*args):

signed_psbt_hww_b64 = psbt.serialize()

printb("PSBT after the first round for the hww:", signed_psbt_hww_b64)

# ==> Process it with bitcoin-core to get the musig pubnonces
partial_psbts = [signed_psbt_hww_b64]

# partial_psbts = []

for core_wallet_name in core_wallet_names:
printb("Processing for:", core_wallet_name)
psbt_res = get_wallet_rpc(
core_wallet_name).walletprocesspsbt(psbt_b64)["psbt"]
printb("PSBT processed by core:")
printb(psbt_res)
partial_psbts.append(psbt_res)

combined_psbt = rpc.combinepsbt(partial_psbts)

# Round 2: get Musig Partial Signatures

printb(wallet_policy.get_descriptor(None))

# TODO: should now do the second round
printb("PSBT after the first round:", combined_psbt)

printb("Starting round 2")

psbt = PSBT()
psbt.deserialize(combined_psbt)

Expand All @@ -211,7 +182,6 @@ def printb(*args):
instructions=instructions_sign_psbt,
testname=f"{test_name}_sign")

printb("SignPsbt yielded:", hww_yielded)
for (input_index, yielded) in hww_yielded:
if isinstance(yielded, MusigPartialSignature):
psbt_key = (
Expand All @@ -236,17 +206,12 @@ def printb(*args):

signed_psbt_hww_b64 = psbt.serialize()

printb("PSBT after the second round for the hww:", signed_psbt_hww_b64)

# ==> Get Musig partial signatures with each bitcoin-core wallet

partial_psbts = [signed_psbt_hww_b64]
for core_wallet_name in core_wallet_names:
printb("Processing for:", core_wallet_name)
psbt_res = get_wallet_rpc(
core_wallet_name).walletprocesspsbt(combined_psbt)["psbt"]
printb("PSBT processed by core:")
printb(psbt_res)
partial_psbts.append(psbt_res)

# ==> finalize the psbt, extract tx and broadcast
Expand Down
23 changes: 0 additions & 23 deletions tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,29 +966,6 @@ def test_sign_psbt_against_wrong_tapleaf_hash(navigator: Navigator, firmware: Fi
"5b82996fe6cf1bf43868511181c64c965b7bf5f16f007acec52dede5288f9225")


def test_sign_psbt_multiple_derivation_paths(navigator: Navigator, firmware: Firmware, client: RaggerClient, test_name: str):
# A previous implementation of the app incompletely checked the derivation paths of keys in certain
# transactions when multiple internal in the policy; that wasn't detected in other tests, so this
# was added in order to avoid regressions.
wallet = WalletPolicy(
name="Cold storage",
descriptor_template="wsh(or_d(multi(4,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*,@3/<0;1>/*),and_v(v:thresh(3,pkh(@0/<2;3>/*),a:pkh(@1/<2;3>/*),a:pkh(@2/<2;3>/*),a:pkh(@3/<2;3>/*)),older(65535))))",
keys_info=["[f5acc2fd/48'/1'/0'/2']tpubDFAqEGNyad35aBCKUAXbQGDjdVhNueno5ZZVEn3sQbW5ci457gLR7HyTmHBg93oourBssgUxuWz1jX5uhc1qaqFo9VsybY1J5FuedLfm4dK", 'tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF',
'tpubDF4kujkh5dAhC1pFgBToZybXdvJFXXGX4BWdDxWqP7EUpG8gxkfMQeDjGPDnTr9e4NrkFmDM1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BQhuriZLhj0mhNcRy5iKxsk2t2qRSsaw8/5TNVxKr+CdTk/HOCByPjMIisbJNrdqkUcvQ/cBCs1WYpeF3pqAauVo+5lUyIrGyTU4gD//8AsmgiAgLc23+KOzv1nhLHL/chcb9HPs+LFIwEixuyLe6M7RAtJhz1rML9MAAAgAEAAIAAAACAAgAAgAMAAAA2IAAAIgIDJ1HzCxSlPAsnEPz/7BEzGQp/cDWxHrGzIyfoq3QCelIc9azC/TAAAIABAACAAAAAgAIAAIABAAAANiAAAAA="

result = client.sign_psbt(psbt_b64, wallet, wallet_hmac, navigator,
instructions=sign_psbt_instruction_approve(
firmware, has_spend_from_wallet=True, save_screenshot=False),
testname=test_name)

assert len(result) == 2


def test_sign_psbt_multiple_derivation_paths(navigator: Navigator, firmware: Firmware, client: RaggerClient, test_name: str):
# A previous implementation of the app incompletely checked the derivation paths of keys in certain
# transactions when multiple internal in the policy; that wasn't detected in other tests, so this
Expand Down

0 comments on commit 08a2ac0

Please sign in to comment.