{-# OPTIONS_GHC -Wno-orphans #-}

-- | Tests for the 'ToCBOR' / 'FromCBOR' codecs of hydra-node types.
--
-- Three layers of protection:
--
--   * Unit tests for 'genericToCBOR' / 'genericFromCBOR' pinning down the
--     constructor-name-tagged format they produce (including that newtypes
--     and single-constructor records carry the tag).
--
--   * Roundtrip properties keeping encoder/decoder pairs in sync: adding a
--     constructor without a matching codec (or with fields decoded in the
--     wrong order) fails here.
--
--   * Golden tests locking the concrete byte-level formats, one sample per
--     constructor. These catch changes that roundtrip properties cannot see,
--     e.g. reordering fields in a data declaration of a generically derived
--     codec, or symmetric encoder+decoder drift. If one fails, the change
--     breaks decoding of persisted data (hydra.db) or the API wire format;
--     only delete and regenerate a golden file as a deliberate, documented
--     format change.
module Hydra.CBORSpec where

import Hydra.Prelude
import Test.Hydra.Prelude

import Cardano.Binary (decodeFull', serialize')
import Codec.CBOR.Write (toStrictByteString)
import Data.ByteString qualified as BS
import Hydra.API.ClientInput (ClientInput)
import Hydra.API.HTTPServer (
  DraftCommitTxRequest,
  DraftCommitTxResponse,
  OperationTimedOut,
  SideLoadSnapshotRequest (..),
  SubmitL2TxRequest,
  SubmitL2TxResponse,
  SubmitTxRequest,
  TransactionSubmitted,
 )
import Hydra.API.ServerOutput (
  ApiMessage,
  ClientMessage,
  DecommitInvalidReason,
  FanoutProgressMode,
  Greetings,
  HeadStatus,
  InvalidInput,
  NetworkInfo,
  ServerOutput,
  TimedServerOutput,
 )
import Hydra.Cardano.Api (ChainPoint (..), NetworkId (..), NetworkMagic (..))
import Hydra.Cardano.Api.Gen ()
import Hydra.Chain (ChainEvent, OnChainTx, PostChainTx, PostTxError)
import Hydra.Chain.ChainState (ChainSlot)
import Hydra.Chain.Direct.State (ChainStateAt)
import Hydra.HeadLogic.Error (RequirementFailure, SideLoadRequirementFailure)
import Hydra.HeadLogic.Outcome (StateChanged)
import Hydra.HeadLogic.State (FanoutMode, HeadState, SeenSnapshot)
import Hydra.HeadLogic.StateEvent (StateEvent (..))
import Hydra.Ledger (ValidationError)
import Hydra.Ledger.Cardano (Tx)
import Hydra.Ledger.Simple (SimpleChainState, SimpleTx)
import Hydra.Network (Connectivity, Host, NodeId, ProtocolVersion, WhichEtcd)
import Hydra.Network.Authenticate (Signed)
import Hydra.Network.Message (Message)
import Hydra.Node.ApiTransactionTimeout (ApiTransactionTimeout)
import Hydra.Node.Environment (Environment)
import Hydra.Node.State (ChainPointTime, Deposit, DepositStatus, NodeState, SyncedStatus)
import Hydra.Node.UnsyncedPeriod (UnsyncedPeriod)
import Hydra.Tx (ConfirmedSnapshot, HeadId, HeadParameters, HeadSeed, Party, Snapshot (..), SnapshotNumber, SnapshotVersion)
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
import Hydra.Tx.Crypto (MultiSignature, Signature)
import Hydra.Tx.DepositPeriod (DepositPeriod)
import Hydra.Tx.OnChainId (OnChainId)
import Hydra.Tx.Snapshot (snapshotCBORTag, snapshotCBORTagV1)
import Test.Hydra.API.ClientInput ()
import Test.Hydra.API.HTTPServer ()
import Test.Hydra.API.ServerOutput ()
import Test.Hydra.CBOR (genGoldenSample, genGoldenSamples, goldenCBOR, roundtripCBOR)
import Test.Hydra.Chain.Direct.State ()
import Test.Hydra.HeadLogic.Outcome ()
import Test.Hydra.HeadLogic.StateEvent ()
import Test.Hydra.Ledger ()
import Test.Hydra.Ledger.Simple ()
import Test.Hydra.Network ()
import Test.Hydra.Network.Authenticate ()
import Test.Hydra.Network.Message ()
import Test.Hydra.Node.ApiTransactionTimeout ()
import Test.Hydra.Node.Environment ()
import Test.Hydra.Node.State ()
import Test.Hydra.Node.UnsyncedPeriod ()
import Test.Hydra.Tx.Gen ()
import Test.QuickCheck (resize, suchThat)
import Test.QuickCheck.Arbitrary.ADT (ADTArbitrary (..), ConstructorArbitraryPair (..), ToADTArbitrary, toADTArbitrary)

-- * ToADTArbitrary instances for per-constructor golden samples

instance ToADTArbitrary (ClientMessage Tx)
instance ToADTArbitrary (TimedServerOutput Tx)
instance ToADTArbitrary InvalidInput
instance ToADTArbitrary HeadStatus
instance ToADTArbitrary FanoutProgressMode
instance ToADTArbitrary NetworkInfo
instance ToADTArbitrary (DecommitInvalidReason Tx)
instance ToADTArbitrary (ConfirmedSnapshot Tx)
instance ToADTArbitrary (PostChainTx Tx)
instance ToADTArbitrary (OnChainTx Tx)
instance ToADTArbitrary (PostTxError Tx)
instance ToADTArbitrary (ChainEvent Tx)
instance ToADTArbitrary (HeadState Tx)
instance ToADTArbitrary (SeenSnapshot Tx)
instance ToADTArbitrary (FanoutMode Tx)
instance ToADTArbitrary (NodeState Tx)
instance ToADTArbitrary SyncedStatus
instance ToADTArbitrary DepositStatus
instance ToADTArbitrary (Deposit Tx)
instance ToADTArbitrary Connectivity
instance ToADTArbitrary WhichEtcd
instance ToADTArbitrary (RequirementFailure Tx)
instance ToADTArbitrary (SideLoadRequirementFailure Tx)

-- * Test types for the generic codec

data GenericCBORSum
  = GenNullary
  | GenPositional Int Text
  | GenRecord {GenericCBORSum -> EventId
genA :: Word64, GenericCBORSum -> [Int]
genB :: [Int], GenericCBORSum -> Maybe Text
genC :: Maybe Text}
  deriving stock (GenericCBORSum -> GenericCBORSum -> Bool
(GenericCBORSum -> GenericCBORSum -> Bool)
-> (GenericCBORSum -> GenericCBORSum -> Bool) -> Eq GenericCBORSum
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GenericCBORSum -> GenericCBORSum -> Bool
== :: GenericCBORSum -> GenericCBORSum -> Bool
$c/= :: GenericCBORSum -> GenericCBORSum -> Bool
/= :: GenericCBORSum -> GenericCBORSum -> Bool
Eq, Int -> GenericCBORSum -> ShowS
[GenericCBORSum] -> ShowS
GenericCBORSum -> [Char]
(Int -> GenericCBORSum -> ShowS)
-> (GenericCBORSum -> [Char])
-> ([GenericCBORSum] -> ShowS)
-> Show GenericCBORSum
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GenericCBORSum -> ShowS
showsPrec :: Int -> GenericCBORSum -> ShowS
$cshow :: GenericCBORSum -> [Char]
show :: GenericCBORSum -> [Char]
$cshowList :: [GenericCBORSum] -> ShowS
showList :: [GenericCBORSum] -> ShowS
Show, (forall x. GenericCBORSum -> Rep GenericCBORSum x)
-> (forall x. Rep GenericCBORSum x -> GenericCBORSum)
-> Generic GenericCBORSum
forall x. Rep GenericCBORSum x -> GenericCBORSum
forall x. GenericCBORSum -> Rep GenericCBORSum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GenericCBORSum -> Rep GenericCBORSum x
from :: forall x. GenericCBORSum -> Rep GenericCBORSum x
$cto :: forall x. Rep GenericCBORSum x -> GenericCBORSum
to :: forall x. Rep GenericCBORSum x -> GenericCBORSum
Generic)

instance ToCBOR GenericCBORSum where
  toCBOR :: GenericCBORSum -> Encoding
toCBOR = GenericCBORSum -> Encoding
forall a. (Generic a, GToCBOR (Rep a)) => a -> Encoding
genericToCBOR

instance FromCBOR GenericCBORSum where
  fromCBOR :: forall s. Decoder s GenericCBORSum
fromCBOR = Decoder s GenericCBORSum
forall a s. (Generic a, GFromCBOR (Rep a)) => Decoder s a
genericFromCBOR

newtype GenericCBORNewtype = GenericCBORNewtype Int
  deriving stock (GenericCBORNewtype -> GenericCBORNewtype -> Bool
(GenericCBORNewtype -> GenericCBORNewtype -> Bool)
-> (GenericCBORNewtype -> GenericCBORNewtype -> Bool)
-> Eq GenericCBORNewtype
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GenericCBORNewtype -> GenericCBORNewtype -> Bool
== :: GenericCBORNewtype -> GenericCBORNewtype -> Bool
$c/= :: GenericCBORNewtype -> GenericCBORNewtype -> Bool
/= :: GenericCBORNewtype -> GenericCBORNewtype -> Bool
Eq, Int -> GenericCBORNewtype -> ShowS
[GenericCBORNewtype] -> ShowS
GenericCBORNewtype -> [Char]
(Int -> GenericCBORNewtype -> ShowS)
-> (GenericCBORNewtype -> [Char])
-> ([GenericCBORNewtype] -> ShowS)
-> Show GenericCBORNewtype
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GenericCBORNewtype -> ShowS
showsPrec :: Int -> GenericCBORNewtype -> ShowS
$cshow :: GenericCBORNewtype -> [Char]
show :: GenericCBORNewtype -> [Char]
$cshowList :: [GenericCBORNewtype] -> ShowS
showList :: [GenericCBORNewtype] -> ShowS
Show, (forall x. GenericCBORNewtype -> Rep GenericCBORNewtype x)
-> (forall x. Rep GenericCBORNewtype x -> GenericCBORNewtype)
-> Generic GenericCBORNewtype
forall x. Rep GenericCBORNewtype x -> GenericCBORNewtype
forall x. GenericCBORNewtype -> Rep GenericCBORNewtype x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GenericCBORNewtype -> Rep GenericCBORNewtype x
from :: forall x. GenericCBORNewtype -> Rep GenericCBORNewtype x
$cto :: forall x. Rep GenericCBORNewtype x -> GenericCBORNewtype
to :: forall x. Rep GenericCBORNewtype x -> GenericCBORNewtype
Generic)

instance ToCBOR GenericCBORNewtype where
  toCBOR :: GenericCBORNewtype -> Encoding
toCBOR = GenericCBORNewtype -> Encoding
forall a. (Generic a, GToCBOR (Rep a)) => a -> Encoding
genericToCBOR

instance FromCBOR GenericCBORNewtype where
  fromCBOR :: forall s. Decoder s GenericCBORNewtype
fromCBOR = Decoder s GenericCBORNewtype
forall a s. (Generic a, GFromCBOR (Rep a)) => Decoder s a
genericFromCBOR

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
  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"genericToCBOR / genericFromCBOR" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"encodes a nullary constructor as just its name tag" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' GenericCBORSum
GenNullary ByteString -> ByteString -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Text -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Text
"GenNullary" :: Text)

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"encodes the name tag followed by fields in declaration order" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Int -> Text -> GenericCBORSum
GenPositional Int
42 Text
"hi")
        ByteString -> ByteString -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Encoding -> ByteString
