forked from Coldcard/firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_addr.py
73 lines (52 loc) · 2.35 KB
/
test_addr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# (c) Copyright 2018 by Coinkite Inc. This file is part of Coldcard <coldcardwallet.com>
# and is covered by GPLv3 license found in COPYING.
#
# test "show address" feature
#
import pytest, time
from pycoin.contrib.msg_signing import verify_message
from ckcc_protocol.protocol import CCProtocolPacker, CCProtoError
from ckcc_protocol.constants import *
@pytest.mark.parametrize('path', [ 'm', "m/1/2", "m/1'/100'"])
@pytest.mark.parametrize('addr_fmt', [ AF_CLASSIC, AF_P2WPKH, AF_P2WPKH_P2SH ])
def test_show_addr_usb(dev, need_keypress, addr_vs_path, path, addr_fmt,):
addr = dev.send_recv(CCProtocolPacker.show_address(path, addr_fmt), timeout=None)
need_keypress('y')
# check expected addr was used
addr_vs_path(addr, path, addr_fmt)
@pytest.mark.parametrize('path', [ 'm', "m/1/2", "m/1'/100'"])
@pytest.mark.parametrize('addr_fmt', [ AF_CLASSIC, AF_P2WPKH, AF_P2WPKH_P2SH ])
@pytest.mark.parametrize('show_qr', [ False, True ])
def test_show_addr_displayed(dev, need_keypress, addr_vs_path, path, addr_fmt, cap_story, show_qr, cap_screen_qr):
time.sleep(0.1)
addr = dev.send_recv(CCProtocolPacker.show_address(path, addr_fmt), timeout=None)
time.sleep(0.1)
title, story = cap_story()
#need_keypress('x')
# check expected addr was used
addr_vs_path(addr, path, addr_fmt)
print('addr_fmt = 0x%x' % addr_fmt)
assert title == 'Address:'
assert path in story
assert addr in story
assert addr in story.split('\n')
if show_qr:
need_keypress('4')
time.sleep(0.1)
qr = cap_screen_qr()
assert qr == addr or qr == addr.upper()
@pytest.mark.parametrize('example_addr', [
'2N2VBntgcoY4wN7H6VfrhH8an1BwieRMZCF', '2N551pf65tPS7VthC1rvwFDbLA1EUDYkTg9'])
def test_addr_vs_bitcoind(bitcoind, match_key, need_keypress, example_addr, dev):
# check our p2wpkh wrapped in p2sh is right
# PROBLEM: your bitcoind probably needs same transaction history as mine, so it knows
# about this address and its contents/key path.
assert example_addr[0] == '2'
resp = bitcoind.getaddressinfo(example_addr)
assert resp['embedded']['iswitness'] == True
assert resp['isscript'] == True
path = resp['hdkeypath']
addr = dev.send_recv(CCProtocolPacker.show_address(path, AF_P2WPKH_P2SH), timeout=None)
need_keypress('y')
assert addr == example_addr
# EOF