Skip to content

Add goldenBundle and goldenBundle' test functions #7057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plutus-ledger-api/test-plugin/Spec/Data/ScriptContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import PlutusTx.TH (compile)

tests :: TestTree
tests =
runTestNested ["test-plugin", "Spec", "Data", "SriptContext"] . pure . testNestedGhc $
runTestNested ["test-plugin", "Spec", "Data", "ScriptContext"] . pure . testNestedGhc $
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes the following file renames:

plutus-ledger-api/test-plugin/Spec/Data/ScriptContext/9.6/alwaysSucceeds.pir.golden
plutus-ledger-api/test-plugin/Spec/Data/ScriptContext/9.6/alwaysSucceeds.uplc.golden
plutus-ledger-api/test-plugin/Spec/Data/ScriptContext/9.6/succeedsIfHasDatum.pir.golden
plutus-ledger-api/test-plugin/Spec/Data/ScriptContext/9.6/succeedsIfHasDatum.uplc.golden

But the contents stayed the same

[ goldenPirReadable "alwaysSucceeds" compiledAlwaysSucceeds
, goldenUPlcReadable "alwaysSucceeds" compiledAlwaysSucceeds
, goldenPirReadable "succeedsIfHasDatum" compiledSucceedsIfHasDatum
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cpu: 597469
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mem: 2006
size: 19
34 changes: 9 additions & 25 deletions plutus-tx-plugin/test/AsData/Budget/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,20 @@ import PlutusTx.Builtins qualified as PlutusTx
import PlutusTx.Code
import PlutusTx.IsData qualified as PlutusTx
import PlutusTx.Lift (liftCodeDef)
import PlutusTx.Test (goldenBudget, goldenEvalCekCatch, goldenPirReadable, goldenUPlcReadable)
import PlutusTx.Test (goldenBundle)
import PlutusTx.TH (compile)

tests :: TestNested
tests =
testNested ("AsData" </> "Budget") . pure $ testNestedGhc
[ goldenPirReadable "onlyUseFirstField" onlyUseFirstField
, goldenUPlcReadable "onlyUseFirstField" onlyUseFirstField
, goldenEvalCekCatch "onlyUseFirstField" [onlyUseFirstField `unsafeApplyCode` inp]
, goldenBudget "onlyUseFirstField" (onlyUseFirstField `unsafeApplyCode` inp)
, goldenPirReadable "onlyUseFirstField-manual" onlyUseFirstFieldManual
, goldenUPlcReadable "onlyUseFirstField-manual" onlyUseFirstFieldManual
, goldenEvalCekCatch "onlyUseFirstField-manual" [onlyUseFirstFieldManual `unsafeApplyCode` inp]
, goldenBudget "onlyUseFirstField-manual" (onlyUseFirstFieldManual `unsafeApplyCode` inp)
, goldenPirReadable "patternMatching" patternMatching
, goldenUPlcReadable "patternMatching" patternMatching
, goldenEvalCekCatch "patternMatching" [patternMatching `unsafeApplyCode` inp]
, goldenBudget "patternMatching" (patternMatching `unsafeApplyCode` inp)
, goldenPirReadable "recordFields" recordFields
, goldenUPlcReadable "recordFields" recordFields
, goldenEvalCekCatch "recordFields" [recordFields `unsafeApplyCode` inp]
, goldenBudget "recordFields" (recordFields `unsafeApplyCode` inp)
, goldenPirReadable "destructSum" destructSum
, goldenUPlcReadable "destructSum" destructSum
, goldenEvalCekCatch "destructSum" [destructSum `unsafeApplyCode` inpSum]
, goldenBudget "destructSum" (destructSum `unsafeApplyCode` inpSum)
, goldenPirReadable "destructSum-manual" destructSumManual
, goldenUPlcReadable "destructSum-manual" destructSumManual
, goldenEvalCekCatch "destructSum-manual" [destructSumManual `unsafeApplyCode` inpSumM]
, goldenBudget "destructSum-manual" (destructSumManual `unsafeApplyCode` inpSumM)
[ goldenBundle "onlyUseFirstField" onlyUseFirstField (onlyUseFirstField `unsafeApplyCode` inp)
, goldenBundle "onlyUseFirstField-manual" onlyUseFirstFieldManual
(onlyUseFirstFieldManual `unsafeApplyCode` inp)
, goldenBundle "patternMatching" patternMatching (patternMatching `unsafeApplyCode` inp)
, goldenBundle "recordFields" recordFields (recordFields `unsafeApplyCode` inp)
, goldenBundle "destructSum" destructSum (destructSum `unsafeApplyCode` inpSum)
, goldenBundle "destructSum-manual" destructSumManual
(destructSumManual `unsafeApplyCode` inpSumM)
]

-- A function that only accesses the first field of `Ints`.
Expand Down
15 changes: 3 additions & 12 deletions plutus-tx-plugin/test/AssocMap/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,9 @@ goldenTests :: TestNested
goldenTests =
testNested "Budget" . pure $
testNestedGhc
[ goldenPirReadable "map1" map1
, goldenUPlcReadable "map1" map1
, goldenEvalCekCatch "map1" $ [map1 `unsafeApplyCode` (liftCodeDef 100)]
, goldenBudget "map1" $ map1 `unsafeApplyCode` (liftCodeDef 100)
, goldenPirReadable "map2" map2
, goldenUPlcReadable "map2" map2
, goldenEvalCekCatch "map2" $ [map2 `unsafeApplyCode` (liftCodeDef 100)]
, goldenBudget "map2" $ map2 `unsafeApplyCode` (liftCodeDef 100)
, goldenPirReadable "map3" map3
, goldenUPlcReadable "map3" map3
, goldenEvalCekCatch "map3" $ [map3 `unsafeApplyCode` (liftCodeDef 100)]
, goldenBudget "map3" $ map3 `unsafeApplyCode` (liftCodeDef 100)
[ goldenBundle "map1" map1 (map1 `unsafeApplyCode` liftCodeDef 100)
, goldenBundle "map2" map2 (map2 `unsafeApplyCode` liftCodeDef 100)
, goldenBundle "map3" map3 (map3 `unsafeApplyCode` liftCodeDef 100)
]

propertyTests :: TestTree
Expand Down
57 changes: 57 additions & 0 deletions plutus-tx-plugin/test/Budget/9.6/matchAsDataE.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(let
Copy link
Contributor Author

@zeme-wana zeme-wana Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data Unit | Unit_match where
Unit : Unit
data Bool | Bool_match where
True : Bool
False : Bool
data (Tuple2 :: * -> * -> *) a b | Tuple2_match where
Tuple2 : a -> b -> Tuple2 a b
in
\(ds : (\a -> data) integer) ->
Tuple2_match
{integer}
{list data}
((let
b = list data
in
\(tup : pair integer b) ->
Tuple2
{integer}
{b}
(fstPair {integer} {b} tup)
(sndPair {integer} {b} tup))
(unConstrData ds))
{integer}
(\(ds : integer) (ds : list data) ->
Bool_match
(ifThenElse {Bool} (equalsInteger 0 ds) True False)
{all dead. integer}
(/\dead -> unIData (headList {data} ds))
(/\dead ->
Tuple2_match
{integer}
{list data}
((let
b = list data
in
\(tup : pair integer b) ->
Tuple2
{integer}
{b}
(fstPair {integer} {b} tup)
(sndPair {integer} {b} tup))
(unConstrData ds))
{integer}
(\(ds : integer) (ds : list data) ->
Bool_match
(ifThenElse {Bool} (equalsInteger 1 ds) True False)
{all dead. integer}
(/\dead -> 1)
(/\dead ->
let
!defaultBody : integer = error {integer}
in
Unit_match (error {Unit}) {integer} defaultBody)
{all dead. dead}))
{all dead. dead}))
(Constr 0 [I 1])
29 changes: 29 additions & 0 deletions plutus-tx-plugin/test/Budget/9.6/matchAsDataE.uplc.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(program
Copy link
Contributor Author

@zeme-wana zeme-wana Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1.0
((\ds ->
case
((\tup ->
constr 0
[(force (force fstPair) tup), (force (force sndPair) tup)])
(unConstrData ds))
[ (\ds ds ->
force
(force ifThenElse
(equalsInteger 0 ds)
(delay (unIData (force headList ds)))
(delay
(case
((\tup ->
constr 0
[ (force (force fstPair) tup)
, (force (force sndPair) tup) ])
(unConstrData ds))
[ (\ds ds ->
force
(force ifThenElse
(equalsInteger 1 ds)
(delay 1)
(delay
((\cse -> case cse [cse])
error)))) ])))) ])
(Constr 0 [I 1])))
1 change: 1 addition & 0 deletions plutus-tx-plugin/test/Budget/9.6/show.eval.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer -2469135780)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 changes: 7 additions & 8 deletions plutus-tx-plugin/test/Budget/9.6/sumAtIndices.pir.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
\(d-1579 : data) ->
\(d : data) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let
!nt-1580 : list data = tailList {data} (unListData d-1579)
!s-1581 : integer = unIData (headList {data} nt-1580)
!nt-1582 : list data
= tailList {data} (tailList {data} (tailList {data} nt-1580))
!s-1583 : integer = unIData (headList {data} nt-1582)
!s-1584 : integer = unIData (headList {data} (tailList {data} nt-1582))
!nt : list data = tailList {data} (unListData d)
!s : integer = unIData (headList {data} nt)
!nt : list data = tailList {data} (tailList {data} (tailList {data} nt))
!s : integer = unIData (headList {data} nt)
!s : integer = unIData (headList {data} (tailList {data} nt))
in
addInteger (addInteger s-1581 s-1583) s-1584
addInteger (addInteger s s) s
Loading