toStrictByteString
          (Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"GenPositional" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Int -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Int
42 :: Int) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"hi" :: Text))

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"encodes record fields in declaration order" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' GenRecord{$sel:genA:GenNullary :: EventId
genA = EventId
7, $sel:genB:GenNullary :: [Int]
genB = [Int
1, Int
2], $sel:genC:GenNullary :: Maybe Text
genC = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"x"}
        ByteString -> ByteString -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Encoding -> ByteString
toStrictByteString
          ( Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"GenRecord" :: Text)
              Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> EventId -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (EventId
7 :: Word64)
              Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Int] -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR ([Int
1, Int
2] :: [Int])
              Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text
"x" :: Text))
          )

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"tags newtypes with their constructor name too" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      GenericCBORNewtype -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Int -> GenericCBORNewtype
GenericCBORNewtype Int
7)
        ByteString -> ByteString -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Encoding -> ByteString
toStrictByteString (Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"GenericCBORNewtype" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Int -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Int
7 :: Int))

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"roundtrips all constructor shapes" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$ do
      ByteString -> Either DecoderError GenericCBORSum
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' (GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' GenericCBORSum
GenNullary) Either DecoderError GenericCBORSum
-> Either DecoderError GenericCBORSum -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` GenericCBORSum -> Either DecoderError GenericCBORSum
forall a b. b -> Either a b
Right GenericCBORSum
GenNullary
      ByteString -> Either DecoderError GenericCBORSum
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' (GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Int -> Text -> GenericCBORSum
GenPositional Int
42 Text
"hi")) Either DecoderError GenericCBORSum
-> Either DecoderError GenericCBORSum -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` GenericCBORSum -> Either DecoderError GenericCBORSum
forall a b. b -> Either a b
Right (Int -> Text -> GenericCBORSum
GenPositional Int
42 Text
"hi")
      ByteString -> Either DecoderError GenericCBORSum
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' (GenericCBORSum -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' GenRecord{$sel:genA:GenNullary :: EventId
genA = EventId
7, $sel:genB:GenNullary :: [Int]
genB = [Int
1, Int
2], $sel:genC:GenNullary :: Maybe Text
genC = Maybe Text
forall a. Maybe a
Nothing})
        Either DecoderError GenericCBORSum
