Tie the withdrawal minimum to the bet amount instead of a separate field

RoundConfig.min_amount_sats was an independently-configurable floor that
could drift out of sync with bet_amount_sats for no real reason (deposits
never had a server-side minimum anyway). Drop the field and enforce
amount_sats >= config.bet_amount_sats directly in request_withdrawal.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 19:25:15 +02:00
co-authored by Claude Sonnet 5
parent 6c51a81f0e
commit 7b3555f8eb
8 changed files with 44 additions and 23 deletions
+7 -7
View File
@@ -19,7 +19,7 @@ class FakeElectrumClient:
EXTERNAL_ADDRESS = "plm1qqph9qup2mp7w7g5nlsdhdc9m2pp44ampzw0ctx"
MIN_AMOUNT_SATS = 100_000_000 # matches RoundConfig.min_amount_sats' column default
BET_AMOUNT_SATS = 1_000_000_000 # matches RoundConfig.bet_amount_sats' column default; also the withdrawal minimum
@pytest.fixture
@@ -57,16 +57,16 @@ async def _make_funded_user(session_factory, index: int, funded_sats: int) -> in
async def test_withdrawal_broadcasts_and_updates_balance(session_factory):
user_id = await _make_funded_user(session_factory, 0, 500_000_000)
user_id = await _make_funded_user(session_factory, 0, 2_000_000_000)
client = FakeElectrumClient()
async with session_factory() as session:
user = await session.get(User, user_id)
withdrawal = await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, 100_000_000)
withdrawal = await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, BET_AMOUNT_SATS)
assert client.broadcasted
assert withdrawal.status == "broadcast"
assert withdrawal.amount_sent_sats < 100_000_000 # fee deducted from the amount
assert withdrawal.amount_sent_sats < BET_AMOUNT_SATS # fee deducted from the amount
async with session_factory() as session:
user = await session.get(User, user_id)
@@ -80,13 +80,13 @@ async def test_withdrawal_broadcasts_and_updates_balance(session_factory):
async def test_withdrawal_rejects_amount_below_minimum(session_factory):
user_id = await _make_funded_user(session_factory, 1, 500_000_000)
user_id = await _make_funded_user(session_factory, 1, 2_000_000_000)
client = FakeElectrumClient()
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, MIN_AMOUNT_SATS - 1)
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, BET_AMOUNT_SATS - 1)
async def test_withdrawal_rejects_insufficient_balance(session_factory):
@@ -96,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, MIN_AMOUNT_SATS)
await request_withdrawal(session, client, user, EXTERNAL_ADDRESS, BET_AMOUNT_SATS)