Coverage for tests/daemon/model/test_mining.py: 100%

67 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1from __future__ import annotations 

2 

3import logging 

4 

5import pytest 

6from monero import ( 

7 MoneroAddAuxiliaryPowResult, 

8 MoneroAuxiliaryPow, 

9 MoneroGenerateBlocksResult, 

10 MoneroMinerData, 

11 MoneroMinerTxSum, 

12 MoneroMiningStatus, 

13 MoneroTx, 

14) 

15 

16from utils import AssertUtils, BaseTestClass 

17 

18logger: logging.Logger = logging.getLogger("TestMoneroDaemonModelMining") 

19 

20 

21@pytest.mark.unit 

22class TestMoneroDaemonModelMining(BaseTestClass): 

23 """Daemon mining model unit tests.""" 

24 

25 def test_mining_status_deserialize(self) -> None: 

26 status: MoneroMiningStatus = MoneroMiningStatus() 

27 status.is_active = True 

28 status.is_background = False 

29 status.address = "9" + "a" * 94 

30 status.speed = 500 

31 status.num_threads = 4 

32 AssertUtils.assert_serialization_integrity(status) 

33 

34 def test_mining_status_inactive_clears_background_and_address_deserialize(self) -> None: 

35 # when isActive is false from_property_tree drops isBackground and address 

36 # even if present in the json 

37 json_str: str = ( 

38 '{"isActive": false, "isBackground": true, ' 

39 '"address": "' + "9" + "a" * 94 + '", "speed": 500, "numThreads": 4}' 

40 ) 

41 status: MoneroMiningStatus = MoneroMiningStatus.deserialize(json_str) 

42 assert status.is_active is False 

43 assert status.is_background is None 

44 assert status.address is None 

45 assert status.speed == 500 

46 assert status.num_threads == 4 

47 

48 def test_miner_tx_sum_deserialize(self) -> None: 

49 summ: MoneroMinerTxSum = MoneroMinerTxSum() 

50 summ.emission_sum_low = 1000 

51 summ.emission_sum_high = 0 

52 summ.fee_sum_low = 10 

53 summ.fee_sum_high = 0 

54 AssertUtils.assert_serialization_integrity(summ) 

55 

56 def test_generate_blocks_result_deserialize(self) -> None: 

57 result: MoneroGenerateBlocksResult = MoneroGenerateBlocksResult() 

58 result.block_hashes = ["a" * 64, "b" * 64] 

59 result.height = 12345 

60 AssertUtils.assert_serialization_integrity(result) 

61 

62 def test_miner_data_deserialize(self) -> None: 

63 data: MoneroMinerData = MoneroMinerData() 

64 data.credits = 0 

65 data.top_block_hash = "a" * 64 

66 data.major_version = 16 

67 data.height = 3000000 

68 data.prev_hash = "b" * 64 

69 data.seed_hash = "c" * 64 

70 data.difficulty = "0x1f4" # daemon reports difficulty as a hex string 

71 data.median_weight = 300000 

72 data.already_generated_coins = 5646232813355588 

73 tx: MoneroTx = MoneroTx() 

74 tx.hash = "d" * 64 

75 tx.fee = 10000 

76 data.tx_pool_backlog = [tx] 

77 AssertUtils.assert_serialization_integrity(data) 

78 

79 def test_auxiliary_pow_deserialize(self) -> None: 

80 aux_pow: MoneroAuxiliaryPow = MoneroAuxiliaryPow("a" * 64, "b" * 64) 

81 assert aux_pow.id == "a" * 64 

82 assert aux_pow.hash == "b" * 64 

83 AssertUtils.assert_serialization_integrity(aux_pow) 

84 

85 def test_add_auxiliary_pow_result_deserialize(self) -> None: 

86 result: MoneroAddAuxiliaryPowResult = MoneroAddAuxiliaryPowResult() 

87 result.credits = 0 

88 result.top_block_hash = "a" * 64 

89 result.block_template_blob = "abcd" 

90 result.block_hashing_blob = "ef01" 

91 result.merkle_root = "b" * 64 

92 result.merkle_tree_depth = 2 

93 result.aux_pow = [MoneroAuxiliaryPow("c" * 64, "d" * 64)] 

94 AssertUtils.assert_serialization_integrity(result)