packages feed

morley-0.4.0: test/Test/Lorentz/Print.hs

{-# LANGUAGE DeriveAnyClass #-}

-- | Tests on Lorentz contracts pretty-printing.
module Test.Lorentz.Print
  ( test_Print_parameter_annotations
  ) where

import Test.HUnit ((@?=))
import Test.Tasty (TestTree)
import Test.Tasty.HUnit (testCase)

import qualified Lorentz as L
import Lorentz.EntryPoints
import Lorentz.Run
import Michelson.Printer.Util (buildRenderDoc)
import Michelson.Typed
import Michelson.Untyped (para)

data MyEntryPoints1
  = Do1 Integer
  | Do2 (Integer, Integer)
  | Do3
  deriving stock Generic
  deriving anyclass IsoValue

instance ParameterEntryPoints MyEntryPoints1 where
  parameterEntryPoints = pepPlain

contract :: L.Contract MyEntryPoints1 ()
contract = L.drop L.# L.unit L.# L.nil L.# L.pair

test_Print_parameter_annotations :: [TestTree]
test_Print_parameter_annotations =
  [ testCase "Simple parameter" $
      let typedContract = compileLorentzContract contract
          untypedContract = convertFullContract typedContract
      in buildRenderDoc (para untypedContract)
         @?=
         "or (int %do1) (or (pair %do2 int int) (unit %do3))"
  ]