Files
plm-lottery/tests/integration/conftest.py
T

53 lines
1.7 KiB
Python

"""Integration fixtures against the local regtest (ADR-58, roadmap B3): the node of `plm-regtest` with Fulcrum.
Nothing here starts them. When the node or Fulcrum is not reachable, every test that asks for them is skipped, so
the suite stays green on a machine without Docker. Bring them up with `docker compose up -d` in `plm-regtest`;
`plm_engine/regtest.py` says how to point at another place.
"""
import pytest
from embit.bip32 import HDKey
from plm_engine import hd
from plm_engine.electrum.client import ElectrumClient
from plm_engine.network import REGTEST
from plm_engine.regtest import RegtestError, RegtestNode, electrum_address, electrum_reachable
@pytest.fixture(scope="session")
def regtest_node() -> RegtestNode:
try:
node = RegtestNode.from_environment()
node.info()
except RegtestError as error:
pytest.skip(f"no regtest node: {error}")
return node
@pytest.fixture(scope="session")
def electrum_endpoint(regtest_node) -> tuple[str, int]:
if not electrum_reachable():
pytest.skip("no Fulcrum on the regtest Electrum port")
return electrum_address()
@pytest.fixture
async def electrum(electrum_endpoint):
"""A connected client that checks the regtest genesis at the handshake (ELC-30)."""
host, port = electrum_endpoint
client = ElectrumClient(host, port, use_ssl=False, genesis_hash=REGTEST.genesis_hash)
await client.connect()
try:
yield client
finally:
await client.close()
@pytest.fixture
def fresh_address():
"""A regtest address nobody has used: the account of a random master key, user index 0."""
import os
master = HDKey.from_seed(os.urandom(32), version=REGTEST.embit["xprv"])
return hd.user_address(hd.account_key(master, REGTEST), 0, REGTEST)