{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}

-- | The node's LeiosFetch codec against the CDDL.
module Test.Consensus.Cardano.LeiosFetch (tests) where

import Cardano.Crypto.Hash (Hash (UnsafeHash))
import Cardano.Ledger.Core (bodyTxL, certsTxBodyL)
import Cardano.Ledger.Dijkstra.TxBody (subTransactionsTxBodyL)
import Codec.CBOR.Read (DeserialiseFailure)
import Data.ByteString.Lazy (ByteString, toStrict)
import qualified Data.ByteString.Short as SBS
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Vector.Strict as V
import Lens.Micro ((&), (.~))
import Network.TypedProtocol.Codec (AnyMessage (..), Codec, CodecF (..))
import Ouroboros.Consensus.Block (SlotNo (..))
import Ouroboros.Consensus.Leios.Types
  ( EndorserBlock
  , LeiosPoint (..)
  , LeiosTx (..)
  , Serialised
  , decodeLeiosPoint
  , decodeLeiosTx
  , decodeSerialisedEndorserBlock
  , encodeLeiosPoint
  , encodeLeiosTx
  , encodeSerialisedEndorserBlock
  , maxTxsPerEndorserBlock
  , mkEndorserBlock
  , serialiseEndorserBlock
  )
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Type
import Ouroboros.Consensus.Shelley.Ledger.Forge (serializeTxForLeios)
import Test.Cardano.Ledger.Dijkstra.Examples (exampleDijkstraTx)
import Test.Tasty
import Test.Tasty.QuickCheck
import Test.Util.Serialisation.CDDL (cddlTest, isCDDLCDisabled)

tests :: TestTree
tests :: TestTree
tests =
  TestName -> [TestTree] -> TestTree
testGroup TestName
"LeiosFetch" ([TestTree] -> TestTree) -> [TestTree] -> TestTree
forall a b. (a -> b) -> a -> b
$
    [ TestName -> Property -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"the node's codec encodes each message as the CDDL specifies" (Property -> TestTree) -> Property -> TestTree
forall a b. (a -> b) -> a -> b
$
        Property
prop_nodeCodecMatchesCDDL
    | Bool -> Bool
not Bool
isCDDLCDisabled
    ]

