From 2ad707a83818fa43e3a3d2a817912e746d7af348 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 31 Jul 2024 21:12:58 +0200 Subject: [PATCH] Add test for `query spo-stake-distribution` --- cabal.project | 14 ++++++++ cardano-testnet/cardano-testnet.cabal | 1 + .../Cardano/Testnet/Test/Cli/Query.hs | 35 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/cabal.project b/cabal.project index 915414234ca..7234a28d9c3 100644 --- a/cabal.project +++ b/cabal.project @@ -32,6 +32,20 @@ packages: trace-resources trace-forward +source-repository-package + type: git + location: https://github.com/IntersectMBO/cardano-api.git + tag: d06c818ac67216ab7a60159827e6b8fccd7ef0ea + --sha256: sha256-AK0UEpOJeyTuTsI3vwAZxyg5xfLJFx7sRP4iti1tj1s= + subdir: cardano-api + +source-repository-package + type: git + location: https://github.com/IntersectMBO/cardano-cli.git + tag: 1810f26b6e1b022adcb9327df3f297af9b5d9247 + --sha256: sha256-4wz1Z11BuAds70rGFHEqZ1OMlJuuB/v8zDMx0+O9g5U= + subdir: cardano-cli + extra-packages: Cabal program-options diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index d44c2302238..98c762c395b 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -234,6 +234,7 @@ test-suite cardano-testnet-test , hedgehog , hedgehog-extras , http-conduit + , lens , lens-aeson , microlens , mtl diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs index 9a68187c027..929eee56ac7 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs @@ -30,11 +30,13 @@ import Cardano.Testnet import Prelude +import Control.Lens ((^?)) import Control.Monad (forM_) import Control.Monad.Catch (MonadCatch) import Data.Aeson (eitherDecodeStrictText) import qualified Data.Aeson as Aeson import qualified Data.Aeson.KeyMap as Aeson +import qualified Data.Aeson.Lens as Aeson import Data.Bifunctor (bimap) import Data.Data (type (:~:) (Refl)) import Data.Either.Extra (mapLeft) @@ -209,6 +211,39 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H. H.noteM_ $ execCli' execConfig [ eraName, "query", "stake-distribution" , "--out-file", stakePoolsOutFile ] + TestQuerySPOStakeDistributionCmd -> + -- spo-stake-distribution + do + -- Query all SPOs + aesonSpoDist :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution", "--all-spos" ] + secondHash <- H.evalMaybe $ T.unpack <$> aesonSpoDist ^? Aeson.nth 1 . Aeson.nth 0 . Aeson._String + secondAmount <- H.evalMaybe $ aesonSpoDist ^? Aeson.nth 1 . Aeson.nth 1 . Aeson._Number + + -- Query individual SPO using result and ensure result is the same + secondSpoInfo :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution", "--spo-key-hash", secondHash ] + individualHash <- H.evalMaybe $ T.unpack <$> secondSpoInfo ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String + individualAmount <- H.evalMaybe $ secondSpoInfo ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number + secondHash === individualHash + secondAmount === individualAmount + + -- Query individual SPO using SPOs verification file + let spoKey = verificationKey . poolNodeKeysCold $ Defaults.defaultSpoKeys 1 + fileQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution" + , "--spo-verification-key-file", unFile spoKey + ] + fileQueryHash <- H.evalMaybe $ T.unpack <$> fileQueryResult ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String + fileQueryAmount <- H.evalMaybe $ fileQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number + + -- Query individual SPO using SPOs bech32 of key and compare to previous result + delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work spoKey + keyQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution" + , "--spo-verification-key", T.unpack $ serialiseToBech32 delegatorVKey + ] + keyQueryHash <- H.evalMaybe $ T.unpack <$> keyQueryResult ^? Aeson.nth 0 . Aeson.nth 0 . Aeson._String + keyQueryAmount <- H.evalMaybe $ keyQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number + fileQueryHash === keyQueryHash + fileQueryAmount === keyQueryAmount + TestQueryStakeAddressInfoCmd -> -- stake-address-info do