Test that a transfer sends what arrives and keeps the price
This commit is contained in:
1 parent
f476d86bc5
commit
2dec33737e
1 file changed
+29
-13
+29
-13
@@ -206,30 +206,46 @@ class LedgerTestCase(unittest.TestCase):
|
|||||||
def test_transfer_mirrors_date_and_cost(self):
|
def test_transfer_mirrors_date_and_cost(self):
|
||||||
source = create_market("Børs_01")
|
source = create_market("Børs_01")
|
||||||
destination = create_market("Lommebok", kind="wallet")
|
destination = create_market("Lommebok", kind="wallet")
|
||||||
|
# 2,0 BTC for 400 000 kr: 0,2 ore per sat.
|
||||||
create_transaction(market_id=source, date="2024-01-10",
|
create_transaction(market_id=source, date="2024-01-10",
|
||||||
leg_in_sats=100000000, leg_out_ore=20000000)
|
leg_in_sats=200000000, leg_out_ore=40000000)
|
||||||
transfer = create_transaction(market_id=source, date="2024-06-01",
|
transfer = create_transaction(market_id=source, date="2024-06-01",
|
||||||
type="transfer_out", leg_out_sats=100000000,
|
type="transfer_out", leg_out_sats=100000000,
|
||||||
fee_sats=1000, fee_ore=50000,
|
fee_sats=1000,
|
||||||
to_market_id=destination, transfer_group="group-1")
|
to_market_id=destination, transfer_group="group-1")
|
||||||
# The API writes the generated transfer_in row together with the transfer_out.
|
# The API writes the generated transfer_in row together with the transfer_out:
|
||||||
|
# the sent sats arrive in full and it carries no fee of its own.
|
||||||
create_transaction(market_id=destination, date="2024-06-01", type="transfer_in",
|
create_transaction(market_id=destination, date="2024-06-01", type="transfer_in",
|
||||||
leg_in_sats=99999000, fee_sats=1000, fee_ore=50000,
|
leg_in_sats=100000000, fee_sats=0,
|
||||||
to_market_id=source, transfer_group="group-1", generated=1)
|
to_market_id=source, transfer_group="group-1", generated=1)
|
||||||
ledger.rebuild()
|
ledger.rebuild()
|
||||||
self.assertEqual(
|
|
||||||
sum(row["sats"] for row in consumptions(transfer)), 100000000
|
# The source gives up the sent sats plus the fee, at the same cost per sat.
|
||||||
)
|
self.assertEqual(sum(row["sats"] for row in consumptions(transfer)), 100001000)
|
||||||
self.assertEqual(
|
self.assertEqual(sum(row["cost_ore"] for row in consumptions(transfer)), 20000200)
|
||||||
sum(row["cost_ore"] for row in consumptions(transfer)), 20000000
|
self.assertEqual(ledger.sats_in_market(source, "2024-12-31"), 99999000)
|
||||||
)
|
self.assertEqual(ledger.sats_in_market(destination, "2024-12-31"), 100000000)
|
||||||
|
|
||||||
source_lot = lots_of(source)[0]
|
source_lot = lots_of(source)[0]
|
||||||
mirror = lots_of(destination)[0]
|
mirror = lots_of(destination)[0]
|
||||||
self.assertEqual(source_lot["sats_remaining"], 0)
|
self.assertEqual(source_lot["sats_remaining"], 99999000)
|
||||||
|
self.assertEqual(source_lot["cost_ore_remaining"], 19999800)
|
||||||
self.assertEqual(mirror["acquired_date"], "2024-01-10")
|
self.assertEqual(mirror["acquired_date"], "2024-01-10")
|
||||||
self.assertEqual(mirror["source_lot_id"], source_lot["id"])
|
self.assertEqual(mirror["source_lot_id"], source_lot["id"])
|
||||||
self.assertEqual(mirror["sats_original"], 99999000)
|
self.assertEqual(mirror["sats_original"], 100000000)
|
||||||
self.assertEqual(mirror["cost_ore_original"], 20050000)
|
# The cost share of the 1 000 fee sats (200 ore) is not mirrored.
|
||||||
|
self.assertEqual(mirror["cost_ore_original"], 20000000)
|
||||||
|
|
||||||
|
# Both sides keep the price of the source lot: 200 000 kr per BTC.
|
||||||
|
self.assertEqual(
|
||||||
|
[lot["btc_price_ore"] for lot in ledger.candidate_lots(source, "2024-12-31")],
|
||||||
|
[20000000],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
[lot["btc_price_ore"]
|
||||||
|
for lot in ledger.candidate_lots(destination, "2024-12-31")],
|
||||||
|
[20000000],
|
||||||
|
)
|
||||||
|
|
||||||
def test_rebuild_twice_gives_the_same_ledger(self):
|
def test_rebuild_twice_gives_the_same_ledger(self):
|
||||||
golden_market()
|
golden_market()
|
||||||
|
|||||||
Reference in new issue
Block a user