-
Notifications
You must be signed in to change notification settings - Fork 74
/
test_protocol.py
38 lines (31 loc) · 1.46 KB
/
test_protocol.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
import pytest
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
def test_high_p1_allowed(client: RaggerClient):
# We reserve p1 for feature flags, so non-zero bits shouldn't be rejected
# for forward-compatibility; this allows graceful degradation for optional features.
# We can't use the client to send this apdu, so we use raw transport.
# We're only testing that no exception is raised.
client.transport_client.exchange(
cla=BitcoinCommandBuilder.CLA_BITCOIN,
ins=BitcoinInsType.GET_MASTER_FINGERPRINT,
p1=0xff,
p2=CURRENT_PROTOCOL_VERSION,
data=b''
)
def test_p2_too_high(client: RaggerClient):
# Tests that sending a p2 > CURRENT_PROTOCOL_VERSION fails with 0x6a86 (WRONG_P1P2)
with pytest.raises(ExceptionRAPDU) as e:
# We can't use the client to send this apdu, so we use raw transport
client.transport_client.exchange(
cla=BitcoinCommandBuilder.CLA_BITCOIN,
ins=BitcoinInsType.GET_MASTER_FINGERPRINT,
p1=0,
p2=CURRENT_PROTOCOL_VERSION + 1,
data=b''
)
assert DeviceException.exc.get(e.value.status) == WrongP1P2Error
assert len(e.value.data) == 0