8
8
{-# LANGUAGE OverloadedStrings #-}
9
9
{-# LANGUAGE ScopedTypeVariables #-}
10
10
{-# LANGUAGE TupleSections #-}
11
+ {-# LANGUAGE TypeApplications #-}
11
12
12
13
module Cardano.Testnet.Test.Cli.Query (
13
14
hprop_cli_queries
@@ -36,10 +37,10 @@ import qualified Data.Aeson.Encode.Pretty as Aeson
36
37
import qualified Data.Aeson.Key as Aeson
37
38
import qualified Data.Aeson.KeyMap as Aeson
38
39
import qualified Data.Aeson.Lens as Aeson
39
- import Data.Bifunctor (bimap )
40
40
import qualified Data.ByteString.Lazy as LBS
41
41
import Data.Default.Class
42
42
import qualified Data.Map as Map
43
+ import Data.Map.Strict (Map )
43
44
import Data.String (IsString (fromString ))
44
45
import Data.Text (Text )
45
46
import qualified Data.Text as T
@@ -128,7 +129,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
128
129
-- leadership-schedule
129
130
do
130
131
let spoKeys = Defaults. defaultSpoKeys 1
131
- spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work $ verificationKey $ poolNodeKeysCold spoKeys
132
+ spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work $ verificationKey $ poolNodeKeysCold spoKeys
132
133
H. noteM_ $ execCli' execConfig [ eraName, " query" , " leadership-schedule"
133
134
, " --genesis" , shelleyGeneisFile
134
135
, " --stake-pool-verification-key" , T. unpack $ serialiseToBech32 spoVerificationKey
@@ -179,10 +180,11 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
179
180
do
180
181
-- to stdout
181
182
stakePoolsOut <- execCli' execConfig [ eraName, " query" , " stake-pools" ]
182
- H. assertWith stakePoolsOut $ \ pools ->
183
- NumPools (length $ lines pools) == nPools
183
+ stakePools <- H. noteShowM $ H. leftFail $ Aeson. eitherDecode @ [String ] $ fromString stakePoolsOut
184
+ H. assertWith stakePools $ \ pools ->
185
+ NumPools (length pools) == nPools
184
186
-- Light test of the query's answer, the ids should exist:
185
- forM_ ( lines stakePoolsOut) $ \ stakePoolId -> do
187
+ forM_ stakePools $ \ stakePoolId -> do
186
188
execCli' execConfig [ eraName, " query" , " pool-state"
187
189
, " --stake-pool-id" , stakePoolId ]
188
190
-- to a file
@@ -199,22 +201,15 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
199
201
do
200
202
-- to stdout
201
203
stakeDistrOut <- execCli' execConfig [ eraName, " query" , " stake-distribution" ]
202
- -- stake addresses with stake
203
- let stakeAddresses :: [(Text , Text )] =
204
- map
205
- ( bimap T. strip T. strip
206
- . T. breakOn " " -- separate address and stake
207
- . T. strip
208
- . fromString )
209
- . drop 2 -- drop header
210
- . lines
211
- $ stakeDistrOut
212
- H. assertWith stakeAddresses $ \ sa ->
204
+ stakeDistr <- H. leftFail $ Aeson. eitherDecode @ (Map String Aeson. Value ) $ fromString stakeDistrOut
205
+ H. note_ stakeDistrOut
206
+ let stakePools = Map. keys stakeDistr
207
+ H. assertWith stakePools $ \ sa ->
213
208
NumPools (length sa) == nPools
214
209
-- Light test of the query's answer, the ids should exist:
215
- forM_ stakeAddresses $ \ ( stakePoolId, _) -> do
210
+ forM_ stakePools $ \ stakePoolId -> do
216
211
execCli' execConfig [ eraName, " query" , " pool-state"
217
- , " --stake-pool-id" , T. unpack stakePoolId ]
212
+ , " --stake-pool-id" , stakePoolId ]
218
213
-- to a file
219
214
let stakePoolsOutFile = work </> " stake-distribution-out.json"
220
215
H. noteM_ $ execCli' execConfig [ eraName, " query" , " stake-distribution"
@@ -244,7 +239,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
244
239
fileQueryAmount <- H. evalMaybe $ fileQueryResult ^? Aeson. nth 0 . Aeson. nth 1 . Aeson. _Number
245
240
246
241
-- Query individual SPO using SPOs bech32 of key and compare to previous result
247
- delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work spoKey
242
+ delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work spoKey
248
243
keyQueryResult :: Aeson. Value <- execCliStdoutToJson execConfig [ eraName, " query" , " spo-stake-distribution"
249
244
, " --spo-verification-key" , T. unpack $ serialiseToBech32 delegatorVKey
250
245
]
@@ -449,6 +444,10 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
449
444
-- TODO @cardano-cli team
450
445
pure ()
451
446
447
+ TestQueryEraHistoryCmd -> do
448
+ -- TODO @cardano-cli team
449
+ pure ()
450
+
452
451
where
453
452
-- | Wait for the part of the epoch when futurePParams are known
454
453
waitForFuturePParamsToStabilise
@@ -482,13 +481,19 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
482
481
minSlotInThisEpochToWaitTo = firstSlotOfEpoch + slotsInEpochToWaitOut + 1
483
482
in slotNo >= minSlotInThisEpochToWaitTo
484
483
485
- readVerificationKeyFromFile :: (HasCallStack , MonadIO m , MonadCatch m , MonadTest m , HasTextEnvelope (VerificationKey keyrole ), SerialiseAsBech32 (VerificationKey keyrole ))
486
- => AsType keyrole
487
- -> FilePath
484
+ readVerificationKeyFromFile
485
+ :: ( HasCallStack
486
+ , MonadIO m
487
+ , MonadCatch m
488
+ , MonadTest m
489
+ , HasTextEnvelope (VerificationKey keyrole )
490
+ , SerialiseAsBech32 (VerificationKey keyrole )
491
+ )
492
+ => FilePath
488
493
-> File content direction
489
494
-> m (VerificationKey keyrole )
490
- readVerificationKeyFromFile asKey work =
491
- H. evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile asKey . VerificationKeyFilePath . File . (work </> ) . unFile
495
+ readVerificationKeyFromFile work =
496
+ H. evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile . VerificationKeyFilePath . File . (work </> ) . unFile
492
497
493
498
_verificationStakeKeyToStakeAddress :: Int -> VerificationKey StakeKey -> StakeAddress
494
499
_verificationStakeKeyToStakeAddress testnetMagic delegatorVKey =
0 commit comments