Safe Haskell | None |
---|---|
Language | Haskell2010 |
Test.Util.Serialisation.Roundtrip
Contents
Synopsis
- roundtrip ∷ (Eq a, Show a) ⇒ (a → Encoding) → (∀ s. Decoder s a) → a → Property
- roundtrip' ∷ (Eq a, Show a) ⇒ (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 SomeResult blk where
- SomeResult ∷ (Eq result, Show result, Typeable result) ⇒ BlockQuery blk result → result → SomeResult blk
- 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)) ⇒ 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_envelopes ∷ ∀ blk. (SerialiseNodeToNode blk (SerialisedHeader blk), HasNestedContent Header blk) ⇒ CodecConfig blk → WithVersion (BlockNodeToNodeVersion blk) (SomeSecond (NestedCtxt Header) blk) → Property
Basic test helpers
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.
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
|
data SomeResult blk where Source #
To easily generate all the possible result
s 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
Eq (SomeResult blk) Source # | |
Defined in Test.Util.Serialisation.Roundtrip Methods (==) ∷ SomeResult blk → SomeResult blk → Bool Source # (/=) ∷ SomeResult blk → SomeResult blk → Bool Source # | |
Show (SomeResult blk) Source # | |
Defined in Test.Util.Serialisation.Roundtrip |
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
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)) ⇒ 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.