Coverage for tests/utils/fake_daemon_rpc_server.py: 100%

10 statements  

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

1from typing import Any 

2from typing_extensions import override 

3 

4from .fake_rpc_server import FakeRpcHandler, FakeRpcServer 

5 

6 

7class _Handler(FakeRpcHandler): 

8 """Answers the json rpc requests of a daemon poller, with a new block at each request.""" 

9 

10 @override 

11 def build_result(self, height: int, method: str) -> dict[str, Any]: 

12 return { 

13 "status": "OK", 

14 "untrusted": False, 

15 "block_header": { 

16 "hash": f"{height:064x}", 

17 "prev_hash": f"{height - 1:064x}", 

18 "miner_tx_hash": f"{height + 1:064x}", 

19 "height": height, 

20 "major_version": 16, 

21 "minor_version": 16, 

22 "timestamp": 1700000000 + height, 

23 "nonce": 1, 

24 "orphan_status": False, 

25 "depth": 0, 

26 "difficulty": 5, 

27 "cumulative_difficulty": 5 * height, 

28 "reward": 600000000000, 

29 "block_size": 100, 

30 "block_weight": 100, 

31 "num_txes": 0, 

32 "long_term_weight": 100, 

33 "pow_hash": "" 

34 } 

35 } 

36 

37 

38class FakeDaemonRpcServer(FakeRpcServer): 

39 """A daemon rpc server for unit tests, that needs no node: every request for the last block header gets a new block, 

40 so the poller of a `MoneroDaemonRpc` notifies its listeners at each poll. 

41 

42 Use it as a context manager. 

43 """ 

44 

45 def __init__(self, first_height: int = 100, response_delay: float = 0.0) -> None: 

46 """Initialize a new FakeDaemonRpcServer. 

47 

48 :param int first_height: height of the first block. 

49 :param float response_delay: seconds that the server takes to answer a request, to have requests in flight. 

50 """ 

51 super().__init__(_Handler, first_height, response_delay)