Coverage for tests/utils/fake_wallet_rpc_server.py: 100%
14 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 19:49 +0000
« 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
4from .fake_rpc_server import FakeRpcHandler, FakeRpcServer
7class _Handler(FakeRpcHandler):
8 """Answers the json rpc requests of a wallet, with a new height at each request. The methods that a test needs have the result of a
9 wallet that has nothing, any other gets a result with the height: what is asked for and the result does not have, the client takes
10 as an error of the request."""
12 @override
13 def build_result(self, height: int, method: str) -> dict[str, Any]:
14 if method == "refresh":
15 return {"blocks_fetched": 0, "received_money": False}
16 if method in ("get_transfers", "rescan_spent"):
17 return {}
18 return {"height": height, "balance": 0, "unlocked_balance": 0}
21class FakeWalletRpcServer(FakeRpcServer):
22 """A wallet rpc server for unit tests, that needs no wallet: every request gets a new height, so the poller of a `MoneroWalletRpc`
23 is always asking the server.
25 Use it as a context manager.
26 """
28 def __init__(self, first_height: int = 100, response_delay: float = 0.0) -> None:
29 """Initialize a new FakeWalletRpcServer.
31 :param int first_height: height of the first response.
32 :param float response_delay: seconds that the server takes to answer a request, to have requests in flight.
33 """
34 super().__init__(_Handler, first_height, response_delay)