B1: plm_engine takes the modules without a database (ADR-59)

HD derivation (pure part), PSBT builder, Electrum client/merkle/quorum/scripthash, network
profile, addresses and header checks move to plm_engine; the old stack imports them from
there. A test forbids framework imports in the package.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 15:31:47 +01:00
1 parent c9784efa07
commit 3ee60a23da
87 files changed
+290 -260

No files matched your search

+14 -14
View File
@@ -1,7 +1,7 @@
import asyncio
import json
from app.electrum.client import ElectrumClient, ElectrumError
from plm_engine.electrum.client import ElectrumClient, ElectrumError
class FakeWriter:
@@ -81,7 +81,7 @@ async def test_request_times_out_instead_of_hanging_forever(monkeypatch):
"""B-01: a server that owes us a reply and never sends one used to hang the
caller permanently — which meant a POST /bets could hang while holding the
per-user lock, and the confirmation poller could stop polling for good."""
from app.electrum import client as client_module
from plm_engine.electrum import client as client_module
monkeypatch.setattr(client_module, "_REQUEST_TIMEOUT_SECONDS", 0.05)
client, reader, writer = await _client_with_fake_transport()
@@ -124,7 +124,7 @@ async def test_pending_request_fails_when_the_connection_drops():
def test_parse_endpoints_puts_the_primary_first_and_dedupes():
from app.electrum.client import ElectrumEndpoint, parse_endpoints
from plm_engine.electrum.client import ElectrumEndpoint, parse_endpoints
endpoints = parse_endpoints(
"primary.example", 50002, True, "second.example:50002, third.example:50001:notls, primary.example:50002"
@@ -137,7 +137,7 @@ def test_parse_endpoints_puts_the_primary_first_and_dedupes():
def test_parse_endpoints_handles_an_empty_fallback_list():
from app.electrum.client import ElectrumEndpoint, parse_endpoints
from plm_engine.electrum.client import ElectrumEndpoint, parse_endpoints
assert parse_endpoints("only.example", 50002, True, "") == [ElectrumEndpoint("only.example", 50002, True)]
assert parse_endpoints("only.example", 50002, True, " , ") == [
@@ -150,7 +150,7 @@ def test_parse_endpoints_rejects_a_malformed_entry():
the fallback is the thing that's needed."""
import pytest
from app.electrum.client import parse_endpoints
from plm_engine.electrum.client import parse_endpoints
for bad in ["nohost:", "host:notaport", "host", "host:50002:weird"]:
with pytest.raises(ValueError):
@@ -169,7 +169,7 @@ async def _send_request(client, writer, reader):
async def test_the_line_limit_is_16_mib_and_connect_applies_it(monkeypatch):
"""ELC-20 / B-75: the StreamReader is opened with a 16 MiB limit, not 64 KiB."""
from app.electrum import client as client_module
from plm_engine.electrum import client as client_module
assert client_module._MAX_LINE_BYTES == 16 * 1024 * 1024
seen = {}
@@ -190,7 +190,7 @@ async def test_an_oversized_reply_fails_its_request_and_keeps_the_connection(mon
"""ELC-20 / B-75: the reply is discarded to its newline (even when it arrives in
pieces), the request whose id is in its head fails at once, and the next reply
on the same connection is still delivered."""
from app.electrum import client as client_module
from plm_engine.electrum import client as client_module
monkeypatch.setattr(client_module, "_MAX_LINE_BYTES", 1024)
client, reader, writer = await _client_with_fake_transport()
@@ -216,7 +216,7 @@ async def test_an_oversized_reply_fails_its_request_and_keeps_the_connection(mon
async def test_an_oversized_reply_with_the_id_at_the_end_also_fails_its_request(monkeypatch):
"""ELC-20: the id is looked for in the last bytes of the line too."""
from app.electrum import client as client_module
from plm_engine.electrum import client as client_module
monkeypatch.setattr(client_module, "_MAX_LINE_BYTES", 1024)
client, reader, writer = await _client_with_fake_transport()
@@ -263,7 +263,7 @@ _PIN = "ab" * 32
def test_parse_endpoints_reads_pins_on_fallbacks_and_the_primary():
"""ELC-01 / ELC-03 / B-84: `host:port:pin=<sha256>` and `host:port:<mode>:pin=<sha256>`,
plus ELECTRUM_CERT_PIN for the primary; the pin is normalised to lower case."""
from app.electrum.client import ElectrumEndpoint, parse_endpoints
from plm_engine.electrum.client import ElectrumEndpoint, parse_endpoints
endpoints = parse_endpoints(
"primary.example",
@@ -284,7 +284,7 @@ def test_parse_endpoints_rejects_malformed_pins():
"""ELC-01 / B-84: a bad pin blocks the start, like any malformed entry."""
import pytest
from app.electrum.client import parse_endpoints
from plm_engine.electrum.client import parse_endpoints
for bad in [
"h:1:pin=",
@@ -328,7 +328,7 @@ class _PinWriter(FakeWriter):
def _answer_features(reader, writer, result=None):
"""Make `writer` answer `server.features` the moment it is asked: a reply fed up front
would be read before its request is registered, and dropped."""
from app.wallet.plm_network import GENESIS_HASH
from plm_engine.network import GENESIS_HASH
original = writer.write
@@ -393,7 +393,7 @@ async def test_a_connection_with_another_certificate_fails_like_an_unreachable_s
async def test_main_builds_clients_with_the_endpoint_pin():
"""ELC-03 / B-84: app.main hands each endpoint's pin to its client."""
from app.electrum.client import ElectrumEndpoint
from plm_engine.electrum.client import ElectrumEndpoint
from app.main import _make_electrum_client
assert _make_electrum_client(ElectrumEndpoint("h", 1, True, _PIN)).pin == _PIN
@@ -404,8 +404,8 @@ async def test_only_a_server_error_object_is_an_explicit_refusal():
"""B-76 / TX-04: a JSON-RPC `error` reply is an ElectrumRpcError carrying the
server's wording (string or object); a timeout or a dropped connection is a plain
ElectrumError — they say nothing about whether the server acted."""
from app.electrum import client as client_module
from app.electrum.client import ElectrumRpcError
from plm_engine.electrum import client as client_module
from plm_engine.electrum.client import ElectrumRpcError
client, reader, writer = await _client_with_fake_transport()
task = asyncio.create_task(client.request("blockchain.transaction.broadcast", ["00"]))