Skip to content

Commit

Permalink
Add an acceptance test to HTTPServerSpec
Browse files Browse the repository at this point in the history
The api specification contains inlineDatumRaw, but only as an optional
field so we need to unit test when we would expect it.
  • Loading branch information
ch1bo authored and locallycompact committed Oct 9, 2024
1 parent e08ab88 commit ed96600
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions hydra-node/test/Hydra/API/HTTPServerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ module Hydra.API.HTTPServerSpec where
import Hydra.Prelude hiding (get)
import Test.Hydra.Prelude

import Cardano.Api.UTxO qualified as UTxO
import Control.Lens ((^?))
import Data.Aeson (Result (Error, Success), eitherDecode, encode, fromJSON)
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens (key, nth)
import Hydra.API.HTTPServer (DraftCommitTxRequest (..), DraftCommitTxResponse (..), SubmitTxRequest (..), TransactionSubmitted, httpApp)
import Hydra.API.ServerOutput (CommitInfo (CannotCommit, NormalCommit))
import Hydra.API.ServerSpec (dummyChainHandle)
import Hydra.Cardano.Api (
mkTxOutDatumInline,
modifyTxOutDatum,
serialiseToTextEnvelope,
)
import Hydra.Chain (Chain (draftCommitTx), PostTxError (..), draftDepositTx)
Expand All @@ -24,6 +28,7 @@ import Test.Aeson.GenericSpecs (roundtripAndGoldenSpecs)
import Test.Hspec.Wai (MatchBody (..), ResponseMatcher (matchBody), get, post, shouldRespondWith, with)
import Test.Hspec.Wai.Internal (withApplication)
import Test.Hydra.Tx.Fixture (defaultPParams)
import Test.Hydra.Tx.Gen (genTxOut)
import Test.QuickCheck (
checkCoverage,
counterexample,
Expand Down Expand Up @@ -147,6 +152,19 @@ apiServerSpec = do
(key "channels" . key "/snapshot/utxo" . key "subscribe" . key "message" . key "payload")
}

prop "has inlineDatumRaw" $ \i ->
forAll genTxOut $ \o -> do
let o' = modifyTxOutDatum (const $ mkTxOutDatumInline (123 :: Integer)) o
let getUTxO = pure $ Just $ UTxO.fromPairs [(i, o')]
withApplication (httpApp @Tx nullTracer dummyChainHandle defaultPParams cantCommit getUTxO getPendingDeposits putClientInput) $ do
get "/snapshot/utxo"
`shouldRespondWith` 200
{ matchBody = MatchBody $ \_ body ->
if isNothing (body ^? key (fromString $ show i) . key "inlineDatumRaw")
then Just $ "\ninlineDatumRaw not found in body:\n" <> show body
else Nothing
}

describe "POST /commit" $ do
let getHeadId = pure $ NormalCommit (generateWith arbitrary 42)
let workingChainHandle =
Expand Down

0 comments on commit ed96600

Please sign in to comment.