Welcome to the team that runs money movement for the platform. Accounts hold balances in a double-entry ledger; funds can be reserved with holds and moved between accounts with idempotent transfers. Every amount is an in…
Welcome to the team that runs money movement for the platform. Accounts hold balances in a double-entry ledger; funds can be reserved with holds and moved between accounts with idempotent transfers. Every amount is an integer number of cents.
This repository has four reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
payments/
models.py domain types (Account, LedgerEntry, Hold)
errors.py ValidationError, UnknownAccount, InsufficientFunds
accounts.py the account store (open / exists / require)
ledger.py append-only double-entry ledger; balance = debits - credits
holds.py funds reserved against an account but not yet moved
transfers.py available() and the idempotent transfer() with a funds check
service.py PaymentsService: deposit, place_hold, release_hold, transfer, balance, available
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
transfer_id.A client that retries transfer with the same transfer_id moves the funds again. It is most common when the caller's connection is unstable and it retries before receiving our response. A slow, sequential retry should simply return without moving money a second time.
transfer_id is a no-op after the first application.Do not change the ledger or the hold model as part of this ticket.
Transfers go through even when the amount is larger than the funds actually available on the source account. Available funds are the ledger balance minus any active holds; a transfer above that should be refused and leave the ledger untouched.
available(src) raises InsufficientFunds.Do not redesign the ledger or the hold model as part of this ticket.
After a hold is released the reserved funds do not come back: available stays low. Merchants report that a cancelled authorization keeps blocking a customer's balance.
release_hold, the hold no longer counts toward held or available.Do not change the transfer path as part of this ticket.
Account balances do not reconcile. The sum of all balances drifts away from zero, and a transfer appears to increase the sender's balance instead of decreasing it. In a double-entry ledger the debit side increases while the credit side decreases by the same amount.
Do not change the public API of the ledger as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.payments/ are submitted; the shipped tests in tests/visible run as they are.Adapted from treasure567/bloomberg-practice (round-2/harbor @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
payments-double-charges-and-ledger-imbalance
Changes under src/ are evaluated.