module Test.Cardano.Ledger.Plutus.ExUnits (spec) where
import Cardano.Ledger.Plutus (
exBudgetToExUnits,
transExUnits,
)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary ()
spec :: Spec
spec :: Spec
spec = do
String -> Gen Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Round-trip to ExBudget" Gen Property
exUnitsToExBudgetRoundTrip
String -> Gen Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Round-trip from ExBudget" Gen Property
exBudgetToExUnitsRoundTrip
exUnitsToExBudgetRoundTrip :: Gen Property
exUnitsToExBudgetRoundTrip :: Gen Property
exUnitsToExBudgetRoundTrip = do
ExUnits
e <- Gen ExUnits
forall a. Arbitrary a => Gen a
arbitrary
let result :: Maybe ExUnits
result = ExBudget -> Maybe ExUnits
exBudgetToExUnits (ExBudget -> Maybe ExUnits) -> ExBudget -> Maybe ExUnits
forall a b. (a -> b) -> a -> b
$ ExUnits -> ExBudget
transExUnits ExUnits
e
Property -> Gen Property
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(Property -> Gen Property) -> Property -> Gen Property
forall a b. (a -> b) -> a -> b
$ String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample
( String
"Before: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ExUnits -> String
forall a. Show a => a -> String
show ExUnits
e
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n After: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Maybe ExUnits -> String
forall a. Show a => a -> String
show Maybe ExUnits
result
)
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ Maybe ExUnits
result Maybe ExUnits -> Maybe ExUnits -> Bool
forall a. Eq a => a -> a -> Bool
== ExUnits -> Maybe ExUnits
forall a. a -> Maybe a
Just ExUnits
e
exBudgetToExUnitsRoundTrip :: Gen Property
exBudgetToExUnitsRoundTrip :: Gen Property
exBudgetToExUnitsRoundTrip = do
ExBudget
e <- Gen ExBudget
forall a. Arbitrary a => Gen a
arbitrary
let result :: Maybe ExBudget
result = ExUnits -> ExBudget
transExUnits (ExUnits -> ExBudget) -> Maybe ExUnits -> Maybe ExBudget
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ExBudget -> Maybe ExUnits
exBudgetToExUnits ExBudget
e
Property -> Gen Property
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(Property -> Gen Property) -> Property -> Gen Property
forall a b. (a -> b) -> a -> b
$ String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample
( String
"Before: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ExBudget -> String
forall a. Show a => a -> String
show ExBudget
e
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n After: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Maybe ExBudget -> String
forall a. Show a => a -> String
show Maybe ExBudget
result
)
(Bool -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$ Maybe ExBudget
result Maybe ExBudget -> Maybe ExBudget -> Bool
forall a. Eq a => a -> a -> Bool
== ExBudget -> Maybe ExBudget
forall a. a -> Maybe a
Just ExBudget
e