Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- roundtrip ∷ (Eq a, Show a) ⇒ (a → Encoding) → (∀ s. Decoder s a) → a → Property
- roundtrip' ∷ ∀ a. (Eq a, Show a) ⇒ (a → Encoding) → (∀ s. Decoder s (ByteString → a)) → a → Property
- roundtripAnd ∷ ∀ a. (Eq a, Show a) ⇒ ShouldCheckCBORValidity → (a → Encoding) → (∀ s. Decoder s (ByteString → a)) → a → Property
- type Arbitrary' a = (Arbitrary a, Eq a, Show a)
- newtype Coherent a = Coherent {
- getCoherent ∷ a
- data WithVersion v a = WithVersion v a
- prop_hashSize ∷ ConvertRawHash blk ⇒ Proxy blk → HeaderHash blk → Property
- roundtrip_ConvertRawHash ∷ (StandardHash blk, ConvertRawHash blk) ⇒ Proxy blk → HeaderHash blk → Property
- roundtrip_SerialiseDisk ∷ ∀ blk. (SerialiseDiskConstraints blk, Arbitrary' blk, Arbitrary' (Header blk), Arbitrary' (LedgerState blk), Arbitrary' (AnnTip blk), Arbitrary' (ChainDepState (BlockProtocol blk))) ⇒ CodecConfig blk → (∀ a. NestedCtxt_ blk Header a → Dict (Eq a, Show a)) → [TestTree]
- 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)) ⇒ (TestName → ShouldCheckCBORValidity) → CodecConfig blk → [TestTree]
- 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]
- 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
- 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)) ⇒ (TestName → ShouldCheckCBORValidity) → CodecConfig blk → (∀ a. NestedCtxt_ blk Header a → Dict (Eq a, Show a)) → TestTree
- roundtrip_envelopes ∷ ∀ blk. (SerialiseNodeToNode blk (SerialisedHeader blk), HasNestedContent Header blk) ⇒ CodecConfig blk → WithVersion (BlockNodeToNodeVersion blk) (SomeSecond (NestedCtxt Header) blk) → Property
- data ShouldCheckCBORValidity
- examplesRoundtrip ∷ ∀ blk. (SerialiseDiskConstraints blk, Eq blk, Show blk, LedgerSupportsProtocol blk) ⇒ CodecConfig blk → Examples blk → [TestTree]
Basic test helpers
Perform roundtrip tests, checking the validity of the encoded CBOR.
See roundtripAnd
∷ ∀ 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.
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.
Coherent | |
|
Instances
Generic (Coherent a) Source # | |
Show a ⇒ Show (Coherent a) Source # | |
Eq a ⇒ Eq (Coherent a) Source # | |
type Rep (Coherent a) Source # | |
Defined in Test.Util.Serialisation.Roundtrip type Rep (Coherent a) = D1 ('MetaData "Coherent" "Test.Util.Serialisation.Roundtrip" "ouroboros-consensus-0.21.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.
WithVersion v a |
Instances
prop_hashSize ∷ ConvertRawHash blk ⇒ Proxy blk → HeaderHash blk → Property Source #
roundtrip_ConvertRawHash ∷ (StandardHash blk, ConvertRawHash blk) ⇒ Proxy blk → HeaderHash blk → Property Source #
roundtrip_SerialiseDisk ∷ ∀ blk. (SerialiseDiskConstraints blk, Arbitrary' blk, Arbitrary' (Header blk), Arbitrary' (LedgerState blk), Arbitrary' (AnnTip blk), Arbitrary' (ChainDepState (BlockProtocol blk))) ⇒ CodecConfig blk → (∀ a. NestedCtxt_ blk Header a → Dict (Eq a, Show a)) → [TestTree] 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)) ⇒ (TestName → ShouldCheckCBORValidity) → 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)) ⇒ (TestName → ShouldCheckCBORValidity) → 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:
- Node to client tests due to this issue.
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
data ShouldCheckCBORValidity Source #
Instances
Roundtrip tests for Example
s
examplesRoundtrip ∷ ∀ blk. (SerialiseDiskConstraints blk, Eq blk, Show blk, LedgerSupportsProtocol blk) ⇒ CodecConfig blk → Examples blk → [TestTree] Source #