From 946da9c5bf335d91c11cc9594704565d237e4dcd Mon Sep 17 00:00:00 2001 From: shum Date: Wed, 26 Aug 2026 15:27:09 +0000 Subject: [PATCH] tests: check ledger parity on the worker's append --- tests/Bots/BadgeServiceTests.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Bots/BadgeServiceTests.hs b/tests/Bots/BadgeServiceTests.hs index 344e385a0f..3b74a223ed 100644 --- a/tests/Bots/BadgeServiceTests.hs +++ b/tests/Bots/BadgeServiceTests.hs @@ -2976,6 +2976,7 @@ testC5WorkerIssuesSecondPeriod :: HasCallStack => TestParams -> IO () testC5WorkerIssuesSecondPeriod ps = do clock <- newTestClock testClockStart codeRef <- newIORef "" + ledgerRef <- newIORef [] withBadgeClient ps clock (seedOneSupporterCode ps >>= writeIORef codeRef) $ \alice -> do code <- readIORef codeRef alice ##> purchaseCodeCmd code @@ -3021,6 +3022,17 @@ testC5WorkerIssuesSecondPeriod ps = do [firstCred, secondCred] -> ("second period credential" :: String, secondCred == firstCred) `shouldBe` ("second period credential", False) _ -> pure () + -- held for the parity check below: the service's database cannot be opened while the service + -- itself is running + clientLedgerRows alice >>= writeIORef ledgerRef + -- ยง10's parity check over the WORKER's append path, not just the redemption's: + -- 'testC5RedeemCodeShowsBadge' compares a two-row ledger written in one transaction, while the + -- row this pass adds is appended against a cursor the client asserted, which is the only place + -- the two codecs can drift on an entry neither database wrote at the same time. + clientRows <- readIORef ledgerRef + withServiceDB ps $ \db -> do + serviceRowCounts db `shouldReturn` (1, 1, 3, 2, 1) + serviceLedgerParityRows db >>= shouldMatchServiceLedger clientRows -- The active profile --------------------------------------------------------------