ouroboros-consensus-test-0.3.1.0: Tests of the consensus layer
Safe HaskellNone
LanguageHaskell2010

Test.Util.Serialisation.Roundtrip

Synopsis

Basic test helpers

roundtrip ∷ (Eq a, Show a) ⇒ (a → Encoding) → (∀ s. Decoder s a) → a → Property Source #

roundtrip' Source #

Arguments

∷ (Eq a, Show a) 
⇒ (a → Encoding)
enc
→ (∀ s. Decoder s (ByteString → a)) 
→ a 
→ Property 

Roundtrip property for values annotated with their serialized form

NOTE: Suppose a consists of a pair of the unannotated value a' and some ByteString. The roundtrip property will fail if that ByteString encoding is not equal to enc a'. One way in which this might happen is if the annotation is not canonical CBOR, but enc does produce canonical CBOR.

Test skeleton

type Arbitrary' a = (Arbitrary a, Eq a, Show a) Source #

Constraints needed in practice for something to be passed in as an Arbitrary argument to a QuickCheck property.

newtype Coherent a Source #

Used to generate slightly less arbitrary values

Like some other QuickCheck modifiers, the exact meaning is context-dependent. The original motivating example is that some of our serialization-adjacent properties require that the generated block contains a header and a body that match, ie are coherent.

Constructors

Coherent 

Fields

Instances

