ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
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

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

Perform roundtrip tests, checking the validity of the encoded CBOR.

See roundtripAnd

roundtripAnd Source #

Arguments

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

Roundtrip property for values annotated with their serialized form

If CheckCBORValidity is passed, then we check that the encoded CBOR is valid using validFlatTerm. In general we want to check this, however there are cases where legacy encoders do not produce valid CBOR but we need to keep them for backwards compatibility. In such cases, the option to skip this check (DoNotCheckCBORValidity) can be used.

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
Generic (Coherent a) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Associated Types

type Rep (Coherent a) ∷ TypeType #

Methods

fromCoherent a → Rep (Coherent a) x #

toRep (Coherent a) x → Coherent a #

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

Defined in Test.Util.Serialisation.Roundtrip

Methods

showsPrecIntCoherent a → ShowS #

showCoherent a → String #

showList ∷ [Coherent a] → ShowS #

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

Defined in Test.Util.Serialisation.Roundtrip

Methods

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

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

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-0.18.0.0-inplace-unstable-consensus-testlib" 'True) (C1 ('MetaCons "Coherent" 'PrefixI 'True) (S1 ('MetaSel ('Just "getCoherent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

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
Foldable (WithVersion v) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

foldMonoid m ⇒ WithVersion v m → m #

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

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

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

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

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

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

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

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

toListWithVersion v a → [a] #

nullWithVersion v a → Bool #

lengthWithVersion v a → Int #

elemEq a ⇒ a → WithVersion v a → Bool #

maximumOrd a ⇒ WithVersion v a → a #

minimumOrd a ⇒ WithVersion v a → a #

sumNum a ⇒ WithVersion v a → a #

productNum a ⇒ WithVersion v a → a #

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) #

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

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

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

Functor (WithVersion v) Source # 
Instance details

Defined in Test.Util.Serialisation.Roundtrip

Methods

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

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

(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

arbitraryGen (WithVersion (QueryVersion, blockVersion) (SomeSecond Query blk)) Source #

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

(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

arbitraryGen (WithVersion version a) Source #

shrinkWithVersion version a → [WithVersion version a] Source #

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

Defined in Test.Util.Serialisation.Roundtrip

Methods

showsPrecIntWithVersion v a → ShowS #

showWithVersion v a → String #

showList ∷ [WithVersion v a] → ShowS #

(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 #

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

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)) ⇒ (TestNameShouldCheckCBORValidity) → 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_all_skipping ∷ ∀ 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)) ⇒ (TestNameShouldCheckCBORValidity) → CodecConfig blk → (∀ a. NestedCtxt_ blk Header a → Dict (Eq a, Show a)) → TestTree Source #

All roundtrip tests, skipping the specified CBOR validity tests.

TODO: the exclusion rule should only be considered for blocks before Conway!

The TestName corresponds to the name of the roundtrip property being tested. At the moment we consider for exclusion:

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.

Exclusion of CBOR validity tests

Roundtrip tests for Examples