@@ -8,7 +8,7 @@ module Spec.Marconi.Cardano.Indexers.UtxoQuery (
88import Cardano.Api qualified as C
99import Control.Lens ((^.) , (^..) , (^?) )
1010import Control.Lens qualified as Lens
11- import Control.Monad (void )
11+ import Control.Monad (void , when )
1212import Control.Monad.IO.Class (MonadIO (liftIO ))
1313import Data.Aeson qualified as Aeson
1414import 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
74108propResolvedDatum :: Property
75109propResolvedDatum = Hedgehog. property $ do
0 commit comments