"""Every test runs against a throwaway master key, never the operator's real one. B-80: opening a round now derives its pool address, so code paths that merely open a round (the scheduler, `POST /bets`, the round route) need a master key — and without this they silently read whatever `MASTER_KEY_PATH`/`XPRV_ENCRYPTION_KEY` of the local `.env` point at, i.e. the real encrypted key on a developer machine and nothing at all on a clean checkout. Tests that build their own key (most of them) simply override it. """ import pytest from cryptography.fernet import Fernet from app.config import settings @pytest.fixture(autouse=True) def _throwaway_master_key(tmp_path, monkeypatch): monkeypatch.setattr(settings, "master_key_path", str(tmp_path / "autouse-master.xprv.enc")) monkeypatch.setattr(settings, "xprv_encryption_key", Fernet.generate_key().decode()) from app.wallet import hd hd._account_key = None hd.generate_master_key() yield hd._account_key = None @pytest.fixture(autouse=True) def _registration_open(monkeypatch): """B-90: a real listener keeps registration closed until its restore-gap check ran; only the tests about that check care, and they set it themselves.""" from app.electrum.listener import ElectrumListener monkeypatch.setattr(ElectrumListener, "registration_open", True) # B-74: the real powLimit needs ~2^32 hashes per header, so tests mine headers at a trivial # target (`0x207fffff`) and this swaps in a limit that allows it. Done at import, not in a # fixture, because some test modules mine headers while they are being collected. The # tests that exercise the limit itself put `MAINNET_POW_LIMIT` back with monkeypatch. from app.rounds import draw as _draw # noqa: E402 _draw.POW_LIMIT = (1 << 256) - 1