-> Either DecoderError GenericCBORSum -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` GenericCBORSum -> Either DecoderError GenericCBORSum
forall a b. b -> Either a b
Right GenRecord{$sel:genA:GenNullary :: EventId
genA = EventId
7, $sel:genB:GenNullary :: [Int]
genB = [Int
1, Int
2], $sel:genC:GenNullary :: Maybe Text
genC = Maybe Text
forall a. Maybe a
Nothing}
      ByteString -> Either DecoderError GenericCBORNewtype
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' (GenericCBORNewtype -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Int -> GenericCBORNewtype
GenericCBORNewtype Int
7)) Either DecoderError GenericCBORNewtype
-> Either DecoderError GenericCBORNewtype -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` GenericCBORNewtype -> Either DecoderError GenericCBORNewtype
forall a b. b -> Either a b
Right (Int -> GenericCBORNewtype
GenericCBORNewtype Int
7)

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"fails decoding an unknown tag naming the type" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      case forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' @GenericCBORSum (Text -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' (Text
"Bogus" :: Text)) of
        Left DecoderError
err -> DecoderError -> [Char]
forall b a. (Show a, IsString b) => a -> b
show DecoderError
err [Char] -> [Char] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
`shouldContain` [Char]
"is not a proper CBOR-encoded GenericCBORSum"
        Right GenericCBORSum
