Skip to content

Commit

Permalink
Add certifier golden testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-pantilie committed Nov 11, 2024
1 parent 7a9a2da commit 4403a3a
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 3 deletions.
5 changes: 2 additions & 3 deletions plutus-executables/executables/uplc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import Agda.Syntax.Translation.ConcreteToAbstract (ToAbstract (toAbstract))
import Agda.TypeChecking.Pretty (PrettyTCM (..))
import Agda.Utils.FileName qualified as HAgda.File
import AgdaUnparse (agdaUnparse)
import Data.Text qualified as Text
import System.Environment (getEnv)

uplcHelpText :: String
Expand Down Expand Up @@ -319,7 +318,7 @@ runAgda certName rawTrace = do
Left err -> error $ show err
stdlibPath <- getEnv "AGDA_STDLIB_SRC"
metatheoryPath <- getEnv "PLUTUS_METHATHEORY_SRC"
let inputFile = HAgda.File.AbsolutePath (Text.pack $ metatheoryPath </> "Certifier.agda")
inputFile <- HAgda.File.absolute (metatheoryPath </> "Certifier.agda")
runTCMPrettyErrors $ do
let opts =
defaultOptions
Expand All @@ -336,7 +335,7 @@ runAgda certName rawTrace = do
internalisedTrace <- toAbstract parsedTrace
decisionProcedureResult <- evalInCurrent DefaultCompute internalisedTrace
final <- prettyTCM decisionProcedureResult
liftIO $ writeFile (certName ++ ".agda") (show final)
liftIO $ writeFile certName (show final)

---------------- Script application ----------------

Expand Down
15 changes: 15 additions & 0 deletions plutus-executables/plutus-executables.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,18 @@ test-suite test-detailed
build-tool-depends:
, plutus-executables:plc
, plutus-executables:uplc

test-suite test-certifier
import: lang, os-support
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: test/certifier
build-depends:
, base
, directory
, filepath
, process
, tasty
, tasty-golden

build-tool-depends: plutus-executables:uplc
43 changes: 43 additions & 0 deletions plutus-executables/test/certifier/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Main (main) where

import System.Directory (withCurrentDirectory)
import System.FilePath (dropExtensions, (<.>), (</>))
import System.Process (callProcess)
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.Golden (findByExtension, goldenVsFile)

path :: String
path = "test/certifier/"

package :: String
package = "plutus-executables"

mkTestCase :: FilePath -> TestTree
mkTestCase input =
let expectedCert = dropExtensions input <.> "out" <.> "golden"
actualCert = dropExtensions input <.> "out"
in goldenVsFile input expectedCert actualCert (mkTest input actualCert)

mkTest :: FilePath -> FilePath -> IO ()
mkTest input testName = do
-- This is a hack which is necessary because we rely on the
-- PLUTUS_METHATHEORY_SRC environment variable
withCurrentDirectory ".."
-- TODO: ignore stdout, capture stderr and exceptions
$ callProcess
"uplc"
[ "optimise"
, "-i"
, package </> input
, "--certify"
, package </> testName
]

main :: IO ()
main = do
uplcFiles <- findByExtension [".uplc"] path
defaultMain
$ testGroup "certifier"
$ mkTestCase
<$> uplcFiles

Loading

0 comments on commit 4403a3a

Please sign in to comment.