Skip to content

Commit

Permalink
Move JSONSchema module to new hydra-node:testlib
Browse files Browse the repository at this point in the history
This allows us to re-use this functionality from hydra-cluster tests,
while still using package-specific functionality from
hydra-node (accessing schema files) and avoids moving this into the
production code base.
  • Loading branch information
ch1bo committed Jan 9, 2024
1 parent 9ec42c4 commit b0fbf51
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ test-suite tests
build-depends:
, aeson
, async
, base >=4.7 && <5
, base >=4.7 && <5
, bytestring
, containers
, directory
, filepath
, hspec
, hydra-cardano-api
, hydra-cluster
, hydra-node
, hydra-node:{hydra-node, testlib}
, hydra-prelude
, hydra-test-utils
, io-classes
Expand Down
11 changes: 9 additions & 2 deletions hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Data.Aeson.Lens (key, _String)
import Data.Aeson.Types (parseEither)
import Hydra.API.HTTPServer (DraftCommitTxResponse (DraftCommitTxResponse))
import Hydra.Cardano.Api (Tx)
import Hydra.JSONSchema (validateJSON, withJsonSpecifications)
import Hydra.Ledger.Cardano.Configuration (pparamsFromJson)
import Hydra.Logging (showLogsOnFailure)
import System.Exit (ExitCode (..))
Expand Down Expand Up @@ -46,8 +47,14 @@ spec =
Left e -> failure $ "Failed to decode JSON: " <> e <> "\n" <> show protocolParameters
Right _ -> pure ()

it "query protocol-parameters matches our schema" $ \_tracer ->
pendingWith "TODO"
it "query protocol-parameters matches our schema" $ \tracer ->
withJsonSpecifications $ \tmpDir ->
withCardanoNodeDevnet tracer tmpDir $ \RunningNode{nodeSocket, networkId} -> do
pparamsValue <- cliQueryProtocolParameters nodeSocket (networkId)
validateJSON
(tmpDir </> "api.json")
(key "components" . key "schemas" . key "ProtocolParameters")
pparamsValue
where
cardanoCliSign txFile =
proc
Expand Down
29 changes: 23 additions & 6 deletions hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ library

ghc-options: -haddock

library testlib
import: project-config
visibility: public
hs-source-dirs: testlib
exposed-modules: Hydra.JSONSchema
other-modules: Paths_hydra_node
build-depends:
, aeson
, base
, containers
, directory
, filepath
, hydra-prelude
, hydra-test-utils
, lens
, lens-aeson
, process
, QuickCheck
, text
, versions
, yaml

executable hydra-node
import: project-config
hs-source-dirs: exe/hydra-node
Expand Down Expand Up @@ -274,7 +296,6 @@ test-suite tests
Hydra.FireForgetSpec
Hydra.HeadLogicSnapshotSpec
Hydra.HeadLogicSpec
Hydra.JSONSchema
Hydra.JSONSchemaSpec
Hydra.Ledger.Cardano.TimeSpec
Hydra.Ledger.CardanoSpec
Expand Down Expand Up @@ -331,7 +352,7 @@ test-suite tests
, hspec-wai
, HUnit
, hydra-cardano-api
, hydra-node
, hydra-node:{hydra-node, testlib}
, hydra-plutus
, hydra-plutus-extras
, hydra-prelude
Expand All @@ -342,7 +363,6 @@ test-suite tests
, lens-aeson
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} >=1.1.1.0
, plutus-tx
, process
, QuickCheck
, quickcheck-dynamic >=3.3.1 && <3.4
, quickcheck-instances
Expand All @@ -354,10 +374,7 @@ test-suite tests
, time
, typed-protocols-examples >=0.1.0.0
, vector
, versions
, wai-extra
, websockets
, yaml

build-tool-depends: hspec-discover:hspec-discover
ghc-options: -threaded -rtsopts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ validateJSON schemaFilePath selector value = do
when (exitCode /= ExitSuccess) $
failure . toString $
unlines
[ "check-jsonschema failed on " <> toText jsonInput <> " with schema " <> toText jsonSchema <> " on input:"
, decodeUtf8 $ encodePretty value
[ "check-jsonschema failed on " <> toText jsonInput <> " with schema " <> toText jsonSchema
, toText err <> toText out
]
where
Expand Down

0 comments on commit b0fbf51

Please sign in to comment.