Skip to content
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

Test that builtin functions don't throw #4555

Merged
merged 12 commits into from
Apr 30, 2022
Prev Previous commit
Next Next commit
Add haddock
  • Loading branch information
zliu41 committed Apr 29, 2022
commit 2d2bc10b9519642eaae206ccf4c0584f388f4a61
9 changes: 9 additions & 0 deletions plutus-core/plutus-core/test/Evaluation/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ test_builtinsDon'tThrow =
"Builtins don't throw"
$ fmap (\fun -> testProperty (display fun) $ prop_builtinsDon'tThrow fun) List.enumerate

-- | Evaluating a builtin function should never throw any exception (the evaluation is allowed
-- to fail with a `KnownTypeError`, of course).
--
-- The test covers both succeeding and failing evaluations and verifies that in either case
-- no exception is thrown. The failing cases use arbitrary `Term` arguments (which doesn't
-- guarantee failure, but most likely), and the succeeding cases generate `Term` arguments
-- based on a builtin function's `TypeScheme`. For `Opaque` arguments it generates arbitrary
-- `Term`s (which technically doesn't guarantee evaluation success, although it is the case
-- with all current builtin functions).
prop_builtinsDon'tThrow :: DefaultFun -> Property
zliu41 marked this conversation as resolved.
Show resolved Hide resolved
zliu41 marked this conversation as resolved.
Show resolved Hide resolved
prop_builtinsDon'tThrow bn = property $ do
args <- forAllNoShow . Gen.choice $ [genArgsWellTyped bn, genArgsArbitrary bn]
Expand Down