Skip to content

Commit b7c7dae

Browse files
committed
Various fixes and additions to the testsuite (Prelude types in Plutus etc)
1 parent 19cb362 commit b7c7dae

File tree

87 files changed

+421
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+421
-329
lines changed

lambda-buffers-codegen/src/LambdaBuffers/Codegen/Plutarch.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ plutarchPrintModuleEnv =
4848
, "DerivingStrategies"
4949
, "DeriveAnyClass"
5050
, "DeriveGeneric"
51+
, "UndecidableInstances"
5152
]

lambda-buffers-codegen/src/LambdaBuffers/Codegen/Purescript/Print/InstanceDef.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ printShowInstance :: MonadPrint m => PC.TyDef -> m (Doc ann)
6565
printShowInstance tyd = do
6666
importClass showClass
6767
importValue genericShow
68-
return $ printInstanceDef showClass (toSaturatedTyApp tyd) ("show" <+> equals <+> printPursQValName genericShow)
68+
return $ printInstanceDef showClass (toSaturatedTyApp tyd) ("show x" <+> equals <+> printPursQValName genericShow <+> "x")
6969

7070
{- | `printDerive qcn tyD` prints a Purescript `derive instance` statement for a type class `qcn` for a type definition `tyd`.
7171
For a `Show` type class on a `Maybe a` type definition it prints

lambda-buffers-codegen/src/LambdaBuffers/Codegen/Purescript/Print/LamVal.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import LambdaBuffers.Codegen.Purescript.Syntax (normalValName)
1414
import LambdaBuffers.Codegen.Purescript.Syntax qualified as Purs
1515
import LambdaBuffers.Compiler.LamTy qualified as LT
1616
import LambdaBuffers.ProtoCompat qualified as PC
17-
import Prettyprinter (Doc, Pretty (pretty), align, colon, comma, dot, dquotes, encloseSep, equals, group, hsep, lbrace, lbracket, line, lparen, parens, rbrace, rbracket, rparen, space, vsep, (<+>))
17+
import Prettyprinter (Doc, Pretty (pretty), align, colon, comma, dot, dquotes, encloseSep, equals, group, hardline, hsep, lbrace, lbracket, line, lparen, parens, rbrace, rbracket, rparen, space, vsep, (<+>))
1818
import Proto.Codegen_Fields qualified as P
1919

2020
type MonadPrint m = LV.MonadPrint m Purs.QValName
@@ -52,11 +52,13 @@ printCaseE :: MonadPrint m => (PC.QTyName, LV.Sum) -> LV.ValueE -> ((LV.Ctor, [L
5252
printCaseE (qtyN, sumTy) caseVal ctorCont = do
5353
caseValDoc <- printValueE caseVal
5454
ctorCaseDocs <-
55-
vsep
55+
align . encloseSep mempty mempty mempty
5656
<$> for
5757
(OMap.assocs sumTy)
5858
( \(cn, ty) -> case ty of -- TODO(bladyjoker): Cleanup by refactoring LT.Ty.
59-
LT.TyProduct fields _ -> printCtorCase qtyN ctorCont (cn, fields)
59+
LT.TyProduct fields _ -> do
60+
ctorCaseDoc <- printCtorCase qtyN ctorCont (cn, fields)
61+
return $ ctorCaseDoc <> hardline
6062
_ -> throwInternalError "Got a non-product in Sum."
6163
)
6264
return $ align $ "case" <+> caseValDoc <+> "of" <> line <> ctorCaseDocs

libs/lbf-plutus/Plutus/V1.lbf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ instance Eq PlutusData
1313
instance Json PlutusData
1414

1515
-- Instances for Prelude types
16-
-- TODO(bladyjoker): Add other Prelude types (Maybe, Either, Text, Bytes etc.)
16+
-- TODO(bladyjoker): Add other Prelude types (Text, Bytes etc.)?
1717
instance PlutusData Bool
1818
instance PlutusData Integer
1919
instance PlutusData (Maybe a) :- PlutusData a

runtimes/haskell/lbr-plutarch/build.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
installPhase = "ln -s $src $out";
5858
};
5959

60-
# lbr-plutarch-tests = hsNixFlake.packages."lbr-plutarch:test:tests";
60+
lbr-plutarch-tests = hsNixFlake.packages."lbr-plutarch:test:tests";
6161
};
6262

63-
# checks.check-lbr-plutarch = hsNixFlake.checks."lbr-plutarch:test:tests";
63+
checks.check-lbr-plutarch = hsNixFlake.checks."lbr-plutarch:test:tests";
6464

6565
};
6666
}

