Coverage for tests/ledger/test_version.py: 100%

21 statements  

« 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. 

22 

23from unittest import TestCase 

24from parameterized import parameterized 

25from ledger.version import HSM2FirmwareVersion 

26 

27import logging 

28 

29logging.disable(logging.CRITICAL) 

30 

31 

32class TestHSM2FirmwareVersion(TestCase): 

33 @parameterized.expand([ 

34 ("same_version", (1, 1, 0), (1, 1, 0), True), 

35 ("firmware_higher_minor", (1, 1, 0), (1, 2, 5), False), 

36 ("firmware_lower_minor", (1, 1, 0), (1, 0, 5), True), 

37 ("firmware_lower_minor_higher_patch", (2, 5, 0), (2, 4, 3), True), 

38 ("different_major_same_minor_patch", (2, 5, 5), (3, 5, 5), False), 

39 ("different_major_same_minor_patch", (2, 5, 5), (3, 5, 5), False), 

40 ]) 

41 def test_supports(self, _, mware_version_t, firmware_version_t, should_be_supported): 

42 mware_version = HSM2FirmwareVersion(mware_version_t[0], mware_version_t[1], 

43 mware_version_t[2]) 

44 firmware_version = HSM2FirmwareVersion(firmware_version_t[0], 

45 firmware_version_t[1], 

46 firmware_version_t[2]) 

47 self.assertEqual(should_be_supported, mware_version.supports(firmware_version)) 

48 

49 @parameterized.expand([ 

50 ("same_version", (1, 1, 0), (1, 1, 0), True), 

51 ("firmware_higher_minor", (1, 1, 0), (1, 2, 5), False), 

52 ("firmware_lower_minor", (1, 1, 0), (1, 0, 5), True), 

53 ("firmware_lower_minor_higher_patch", (2, 5, 0), (2, 4, 3), True), 

54 ("different_major_same_minor_patch", (2, 5, 5), (3, 5, 5), False), 

55 ("different_major_same_minor_patch", (2, 5, 5), (3, 5, 5), False), 

56 ]) 

57 def test_greater_or_equal(self, _, version_a_t, version_b_t, is_geq): 

58 version_a = HSM2FirmwareVersion(version_a_t[0], version_a_t[1], version_a_t[2]) 

59 version_b = HSM2FirmwareVersion(version_b_t[0], version_b_t[1], version_b_t[2]) 

60 self.assertEqual(is_geq, version_a >= version_b) 

61 

62 @parameterized.expand([ 

63 ("same_version", (1, 2, 3), (1, 2, 3), True), 

64 ("different_major", (1, 2, 3), (7, 2, 3), False), 

65 ("different_minor", (1, 2, 3), (1, 4, 3), False), 

66 ("different_patch", (1, 2, 3), (1, 2, 5), False), 

67 ]) 

68 def test_equal(self, _, version_a_t, version_b_t, is_eq): 

69 version_a = HSM2FirmwareVersion(version_a_t[0], version_a_t[1], version_a_t[2]) 

70 version_b = HSM2FirmwareVersion(version_b_t[0], version_b_t[1], version_b_t[2]) 

71 self.assertEqual(is_eq, version_a == version_b)