| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Cardano.Ledger.Binary.RoundTrip
Description
Defines reusable abstractions for testing RoundTrip properties of CBOR instances
Synopsis
- roundTripSpec ∷ (Show t, Eq t, Typeable t, Arbitrary t) ⇒ Trip t t → Spec
- roundTripCborSpec ∷ (Show t, Eq t, Arbitrary t, EncCBOR t, DecCBOR t) ⇒ Spec
- roundTripAnnCborSpec ∷ (Show t, Eq t, Arbitrary t, ToCBOR t, DecCBOR (Annotator t)) ⇒ Spec
- roundTripRangeSpec ∷ (Show t, Eq t, Typeable t, Arbitrary t) ⇒ Trip t t → Version → Version → Spec
- roundTripExpectation ∷ (Show t, Eq t, Typeable t, HasCallStack) ⇒ Trip t t → t → Expectation
- roundTripRangeExpectation ∷ (Show t, Eq t, Typeable t, HasCallStack) ⇒ Trip t t → Version → Version → t → Expectation
- roundTripFailureExpectation ∷ (Typeable t, Eq t, HasCallStack) ⇒ Trip t t → t → Expectation
- roundTripRangeFailureExpectation ∷ (Typeable t, Eq t, HasCallStack) ⇒ Trip t t → Version → Version → t → Expectation
- roundTripCborExpectation ∷ (Show t, Eq t, EncCBOR t, DecCBOR t, HasCallStack) ⇒ t → Expectation
- roundTripCborRangeExpectation ∷ (Show t, Eq t, EncCBOR t, DecCBOR t, HasCallStack) ⇒ Version → Version → t → Expectation
- roundTripCborFailureExpectation ∷ (EncCBOR t, DecCBOR t, Eq t, HasCallStack) ⇒ t → Expectation
- roundTripCborRangeFailureExpectation ∷ (EncCBOR t, DecCBOR t, Eq t, HasCallStack) ⇒ Version → Version → t → Expectation
- roundTripAnnExpectation ∷ (Show t, Eq t, ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ t → Expectation
- roundTripAnnRangeExpectation ∷ (Show t, Eq t, ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ Version → Version → t → Expectation
- roundTripAnnFailureExpectation ∷ (ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ t → Expectation
- roundTripAnnRangeFailureExpectation ∷ (ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ Version → Version → t → Expectation
- embedTripSpec ∷ (Show a, Typeable a, Typeable b, Arbitrary a, Eq b, HasCallStack) ⇒ Version → Version → Trip a b → (b → a → Expectation) → Spec
- embedTripExpectation ∷ ∀ a b. (Typeable b, Eq b, HasCallStack) ⇒ Version → Version → Trip a b → (b → a → Expectation) → a → Expectation
- embedTripAnnExpectation ∷ (ToCBOR a, DecCBOR (Annotator b), HasCallStack) ⇒ Version → Version → (b → a → Expectation) → a → Expectation
- embedTripFailureExpectation ∷ (Typeable b, Eq b, HasCallStack) ⇒ Trip a b → a → Expectation
- embedTripRangeFailureExpectation ∷ ∀ a b. (Typeable b, Eq b, HasCallStack) ⇒ Trip a b → Version → Version → a → Expectation
- roundTripTwiddledProperty ∷ (Show t, Eq t, Twiddle t, DecCBOR t) ⇒ Version → t → Property
- roundTripAnnTwiddledProperty ∷ (Twiddle t, DecCBOR (Annotator t), Testable q) ⇒ (t → t → q) → Version → t → Property
- data RoundTripFailure = RoundTripFailure {}
- data Trip a b = Trip {
- tripEncoder ∷ a → Encoding
- tripDecoder ∷ ∀ s. Decoder s b
- tripDropper ∷ ∀ s. Decoder s ()
- mkTrip ∷ (a → Encoding) → (∀ s. Decoder s b) → Trip a b
- cborTrip ∷ (EncCBOR a, DecCBOR b) ⇒ Trip a b
- roundTrip ∷ (Eq t, Typeable t) ⇒ Version → Trip t t → t → Either RoundTripFailure t
- roundTripTwiddled ∷ (Twiddle t, DecCBOR t, Eq t) ⇒ Version → t → Gen (Either RoundTripFailure t)
- roundTripAnn ∷ (ToCBOR t, DecCBOR (Annotator t)) ⇒ Version → t → Either RoundTripFailure t
- roundTripAnnTwiddled ∷ (Twiddle t, DecCBOR (Annotator t)) ⇒ Version → t → Gen (Either RoundTripFailure t)
- embedTrip ∷ ∀ a b. (Eq b, Typeable b) ⇒ Version → Version → Trip a b → a → Either RoundTripFailure b
- embedTripAnn ∷ (ToCBOR a, DecCBOR (Annotator b)) ⇒ Version → Version → a → Either RoundTripFailure b
- embedTripLabel ∷ ∀ a b. Eq b ⇒ Text → Version → Version → Trip a b → a → Either RoundTripFailure b
- embedTripLabelExtra ∷ ∀ a b. Eq b ⇒ Text → Version → Version → Trip a b → a → Either RoundTripFailure (b, Encoding, ByteString)
- decodeAnnExtra ∷ Text → Version → Version → (∀ s. Decoder s (Annotator t)) → Encoding → Either RoundTripFailure (t, ByteString)
Spec
roundTripSpec ∷ (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.
roundTripCborSpec ∷ (Show t, Eq t, Arbitrary t, EncCBOR t, DecCBOR t) ⇒ Spec Source #
Tests the roundtrip property using QuickCheck generators for all possible versions
starting with shelleyProtVer.
roundTripAnnCborSpec ∷ (Show t, Eq t, Arbitrary t, ToCBOR t, DecCBOR (Annotator t)) ⇒ Spec Source #
Tests the roundtrip property using QuickCheck generators for all possible versions
starting with shelleyProtVer.
roundTripRangeSpec ∷ (Show t, Eq t, Typeable t, Arbitrary t) ⇒ Trip t t → Version → Version → Spec Source #
Tests the roundtrip property using QuickCheck generators for specific range of versions
Expectations
Trip
roundTripExpectation ∷ (Show t, Eq t, Typeable t, HasCallStack) ⇒ Trip t t → t → Expectation Source #
Verify that round triping through the binary form holds for all versions starting
with shelleyProtVer.
roundTripRangeExpectation Source #
Arguments
| ∷ (Show t, Eq t, Typeable t, HasCallStack) | |
| ⇒ Trip t t | |
| → Version | From Version |
| → Version | To Version |
| → t | |
| → Expectation |
Verify that round triping through the binary form holds for a range of versions.
In other words check that:
deserialize version . serialize version === id serialize version . deserialize version . serialize version === serialize version
roundTripFailureExpectation ∷ (Typeable t, Eq t, HasCallStack) ⇒ Trip t t → t → Expectation Source #
roundTripRangeFailureExpectation Source #
Arguments
| ∷ (Typeable t, Eq t, HasCallStack) | |
| ⇒ Trip t t | |
| → Version | From Version |
| → Version | To Version |
| → t | |
| → Expectation |
Enc/DecCBOR
roundTripCborExpectation ∷ (Show t, Eq t, EncCBOR t, DecCBOR t, HasCallStack) ⇒ t → Expectation Source #
roundTripCborRangeExpectation Source #
Arguments
| ∷ (Show t, Eq t, EncCBOR t, DecCBOR t, HasCallStack) | |
| ⇒ Version | From Version |
| → Version | To Version |
| → t | |
| → Expectation |
roundTripCborFailureExpectation ∷ (EncCBOR t, DecCBOR t, Eq t, HasCallStack) ⇒ t → Expectation Source #
roundTripCborRangeFailureExpectation Source #
Arguments
| ∷ (EncCBOR t, DecCBOR t, Eq t, HasCallStack) | |
| ⇒ Version | From Version |
| → Version | To Version |
| → t | |
| → Expectation |
roundTripAnnExpectation ∷ (Show t, Eq t, ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ t → Expectation Source #
roundTripAnnRangeExpectation ∷ (Show t, Eq t, ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ Version → Version → t → Expectation Source #
roundTripAnnFailureExpectation ∷ (ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ t → Expectation Source #
roundTripAnnRangeFailureExpectation ∷ (ToCBOR t, DecCBOR (Annotator t), HasCallStack) ⇒ Version → Version → t → Expectation Source #
Embed
Arguments
| ∷ (Show a, Typeable a, Typeable b, Arbitrary a, Eq b, HasCallStack) | |
| ⇒ Version | Version for the encoder |
| → Version | Version for the decoder |
| → Trip a b | |
| → (b → a → Expectation) | |
| → Spec |
Tests the embedtrip property using QuickCheck generators
Arguments
| ∷ ∀ a b. (Typeable b, Eq b, HasCallStack) | |
| ⇒ Version | Version for the encoder |
| → Version | Version for the decoder |
| → Trip a b | |
| → (b → a → Expectation) | |
| → a | |
| → Expectation |
embedTripAnnExpectation Source #
Arguments
| ∷ (ToCBOR a, DecCBOR (Annotator b), HasCallStack) | |
| ⇒ Version | Version for the encoder |
| → Version | Version for the decoder |
| → (b → a → Expectation) | |
| → a | |
| → Expectation |
This is just like roundTripAnnExpectation, except it allows for source and target
types to be different. This is very useful to test translation of the same type family
from one era to another.
embedTripFailureExpectation ∷ (Typeable b, Eq b, HasCallStack) ⇒ Trip a b → a → Expectation Source #
embedTripRangeFailureExpectation Source #
Arguments
| ∷ ∀ a b. (Typeable b, Eq b, HasCallStack) | |
| ⇒ Trip a b | |
| → Version | From Version |
| → Version | To Version |
| → a | |
| → Expectation |
roundTripAnnTwiddledProperty ∷ (Twiddle t, DecCBOR (Annotator t), Testable q) ⇒ (t → t → q) → Version → t → Property Source #
Tripping failure
data RoundTripFailure Source #
Constructors
| RoundTripFailure | |
Fields
| |
Instances
| Show RoundTripFailure Source # | |
Defined in Test.Cardano.Ledger.Binary.RoundTrip Methods showsPrec ∷ Int → RoundTripFailure → ShowS # show ∷ RoundTripFailure → String # showList ∷ [RoundTripFailure] → ShowS # | |
Tripping definitions
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 → 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
Tripping functions
roundTrip ∷ (Eq t, Typeable t) ⇒ Version → Trip t t → t → Either RoundTripFailure t Source #
Check that serialization followed by deserialization of the value produces the same value back. We also check that re-serialization is idempotent. In other words, we ensure that deserialization does not modify the decoded value in a way that its binary representation has changed. Dropper is checked as well.
roundTripTwiddled ∷ (Twiddle t, DecCBOR t, Eq t) ⇒ Version → t → Gen (Either RoundTripFailure t) Source #
roundTripAnn ∷ (ToCBOR t, DecCBOR (Annotator t)) ⇒ Version → t → Either RoundTripFailure t Source #
roundTripAnnTwiddled ∷ (Twiddle t, DecCBOR (Annotator t)) ⇒ Version → t → Gen (Either RoundTripFailure t) Source #
Arguments
| ∷ ∀ a b. (Eq b, Typeable b) | |
| ⇒ Version | Version for the encoder |
| → Version | Version for the decoder |
| → Trip a b | |
| → a | |
| → Either RoundTripFailure b |
Can we serialise a type, and then deserialise it as something else?
Arguments
| ∷ ∀ a b. Eq b | |
| ⇒ Text | |
| → Version | Version for the encoder |
| → Version | Version for the decoder |
| → Trip a b | |
| → a | |
| → Either RoundTripFailure (b, Encoding, ByteString) |
Arguments
| ∷ Text | |
| → Version | Version for the encoder |
| → Version | Version for the decoder |
| → (∀ s. Decoder s (Annotator t)) | |
| → Encoding | |
| → Either RoundTripFailure (t, ByteString) |