Skip to content

Commit 231b376

Browse files
committed
Added Bounded plugin tests
1 parent ec7d785 commit 231b376

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

plutus-tx-plugin/plutus-tx-plugin.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ test-suite plutus-tx-plugin-tests
116116
main-is: Spec.hs
117117
other-modules:
118118
Array.Spec
119+
Bounded.Spec
119120
AsData.Budget.Spec
120121
AsData.Budget.Types
121122
AssocMap.Golden
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{-# LANGUAGE BlockArguments #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE TemplateHaskell #-}
5+
{-# LANGUAGE NoImplicitPrelude #-}
6+
{-# LANGUAGE TypeApplications #-}
7+
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-}
8+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-cse-iterations=0 #-}
9+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-pir=0 #-}
10+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-uplc=0 #-}
11+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-optimize #-}
12+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-simplifier-beta #-}
13+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-simplifier-evaluate-builtins #-}
14+
15+
module Bounded.Spec where
16+
17+
import PlutusTx
18+
import PlutusTx.Test (goldenPirReadable)
19+
import Test.Tasty.Extras
20+
import PlutusTx.Bounded
21+
import PlutusTx.Prelude
22+
import PlutusTx.Plugin (plc)
23+
import Data.Proxy (Proxy (..))
24+
25+
data SomeVeryLargeEnum
26+
= E1
27+
| E2
28+
| E3
29+
| E4
30+
| E5
31+
| E6
32+
| E7
33+
| E8
34+
| E9
35+
| E10
36+
deriveBounded ''SomeVeryLargeEnum
37+
38+
data SingleConstructor a = SingleConstructor Bool a ()
39+
deriveBounded ''SingleConstructor
40+
41+
newtype PhantomADT e = PhantomADT ()
42+
deriveBounded ''PhantomADT
43+
44+
minAndMax :: Bounded a => (a, a)
45+
minAndMax = (minBound,maxBound)
46+
47+
compiledSomeVeryLargeEnum :: CompiledCode (SomeVeryLargeEnum, SomeVeryLargeEnum)
48+
compiledSomeVeryLargeEnum = plc (Proxy @"compiledSomeVeryLargeEnum") minAndMax
49+
50+
compiledSingleConstructor :: CompiledCode (SingleConstructor Ordering, SingleConstructor Ordering)
51+
compiledSingleConstructor = plc (Proxy @"compiledSingleConstructor") minAndMax
52+
53+
{- here cannot use Ordering or Either as the phantom type because of
54+
pir compile error (unrelated to Bounded):
55+
GHC Core to PLC plugin: Error: Error from the PIR compiler:
56+
Error during compilation: Type bindings cannot appear in recursive let, use datatypebind instead
57+
See https://github.com/IntersectMBO/plutus/issues/7498
58+
-}
59+
compiledPhantomADT :: CompiledCode (PhantomADT Bool, PhantomADT Bool)
60+
compiledPhantomADT = plc (Proxy @"compiledPhantomADT") minAndMax
61+
62+
tests :: TestNested
63+
tests =
64+
testNested
65+
"Bounded"
66+
[ testNestedGhc
67+
[ goldenPirReadable "SomeVeryLargeEnum" compiledSomeVeryLargeEnum
68+
, goldenPirReadable "SingleConstructor" compiledSingleConstructor
69+
, goldenPirReadable "PhantomADT" compiledPhantomADT
70+
]
71+
]

plutus-tx-plugin/test/Spec.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Main (main) where
22

3+
import Bounded.Spec qualified as Bounded
34
import Array.Spec qualified as Array
45
import AsData.Budget.Spec qualified as AsData.Budget
56
import AssocMap.Spec qualified as AssocMap
@@ -61,5 +62,6 @@ tests =
6162
, embed AssocMap.propertyTests
6263
, embed List.propertyTests
6364
, Array.smokeTests
65+
, Bounded.tests
6466
, CallTrace.tests
6567
]

plutus-tx/src/PlutusTx/Prelude.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module PlutusTx.Prelude
2020
module Eq
2121
, module Enum
2222
, module Ord
23+
, module Bounded
2324
, module Semigroup
2425
, module Monoid
2526
, module Numeric
@@ -230,6 +231,7 @@ import PlutusTx.Builtins
230231
, verifySchnorrSecp256k1Signature
231232
)
232233

234+
import PlutusTx.Bounded as Bounded
233235
import PlutusTx.Builtins qualified as Builtins
234236
import PlutusTx.Builtins.Internal qualified as BI
235237
import PlutusTx.Either as Either

0 commit comments

Comments
 (0)