Instances details
Eq a ⇒ Eq (Coherent a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

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

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

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

Defined in Test.Util.Serialisation.Roundtrip

Generic (Coherent a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Associated Types

type Rep (Coherent a) ∷ TypeType Source #

Methods

fromCoherent a → Rep (Coherent a) x Source #

toRep (Coherent a) x → Coherent a Source #

type Rep (Coherent a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

type Rep (Coherent a) = D1 ('MetaData "Coherent" "Test.Util.Serialisation.Roundtrip" "ouroboros-consensus-test-0.3.1.0-inplace" 'True) (C1 ('MetaCons "Coherent" 'PrefixI 'True) (S1 ('MetaSel ('Just "getCoherent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

data SomeResult blk where Source #

To easily generate all the possible results of the Query GADT, we introduce an existential that also bundles the corresponding Query as evidence. We also capture Eq, Show, and Typeable constraints, as we need them in the tests.

Constructors

SomeResult ∷ (Eq result, Show result, Typeable result) ⇒ BlockQuery blk result → result → SomeResult blk 

Instances

Instances details
Eq (SomeResult blk) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

(==)SomeResult blk → SomeResult blk → Bool Source #

(/=)SomeResult blk → SomeResult blk → Bool Source #

Show (SomeResult blk) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

showsPrecIntSomeResult blk → ShowS Source #

showSomeResult blk → String Source #

showList ∷ [SomeResult blk] → ShowS Source #

data WithVersion v a Source #

Used to generate arbitrary values for the serialisation roundtrip tests. As the serialisation format can change with the version, not all arbitrary values of the type might be valid for each version.

For example, a certain constructor can only be used after a certain version and can thus not be generated for any prior versions.

Constructors

WithVersion v a 

Instances

Instances details
Functor (WithVersion v) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

fmap ∷ (a → b) → WithVersion v a → WithVersion v b Source #

(<$) ∷ a → WithVersion v b → WithVersion v a Source #

Foldable (WithVersion v) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

foldMonoid m ⇒ WithVersion v m → m Source #

foldMapMonoid m ⇒ (a → m) → WithVersion v a → m Source #

foldMap'Monoid m ⇒ (a → m) → WithVersion v a → m Source #

foldr ∷ (a → b → b) → b → WithVersion v a → b Source #

foldr' ∷ (a → b → b) → b → WithVersion v a → b Source #

foldl ∷ (b → a → b) → b → WithVersion v a → b Source #

foldl' ∷ (b → a → b) → b → WithVersion v a → b Source #

foldr1 ∷ (a → a → a) → WithVersion v a → a Source #

foldl1 ∷ (a → a → a) → WithVersion v a → a Source #

toListWithVersion v a → [a] Source #

nullWithVersion v a → Bool Source #

lengthWithVersion v a → Int Source #

elemEq a ⇒ a → WithVersion v a → Bool Source #

maximumOrd a ⇒ WithVersion v a → a Source #

minimumOrd a ⇒ WithVersion v a → a Source #

sumNum a ⇒ WithVersion v a → a Source #

productNum a ⇒ WithVersion v a → a Source #

Traversable (WithVersion v) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

traverseApplicative f ⇒ (a → f b) → WithVersion v a → f (WithVersion v b) Source #

sequenceAApplicative f ⇒ WithVersion v (f a) → f (WithVersion v a) Source #

mapMMonad m ⇒ (a → m b) → WithVersion v a → m (WithVersion v b) Source #

sequenceMonad m ⇒ WithVersion v (m a) → m (WithVersion v a) Source #

(Eq v, Eq a) ⇒ Eq (WithVersion v a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

(==)WithVersion v a → WithVersion v a → Bool Source #

(/=)WithVersion v a → WithVersion v a → Bool Source #

(Show v, Show a) ⇒ Show (WithVersion v a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

(blockVersion ~ BlockNodeToClientVersion blk, Arbitrary blockVersion, Arbitrary (WithVersion (BlockNodeToClientVersion blk) (SomeSecond BlockQuery blk))) ⇒ Arbitrary (WithVersion (QueryVersion, blockVersion) (SomeSecond Query blk)) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

arbitrary ∷ Gen (WithVersion (QueryVersion, blockVersion) (SomeSecond Query blk))

shrinkWithVersion (QueryVersion, blockVersion) (SomeSecond Query blk) → [WithVersion (QueryVersion, blockVersion) (SomeSecond Query blk)]

(Arbitrary version, Arbitrary a) ⇒ Arbitrary (WithVersion version a) Source #

This is OVERLAPPABLE because we have to override the default behaviour for e.g. Querys.

Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

arbitrary ∷ Gen (WithVersion version a)

shrinkWithVersion version a → [WithVersion version a]

prop_hashSizeConvertRawHash blk ⇒ Proxy blk → HeaderHash blk → Property Source #

roundtrip_ConvertRawHash ∷ (StandardHash blk, ConvertRawHash blk) ⇒ Proxy blk → HeaderHash blk → Property Source #

roundtrip_SerialiseNodeToClient ∷ ∀ blk. (SerialiseNodeToClientConstraints blk, Show (BlockNodeToClientVersion blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) blk, ArbitraryWithVersion (BlockNodeToClientVersion blk) (GenTx blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (ApplyTxErr blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (SomeSecond BlockQuery blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (SomeResult blk), ArbitraryWithVersion (QueryVersion, BlockNodeToClientVersion blk) (SomeSecond Query blk), EncodeDisk blk blk, DecodeDisk blk (ByteString → blk)) ⇒ CodecConfig blk → [TestTree] Source #

roundtrip_SerialiseNodeToNode ∷ ∀ blk. (SerialiseNodeToNodeConstraints blk, Show (BlockNodeToNodeVersion blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) blk, ArbitraryWithVersion (BlockNodeToNodeVersion blk) (Header blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (GenTx blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (GenTxId blk), EncodeDisk blk blk, DecodeDisk blk (ByteString → blk), HasNestedContent Header blk, EncodeDiskDep (NestedCtxt Header) blk, DecodeDiskDep (NestedCtxt Header) blk) ⇒ CodecConfig blk → [TestTree] Source #

roundtrip_all ∷ ∀ blk. (SerialiseDiskConstraints blk, SerialiseNodeToNodeConstraints blk, SerialiseNodeToClientConstraints blk, Show (BlockNodeToNodeVersion blk), Show (BlockNodeToClientVersion blk), StandardHash blk, GetHeader blk, Arbitrary' blk, Arbitrary' (Header blk), Arbitrary' (HeaderHash blk), Arbitrary' (LedgerState blk), Arbitrary' (AnnTip blk), Arbitrary' (ChainDepState (BlockProtocol blk)), ArbitraryWithVersion (BlockNodeToNodeVersion blk) blk, ArbitraryWithVersion (BlockNodeToNodeVersion blk) (Coherent blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (Header blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (GenTx blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (GenTxId blk), ArbitraryWithVersion (BlockNodeToNodeVersion blk) (SomeSecond (NestedCtxt Header) blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) blk, ArbitraryWithVersion (BlockNodeToClientVersion blk) (GenTx blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (ApplyTxErr blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (SomeSecond BlockQuery blk), ArbitraryWithVersion (BlockNodeToClientVersion blk) (SomeResult blk), ArbitraryWithVersion (QueryVersion, BlockNodeToClientVersion blk) (SomeSecond Query blk)) ⇒ CodecConfig blk → (∀ a. NestedCtxt_ blk Header a → Dict (Eq a, Show a)) → TestTree Source #

All roundtrip tests

roundtrip_envelopes ∷ ∀ blk. (SerialiseNodeToNode blk (SerialisedHeader blk), HasNestedContent Header blk) ⇒ CodecConfig blk → WithVersion (BlockNodeToNodeVersion blk) (SomeSecond (NestedCtxt Header) blk) → Property Source #

This is similar to the roundtrip tests for headers, except we don't start with a header but some fixed bytestring in the payload. This makes debugging a bit easier as we can focus on just the envelope.