File tree 2 files changed +14
-12
lines changed
test/Test/Cardano/Db/Mock/Unit/Conway/Config
2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 2
2
{-# LANGUAGE DataKinds #-}
3
3
{-# LANGUAGE FlexibleContexts #-}
4
4
{-# LANGUAGE KindSignatures #-}
5
+ {-# LANGUAGE OverloadedStrings #-}
5
6
{-# LANGUAGE ScopedTypeVariables #-}
6
7
{-# LANGUAGE TypeApplications #-}
7
8
@@ -207,14 +208,15 @@ queryVoteCounts txHash idx = do
207
208
pure countRows
208
209
pure (maybe 0 unValue res)
209
210
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
214
212
queryConsumedTxOutCount = 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 =
42
42
-- Should not have consumed_by_tx
43
43
assertEqBackoff
44
44
dbSync
45
- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
45
+ Query. queryConsumedTxOutCount
46
46
0
47
47
[]
48
48
" Unexpected consumed_by_tx count"
@@ -72,7 +72,7 @@ consumeTxConsumed =
72
72
-- Should have consumed_by_tx
73
73
assertEqBackoff
74
74
dbSync
75
- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
75
+ Query. queryConsumedTxOutCount
76
76
2
77
77
[]
78
78
" Unexpected consumed_by_tx count"
You can’t perform that action at this time.
0 commit comments