From 154bedd63010f1823aed9e8f6759996a011a8038 Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 22 Oct 2026 13:43:53 +0000 Subject: [PATCH] store: read no confirmed units as 0 --- apps/simplex-store-service/src/StoreService/Names/Store.hs | 2 +- tests/Bots/StoreService/NamesBalancesTests.hs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/simplex-store-service/src/StoreService/Names/Store.hs b/apps/simplex-store-service/src/StoreService/Names/Store.hs index 6676149e6c..5d091a828c 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Store.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Store.hs @@ -1034,7 +1034,7 @@ pendingCase = " CASE WHEN" <> uncreditedMoney <> " THEN " <> literal LPUncredited <> " WHEN COALESCE(p.amount, 0) = 0 AND (p.crypto_paid IS NOT NULL OR p.paid_in_full = 1) THEN " <> literal LPConfirming <> " WHEN" <> cardInvoice <> " AND COALESCE(p.amount, 0) > p.confirmed_amount THEN " <> literal LPUnconfirmed - <> " WHEN p.received_units > p.confirmed_units THEN " <> literal LPUnconfirmed + <> " WHEN p.received_units > COALESCE(p.confirmed_units, 0) THEN " <> literal LPUnconfirmed <> " WHEN" <> cryptoInvoice <> " AND p.received_units IS NULL AND COALESCE(p.amount, 0) > 0 THEN " <> literal LPUncounted <> " END" where diff --git a/tests/Bots/StoreService/NamesBalancesTests.hs b/tests/Bots/StoreService/NamesBalancesTests.hs index df038532a7..68cde59f07 100644 --- a/tests/Bots/StoreService/NamesBalancesTests.hs +++ b/tests/Bots/StoreService/NamesBalancesTests.hs @@ -81,6 +81,7 @@ namesBalancesTests = describe "StoreService names: balances" $ do it "tells each case of pending money and selects confirmed money not all credited, by the order whatever the invoice's status" testLateScans it "leaves 0.1 and 0.2 BTC credited against 0.3 confirmed neither pending nor selected" testExactUnits it "tells confirmed money not credited as such while its cents still read 0, as Monero's can" testConfirmedBeforeCents + it "reads crypto received with no confirmed figure as unconfirmed" testNoConfirmedFigure it "alerts on pending money past the cutoff once, again only when more arrives, claimed by one of two instances" testLateAlerts it "alerts again on money that could not be counted in units when more of it arrives" testUncountedAlertRepeats describe "turns" $ do @@ -647,6 +648,11 @@ testConfirmedBeforeCents = withServiceStore $ \st -> do withTransaction st (\db -> latePending db (InvoiceId "inv-x")) `shouldReturn` Just LPUncredited withTransaction st uncreditedLateInvoices `shouldReturn` [InvoiceId "inv-x"] +testNoConfirmedFigure :: IO () +testNoConfirmedFigure = withServiceStore $ \st -> do + closedWith st "x" False (cryptoPaid 300000 0) {pConfirmedUnits = Nothing} t0 + withTransaction st (\db -> latePending db (InvoiceId "inv-x")) `shouldReturn` Just LPUnconfirmed + testLateAlerts :: IO () testLateAlerts = withServiceStore $ \st -> do closedWith st "old" False (cryptoPaid 300000 0) t0