Skip to content

Commit 0c09ec3

Browse files
PLT-8935 Typo in UtxoQuery SQL statement (#276)
1 parent 8f4e4f8 commit 0c09ec3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

marconi-cardano-indexers/src/Marconi/Cardano/Indexers/UtxoQuery.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ instance
304304
Nothing -> mempty
305305
Just lo -> (["u.slotNo >= :lowerBound"], [":lowerBound" := lo])
306306
upperBoundFilter = case q ^. upperBound <|> C.chainPointToSlotNo point of
307-
Nothing -> (["s.slotNo IS NULL"], [])
307+
Nothing -> (["futureSpent.slotNo IS NULL"], [])
308308
Just hi ->
309309
( -- created before the upperBound
310310

marconi-cardano-indexers/test/Spec/Marconi/Cardano/Indexers/UtxoQuery.hs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Spec.Marconi.Cardano.Indexers.UtxoQuery (
88
import Cardano.Api qualified as C
99
import Control.Lens ((^.), (^..), (^?))
1010
import Control.Lens qualified as Lens
11-
import Control.Monad (void)
11+
import Control.Monad (void, when)
1212
import Control.Monad.IO.Class (MonadIO (liftIO))
1313
import Data.Aeson qualified as Aeson
1414
import Data.List qualified as List
@@ -34,9 +34,13 @@ tests =
3434
[ testGroup
3535
"Indexer"
3636
[ testPropertyNamed
37-
"All returned utxos are unspent"
37+
"All returned utxos are unspent or spent after the upper bound"
3838
"propAllUnspent"
3939
propAllUnspent
40+
, testPropertyNamed
41+
"All returned utxos are unspent when the queried point is genesis with no upper bound"
42+
"propAllUnspentWhenPointGenesis"
43+
propAllUnspentWhenPointGenesis
4044
, testPropertyNamed
4145
"Future spent has a corresponding txIn"
4246
"propFutureSpentAreTxIn"
@@ -70,6 +74,36 @@ propAllUnspent = Hedgehog.property $ do
7074
Hedgehog.assert $
7175
all (> point) (res ^.. Lens.folded . UtxoQuery.spentInfo . Lens.folded . Core.point)
7276

77+
{- | When the @point@ passed to @Core.'query'@ is 'genesis', and there is no provided upper bound,
78+
the query should return all UTxOs that are unspent given the full history.
79+
-}
80+
propAllUnspentWhenPointGenesis :: Property
81+
propAllUnspentWhenPointGenesis = Hedgehog.property $ do
82+
events <- Hedgehog.forAll Test.Mockchain.genMockchainWithInfo
83+
let
84+
utxoEvents =
85+
Test.Utxo.getTimedUtxosEvents $
86+
Test.Mockchain.mockchainWithInfoAsMockchain events
87+
utxos = utxoEvents ^.. Lens.folded . Core.event . Lens.folded . Lens.folded
88+
hasUtxoEvents = not $ null utxos
89+
90+
Hedgehog.cover 90 "Has at least one UTxO" hasUtxoEvents
91+
when hasUtxoEvents $ do
92+
-- Take the last UTxO to guarantee the result should
93+
-- have at least one element.
94+
let
95+
event = last utxos
96+
address = event ^. Utxo.address
97+
98+
res :: [UtxoQuery.UtxoResult] <-
99+
liftIO $
100+
Test.UtxoQuery.withIndexer events $
101+
Core.query Core.genesis (UtxoQuery.UtxoQueryInput address Nothing Nothing)
102+
103+
Hedgehog.assert $
104+
-- This should be empty since none of the returned UTxOs should have been spent.
105+
null (res ^.. Lens.folded . UtxoQuery.spentInfo . Lens.folded)
106+
73107
-- | If an UTxO has a datum, it should be resolved
74108
propResolvedDatum :: Property
75109
propResolvedDatum = Hedgehog.property $ do

0 commit comments

Comments
 (0)