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

Test.Cardano.Ledger.Binary.RoundTrip

Description

Defines reusable abstractions for testing RoundTrip properties of CBOR instances

Synopsis

Spec

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.

roundTripCborSpec ∷ ∀ t. (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 ∷ ∀ t. (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 ∷ ∀ t. (Show t, Eq t, Typeable t, Arbitrary t) ⇒ Trip t t → VersionVersionSpec 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

∷ ∀ t. (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

roundTripRangeFailureExpectation Source #

Arguments

∷ ∀ t. (Typeable t, Eq t, HasCallStack) 
Trip t t 
Version

From Version

Version

To Version

→ t 
Expectation 

Enc/DecCBOR

roundTripCborRangeExpectation Source #

Arguments

∷ ∀ t. (Show t, Eq t, EncCBOR t, DecCBOR t, HasCallStack) 
Version

From Version

Version

To Version

→ t 
Expectation 

roundTripCborRangeFailureExpectation Source #

Arguments

∷ ∀ t. (EncCBOR t, DecCBOR t, Eq t, HasCallStack) 
Version

From Version

Version

To Version

→ t 
Expectation 

Embed

embedTripSpec Source #

Arguments

∷ ∀ a b. (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

embedTripExpectation Source #

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

∷ ∀ a b. (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.

embedTripRangeFailureExpectation Source #

Arguments

∷ ∀ a b. (Typeable b, Eq b, HasCallStack) 
Trip a b 
Version

From Version

Version

To Version

→ a 
Expectation 

roundTripAnnTwiddledProperty ∷ ∀ t q. (Twiddle t, DecCBOR (Annotator t), Testable q) ⇒ (t → t → q) → Version → t → Property Source #

Tripping failure

data RoundTripFailure Source #

Constructors

RoundTripFailure 

Fields

Tripping definitions

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. (EncCBOR a, DecCBOR b) ⇒ Trip a b Source #

Tripping functions

roundTrip ∷ ∀ t. (Eq t, Typeable t) ⇒ VersionTrip 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 ∷ ∀ t. (Twiddle t, DecCBOR t, Eq t) ⇒ Version → t → Gen (Either RoundTripFailure t) Source #

embedTrip 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?

embedTripAnn Source #

Arguments

∷ ∀ a b. (ToCBOR a, DecCBOR (Annotator b)) 
Version

Encoder version for test failure reporting

Version

Decoder version

→ a 
Either RoundTripFailure b 

embedTripLabel Source #

Arguments

∷ ∀ a b. Eq b 
Text 
Version

Version for the encoder

Version

Version for the decoder

Trip a b 
→ a 
Either RoundTripFailure b 

embedTripLabelExtra Source #

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) 

decodeAnnExtra Source #

Arguments

∷ ∀ t. Text 
Version

Version for the encoder

Version

Version for the decoder

→ (∀ s. Decoder s (Annotator t)) 
Encoding 
Either RoundTripFailure (t, ByteString)