plutus-conformance-1.0.0.0: Conformance Test Suite for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusConformance.Common

Description

Plutus conformance test suite library.

Synopsis

Documentation

shownParseErrorText Source #

The text shown when a file fails to parse or decode. We don't want to show the detailed errors so that users of the test suite can produce the expected output more easily. This is used in .uplc.expected and .budget.expected files.

shownEvaluationFailureText Source #

The text shown when evaluation fails. This is used in .uplc.expected and .budget.expected files.

parseTxtTextEither ParserErrorBundle (Program Name DefaultUni DefaultFun SrcSpan) Source #

The default parser to parse UPLC program inputs. FIXME: unlike the flat decoder, this does not detect free variables: they will only be detected if/when we deBruijnify the program.

type UplcProg = Program Name DefaultUni DefaultFun () Source #

The input/output UPLC program type.

data Format Source #

The format of the test-case input files that the tests should be run against: either the textual `.uplc` representation or the flat-encoded `.flat` representation of the same program. See formatExtension.

Constructors

Textual 
Flat 

Instances

Instances details
Show Format Source # 
Instance details

Defined in PlutusConformance.Common

Eq Format Source # 
Instance details

Defined in PlutusConformance.Common

Methods

(==)FormatFormatBool Source #

(/=)FormatFormatBool Source #

IsOption Format Source #

This instance allows Format to be used as a tasty command-line option (`--format=textual` or `--format=flat`), so that users of the test suites can choose which input format the tests are run against. The default is uplc.

Instance details

Defined in PlutusConformance.Common

formatExtensionFormatString Source #

The filename extension (without the leading dot) used for a given Format.

data EvaluationResult res Source #

Instances

Instances details
Functor EvaluationResult Source # 
Instance details

Defined in PlutusConformance.Common

Methods

fmap ∷ (a → b) → EvaluationResult a → EvaluationResult b Source #

(<$) ∷ a → EvaluationResult b → EvaluationResult a Source #

data UplcEvaluator Source #

The evaluator to be tested.

Constructors

UplcEvaluatorWithoutCosting (UplcEvaluatorFun UplcProg)

An evaluator that just produces an output program, or fails.

UplcEvaluatorWithCosting (CostModelParamsUplcEvaluatorFun (UplcProg, ExBudget))

An evaluator that produces an output program along with the cost of evaluating it, or fails. Note that nothing cares about the cost of failing programs, so we don't test for conformance there.

dirsWithNoFlatFiles ∷ [FilePath] Source #

Directories under which no `.flat` input files are expected and hence shouldn't lead to errors. These test the textual parser's handling of constants, and there are generally no flat equivalents for these tests. This applies to the directory itself and everything below it.

discoverTests Source #

Arguments

Format

The format of the test-case input files to run the tests against (.uplc or .flat).

UplcEvaluator

The evaluator to be tested.

CostModelParams 
→ (FilePathBool)

A function that takes a test directory and returns a Bool indicating whether the evaluation test for the file in that directory is expected to fail.

→ (FilePathBool)

A function that takes a test directory and returns a Bool indicating whether the budget test for the file in that directory is expected to fail.

FilePath

The directory to search for tests.

IO TestTree 

Walk a file tree, making test groups for directories with subdirectories, and test cases for directories without. We expect every test directory to contain a single input file, in the given Format, whose name matches that of the directory. For example, if the Format is UPLC then the directory `modInteger-15` should contain `modInteger-15.uplc`, and that file should contain a textual UPLC program; if the Format is Flat then it should instead contain `modInteger-15.flat`, a flat-encoded UPLC program. The evaluation golden file is named to match: `modInteger-15.uplc.expected` for Textual, or `modInteger-15.flat.expected` for Flat. The budget golden file, however, is always `modInteger-15.budget.expected` regardless of format, since there's no per-format budget convention (the budget only depends on the AST, not on how it was obtained). These golden files will be created by the testing machinery if they aren't already present.

Every test-case directory is expected to have an input file for the requested Format; a missing input file is treated as an error, except under the directories listed in dirsWithNoFlatFiles, where (in Flat mode only) no `.flat` files is expected and the directory is skipped instead (for example `.flat` files don't make sense for the tests under `test-casesuplcevaluationbuiltinparser`, which test the handling of constants by the textual parser).

looksLikeUplcProgramTextBool Source #

Check whether some text looks like it's meant to be a UPLC program, ie, whether it begins with `(program` once whitespace and comments (which may appear before the `(` and/or between the `(` and program, as `--` line comments or `{- -}` block comments -- possibly nested, matching the real lexer's whitespace parser in PlutusCore.Parser.ParserCommon -- are ignored).

expectedToProgTextEither Text UplcProg Source #

Turn the expected file content in text to a UplcProg unless the expected result is a parse or evaluation error. We use the same shape-based check as getInputProg (looksLikeUplcProgram) to decide whether the content represents a program at all, rather than just trying to parse it and seeing whether that fails: this way, things like the literal `"parse error"` and `"evaluation failure"` markers are recognised as failures without needing to attempt (and fail) a real parse.

