File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
test/Test/Cardano/Db/Mock/Unit/Conway/Config Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 22{-# LANGUAGE DataKinds #-}
33{-# LANGUAGE FlexibleContexts #-}
44{-# LANGUAGE KindSignatures #-}
5+ {-# LANGUAGE OverloadedStrings #-}
56{-# LANGUAGE ScopedTypeVariables #-}
67{-# LANGUAGE TypeApplications #-}
78
@@ -207,14 +208,15 @@ queryVoteCounts txHash idx = do
207208 pure countRows
208209 pure (maybe 0 unValue res)
209210
210- queryConsumedTxOutCount ::
211- forall (a :: Db. TxOutTableType ) io .
212- (MonadIO io , Db. TxOutFields a ) =>
213- ReaderT SqlBackend io Word64
211+ queryConsumedTxOutCount :: MonadIO io => ReaderT SqlBackend io Word64
214212queryConsumedTxOutCount = do
215- res <- selectOne $ do
216- txOut <- from $ table @ (Db. TxOutTable a )
217- where_ (not_ $ isNothing_ $ txOut ^. Db. txOutConsumedByTxIdField @ a )
218- pure countRows
219-
220- pure $ maybe 0 unValue res
213+ maybe 0 unSingle . head <$> rawSql @ (Single Word64 ) q []
214+ where
215+ -- tx_out.consumed_by_tx_id may or may not exist, depending on the runtime configuration!
216+ -- We use an obscure trick to avoid the error `column "consumed_by_tx_id" does not exist`
217+ q =
218+ " select count "
219+ <> " from (select null as consumed_by_tx_id)"
220+ <> " cross join lateral ("
221+ <> " select count(*) from tx_out where consumed_by_tx_id is not null"
222+ <> " ) as count"
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ consumeTx =
4242 -- Should not have consumed_by_tx
4343 assertEqBackoff
4444 dbSync
45- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
45+ Query. queryConsumedTxOutCount
4646 0
4747 []
4848 " Unexpected consumed_by_tx count"
@@ -72,7 +72,7 @@ consumeTxConsumed =
7272 -- Should have consumed_by_tx
7373 assertEqBackoff
7474 dbSync
75- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
75+ Query. queryConsumedTxOutCount
7676 2
7777 []
7878 " Unexpected consumed_by_tx count"
You can’t perform that action at this time.
0 commit comments