Skip to content

Commit 78da7be

Browse files
committed
Add test for query spo-stake-distribution
1 parent c775002 commit 78da7be

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ test-suite cardano-testnet-test
234234
, hedgehog
235235
, hedgehog-extras
236236
, http-conduit
237+
, lens
237238
, lens-aeson
238239
, microlens
239240
, mtl

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ import Cardano.Testnet
3333

3434
import Prelude
3535

36+
import Control.Lens ((^?))
3637
import Control.Monad (forM_)
3738
import Control.Monad.Catch (MonadCatch)
3839
import qualified Data.Aeson as Aeson
3940
import qualified Data.Aeson.Encode.Pretty as Aeson
41+
import qualified Data.Aeson.Lens as Aeson
4042
import qualified Data.Aeson.Key as Aeson
4143
import qualified Data.Aeson.KeyMap as Aeson
4244
import Data.Bifunctor (bimap)
@@ -231,6 +233,39 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
231233
H.noteM_ $ execCli' execConfig [ eraName, "query", "stake-distribution"
232234
, "--out-file", stakePoolsOutFile ]
233235

236+
TestQuerySPOStakeDistributionCmd ->
237+
-- spo-stake-distribution
238+
do
239+
-- Query all SPOs
240+
aesonSpoDist :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution", "--all-spos" ]
241+
secondHash <- H.evalMaybe $ T.unpack <$> aesonSpoDist ^? Aeson.nth 1 . Aeson.nth 0 . Aeson._String
242+
secondAmount <- H.evalMaybe $ aesonSpoDist ^? Aeson.nth 1 . Aeson.nth 1 . Aeson._Number
243+
244+
-- Query individual SPO using result and ensure result is the same
245+
secondSpoInfo :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution", "--spo-key-hash", secondHash ]
246+
individualHash <- H.evalMaybe $ T.unpack <$> secondSpoInfo ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String
247+
individualAmount <- H.evalMaybe $ secondSpoInfo ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number
248+
secondHash === individualHash
249+
secondAmount === individualAmount
250+
251+
-- Query individual SPO using SPOs verification file
252+
let spoKey = verificationKey . poolNodeKeysCold $ Defaults.defaultSpoKeys 1
253+
fileQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution"
254+
, "--spo-verification-key-file", unFile spoKey
255+
]
256+
fileQueryHash <- H.evalMaybe $ T.unpack <$> fileQueryResult ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String
257+
fileQueryAmount <- H.evalMaybe $ fileQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number
258+
259+
-- Query individual SPO using SPOs bech32 of key and compare to previous result
260+
delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work spoKey
261+
keyQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution"
262+
, "--spo-verification-key", T.unpack $ serialiseToBech32 delegatorVKey
263+
]
264+
keyQueryHash <- H.evalMaybe $ T.unpack <$> keyQueryResult ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String
265+
keyQueryAmount <- H.evalMaybe $ keyQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number
266+
fileQueryHash === keyQueryHash
267+
fileQueryAmount === keyQueryAmount
268+
234269
TestQueryStakeAddressInfoCmd ->
235270
-- stake-address-info
236271
do
@@ -363,9 +398,6 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
363398
-- treasury
364399
H.noteM_ $ execCli' execConfig [ eraName, "query", "treasury" ]
365400

366-
TestQuerySPOStakeDistributionCmd -> do
367-
pure () -- FIXME: https://github.com/IntersectMBO/cardano-node/pull/5932
368-
369401
where
370402
-- | Wait for the part of the epoch when futurePParams are known
371403
waitForFuturePParamsToStabilise

0 commit comments

Comments
 (0)