mlabs-haskell / lambda-buffers

LambdaBuffers toolkit for sharing types and their semantics between different languages
https://mlabs-haskell.github.io/lambda-buffers/
Apache License 2.0
29 stars 0 forks source link

Catalyst milestone 3: Testing and documentation #89

Closed bladyjoker closed 11 months ago

bladyjoker commented 1 year ago

Outputs

Acceptance Criteria

Evidence of Milestone Completion

References:

bladyjoker commented 1 year ago

Documentation strategy

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.

Testing strategy

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"]}.

Testing encoding typeclasses: from . to goldens

For each typeclass, we maintain a set of golden' files of known good/bad that lift into the target language withfromand write it back withto` 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:

Testing equality typeclasses: symmetry and transitivity

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.

TODO (provide time estimates)

  1. Define the version 1 of Prelude and Plutus LBF libraries which MUST be supported
  2. Support the Json typeclass
    1. Codegen
    2. Runtime support
  3. Support the Plutarch backend
  4. Document typeclasses
    1. Eq
    2. PlutusData
    3. Json
  5. Document backends
    1. Sum/Product/Record type construction and deconstruction (Haskell, Purescript, Plutarch)
    2. Eq/Json/PlutusData typeclass use (Haskell, Purescript, Plutarch minus Json)
  6. Devise goldens
    1. Eq
    2. PlutusData
    3. Json
  7. Implement the test suite
    1. Provide assertions
    2. Hook to the CI