cardano-ledger-binary-1.4.0.0: Binary serialization library used throughout ledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Cardano.Ledger.Binary.Plain.RoundTrip

Description

Defines reusable abstractions for testing RoundTrip properties of plain encoders/decoders

Synopsis

Documentation

roundTripSpec ∷ ∀ t. (Show t, Eq t, Typeable t, Arbitrary t) ⇒ Trip t t → Spec Source #

Tests the roundtrip property using QuickCheck generators for all possible versions starting with shelleyProtVer.

roundTripExpectation ∷ (Show t, Eq t, Typeable t, HasCallStack) ⇒ Trip t t → t → Expectation Source #

Verify that round triping through the binary form holds

embedTripSpec ∷ ∀ a b. (Eq b, Show a, Typeable a, Typeable b, Arbitrary a, HasCallStack) ⇒ Trip a b → (b → a → Expectation) → Spec Source #

Tests the embedtrip property using QuickCheck generators

embedTripExpectation ∷ ∀ a b. (Typeable b, Eq b, HasCallStack) ⇒ Trip a b → (b → a → Expectation) → a → Expectation Source #

data RoundTripFailure Source #

Constructors

RoundTripFailure 

Fields

data Trip a b Source #

A definition of a CBOR trip through binary representation of one type to another. In this module this is called an embed. When a source and target type is the exact same one then it would be a dual and is expected to round trip.

Constructors

Trip 

Fields

mkTrip ∷ ∀ a b. (a → Encoding) → (∀ s. Decoder s b) → Trip a b Source #

Construct a Trip using encoder and decoder, with dropper set to the decoder which drops the value

cborTrip ∷ ∀ a b. (ToCBOR a, FromCBOR b) ⇒ Trip a b Source #

roundTrip ∷ ∀ t. (Eq t, Typeable t) ⇒ Trip t t → t → Either RoundTripFailure t Source #

embedTrip ∷ ∀ a b. (Eq b, Typeable b) ⇒ Trip a b → a → Either RoundTripFailure b Source #

Can we serialise a type, and then deserialise it as something else?

embedTripLabel ∷ ∀ a b. Eq b ⇒ TextTrip a b → a → Either RoundTripFailure b Source #