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

Test.Cardano.Ledger.Binary.Twiddle

Synopsis

Documentation

data Twiddler a Source #

Constructors

Twiddler 

Instances

Instances details
(Twiddle a, Arbitrary a, EncCBOR a) ⇒ Arbitrary (Twiddler a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Show a ⇒ Show (Twiddler a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

(EncCBOR a, DecCBOR a) ⇒ DecCBOR (Twiddler a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Typeable a ⇒ EncCBOR (Twiddler a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

encCBORTwiddler a → Encoding Source #

encodedSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy (Twiddler a) → Size Source #

encodedListSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy [Twiddler a] → Size Source #

Eq a ⇒ Eq (Twiddler a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

(==)Twiddler a → Twiddler a → Bool Source #

(/=)Twiddler a → Twiddler a → Bool Source #

class Twiddle a where Source #

Introducing random variations into the CBOR encoding of a value while preserving the round-trip properties.

For any value `x :: a`, where a derives Twiddle, and for any version of the decoder, the following property must hold: >>> fmap ((== x) . encodingToTerm version . encCBOR) (twiddle x)

Minimal complete definition

Nothing

Methods

twiddleVersion → a → Gen Term Source #

Given a value of type a, generates a CBOR Term that can contain slight variations without changing the semantics. After encoding and decoding the Term, we should get back the original value that was being twiddled.

In addition to varying the low-level CBOR tokens, twiddle can also be used to introduce higher level variations. For example if the schema of a value allows a field to be either an empty list or absent entirely, and both are interpreted the same way, then twiddle can be used to randomly pick either of these representations.

default twiddle ∷ ∀ p. (Generic a, TwiddleL (Rep a p)) ⇒ Version → a → Gen Term Source #

Instances

Instances details
Twiddle Void Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionVoidGen Term Source #

Twiddle Int64 Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionInt64Gen Term Source #

Twiddle ByteString Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Twiddle Term Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionTermGen Term Source #

Twiddle Text Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionTextGen Term Source #

Twiddle Integer Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionIntegerGen Term Source #

Twiddle Bool Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionBoolGen Term Source #

Twiddle Double Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionDoubleGen Term Source #

Twiddle Float Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionFloatGen Term Source #

Twiddle Int Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionIntGen Term Source #

Twiddle a ⇒ Twiddle (StrictSeq a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionStrictSeq a → Gen Term Source #

Twiddle a ⇒ Twiddle (Seq a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionSeq a → Gen Term Source #

Twiddle a ⇒ Twiddle (Set a) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionSet a → Gen Term Source #

Twiddle a ⇒ Twiddle [a] Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersion → [a] → Gen Term Source #

(Twiddle k, Twiddle v) ⇒ Twiddle (Map k v) Source # 
Instance details

Defined in Test.Cardano.Ledger.Binary.Twiddle

Methods

twiddleVersionMap k v → Gen Term Source #

toTwiddlerTwiddle a ⇒ Version → a → Gen (Twiddler a) Source #

Wraps an arbitrary value into a Twiddler

toTermEncCBOR a ⇒ Version → a → Term Source #

twiddleInvariantProp ∷ ∀ a. Twiddle a ⇒ Version → a → Gen Property Source #

Function for testing the invariant of a Twiddle instance. For a correct implementation, this property should always hold.

emptyOrNothing ∷ ∀ t b. (Foldable t, Twiddle (t Void), Monoid (t Void), Twiddle (t b)) ⇒ Version → t b → Gen (Maybe Term) Source #

Optional containers have two "empty" representations. One of them is to return an empty container and the other is to omit the field. This utility function randomly picks one of these representations, where omission is represented by Nothing and empty container is returned with Just. These values can then be easily concatenated with catMaybes.

twiddleStrictMaybeTwiddle a ⇒ VersionStrictMaybe a → Gen (Maybe Term) Source #

Utility function for twiddling optional fields. It works similarly to the twiddle method of StrictMaybe, but lifts the Maybe constructor out from the term so it can be easily concatenated with catMaybes.