"""Test doubles for what the services ask of the network (B-76 and after).""" from app.electrum.client import ElectrumRpcError def rpc_error(message: str, code: int = -26) -> ElectrumRpcError: """A server that answered with a JSON-RPC `error` object — an explicit refusal.""" return ElectrumRpcError({"code": code, "message": message}) class FakeNetwork: """The ElectrumListener surface a broadcast needs: `known` is what `transaction_known` answers (True: some server has it, False: every server denies it, None: too few answers to tell); fanned-out transactions are recorded.""" def __init__(self, known: bool | None = False): self.known = known self.asked: list[str] = [] self.fanned_out: list[str] = [] async def transaction_known(self, txid: str) -> bool | None: self.asked.append(txid) return self.known def fan_out_transaction(self, raw_tx_hex: str) -> None: self.fanned_out.append(raw_tx_hex)