Fund every test account from the bank

This commit is contained in:
ai-bot committed 2026-11-16 19:33:15 +00:00
1 parent 4a156e9d11
commit e72232fe3c
1 file changed
+25 -2
+25 -2
View File
@@ -30,7 +30,15 @@ TRANSACTION_DEFAULTS = {
}
def create_market(name, kind="exchange", taxable=1, custody_market_id=None):
def create_market(name, kind="exchange", taxable=1, custody_market_id=None,
kroner_ore=100000000):
"""Create an account, funded from the bank unless kroner_ore is 0.
No real account may go negative (docs/spec.md section 3.11), so a fixture that
pays kroner has to be funded first. The funding is dated before every other
row, so the replay sees it first and no figure moves: it is a transfer.
"""
bank = int(database.get_setting("bank_market_id"))
conn = database.connect()
try:
with conn:
@@ -39,7 +47,22 @@ def create_market(name, kind="exchange", taxable=1, custody_market_id=None):
" VALUES (?, ?, ?, ?)",
(name, kind, taxable, custody_market_id),
)
return cursor.lastrowid
market_id = cursor.lastrowid
if kroner_ore:
group = "fund-%d" % market_id
conn.execute(
"INSERT INTO transactions (date, type, market_id, leg_out_ore,"
" to_market_id, transfer_group, created_at, updated_at)"
" VALUES ('2000-01-01', 'transfer_out', ?, ?, ?, ?, 'x', 'x')",
(bank, kroner_ore, market_id, group),
)
conn.execute(
"INSERT INTO transactions (date, type, market_id, leg_in_ore,"
" to_market_id, transfer_group, generated, created_at, updated_at)"
" VALUES ('2000-01-01', 'transfer_in', ?, ?, ?, ?, 1, 'x', 'x')",
(market_id, kroner_ore, bank, group),
)
return market_id
finally:
conn.close()