runtimes/haskell/lbr-plutus/src/LambdaBuffers/Runtime/Plutus/Json.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,29 @@ instance Json PlutusV1.TxOutRef where
296296
return $ PlutusV1.TxOutRef txId index
297297
)
298298

299+
instance Json PlutusV1.TxOut where
300+
toJson (PlutusV1.TxOut addr val datHash) = object ["address" .= toJson addr, "value" .= toJson val, "datum_hash" .= toJson datHash]
301+
fromJson =
302+
withObject
303+
"Plutus.V1.TxOut"
304+
( \obj -> do
305+
addr <- obj .: "address"
306+
val <- obj .: "value"
307+
datHash <- obj .: "datum_hash"
308+
return $ PlutusV1.TxOut addr val datHash
309+
)
310+
311+
instance Json PlutusV1.TxInInfo where
312+
toJson (PlutusV1.TxInInfo outRef out) = object ["reference" .= toJson outRef, "output" .= toJson out]
313+
fromJson =
314+
withObject
315+
"Plutus.V1.TxInInfo"
316+
( \obj -> do
317+
outRef <- obj .: "reference"
318+
out <- obj .: "output"
319+
return $ PlutusV1.TxInInfo outRef out
320+
)
321+
299322
instance Json PlutusV2.TxOut where
300323
toJson (PlutusV2.TxOut addr val dat mayRefScript) = object ["address" .= toJson addr, "value" .= toJson val, "datum" .= toJson dat, "reference_script" .= toJson mayRefScript]
301324
fromJson =

testsuites/lbt-plutus/api/Foo.lbf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Foo
33
import Foo.Bar
44
import Plutus.V1 (PlutusData, Address, AssetClass, Bytes, Credential, CurrencySymbol, Datum, DatumHash, Extended, Interval, LowerBound, Map, POSIXTime, POSIXTimeRange, PlutusData, PubKeyHash, Redeemer, RedeemerHash, ScriptHash, StakingCredential, TokenName, TxId, TxOutRef, UpperBound, Value)
55
import Plutus.V2 (OutputDatum, TxInInfo, TxOut)
6-
import Prelude (Eq, Json, Maybe, Either, List)
6+
import Prelude (Eq, Json, Maybe, Either, List, Integer)
77

88
prod A = (FooSum Address Value Datum)
99

@@ -63,3 +63,15 @@ prod E a b = Address
6363
derive Eq (E a b)
6464
derive Json (E a b)
6565
derive PlutusData (E a b)
66+
67+
prod FInt = (F Integer)
68+
69+
derive Eq FInt
70+
derive Json FInt
71+
derive PlutusData FInt
72+
73+
prod GInt = (G Integer)
74+
75+
derive Eq GInt
76+
derive Json GInt
77+
derive PlutusData GInt

testsuites/lbt-plutus/api/Foo/Bar.lbf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,18 @@ record FooComplicated a b c = {
2929

3030
derive Eq (FooComplicated a b c)
3131
derive Json (FooComplicated a b c)
32-
derive PlutusData (FooComplicated a b c)
32+
derive PlutusData (FooComplicated a b c)
33+
34+
-- Making sure recursive definitions work.
35+
36+
sum F a = Rec (G a) | Nil
37+
38+
derive Eq (F a)
39+
derive Json (F a)
40+
derive PlutusData (F a)
41+
42+
sum G a = Rec (F a) | Nil
43+
44+
derive Eq (G a)
45+
derive Json (G a)
46+
derive PlutusData (G a)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"fields":[1],"name":"Integer"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"fields":[{"fields":[{"fields":[1],"name":"Integer"}],"index":0}],"name":"Constr"}

0 commit comments

Comments
 (0)