add golden tests

This commit is contained in:
Kylix Afonso 2023-03-15 11:08:40 +00:00
parent e9053be78f
commit 18b3801c99
6 changed files with 305 additions and 1 deletions

View file

@ -4,6 +4,10 @@ This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0).
## Unreleased (Candidate for 1.0.0)
### Added
- Golden tests for the script exports.
### Modified
- For consistency and performance, the following data types are encoded as flat

44
agora-test/Golden.hs Normal file
View file

@ -0,0 +1,44 @@
module Golden (testGolden) where
import Agora.Bootstrap qualified as Bootstrap
import Agora.Linker (linker)
import Data.ByteString.Lazy qualified as LBS
import Data.Text qualified as Text
import Plutarch (Config (Config), TracingMode (DoTracing, NoTracing))
import ScriptExport.File qualified as ScriptExport
import ScriptExport.Options qualified as ScriptExport
import ScriptExport.Types qualified as ScriptExport
import System.Directory (createDirectoryIfMissing)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Golden (goldenVsString)
import Test.Tasty.Providers (TestName)
builders :: ScriptExport.Builders
builders =
mconcat
[ ScriptExport.insertScriptExportWithLinker "agora" (Bootstrap.agoraScripts (Config NoTracing)) linker
, ScriptExport.insertScriptExportWithLinker "agoraDebug" (Bootstrap.agoraScripts (Config DoTracing)) linker
]
testGolden :: TestTree
testGolden =
testGroup
"Golden tests for script export"
[ goldenTest "agora" "./agora-test/goldens/"
, goldenTest "agoraDebug" "./agora-test/goldens/"
]
goldenTest :: TestName -> FilePath -> TestTree
goldenTest builder outputPath =
goldenVsString
builder
(outputPath <> builder <> "-golden.json")
(callExportScript builder outputPath)
-- Call the script server and generate an unapplied script set.
callExportScript :: String -> FilePath -> IO LBS.ByteString
callExportScript builder outputPath = do
_ <- createDirectoryIfMissing False outputPath
let sampleFilePath = outputPath <> builder <> ".json"
ScriptExport.runFile builders (ScriptExport.FileOptions {out = outputPath, param = "", builder = Text.pack builder})
LBS.readFile sampleFilePath

View file

@ -1,4 +1,5 @@
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Golden qualified
import Test.Tasty (defaultMain, testGroup)
--------------------------------------------------------------------------------
@ -22,7 +23,8 @@ main = do
defaultMain $
testGroup
"test suite"
[ testGroup
[ Golden.testGolden
, testGroup
"Effects"
[ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
, toTestTree $ group "Governor Mutation Effect" GovernorMutation.specs

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -126,6 +126,7 @@ common test-deps
, agora
, cryptonite
, data-default-class
, directory
, memory
, mtl
, plutarch-context-builder
@ -133,6 +134,7 @@ common test-deps
, QuickCheck
, quickcheck-instances
, tasty
, tasty-golden
, tasty-hedgehog
, tasty-hunit
, tasty-quickcheck
@ -231,7 +233,9 @@ test-suite agora-test
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: agora-test
other-modules: Golden
build-depends:
, agora
, agora-specs
, agora-testlib