Closed bladyjoker closed 11 months ago
Each typeclass receives a Specification document that closely explains the required semantics for LB types (sum/products/records).
Each backend receives a User documentation that elaborates on how the generated code is used.
LambdaBuffers works with typeclasses, such as Eq, PlutusData and JSON. When a LB type has been declared with support for any of such typeclass, values of said types need to be handled in exactly the same manner as elaborated in the Specification for a given Typeclass in ALL support target language environments.
Concretely, if a type Foo
has been declared with support for JSON
, and toJson
and fromJson
methods have been generated for target languages, they have to be in correspondence.
module Foo
import Prelude (Json)
sum Foo = Bar Integer | Baz Text
deriving Json Foo
In Haskell and Purescript values of Foo
would be Bar 1
and Baz "baz"
, and their respective JSON mappings would be {"constructor" : "Bar", "product" : [1]}
and {"constructor" : "Baz", "product" : ["baz"]}
.
from . to
goldensFor each typeclass, we maintain a set of golden' files of known good/bad that lift into the target language with
fromand write it back with
to` into a separate file. Then we provide an assertion that these files are semantically 'equal' (for example JSON spaces don't matter and such).
Example test:
sym :: (a :~: b) -> b :~: a
trans :: (a :~: b) -> (b :~: c) -> a :~: c
This could be done with goldens and randomized testing. However, goldens
approach assumes a correct marshaling procedure while the randomized
assumes generators. Perhaps having both makes sense.
Prelude
and Plutus
LBF libraries which MUST be supportedgoldens
Outputs
[x] A test suite checking for correct mapping from schema data types to PlutusData encodings against a known-good corpus of such mappings (golden tests).
Plutus.V1.PlutusData
derivation testsforall (golden : Days.Day.*.pd.json): (toJson . toPlutusData . fromPlutusData . fromJson) golden == golden
forall (x : Foo.*): (fromPlutusData . toPlutusData) x == x
Plutus.V1.PlutusData
instance testsforall (golden : *.pd.json): (toJson . toPlutusData . fromPlutusData . fromJson) golden == golden
[x] A test suite checking for roundtrip compatibility between codegened target environments.
[x] A modular and contract-based test suite architecture streamlining codegen testing compliance for any of the supported typeclasses.
lbt
(ie. a LambdaBuffers test suite) for the corresponding LambdaBuffers package. A package is a collection of LambdaBuffers schemas and their associated runtime libraries.[x] A document mapping the schema data types and typeclasses to their corresponding code-generated variants in the target environments.
Acceptance Criteria
Evidence of Milestone Completion
lbf
(LambdaBuffers Frontend) test suite.References: