-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-370: NoThunks for EvaluationContext (#4734)
* NoThunks for EvaluationContext * Modify a comment * Update a comment * Add test cases * Add some comments
- Loading branch information
Showing
11 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Spec.NoThunks (tests) where | ||
|
||
import NoThunks.Class | ||
|
||
import PlutusLedgerApi.V1 as V1 | ||
import PlutusLedgerApi.V2 as V2 | ||
import PlutusLedgerApi.V3 as V3 | ||
|
||
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults as Plutu | ||
import PlutusCore.Pretty | ||
|
||
import Control.Monad.Extra (whenJust) | ||
import Data.List.Extra (enumerate) | ||
import Data.Map qualified as Map | ||
import Data.Maybe (fromJust) | ||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup | ||
"NoThunks" | ||
[ testCase "EvaluationContext V1" evaluationContextV1 | ||
, testCase "EvaluationContext V2" evaluationContextV2 | ||
, testCase "EvaluationContext V3" evaluationContextV3 | ||
] | ||
|
||
costParams :: [Integer] | ||
costParams = Map.elems (fromJust defaultCostModelParams) | ||
|
||
evaluationContextV1 :: Assertion | ||
evaluationContextV1 = do | ||
let v1CostParams = take (length $ enumerate @V1.ParamName) costParams | ||
!evalCtx <- | ||
either (assertFailure . display) pure $ | ||
V1.mkEvaluationContext v1CostParams | ||
failIfThunk =<< noThunks [] evalCtx | ||
|
||
evaluationContextV2 :: Assertion | ||
evaluationContextV2 = do | ||
let v2CostParams = take (length $ enumerate @V2.ParamName) costParams | ||
!evalCtx <- | ||
either (assertFailure . display) pure $ | ||
V2.mkEvaluationContext v2CostParams | ||
failIfThunk =<< noThunks [] evalCtx | ||
|
||
evaluationContextV3 :: Assertion | ||
evaluationContextV3 = do | ||
let v3CostParams = take (length $ enumerate @V3.ParamName) costParams | ||
!evalCtx <- | ||
either (assertFailure . display) pure $ | ||
V3.mkEvaluationContext v3CostParams | ||
failIfThunk =<< noThunks [] evalCtx | ||
|
||
failIfThunk :: Show a => Maybe a -> IO () | ||
failIfThunk mbThunkInfo = | ||
whenJust mbThunkInfo $ \thunkInfo -> | ||
assertFailure $ "Unexpected thunk: " <> show thunkInfo |