v -> HasCallStack => [Char] -> Expectation
[Char] -> Expectation
expectationFailure ([Char] -> Expectation) -> [Char] -> Expectation
forall a b. (a -> b) -> a -> b
$ [Char]
"unexpectedly decoded: " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> GenericCBORSum -> [Char]
forall b a. (Show a, IsString b) => a -> b
show GenericCBORSum
v

  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"API types" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    Proxy (ClientInput Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ClientInput Tx) -> Spec) -> Proxy (ClientInput Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ClientInput Tx)
    Proxy (ServerOutput Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ServerOutput Tx) -> Spec)
-> Proxy (ServerOutput Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ServerOutput Tx)
    Proxy (TimedServerOutput Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (TimedServerOutput Tx) -> Spec)
-> Proxy (TimedServerOutput Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(TimedServerOutput Tx)
    Proxy (ClientMessage Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ClientMessage Tx) -> Spec)
-> Proxy (ClientMessage Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ClientMessage Tx)
    Proxy (Greetings Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (Greetings Tx) -> Spec) -> Proxy (Greetings Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(Greetings Tx)
    Proxy InvalidInput -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy InvalidInput -> Spec) -> Proxy InvalidInput -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @InvalidInput
    Proxy (ApiMessage Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ApiMessage Tx) -> Spec) -> Proxy (ApiMessage Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ApiMessage Tx)
    Proxy HeadStatus -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy HeadStatus -> Spec) -> Proxy HeadStatus -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @HeadStatus
    Proxy NetworkInfo -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy NetworkInfo -> Spec) -> Proxy NetworkInfo -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @NetworkInfo
    Proxy (DraftCommitTxRequest Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (DraftCommitTxRequest Tx) -> Spec)
