Cover the kroner balance, the refusal and the bank
This commit is contained in:
1 parent
49b7af0c28
commit
ce6f041032
1 file changed
+45
@@ -294,5 +294,50 @@ class LedgerTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(snapshot(), first)
|
self.assertEqual(snapshot(), first)
|
||||||
|
|
||||||
|
|
||||||
|
def test_kroner_transfer_moves_the_balance(self):
|
||||||
|
source = create_market("Børs_01")
|
||||||
|
destination = create_market("Lommebok", kind="wallet")
|
||||||
|
# Buy 1,0 BTC for 200 000 kr, then sell it for 500 000 kr: 300 000 kr left.
|
||||||
|
create_transaction(market_id=source, date="2024-01-10",
|
||||||
|
leg_in_sats=100000000, leg_out_ore=20000000)
|
||||||
|
create_transaction(market_id=source, date="2024-02-10",
|
||||||
|
leg_in_ore=50000000, leg_out_sats=100000000)
|
||||||
|
transfer = create_transaction(market_id=source, date="2024-03-10",
|
||||||
|
type="transfer_out", leg_out_ore=10000000,
|
||||||
|
to_market_id=destination, transfer_group="group-1")
|
||||||
|
create_transaction(market_id=destination, date="2024-03-10", type="transfer_in",
|
||||||
|
leg_in_ore=10000000, to_market_id=source,
|
||||||
|
transfer_group="group-1", generated=1)
|
||||||
|
ledger.rebuild()
|
||||||
|
self.assertEqual(ledger.kroner_in_market(source, "2024-12-31"), 20000000)
|
||||||
|
self.assertEqual(ledger.kroner_in_market(destination, "2024-12-31"), 10000000)
|
||||||
|
# Kroner are not coins: the transfer consumed no lots.
|
||||||
|
self.assertEqual(consumptions(transfer), [])
|
||||||
|
|
||||||
|
def test_a_transfer_cannot_overdraw_kroner(self):
|
||||||
|
source = create_market("Børs_01")
|
||||||
|
destination = create_market("Lommebok", kind="wallet")
|
||||||
|
create_transaction(market_id=source, date="2024-01-10",
|
||||||
|
leg_in_sats=100000000, leg_out_ore=20000000)
|
||||||
|
create_transaction(market_id=source, date="2024-02-10",
|
||||||
|
leg_in_ore=50000000, leg_out_sats=100000000)
|
||||||
|
# 300 000 kr on the account, and a transfer of 400 000 kr.
|
||||||
|
create_transaction(market_id=source, date="2024-03-10",
|
||||||
|
type="transfer_out", leg_out_ore=40000000,
|
||||||
|
to_market_id=destination, transfer_group="group-1")
|
||||||
|
with self.assertRaises(ledger.LedgerError) as caught:
|
||||||
|
ledger.rebuild()
|
||||||
|
self.assertIn("10 000 kr", str(caught.exception))
|
||||||
|
|
||||||
|
def test_the_bank_stays_at_zero(self):
|
||||||
|
bank = create_market("Bank", kind="other", taxable=0)
|
||||||
|
# One row with both kroner legs, as the server writes an admin_cost.
|
||||||
|
cost = create_transaction(market_id=bank, date="2024-05-01", type="admin_cost",
|
||||||
|
leg_out_ore=50000, leg_in_ore=50000)
|
||||||
|
ledger.rebuild()
|
||||||
|
self.assertEqual(ledger.kroner_in_market(bank, "2024-12-31"), 0)
|
||||||
|
self.assertEqual(consumptions(cost), [])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user