decodeFlatExpectedByteStringEither Text UplcProg Source #

Decode the content of a `.flat.expected` golden file. A `.flat.expected` file records either a successful evaluation result (as flat-encoded bytes) or a failure (as the UTF8-encoded text of shownParseError or shownEvaluationFailure) -- exactly mirroring the `.uplc.expected` convention (see expectedToProg), rather than the old convention of an empty file standing in for "some failure, reason unspecified". We check for the text markers first (a valid flat encoding could coincidentally also be valid UTF8, but it will essentially never happen to be the exact text of one of the two markers).

If the content is neither a recognised failure marker nor a valid flat encoding (for example because the golden file is empty, using the old convention, or has been corrupted), we don't fail outright: instead we return Left with the flat decoder's error text as the "expected" reason. This will essentially never match a real tested value (which is always either a real program or exactly shownParseError/shownEvaluationFailure), so it surfaces as an ordinary golden-mismatch test failure -- visible on a normal run, and fixable with `--accept` like any other outdated golden file (which is how the old empty-file goldens get migrated to the new convention), rather than a special-cased crash.

getExpectedProgFormatFilePathIO (Either Text UplcProg) Source #

Obtain the expected UplcProg from a golden `.expected` file in the given Format: parsed as text for Textual (via expectedToProg), or decoded via decodeFlatExpected for Flat.

getInputProgFormatFilePathIO (Either Text UplcProg) Source #

Obtain the input UplcProg from a test-case input file in the given Format, either by parsing it (for textual) or by flat-decoding it (for Flat). Rather than relying on the parser or decoder itself to fail, we check directly whether the file looks like it's even meant to contain a program: a `.uplc` file is expected to begin with `(program` (once any leading whitespace and comments are ignored: see looksLikeUplcProgram), and a `.flat` file is expected to be non-empty. If a file doesn't meet this expectation, we treat it as shownParseError without attempting to parse or decode it. Otherwise, we go ahead and parse/decode it to get the actual program (this may still fail, for example if the program contains an ill-formed constant).

getTestedValueFormatUplcEvaluatorFun res → FilePathIO (Either Text res) Source #

Get the tested value from a test-case input file in the given Format. The tested value is either the shown parse error or evaluation error, or a res.

compareAlphaEq Source #

Arguments

Either Text UplcProg

golden value

Either Text UplcProg

tested value

Maybe String

If two values are the same, it returns Nothing. If they are different, it returns an error that will be printed to the user.

The comparison function used for the golden test. This function checks alpha-equivalence of programs when the output is a program. Both Textual and Flat golden values now record the failure reason precisely (see decodeFlatExpected), so in both cases we require it to match.

updateGoldenFile Source #

Arguments

Format 
FilePath

the path to write the golden file to

Either Text UplcProg 
IO () 

Update the golden file with the tested value, in the given Format: as text for Textual (unchanged from before), or, for Flat, as flat-encoded bytes on success or the UTF8-encoded failure-reason text on failure (see decodeFlatExpected). TODO abstract out for other tests.

representativeGoldenTestTestTree Source #

A golden test that is never actually run: it exists only so that it can be passed to parseOptions to make tasty register the Golden test provider's own options (`--accept`, `--no-create`, `--size-cutoff`, `--delete-output`) before the real test tree (which needs the parsed `--format` option to be built in the first place) exists. See the comment in runUplcEvalTests.

runUplcEvalTests Source #

Arguments

UplcEvaluator

The action to run the input through for the tests.

→ (FilePathBool)

A function that takes a test name and returns whether it should labelled as ExpectedFailure.

→ (FilePathBool)

A function that takes a test name and returns whether it should labelled as ExpectedBudgetFailure.

IO () 

Run the UPLC evaluation tests given an evaluator that evaluates UPLC programs. By default the tests are run against the textual `.uplc` test-case files, but passing `--format=flat` on the command line makes them run against the flat-encoded `.flat` files instead (see Format).

unDeBruijnProgramProgram NamedDeBruijn DefaultUni DefaultFun () → Either FreeVariableError UplcProg Source #

Turn a Program using de Bruijn-indexed variables (as decoded from a `.flat` file) into the Name-based representation used elsewhere in this module, so that it can be compared with a program obtained by parsing a textual `.uplc` file.

decodeFlatProgByteStringEither String UplcProg Source #

Decode a flat-encoded UPLC program. We use the UnrestrictedProgram wrapper so that the decoding doesn't reject programs on the grounds of using builtins or term constructs which are unavailable in the version declared by the program: we just want to know whether the bytes decode to the same AST as the textual program that they're supposed to correspond to, not whether they're a valid on-chain script.

encodeFlatProgUplcProgByteString Source #

Encode a UplcProg as flat bytes: the inverse of decodeFlatProg. Converts the program's names to de Bruijn indices first (that's the representation flat actually encodes), then encodes it via the same UnrestrictedProgram wrapper decodeFlatProg uses, for the same reason (avoiding rejecting programs on the grounds of builtins/term constructs unavailable in the declared version). Used to write `.flat.expected` golden files when accepting a Flat-format test result.