prop_nodeCodecMatchesCDDL :: Property
prop_nodeCodecMatchesCDDL :: Property
prop_nodeCodecMatchesCDDL =
  Gen
  (AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> (AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
    -> Property)
-> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen
  (AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
genMessage ((AnyMessage
    (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  -> Property)
 -> Property)
-> (AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
    -> Property)
-> Property
forall a b. (a -> b) -> a -> b
$ \(AnyMessage Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx) st st'
msg) ->
    IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
      result <-
        IO ByteString -> TestName -> Text -> IO (Either TestName ())
cddlTest
          (ByteString -> IO ByteString
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$ LazyByteString -> ByteString
toStrict (LazyByteString -> ByteString) -> LazyByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ CodecF
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  DeserialiseFailure
  IO
  SomeMessage
  LazyByteString
-> forall (st :: LeiosFetch
                   LeiosPoint (Serialised EndorserBlock) LeiosTx)
          (st' :: LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx).
   (StateTokenI st, ActiveState st) =>
   Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx) st st'
   -> LazyByteString
forall ps failure (m :: * -> *) (f :: ps -> *) bytes.
CodecF ps failure m f bytes
-> forall (st :: ps) (st' :: ps).
   (StateTokenI st, ActiveState st) =>
   Message ps st st' -> bytes
encode CodecF
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  DeserialiseFailure
  IO
  SomeMessage
  LazyByteString
nodeCodec Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx) st st'
msg)
          TestName
"ntnleiosfetch.cddl"
          (TestName -> Text
T.pack TestName
"leiosFetchMessage")
      pure $ either (`counterexample` False) (const $ property True) result
 where
  nodeCodec ::
    Codec (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx) DeserialiseFailure IO ByteString
  nodeCodec :: CodecF
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  DeserialiseFailure
  IO
  SomeMessage
  LazyByteString
nodeCodec =
    Int
-> (LeiosPoint -> Encoding)
-> (forall s. Decoder s LeiosPoint)
-> (Serialised EndorserBlock -> Encoding)
-> (forall s. Decoder s (Serialised EndorserBlock))
-> (LeiosTx -> Encoding)
-> (forall s. Decoder s LeiosTx)
-> CodecF
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     DeserialiseFailure
     IO
     SomeMessage
     LazyByteString
forall point eb tx (m :: * -> *).
MonadST m =>
Int
-> (point -> Encoding)
-> (forall s. Decoder s point)
-> (eb -> Encoding)
-> (forall s. Decoder s eb)
-> (tx -> Encoding)
-> (forall s. Decoder s tx)
-> Codec
     (LeiosFetch point eb tx) DeserialiseFailure m LazyByteString
codecLeiosFetch
      Int
maxTxsPerEndorserBlock
      LeiosPoint -> Encoding
encodeLeiosPoint
      Decoder s LeiosPoint
forall s. Decoder s LeiosPoint
decodeLeiosPoint
      Serialised EndorserBlock -> Encoding
encodeSerialisedEndorserBlock
      Decoder s (Serialised EndorserBlock)
forall s. Decoder s (Serialised EndorserBlock)
decodeSerialisedEndorserBlock
      LeiosTx -> Encoding
encodeLeiosTx
      Decoder s LeiosTx
forall s. Decoder s LeiosTx
decodeLeiosTx

  genMessage :: Gen
  (AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
genMessage =
    [Gen
   (AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))]
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ AnyMessage
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AnyMessage
   (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
 -> Gen
      (AnyMessage
         (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)))
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall a b. (a -> b) -> a -> b
$ Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  'StIdle
  'StDone
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  'StIdle
  'StDone
forall point eb tx.
Message (LeiosFetch point eb tx) 'StIdle 'StDone
MsgDone
      , Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  'StIdle
  ('StBusy 'StBlock)
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage (Message
   (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
   'StIdle
   ('StBusy 'StBlock)
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> (LeiosPoint
    -> Message
         (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
         'StIdle
         ('StBusy 'StBlock))
-> LeiosPoint
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosPoint
-> Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     'StIdle
     ('StBusy 'StBlock)
forall point eb tx.
point
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlock)
MsgLeiosBlockRequest (LeiosPoint
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Gen LeiosPoint
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen LeiosPoint
genPoint
      , Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  ('StBusy 'StBlock)
  'StIdle
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage (Message
   (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
   ('StBusy 'StBlock)
   'StIdle
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> (Serialised EndorserBlock
    -> Message
         (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
         ('StBusy 'StBlock)
         'StIdle)
-> Serialised EndorserBlock
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Serialised EndorserBlock
-> Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     ('StBusy 'StBlock)
     'StIdle
forall eb point tx.
eb -> Message (LeiosFetch point eb tx) ('StBusy 'StBlock) 'StIdle
MsgLeiosBlock (Serialised EndorserBlock
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Gen (Serialised EndorserBlock)
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Serialised EndorserBlock)
genEb
      , (Message
   (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
   'StIdle
   ('StBusy 'StBlockTxs)
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Gen
     (Message
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
        'StIdle
        ('StBusy 'StBlockTxs))
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  'StIdle
  ('StBusy 'StBlockTxs)
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage (Gen
   (Message
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
      'StIdle
      ('StBusy 'StBlockTxs))
 -> Gen
      (AnyMessage
         (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)))
-> Gen
     (Message
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
        'StIdle
        ('StBusy 'StBlockTxs))
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall a b. (a -> b) -> a -> b
$ LeiosPoint
-> TxBitmaps
-> Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     'StIdle
     ('StBusy 'StBlockTxs)
forall point eb tx.
point
-> TxBitmaps
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlockTxs)
MsgLeiosBlockTxsRequest (LeiosPoint
 -> TxBitmaps
 -> Message
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
      'StIdle
      ('StBusy 'StBlockTxs))
-> Gen LeiosPoint
-> Gen
     (TxBitmaps
      -> Message
           (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
           'StIdle
           ('StBusy 'StBlockTxs))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen LeiosPoint
genPoint Gen
  (TxBitmaps
   -> Message
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
        'StIdle
        ('StBusy 'StBlockTxs))
-> Gen TxBitmaps
-> Gen
     (Message
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
        'StIdle
        ('StBusy 'StBlockTxs))
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxBitmaps
genBitmaps
      , Message
  (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
  ('StBusy 'StBlockTxs)
  'StIdle
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage (Message
   (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
   ('StBusy 'StBlockTxs)
   'StIdle
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> ([LeiosTx]
    -> Message
         (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
         ('StBusy 'StBlockTxs)
         'StIdle)
-> [LeiosTx]
-> AnyMessage
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector LeiosTx
-> Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     ('StBusy 'StBlockTxs)
     'StIdle
forall tx point eb.
Vector tx
-> Message (LeiosFetch point eb tx) ('StBusy 'StBlockTxs) 'StIdle
MsgLeiosBlockTxs (Vector LeiosTx
 -> Message
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
      ('StBusy 'StBlockTxs)
      'StIdle)
-> ([LeiosTx] -> Vector LeiosTx)
-> [LeiosTx]
-> Message
     (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
     ('StBusy 'StBlockTxs)
     'StIdle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LeiosTx] -> Vector LeiosTx
forall a. [a] -> Vector a
V.fromList ([LeiosTx]
 -> AnyMessage
      (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Gen [LeiosTx]
-> Gen
     (AnyMessage
        (LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen LeiosTx -> Gen [LeiosTx]
forall a. Gen a -> Gen [a]
listOf (LeiosTx -> Gen LeiosTx
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LeiosTx
tx)
      ]

  genPoint :: Gen LeiosPoint
genPoint = SlotNo -> EndorserBlockHash -> LeiosPoint
MkLeiosPoint (SlotNo -> EndorserBlockHash -> LeiosPoint)
-> Gen SlotNo -> Gen (EndorserBlockHash -> LeiosPoint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word64 -> SlotNo
SlotNo (Word64 -> SlotNo) -> Gen Word64 -> Gen SlotNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary) Gen (EndorserBlockHash -> LeiosPoint)
-> Gen EndorserBlockHash -> Gen LeiosPoint
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EndorserBlockHash
forall {a}. Gen (Hash HASH a)
genHash

  -- strictly ascending indices, each with a non-zero bitmap, as the decoder
  -- requires
  genBitmaps :: Gen TxBitmaps
genBitmaps = do
    indices <- Set Word16 -> [Word16]
forall a. Set a -> [a]
Set.toAscList (Set Word16 -> [Word16])
-> ([Word16] -> Set Word16) -> [Word16] -> [Word16]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word16] -> Set Word16
forall a. Ord a => [a] -> Set a
Set.fromList ([Word16] -> [Word16]) -> Gen [Word16] -> Gen [Word16]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Word16]
forall a. Arbitrary a => Gen a
arbitrary
    traverse (\Word16
i -> (,) Word16
i (Word64 -> (Word16, Word64))
-> (Positive Word64 -> Word64)
-> Positive Word64
-> (Word16, Word64)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Positive Word64 -> Word64
forall a. Positive a -> a
getPositive (Positive Word64 -> (Word16, Word64))
-> Gen (Positive Word64) -> Gen (Word16, Word64)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Positive Word64)
forall a. Arbitrary a => Gen a
arbitrary) indices

  genEb :: Gen (Serialised EndorserBlock)
genEb = EndorserBlock -> Serialised EndorserBlock
serialiseEndorserBlock (EndorserBlock -> Serialised EndorserBlock)
-> ([(TxHash, BytesSize)] -> EndorserBlock)
-> [(TxHash, BytesSize)]
-> Serialised EndorserBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(TxHash, BytesSize)] -> EndorserBlock
mkEndorserBlock ([(TxHash, BytesSize)] -> Serialised EndorserBlock)
-> Gen [(TxHash, BytesSize)] -> Gen (Serialised EndorserBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (TxHash, BytesSize) -> Gen [(TxHash, BytesSize)]
forall a. Gen a -> Gen [a]
listOf1 ((,) (TxHash -> BytesSize -> (TxHash, BytesSize))
-> Gen TxHash -> Gen (BytesSize -> (TxHash, BytesSize))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxHash
forall {a}. Gen (Hash HASH a)
genHash Gen (BytesSize -> (TxHash, BytesSize))
-> Gen BytesSize -> Gen (TxHash, BytesSize)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen BytesSize
forall a. Arbitrary a => Gen a
arbitrary)

  -- As the forge writes it, but without certificates and sub-transactions.
  --
  -- FIXME Workaround for a cuddle bug: it rejects an optional entry in a group
  -- spliced into an array, as the bls_key of the pool registrations, here and
  -- in the sub-transactions, although they match the CDDL.
  tx :: LeiosTx
tx =
    ByteString -> LeiosTx
MkLeiosTx (ByteString -> LeiosTx)
-> (Tx TopTx DijkstraEra -> ByteString)
-> Tx TopTx DijkstraEra
-> LeiosTx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx DijkstraEra -> ByteString
forall era.
(EraTx era, SafeToHash (Tx TopTx era)) =>
Tx TopTx era -> ByteString
serializeTxForLeios (Tx TopTx DijkstraEra -> LeiosTx)
-> Tx TopTx DijkstraEra -> LeiosTx
forall a b. (a -> b) -> a -> b
$
      Tx TopTx DijkstraEra
exampleDijkstraTx
        Tx TopTx DijkstraEra
-> (Tx TopTx DijkstraEra -> Tx TopTx DijkstraEra)
-> Tx TopTx DijkstraEra
forall a b. a -> (a -> b) -> b
& (TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
-> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel).
Lens' (Tx l DijkstraEra) (TxBody l DijkstraEra)
bodyTxL ((TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
 -> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra))
-> ((StrictSeq (DijkstraTxCert DijkstraEra)
     -> Identity (StrictSeq (DijkstraTxCert DijkstraEra)))
    -> TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
-> (StrictSeq (DijkstraTxCert DijkstraEra)
    -> Identity (StrictSeq (DijkstraTxCert DijkstraEra)))
-> Tx TopTx DijkstraEra
-> Identity (Tx TopTx DijkstraEra)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxCert DijkstraEra)
 -> Identity (StrictSeq (TxCert DijkstraEra)))
-> TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra)
(StrictSeq (DijkstraTxCert DijkstraEra)
 -> Identity (StrictSeq (DijkstraTxCert DijkstraEra)))
-> TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxCert era))
forall (l :: TxLevel).
Lens' (TxBody l DijkstraEra) (StrictSeq (TxCert DijkstraEra))
certsTxBodyL ((StrictSeq (DijkstraTxCert DijkstraEra)
  -> Identity (StrictSeq (DijkstraTxCert DijkstraEra)))
 -> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra))
-> StrictSeq (DijkstraTxCert DijkstraEra)
-> Tx TopTx DijkstraEra
-> Tx TopTx DijkstraEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictSeq (DijkstraTxCert DijkstraEra)
forall a. Monoid a => a
mempty
        Tx TopTx DijkstraEra
-> (Tx TopTx DijkstraEra -> Tx TopTx DijkstraEra)
-> Tx TopTx DijkstraEra
forall a b. a -> (a -> b) -> b
& (TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
-> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel).
Lens' (Tx l DijkstraEra) (TxBody l DijkstraEra)
bodyTxL ((TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
 -> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra))
-> ((OMap TxId (Tx SubTx DijkstraEra)
     -> Identity (OMap TxId (Tx SubTx DijkstraEra)))
    -> TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra))
-> (OMap TxId (Tx SubTx DijkstraEra)
    -> Identity (OMap TxId (Tx SubTx DijkstraEra)))
-> Tx TopTx DijkstraEra
-> Identity (Tx TopTx DijkstraEra)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OMap TxId (Tx SubTx DijkstraEra)
 -> Identity (OMap TxId (Tx SubTx DijkstraEra)))
-> TxBody TopTx DijkstraEra -> Identity (TxBody TopTx DijkstraEra)
forall era.
DijkstraEraTxBody era =>
Lens' (TxBody TopTx era) (OMap TxId (Tx SubTx era))
Lens' (TxBody TopTx DijkstraEra) (OMap TxId (Tx SubTx DijkstraEra))
subTransactionsTxBodyL ((OMap TxId (Tx SubTx DijkstraEra)
  -> Identity (OMap TxId (Tx SubTx DijkstraEra)))
 -> Tx TopTx DijkstraEra -> Identity (Tx TopTx DijkstraEra))
-> OMap TxId (Tx SubTx DijkstraEra)
-> Tx TopTx DijkstraEra
-> Tx TopTx DijkstraEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ OMap TxId (Tx SubTx DijkstraEra)
forall a. Monoid a => a
mempty

  genHash :: Gen (Hash HASH a)
genHash = ShortByteString -> Hash HASH a
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (ShortByteString -> Hash HASH a)
-> ([Word8] -> ShortByteString) -> [Word8] -> Hash HASH a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ShortByteString
SBS.pack ([Word8] -> Hash HASH a) -> Gen [Word8] -> Gen (Hash HASH a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen Word8 -> Gen [Word8]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
32 Gen Word8
forall a. Arbitrary a => Gen a
arbitrary