Skip to content

Commit 7423fcf

Browse files
committed
test: GetAddress returns BIP-86 taproot addresses
Drives the emulator through the full GetAddress path for SPENDTAPROOT -- fsm_msgGetAddress, path_mismatched's m/86' branch, compute_address, the BIP-86 tweak and bech32m encoding -- none of which the firmware's C unit tests reach. Expected values are the three official BIP-86 vectors. BIP-86 publishes them against the "abandon abandon ... about" mnemonic, which is exactly what setup_mnemonic_abandon loads, so these are the spec's constants and not values our implementation produced. Verified against a locally built emulator: 1 passed. Also mutation checked -- flipping one character of the first expected address makes it fail, so the assertions are not vacuous. NOTE: gated at 7.16.0 via TAPROOT_FIRMWARE_VERSION. develop is currently 7.15.0, so this SKIPS until the project version bumps. A gate that is never reached is a test that is silently green forever -- keep the constant in step with CMakeLists.txt.
1 parent d88a073 commit 7423fcf

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This file is part of the KeepKey project.
2+
#
3+
# This library is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU Lesser General Public License version 3
5+
# as published by the Free Software Foundation.
6+
#
7+
# This library is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Lesser General Public License for more details.
11+
#
12+
# You should have received a copy of the License along with this library.
13+
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
14+
15+
import common
16+
import unittest
17+
18+
from keepkeylib import types_pb2 as proto
19+
from keepkeylib.tools import parse_path
20+
21+
22+
# Version in which SPENDTAPROOT support lands. Keep this in step with
23+
# CMakeLists.txt: if the firmware version is below it these tests SKIP, so a
24+
# value that is never reached makes them silently green forever.
25+
TAPROOT_FIRMWARE_VERSION = "7.16.0"
26+
27+
28+
class TestMsgGetaddressTaproot(common.KeepKeyTest):
29+
30+
def test_taproot_bip86_vectors(self):
31+
"""Official BIP-86 test vectors.
32+
33+
https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki
34+
35+
BIP-86 publishes these against the "abandon abandon ... about"
36+
mnemonic, which is exactly what setup_mnemonic_abandon loads. The
37+
expected addresses are therefore the spec's own constants, not values
38+
this implementation produced -- the comparison is against independent
39+
ground truth.
40+
"""
41+
self.requires_firmware(TAPROOT_FIRMWARE_VERSION)
42+
self.setup_mnemonic_abandon()
43+
self.client.clear_session()
44+
45+
# Account 0, first receiving address
46+
self.assertEqual(
47+
self.client.get_address(
48+
"Bitcoin", parse_path("86'/0'/0'/0/0"), False, None,
49+
script_type=proto.SPENDTAPROOT),
50+
'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr')
51+
52+
# Account 0, second receiving address
53+
self.assertEqual(
54+
self.client.get_address(
55+
"Bitcoin", parse_path("86'/0'/0'/0/1"), False, None,
56+
script_type=proto.SPENDTAPROOT),
57+
'bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh')
58+
59+
# Account 0, first change address
60+
self.assertEqual(
61+
self.client.get_address(
62+
"Bitcoin", parse_path("86'/0'/0'/1/0"), False, None,
63+
script_type=proto.SPENDTAPROOT),
64+
'bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7')
65+
66+
67+
if __name__ == '__main__':
68+
unittest.main()

0 commit comments

Comments
 (0)