-> Proxy (DraftCommitTxRequest Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(DraftCommitTxRequest Tx)
    Proxy (DraftCommitTxResponse Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (DraftCommitTxResponse Tx) -> Spec)
-> Proxy (DraftCommitTxResponse Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(DraftCommitTxResponse Tx)
    Proxy (SubmitTxRequest Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (SubmitTxRequest Tx) -> Spec)
-> Proxy (SubmitTxRequest Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(SubmitTxRequest Tx)
    Proxy TransactionSubmitted -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy TransactionSubmitted -> Spec)
-> Proxy TransactionSubmitted -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @TransactionSubmitted
    Proxy (SideLoadSnapshotRequest Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (SideLoadSnapshotRequest Tx) -> Spec)
-> Proxy (SideLoadSnapshotRequest Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(SideLoadSnapshotRequest Tx)
    Proxy (SubmitL2TxRequest Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (SubmitL2TxRequest Tx) -> Spec)
-> Proxy (SubmitL2TxRequest Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(SubmitL2TxRequest Tx)
    Proxy SubmitL2TxResponse -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy SubmitL2TxResponse -> Spec)
-> Proxy SubmitL2TxResponse -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SubmitL2TxResponse
    Proxy OperationTimedOut -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy OperationTimedOut -> Spec)
-> Proxy OperationTimedOut -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @OperationTimedOut

  -- 'Snapshot' gained 'depositTxId' between two released layouts. Its fields are
  -- a bare concatenation, so only the leading tag tells them apart and a node
  -- must keep decoding the older one to replay an event log written before the
  -- field existed.
  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"Snapshot layouts" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    let snapshot :: Snapshot Tx
snapshot = Gen (Snapshot Tx) -> Int -> Snapshot Tx
forall a. Gen a -> Int -> a
generateWith (Int -> Gen (Snapshot Tx) -> Gen (Snapshot Tx)
forall a. HasCallStack => Int -> Gen a -> Gen a
resize Int
5 Gen (Snapshot Tx)
forall a. Arbitrary a => Gen a
arbitrary) Int
42 :: Snapshot Tx
        Snapshot{HeadId
headId :: HeadId
$sel:headId:Snapshot :: forall tx. Snapshot tx -> HeadId
headId, SnapshotVersion
version :: SnapshotVersion
$sel:version:Snapshot :: forall tx. Snapshot tx -> SnapshotVersion
version, SnapshotNumber
number :: SnapshotNumber
$sel:number:Snapshot :: forall tx. Snapshot tx -> SnapshotNumber
number, [Tx]
confirmed :: [Tx]
$sel:confirmed:Snapshot :: forall tx. Snapshot tx -> [tx]
confirmed, UTxOType Tx
utxo :: UTxOType Tx
$sel:utxo:Snapshot :: forall tx. Snapshot tx -> UTxOType tx
utxo, Maybe (UTxOType Tx)
utxoToCommit :: Maybe (UTxOType Tx)
$sel:utxoToCommit:Snapshot :: forall tx. Snapshot tx -> Maybe (UTxOType tx)
utxoToCommit, Maybe (UTxOType Tx)
utxoToDecommit :: Maybe (UTxOType Tx)
$sel:utxoToDecommit:Snapshot :: forall tx. Snapshot tx -> Maybe (UTxOType tx)
utxoToDecommit} = Snapshot Tx
snapshot

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"writes the current layout under a tag of its own" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
      Snapshot Tx -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' Snapshot Tx
snapshot ByteString -> (ByteString -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` ByteString -> ByteString -> Bool
BS.isPrefixOf (Text -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' Text
snapshotCBORTag)

    [Char] -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
"decodes the layout written before depositTxId existed" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$ do
      let legacy :: ByteString
legacy =
            Encoding -> ByteString
toStrictByteString (Encoding -> ByteString) -> Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$
              Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Text
snapshotCBORTagV1
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> HeadId -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR HeadId
headId
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SnapshotVersion -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SnapshotVersion
version
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SnapshotNumber -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SnapshotNumber
number
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Tx] -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR [Tx]
confirmed
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> UTxO -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR UTxO
utxo
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Maybe UTxO -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Maybe UTxO
utxoToCommit
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Maybe UTxO -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Maybe UTxO
utxoToDecommit
      ByteString -> Either DecoderError (Snapshot Tx)
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull' ByteString
legacy Either DecoderError (Snapshot Tx)
-> Either DecoderError (Snapshot Tx) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Snapshot Tx -> Either DecoderError (Snapshot Tx)
forall a b. b -> Either a b
Right Snapshot Tx
snapshot{depositTxId = Nothing}

  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"protocol types" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    Proxy (Snapshot Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (Snapshot Tx) -> Spec) -> Proxy (Snapshot Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(Snapshot Tx)
    Proxy (ConfirmedSnapshot Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ConfirmedSnapshot Tx) -> Spec)
-> Proxy (ConfirmedSnapshot Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ConfirmedSnapshot Tx)
    Proxy (PostChainTx Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (PostChainTx Tx) -> Spec) -> Proxy (PostChainTx Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(PostChainTx Tx)
    Proxy (OnChainTx Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (OnChainTx Tx) -> Spec) -> Proxy (OnChainTx Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(OnChainTx Tx)
    Proxy (PostTxError Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (PostTxError Tx) -> Spec) -> Proxy (PostTxError Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(PostTxError Tx)
    Proxy (ChainEvent Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (ChainEvent Tx) -> Spec) -> Proxy (ChainEvent Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(ChainEvent Tx)
    Proxy ChainStateAt -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ChainStateAt -> Spec) -> Proxy ChainStateAt -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ChainStateAt
    Proxy (HeadState Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (HeadState Tx) -> Spec) -> Proxy (HeadState Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(HeadState Tx)
    Proxy (SeenSnapshot Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (SeenSnapshot Tx) -> Spec)
-> Proxy (SeenSnapshot Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(SeenSnapshot Tx)
    Proxy (NodeState Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (NodeState Tx) -> Spec) -> Proxy (NodeState Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(NodeState Tx)
    Proxy (Deposit Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (Deposit Tx) -> Spec) -> Proxy (Deposit Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(Deposit Tx)
    Proxy Environment -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy Environment -> Spec) -> Proxy Environment -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Environment
    Proxy Connectivity -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy Connectivity -> Spec) -> Proxy Connectivity -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Connectivity
    Proxy HeadId -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy HeadId -> Spec) -> Proxy HeadId -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @HeadId
    Proxy HeadSeed -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy HeadSeed -> Spec) -> Proxy HeadSeed -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @HeadSeed
    Proxy OnChainId -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy OnChainId -> Spec) -> Proxy OnChainId -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @OnChainId
    Proxy Party -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy Party -> Spec) -> Proxy Party -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Party
    Proxy HeadParameters -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy HeadParameters -> Spec) -> Proxy HeadParameters -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @HeadParameters
    Proxy ContestationPeriod -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ContestationPeriod -> Spec)
-> Proxy ContestationPeriod -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ContestationPeriod
    Proxy DepositPeriod -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy DepositPeriod -> Spec) -> Proxy DepositPeriod -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @DepositPeriod
    Proxy SnapshotNumber -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy SnapshotNumber -> Spec) -> Proxy SnapshotNumber -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SnapshotNumber
    Proxy SnapshotVersion -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy SnapshotVersion -> Spec) -> Proxy SnapshotVersion -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SnapshotVersion
    Proxy ChainSlot -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ChainSlot -> Spec) -> Proxy ChainSlot -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ChainSlot
    Proxy (Signature (Snapshot Tx)) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (Signature (Snapshot Tx)) -> Spec)
-> Proxy (Signature (Snapshot Tx)) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(Signature (Snapshot Tx))
    Proxy (MultiSignature (Snapshot Tx)) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (MultiSignature (Snapshot Tx)) -> Spec)
-> Proxy (MultiSignature (Snapshot Tx)) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(MultiSignature (Snapshot Tx))
    Proxy (Signed (Message Tx)) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (Signed (Message Tx)) -> Spec)
-> Proxy (Signed (Message Tx)) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(Signed (Message Tx))
    Proxy NodeId -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy NodeId -> Spec) -> Proxy NodeId -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @NodeId
    Proxy ProtocolVersion -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ProtocolVersion -> Spec) -> Proxy ProtocolVersion -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ProtocolVersion
    Proxy Host -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy Host -> Spec) -> Proxy Host -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Host
    Proxy ValidationError -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ValidationError -> Spec) -> Proxy ValidationError -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ValidationError
    Proxy ApiTransactionTimeout -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ApiTransactionTimeout -> Spec)
-> Proxy ApiTransactionTimeout -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ApiTransactionTimeout
    Proxy UnsyncedPeriod -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy UnsyncedPeriod -> Spec) -> Proxy UnsyncedPeriod -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @UnsyncedPeriod
    Proxy ChainPointTime -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ChainPointTime -> Spec) -> Proxy ChainPointTime -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ChainPointTime
    Proxy SimpleTx -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy SimpleTx -> Spec) -> Proxy SimpleTx -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SimpleTx
    Proxy SimpleChainState -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy SimpleChainState -> Spec) -> Proxy SimpleChainState -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SimpleChainState
    Proxy NetworkId -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy NetworkId -> Spec) -> Proxy NetworkId -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @NetworkId
    Proxy NetworkMagic -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy NetworkMagic -> Spec) -> Proxy NetworkMagic -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @NetworkMagic
    Proxy ChainPoint -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy ChainPoint -> Spec) -> Proxy ChainPoint -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @ChainPoint

  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"persisted types" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    Proxy (StateChanged Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (StateChanged Tx) -> Spec)
-> Proxy (StateChanged Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(StateChanged Tx)
    Proxy (StateEvent Tx) -> Spec
forall a.
(Arbitrary a, ToCBOR a, FromCBOR a, Eq a, Show a) =>
Proxy a -> Spec
roundtripCBOR (Proxy (StateEvent Tx) -> Spec) -> Proxy (StateEvent Tx) -> Spec
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(StateEvent Tx)
    -- Locks the on-disk format of hydra.db events: one sample per
    -- 'StateChanged' constructor, stored as raw CBOR.
    [Char] -> [Char] -> Gen [StateEvent Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"StateEvent Tx" [Char]
"golden/StateEvent.cbor" Gen [StateEvent Tx]
genGoldenStateEvents

  -- One golden per CBOR-encoded type, one sample per constructor. Locks the
  -- byte-level formats of the hydra.db event payloads and the API/network
  -- wire messages.
  [Char] -> Spec -> Spec
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"golden formats" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    [Char] -> [Char] -> Gen [ClientInput Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ClientInput Tx" [Char]
"golden/ClientInput.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(ClientInput Tx))
    [Char] -> [Char] -> Gen [ServerOutput Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ServerOutput Tx" [Char]
"golden/ServerOutput.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(ServerOutput Tx))
    [Char] -> [Char] -> Gen [TimedServerOutput Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"TimedServerOutput Tx" [Char]
"golden/TimedServerOutput.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(TimedServerOutput Tx))
    [Char] -> [Char] -> Gen [ClientMessage Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ClientMessage Tx" [Char]
"golden/ClientMessage.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(ClientMessage Tx))
    [Char] -> [Char] -> Gen [Greetings Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Greetings Tx" [Char]
"golden/Greetings.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(Greetings Tx))
    [Char] -> [Char] -> Gen [InvalidInput] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"InvalidInput" [Char]
"golden/InvalidInput.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @InvalidInput)
    [Char] -> [Char] -> Gen [HeadStatus] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"HeadStatus" [Char]
"golden/HeadStatus.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @HeadStatus)
    [Char] -> [Char] -> Gen [FanoutProgressMode] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"FanoutProgressMode" [Char]
"golden/FanoutProgressMode.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @FanoutProgressMode)
    [Char] -> [Char] -> Gen [NetworkInfo] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"NetworkInfo" [Char]
"golden/NetworkInfo.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @NetworkInfo)
    [Char] -> [Char] -> Gen [DecommitInvalidReason Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"DecommitInvalidReason Tx" [Char]
"golden/DecommitInvalidReason.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(DecommitInvalidReason Tx))
    [Char] -> [Char] -> Gen [Message Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Message Tx" [Char]
"golden/Message.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(Message Tx))
    [Char] -> [Char] -> Gen [ConfirmedSnapshot Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ConfirmedSnapshot Tx" [Char]
"golden/ConfirmedSnapshot.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(ConfirmedSnapshot Tx))
    [Char] -> [Char] -> Gen [PostChainTx Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"PostChainTx Tx" [Char]
"golden/PostChainTx.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(PostChainTx Tx))
    [Char] -> [Char] -> Gen [OnChainTx Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"OnChainTx Tx" [Char]
"golden/OnChainTx.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(OnChainTx Tx))
    [Char] -> [Char] -> Gen [PostTxError Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"PostTxError Tx" [Char]
"golden/PostTxError.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(PostTxError Tx))
    [Char] -> [Char] -> Gen [ChainEvent Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ChainEvent Tx" [Char]
"golden/ChainEvent.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(ChainEvent Tx))
    [Char] -> [Char] -> Gen [HeadState Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"HeadState Tx" [Char]
"golden/HeadState.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(HeadState Tx))
    [Char] -> [Char] -> Gen [SeenSnapshot Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"SeenSnapshot Tx" [Char]
"golden/SeenSnapshot.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(SeenSnapshot Tx))
    [Char] -> [Char] -> Gen [FanoutMode Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"FanoutMode Tx" [Char]
"golden/FanoutMode.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(FanoutMode Tx))
    [Char] -> [Char] -> Gen [NodeState Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"NodeState Tx" [Char]
"golden/NodeState.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(NodeState Tx))
    [Char] -> [Char] -> Gen [SyncedStatus] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"SyncedStatus" [Char]
"golden/SyncedStatus.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @SyncedStatus)
    [Char] -> [Char] -> Gen [DepositStatus] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"DepositStatus" [Char]
"golden/DepositStatus.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @DepositStatus)
    [Char] -> [Char] -> Gen [Deposit Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Deposit Tx" [Char]
"golden/Deposit.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(Deposit Tx))
    [Char] -> [Char] -> Gen [Connectivity] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Connectivity" [Char]
"golden/Connectivity.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @Connectivity)
    [Char] -> [Char] -> Gen [WhichEtcd] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"WhichEtcd" [Char]
"golden/WhichEtcd.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @WhichEtcd)
    [Char] -> [Char] -> Gen [RequirementFailure Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"RequirementFailure Tx" [Char]
"golden/RequirementFailure.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(RequirementFailure Tx))
    [Char] -> [Char] -> Gen [SideLoadRequirementFailure Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"SideLoadRequirementFailure Tx" [Char]
"golden/SideLoadRequirementFailure.cbor" (forall a. ToADTArbitrary a => Gen [a]
genGoldenSamples @(SideLoadRequirementFailure Tx))
    -- Single-constructor domain types (tagged newtypes and records), sampled
    -- through their own 'Arbitrary' instances.
    [Char] -> [Char] -> Gen [HeadId] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"HeadId" [Char]
"golden/HeadId.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @HeadId)
    [Char] -> [Char] -> Gen [HeadSeed] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"HeadSeed" [Char]
"golden/HeadSeed.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @HeadSeed)
    [Char] -> [Char] -> Gen [OnChainId] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"OnChainId" [Char]
"golden/OnChainId.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @OnChainId)
    [Char] -> [Char] -> Gen [Party] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Party" [Char]
"golden/Party.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @Party)
    [Char] -> [Char] -> Gen [HeadParameters] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"HeadParameters" [Char]
"golden/HeadParameters.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @HeadParameters)
    [Char] -> [Char] -> Gen [ContestationPeriod] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ContestationPeriod" [Char]
"golden/ContestationPeriod.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ContestationPeriod)
    [Char] -> [Char] -> Gen [DepositPeriod] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"DepositPeriod" [Char]
"golden/DepositPeriod.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @DepositPeriod)
    [Char] -> [Char] -> Gen [SnapshotNumber] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"SnapshotNumber" [Char]
"golden/SnapshotNumber.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @SnapshotNumber)
    [Char] -> [Char] -> Gen [SnapshotVersion] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"SnapshotVersion" [Char]
"golden/SnapshotVersion.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @SnapshotVersion)
    [Char] -> [Char] -> Gen [ChainSlot] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ChainSlot" [Char]
"golden/ChainSlot.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ChainSlot)
    [Char] -> [Char] -> Gen [Signature (Snapshot Tx)] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Signature (Snapshot Tx)" [Char]
"golden/Signature.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @(Signature (Snapshot Tx)))
    [Char] -> [Char] -> Gen [MultiSignature (Snapshot Tx)] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"MultiSignature (Snapshot Tx)" [Char]
"golden/MultiSignature.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @(MultiSignature (Snapshot Tx)))
    [Char] -> [Char] -> Gen [Snapshot Tx] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Snapshot Tx" [Char]
"golden/Snapshot.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @(Snapshot Tx))
    [Char] -> [Char] -> Gen [Signed (Message Tx)] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Signed (Message Tx)" [Char]
"golden/Signed.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @(Signed (Message Tx)))
    [Char] -> [Char] -> Gen [NodeId] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"NodeId" [Char]
"golden/NodeId.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @NodeId)
    [Char] -> [Char] -> Gen [ProtocolVersion] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ProtocolVersion" [Char]
"golden/ProtocolVersion.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ProtocolVersion)
    [Char] -> [Char] -> Gen [Host] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Host" [Char]
"golden/Host.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @Host)
    [Char] -> [Char] -> Gen [ValidationError] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ValidationError" [Char]
"golden/ValidationError.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ValidationError)
    [Char] -> [Char] -> Gen [ApiTransactionTimeout] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ApiTransactionTimeout" [Char]
"golden/ApiTransactionTimeout.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ApiTransactionTimeout)
    [Char] -> [Char] -> Gen [UnsyncedPeriod] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"UnsyncedPeriod" [Char]
"golden/UnsyncedPeriod.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @UnsyncedPeriod)
    [Char] -> [Char] -> Gen [ChainPointTime] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ChainPointTime" [Char]
"golden/ChainPointTime.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ChainPointTime)
    [Char] -> [Char] -> Gen [ChainStateAt] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ChainStateAt" [Char]
"golden/ChainStateAt.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @ChainStateAt)
    [Char] -> [Char] -> Gen [Environment] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"Environment" [Char]
"golden/Environment.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @Environment)
    [Char] -> [Char] -> Gen [NetworkMagic] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"NetworkMagic" [Char]
"golden/NetworkMagic.cbor" (forall a. Arbitrary a => Gen [a]
genGoldenSample @NetworkMagic)
    -- Multi-constructor orphans from hydra-cardano-api, enumerated explicitly
    -- ('ToADTArbitrary' needs field-wise 'Arbitrary' instances these types
    -- do not have).
    [Char] -> [Char] -> Gen [NetworkId] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"NetworkId" [Char]
"golden/NetworkId.cbor" Gen [NetworkId]
genGoldenNetworkIds
    [Char] -> [Char] -> Gen [ChainPoint] -> Spec
forall a.
(ToCBOR a, FromCBOR a) =>
[Char] -> [Char] -> Gen [a] -> Spec
goldenCBOR [Char]
"ChainPoint" [Char]
"golden/ChainPoint.cbor" Gen [ChainPoint]
genGoldenChainPoints

-- | One sample per 'NetworkId' constructor.
genGoldenNetworkIds :: Gen [NetworkId]
genGoldenNetworkIds :: Gen [NetworkId]
genGoldenNetworkIds = do
  NetworkMagic
magic <- Gen NetworkMagic
forall a. Arbitrary a => Gen a
arbitrary
  [NetworkId] -> Gen [NetworkId]
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [NetworkId
Hydra.Cardano.Api.Mainnet, NetworkMagic -> NetworkId
Testnet NetworkMagic
magic]

-- | One sample per 'ChainPoint' constructor.
genGoldenChainPoints :: Gen [ChainPoint]
genGoldenChainPoints :: Gen [ChainPoint]
genGoldenChainPoints = do
  ChainPoint
point <- Gen ChainPoint
forall a. Arbitrary a => Gen a
arbitrary Gen ChainPoint -> (ChainPoint -> Bool) -> Gen ChainPoint
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` (ChainPoint -> ChainPoint -> Bool
forall a. Eq a => a -> a -> Bool
/= ChainPoint
ChainPointAtGenesis)
  [ChainPoint] -> Gen [ChainPoint]
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [ChainPoint
ChainPointAtGenesis, ChainPoint
point]

-- | One 'StateEvent' per 'StateChanged' constructor, in declaration order:
-- 'ToADTArbitrary' enumerates the constructors generically, so coverage of
-- every constructor holds by construction and new constructors are included
-- automatically. Samples are generated small (resized): the golden file
-- locks tags and field order, which small values exercise just as well.
genGoldenStateEvents :: Gen [StateEvent Tx]
genGoldenStateEvents :: Gen [StateEvent Tx]
genGoldenStateEvents = do
  ADTArbitrary{[ConstructorArbitraryPair (StateChanged Tx)]
adtCAPs :: [ConstructorArbitraryPair (StateChanged Tx)]
adtCAPs :: forall a. ADTArbitrary a -> [ConstructorArbitraryPair a]
adtCAPs} <- Int
-> Gen (ADTArbitrary (StateChanged Tx))
-> Gen (ADTArbitrary (StateChanged Tx))
forall a. HasCallStack => Int -> Gen a -> Gen a
resize Int
5 (Gen (ADTArbitrary (StateChanged Tx))
 -> Gen (ADTArbitrary (StateChanged Tx)))
-> Gen (ADTArbitrary (StateChanged Tx))
-> Gen (ADTArbitrary (StateChanged Tx))
forall a b. (a -> b) -> a -> b
$ Proxy (StateChanged Tx) -> Gen (ADTArbitrary (StateChanged Tx))
forall a. ToADTArbitrary a => Proxy a -> Gen (ADTArbitrary a)
toADTArbitrary (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(StateChanged Tx))
  [(EventId, ConstructorArbitraryPair (StateChanged Tx))]
-> ((EventId, ConstructorArbitraryPair (StateChanged Tx))
    -> Gen (StateEvent Tx))
-> Gen [StateEvent Tx]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([EventId]
-> [ConstructorArbitraryPair (StateChanged Tx)]
-> [(EventId, ConstructorArbitraryPair (StateChanged Tx))]
forall a b. [a] -> [b] -> [(a, b)]
zip [EventId
0 ..] [ConstructorArbitraryPair (StateChanged Tx)]
adtCAPs) (((EventId, ConstructorArbitraryPair (StateChanged Tx))
  -> Gen (StateEvent Tx))
 -> Gen [StateEvent Tx])
-> ((EventId, ConstructorArbitraryPair (StateChanged Tx))
    -> Gen (StateEvent Tx))
-> Gen [StateEvent Tx]
forall a b. (a -> b) -> a -> b
$ \(EventId
i, ConstructorArbitraryPair{StateChanged Tx
capArbitrary :: StateChanged Tx
capArbitrary :: forall a. ConstructorArbitraryPair a -> a
capArbitrary}) ->
    EventId -> StateChanged Tx -> UTCTime -> StateEvent Tx
forall tx. EventId -> StateChanged tx -> UTCTime -> StateEvent tx
StateEvent EventId
i StateChanged Tx
capArbitrary (UTCTime -> StateEvent Tx) -> Gen UTCTime -> Gen (StateEvent Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary