Move all business/round parameters into DB config, out of env entirely
RoundConfig gains round_duration_seconds, round_cooldown_seconds, min_amount_sats, fee_rate_sat_vb and rbf_timeout_seconds (plus a hardcoded default for the pre-existing bet_amount_sats) as column defaults on the model itself — get_round_config no longer seeds from Settings at all. Every call site that read these from settings (scheduler, bets, withdrawals, rounds service/route, RBF bumper) now reads the DB-backed RoundConfig instead. app/config.py now holds only true env-driven infra/secrets (database URL, Electrum connection, master key, JWT, admin token) — no business parameter has an env var anymore, matching an explicit decision to drop the "seed from settings" indirection entirely rather than keep a env fallback nobody should rely on. Migration backfills the existing round_config row via server_default (matching the old settings defaults) then drops the default, so future rows go through the ORM/model defaults instead of a stale constant. Tests updated: should_bump's timeout_seconds is now required (no settings fallback); test_scheduler.py seeds a RoundConfig row directly instead of monkeypatching settings; test_withdrawals.py and test_rounds_service.py use local constants mirroring the model defaults instead of reading them off settings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48a9eeb839
commit
30bde96b6e
14 files changed
+119
-52
No files matched your search
@@ -3,11 +3,12 @@ from datetime import datetime, timedelta, timezone
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
from app.config import settings
|
||||
from app.db.base import Base
|
||||
from app.db.models import Round
|
||||
from app.rounds.service import get_active_round, open_new_round_if_needed
|
||||
|
||||
ROUND_COOLDOWN_SECONDS = 30 # matches RoundConfig.round_cooldown_seconds' column default
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def session_factory():
|
||||
@@ -72,7 +73,7 @@ async def test_withholds_new_round_during_cooldown(session_factory):
|
||||
|
||||
|
||||
async def test_opens_new_round_once_cooldown_elapses(session_factory):
|
||||
stale_close = datetime.now(timezone.utc) - timedelta(seconds=settings.round_cooldown_seconds + 1)
|
||||
stale_close = datetime.now(timezone.utc) - timedelta(seconds=ROUND_COOLDOWN_SECONDS + 1)
|
||||
async with session_factory() as session:
|
||||
session.add(Round(status="closed", closed_at=stale_close))
|
||||
await session.commit()
|
||||
|
||||
@@ -4,9 +4,8 @@ import pytest
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
from app.config import settings
|
||||
from app.db.base import Base
|
||||
from app.db.models import Round
|
||||
from app.db.models import Round, RoundConfig
|
||||
from app.rounds.scheduler import RoundScheduler
|
||||
|
||||
|
||||
@@ -31,8 +30,8 @@ async def test_tick_survives_sqlite_naive_datetime_roundtrip(session_factory, mo
|
||||
it directly against datetime.now(timezone.utc) and crashed with
|
||||
"can't compare offset-naive and offset-aware datetimes" on every tick once a
|
||||
round existed — this must not happen."""
|
||||
monkeypatch.setattr(settings, "round_duration_seconds", 3600) # not due yet
|
||||
async with session_factory() as session:
|
||||
session.add(RoundConfig(fee_address="", round_duration_seconds=3600)) # not due yet
|
||||
session.add(Round(status="open", opened_at=datetime.now(timezone.utc)))
|
||||
await session.commit()
|
||||
|
||||
@@ -41,9 +40,9 @@ async def test_tick_survives_sqlite_naive_datetime_roundtrip(session_factory, mo
|
||||
|
||||
|
||||
async def test_tick_closes_round_with_no_participants_once_due(session_factory, monkeypatch):
|
||||
monkeypatch.setattr(settings, "round_duration_seconds", 1)
|
||||
past = datetime.now(timezone.utc) - timedelta(seconds=10)
|
||||
async with session_factory() as session:
|
||||
session.add(RoundConfig(fee_address="", round_duration_seconds=1))
|
||||
session.add(Round(status="open", opened_at=past))
|
||||
await session.commit()
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ class FakeElectrumClient:
|
||||
|
||||
|
||||
EXTERNAL_ADDRESS = "plm1qqph9qup2mp7w7g5nlsdhdc9m2pp44ampzw0ctx"
|
||||
MIN_AMOUNT_SATS = 100_000_000 # matches RoundConfig.min_amount_sats' column default
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -85,7 +86,7 @@ async def test_withdrawal_rejects_amount_below_minimum(session_factory):
|
||||
async with session_factory() as session:
|
||||
user = await session.get(User, user_id)
|
||||
with pytest.raises(WithdrawalError, match="minimum"):
|
||||
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, settings.min_amount_sats - 1)
|
||||
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, MIN_AMOUNT_SATS - 1)
|
||||
|
||||
|
||||
async def test_withdrawal_rejects_insufficient_balance(session_factory):
|
||||
@@ -95,4 +96,4 @@ async def test_withdrawal_rejects_insufficient_balance(session_factory):
|
||||
async with session_factory() as session:
|
||||
user = await session.get(User, user_id)
|
||||
with pytest.raises(WithdrawalError, match="insufficient balance"):
|
||||
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, settings.min_amount_sats)
|
||||
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, MIN_AMOUNT_SATS)
|
||||
Reference in new issue
Block a user