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

Test.Cardano.Ledger.Binary.Cddl

Synopsis

Documentation

cddlRoundTripCborSpec Source #

Arguments

∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) 
Version

Serialization version

Text

Name of the CDDL variable to test

SpecWith CddlData 

Using the supplied CddlData inside the SpecWith generate random data and run the cddlRoundTripExpectation for the supplied CDDL variable

cddlRoundTripExpectation Source #

Arguments

∷ (HasCallStack, Show a, Eq a) 
Text 
Version

Version to use for decoding

Version

Version to use for encoding

Trip a a

Decode/encoder that needs tsting

CddlVarFile

Randomly generated data and the CDDL spec

Expectation 

Verify that random data generated is:

  • Decoded successfully into a Haskell type using the decoder in Trip and the version supplied
  • When reencoded conforms to the CDDL spec and produces valid FlatTerm
  • When decoded again from the bytes produced by the encoder matches the type exactly when it was decoded from random bytes

cddlRoundTripAnnCborSpec Source #

Arguments

∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) 
Version

Serialization version

Text

Cddl variable name

SpecWith CddlData 

Similar to cddlRoundTripCborSpec, but for Annotator.

cddlRoundTripAnnExpectation ∷ ∀ a. (HasCallStack, Show a, Eq a) ⇒ TextVersionVersionTrip a (Annotator a) → CddlVarFileExpectation Source #

Same as cddlRoundTripExpectation, but works for decoders that are wrapped into Annotator

Helper functions and types

newtype Cddl Source #

Contents of CDDL Spec

Constructors

Cddl 

Fields

newtype Cbor Source #

Binary form of CBOR data.

Constructors

Cbor 

Fields

newtype DiagCbor Source #

Human readable CBOR, which was randomly generated.

Constructors

DiagCbor 

data CddlData Source #

Constructors

CddlData 

Fields

data CddlVarFile Source #

Constructors

CddlVarFile 

Fields

beforeAllCddlFile Source #

Arguments

HasCallStack 
Int

Number of random cases to generate

IO [ByteString]

Action that produces a list of valid CDDL specs

SpecWith CddlData 
Spec 

Given an action that produces CDDL content, we combine it all into CddlData and make it available to every subsequent Spec. Important point about this is that the supplied action will only be executed once.

withCddlVarFile Source #

Arguments

HasCallStack 
Text

Name of the variable that will be tested

CddlData

CddlData that will be used for random data generation

→ (CddlVarFileIO b)

Action that can use the random data for roundtrip and conformance testing

IO b 

Given a CddlData and a CDDL variable name present in the supplied data, generate a CddlVarFile, that contains random data for that variable.

diagCborToCborHasCallStackDiagCborIO Cbor Source #

Convert randomly generated Cbor in special Diag (human readable) format to binary CBOR format

validateCddlConformance Source #

Arguments

FilePath

File path to the file with CDDL spec

ByteString

CBOR encoded data that should conform with CDDL spec

IO (Either String ByteString) 

Run a cddl process and validate that encoded data is in confomrance with the supplied CDDL spec

readProcessNoFailureStringProcessConfig stdin stdout stderr → ByteStringIO (Either String ByteString) Source #

Run a process with readProcess and return Left on failure, which will contain the output produced on stderr. Accepts lazy bytestring as input for the spawned process. In case when a process exits successfuly, the output is returned on the Right. Upon a successful exit, stderr output is ignored to avoid polluting test suite output with copious amounts of warnings.

usingTempFileByteString → (FilePathIO a) → IO a Source #

Write binary data to a temporary file and apply an action to a temporary file name path that contains that data. File is guaranteed to be alive only until the supplied action is active, therefore make sure not to return the name for the temporary file name.