module Hydra.API.ClientInputSpec where import Hydra.Prelude import Test.Hydra.Prelude import Data.Aeson (Result (..), fromJSON) import Hydra.API.ClientInput (ClientInput) import Hydra.Cardano.Api (serialiseToTextEnvelope) import Hydra.Ledger.Cardano (Tx) import Hydra.Ledger.Simple (SimpleTx) import Test.Aeson.GenericSpecs ( Settings (..), defaultSettings, roundtripAndGoldenSpecsWithSettings, ) import Test.QuickCheck (counterexample, forAll, property) spec :: Spec spec :: Spec spec = Spec -> Spec forall a. SpecWith a -> SpecWith a parallel (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do Settings -> Proxy (ReasonablySized (ClientInput SimpleTx)) -> Spec forall a. (Arbitrary a, ToJSON a, FromJSON a, Typeable a) => Settings -> Proxy a -> Spec roundtripAndGoldenSpecsWithSettings Settings settings (forall t. Proxy t forall {k} (t :: k). Proxy t Proxy @(ReasonablySized (ClientInput SimpleTx))) Settings -> Proxy (ReasonablySized (ClientInput Tx)) -> Spec forall a. (Arbitrary a, ToJSON a, FromJSON a, Typeable a) => Settings -> Proxy a -> Spec roundtripAndGoldenSpecsWithSettings Settings settings (forall t. Proxy t forall {k} (t :: k). Proxy t Proxy @(ReasonablySized (ClientInput Tx))) String -> Spec -> Spec forall a. HasCallStack => String -> SpecWith a -> SpecWith a describe String "FromJSON (ValidatedTx era)" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do String -> Property -> Spec forall prop. (HasCallStack, Testable prop) => String -> prop -> Spec prop String "accepts transactions produced via cardano-cli" (Property -> Spec) -> Property -> Spec forall a b. (a -> b) -> a -> b $ Gen Tx -> (Tx -> Property) -> Property forall a prop. (Show a, Testable prop) => Gen a -> (a -> prop) -> Property forAll (forall a. Arbitrary a => Gen a arbitrary @Tx) ((Tx -> Property) -> Property) -> (Tx -> Property) -> Property forall a b. (a -> b) -> a -> b $ \Tx tx -> let envelope :: Value envelope = TextEnvelope -> Value forall a. ToJSON a => a -> Value toJSON (TextEnvelope -> Value) -> TextEnvelope -> Value forall a b. (a -> b) -> a -> b $ Maybe TextEnvelopeDescr -> Tx -> TextEnvelope forall a. HasTextEnvelope a => Maybe TextEnvelopeDescr -> a -> TextEnvelope serialiseToTextEnvelope (TextEnvelopeDescr -> Maybe TextEnvelopeDescr forall a. a -> Maybe a Just TextEnvelopeDescr "Tx Babbage") Tx tx in case forall a. FromJSON a => Value -> Result a fromJSON @Tx Value envelope of Success{} -> Bool -> Property forall prop. Testable prop => prop -> Property property Bool True Error String e -> String -> Property -> Property forall prop. Testable prop => String -> prop -> Property counterexample (Text -> String forall a. ToString a => a -> String toString (Text -> String) -> Text -> String forall a b. (a -> b) -> a -> b $ String -> Text forall a. ToText a => a -> Text toText String e) (Property -> Property) -> Property -> Property forall a b. (a -> b) -> a -> b $ Bool -> Property forall prop. Testable prop => prop -> Property property Bool False settings :: Settings settings :: Settings settings = Settings defaultSettings { sampleSize = 200 }