Coverage for tests/ledger/hsm2dongle_cmds/test_signer_heartbeat.py: 100%
21 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2021 RSK Labs Ltd
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy of
6# this software and associated documentation files (the "Software"), to deal in
7# the Software without restriction, including without limitation the rights to
8# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9# of the Software, and to permit persons to whom the Software is furnished to do
10# so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
23from ..test_hsm2dongle import TestHSM2DongleBase
24from ledger.hsm2dongle import HSM2DongleBaseError
25from ledger.signature import HSM2DongleSignature
26from ledgerblue.commException import CommException
28import logging
30logging.disable(logging.CRITICAL)
33class TestHSM2SignerHeartbeat(TestHSM2DongleBase):
34 SIG = "3046022100e4c30ef37a1228a2faf2a88c8fb52a1dfe006a222d0961" \
35 "c43792018481d0d5e2022100b206abd9c8a46336f9684a84083613fb" \
36 "e4d31c34f7c023e5716545a00a709318"
38 def test_ok(self):
39 self.dongle.exchange.side_effect = [
40 b"",
41 bytes.fromhex("aabbcc" + self.SIG),
42 bytes.fromhex("ddeeff00112233445566778899"),
43 bytes.fromhex("001122aabbccddeeff"),
44 bytes.fromhex("ffffffddddddccccbb"),
45 ]
47 self.assertEqual((True, {
48 "pubKey": "ddddddccccbb",
49 "message": "00112233445566778899",
50 "tweak": "aabbccddeeff",
51 "signature": HSM2DongleSignature(bytes.fromhex(self.SIG))
52 }), self.hsm2dongle.get_signer_heartbeat("1133557799aa"))
54 self.assert_exchange([
55 bytes.fromhex("60011133557799aa"),
56 bytes.fromhex("6002"),
57 bytes.fromhex("6003"),
58 bytes.fromhex("6004"),
59 bytes.fromhex("6005"),
60 ])
62 def test_error_result(self):
63 self.dongle.exchange.side_effect = [
64 b"",
65 bytes.fromhex("aabbcc" + self.SIG),
66 CommException("an-error-result", 0x6b01)
67 ]
69 self.assertEqual((False, 0x6b01),
70 self.hsm2dongle.get_signer_heartbeat("1133557799aa"))
72 self.assert_exchange([
73 bytes.fromhex("60011133557799aa"),
74 bytes.fromhex("6002"),
75 bytes.fromhex("6003"),
76 ])
78 def test_exception(self):
79 self.dongle.exchange.side_effect = [
80 b"",
81 CommException("an-exception")
82 ]
84 with self.assertRaises(HSM2DongleBaseError):
85 self.hsm2dongle.get_signer_heartbeat("1133557799aa")
87 self.assert_exchange([
88 bytes.fromhex("60011133557799aa"),
89 bytes.fromhex("6002"),
90 ])