Skip to content

Commit 232511b

Browse files
authored
Merge pull request #5327 from IntersectMBO/nm/exunits-tests
Move cardano-ledger-core ExUnits tests from testlib to test
2 parents 7072596 + d65c653 commit 232511b

File tree

4 files changed

+53
-58
lines changed

4 files changed

+53
-58
lines changed

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
### `testlib`
1414

15+
* Remove `Test.Cardano.Ledger.Plutus.ExUnits`
1516
* Remove the `accountsToUMap` member function from the `EraTest` class.
1617
- Also remove the related `accountsFromUMap` function.
1718
* Remove the following from `Core.Arbitrary`:

libs/cardano-ledger-core/cardano-ledger-core.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ library testlib
185185
Test.Cardano.Ledger.Era
186186
Test.Cardano.Ledger.Imp.Common
187187
Test.Cardano.Ledger.Plutus
188-
Test.Cardano.Ledger.Plutus.ExUnits
189188
Test.Cardano.Ledger.Plutus.Examples
190189
Test.Cardano.Ledger.Plutus.Guardrail
191190
Test.Cardano.Ledger.Plutus.ScriptTestContext

libs/cardano-ledger-core/test/Test/Cardano/Ledger/PlutusSpec.hs

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE BinaryLiterals #-}
33
{-# LANGUAGE DataKinds #-}
44
{-# LANGUAGE FlexibleContexts #-}
5-
{-# LANGUAGE ImportQualifiedPost #-}
65
{-# LANGUAGE OverloadedStrings #-}
76
{-# LANGUAGE ScopedTypeVariables #-}
87
{-# LANGUAGE TypeApplications #-}
@@ -24,12 +23,62 @@ import Data.Word
2423
import Numeric.Natural (Natural)
2524
import Test.Cardano.Ledger.Common
2625
import Test.Cardano.Ledger.Core.Arbitrary ()
27-
import Test.Cardano.Ledger.Plutus.ExUnits qualified as ExUnits
2826
import Test.Cardano.Ledger.Plutus.ToPlutusData (roundTripPlutusDataSpec)
2927

3028
spec :: Spec
3129
spec = do
32-
costModelsSpec
30+
describe "Plutus" $ do
31+
costModelsSpec
32+
exUnitsSpec
33+
dataSpec
34+
35+
costModelsSpec :: Spec
36+
costModelsSpec = do
37+
describe "CostModels" $ do
38+
prop "flattenCostModels . mkCostModelsLenient" $ \valid unknown -> do
39+
let cms1Flat = flattenCostModels valid <> unknown
40+
cms2Flat = unknown <> flattenCostModels valid
41+
cms1 <- mkCostModelsLenient cms1Flat
42+
cms2 <- mkCostModelsLenient cms2Flat
43+
flattenCostModels cms1 `shouldBe` cms1Flat
44+
flattenCostModels cms2 `shouldBe` cms2Flat
45+
46+
exUnitsSpec :: Spec
47+
exUnitsSpec = do
48+
describe "ExUnits" $ do
49+
prop "Round-trip to ExBudget" exUnitsToExBudgetRoundTrip
50+
prop "Round-trip from ExBudget" exBudgetToExUnitsRoundTrip
51+
52+
-- ExUnits should remain intact when translating to and from the Plutus ExBudget type
53+
exUnitsToExBudgetRoundTrip :: Gen Property
54+
exUnitsToExBudgetRoundTrip = do
55+
e <- arbitrary
56+
let result = exBudgetToExUnits $ transExUnits e
57+
pure
58+
$ counterexample
59+
( "Before: "
60+
<> show e
61+
<> "\n After: "
62+
<> show result
63+
)
64+
$ result == Just e
65+
66+
-- Plutus ExBudget should remain intact when translating to and from the ExUnits type
67+
exBudgetToExUnitsRoundTrip :: Gen Property
68+
exBudgetToExUnitsRoundTrip = do
69+
e <- arbitrary
70+
let result = transExUnits <$> exBudgetToExUnits e
71+
pure
72+
$ counterexample
73+
( "Before: "
74+
<> show e
75+
<> "\n After: "
76+
<> show result
77+
)
78+
$ result == Just e
79+
80+
dataSpec :: Spec
81+
dataSpec = do
3382
describe "RoundTrip ToPlutusData" $ do
3483
roundTripPlutusDataSpec @Version
3584
roundTripPlutusDataSpec @Word
@@ -50,16 +99,3 @@ spec = do
5099
roundTripPlutusDataSpec @ProtVer
51100
roundTripPlutusDataSpec @CostModels
52101
roundTripPlutusDataSpec @Integer
53-
describe "ExUnits" $ do
54-
ExUnits.spec
55-
56-
costModelsSpec :: Spec
57-
costModelsSpec = do
58-
describe "CostModels" $ do
59-
prop "flattenCostModels . mkCostModelsLenient" $ \valid unknown -> do
60-
let cms1Flat = flattenCostModels valid <> unknown
61-
cms2Flat = unknown <> flattenCostModels valid
62-
cms1 <- mkCostModelsLenient cms1Flat
63-
cms2 <- mkCostModelsLenient cms2Flat
64-
flattenCostModels cms1 `shouldBe` cms1Flat
65-
flattenCostModels cms2 `shouldBe` cms2Flat

libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Plutus/ExUnits.hs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)