module Test.Cardano.Ledger.Conway.Spec (spec) where import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Conway.Tx (tierRefScriptFee) import Test.Cardano.Ledger.Common spec :: Spec spec :: Spec spec = do String -> Spec -> Spec forall a. HasCallStack => String -> SpecWith a -> SpecWith a describe String "Various tests for functions defined in Conway" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do String -> (Positive Int -> Rational -> NonNegative Int -> Property) -> Spec forall prop. (HasCallStack, Testable prop) => String -> prop -> Spec prop String "tierRefScriptFee is a linear function when growth is 1" ((Positive Int -> Rational -> NonNegative Int -> Property) -> Spec) -> (Positive Int -> Rational -> NonNegative Int -> Property) -> Spec forall a b. (a -> b) -> a -> b $ \(Positive Int sizeIncrement) Rational baseFee (NonNegative Int size) -> HasCallStack => Rational -> Int -> Rational -> Int -> Coin Rational -> Int -> Rational -> Int -> Coin tierRefScriptFee Rational 1 Int sizeIncrement Rational baseFee Int size Coin -> Coin -> Property forall a. (Eq a, Show a) => a -> a -> Property === Integer -> Coin Coin (Rational -> Integer forall b. Integral b => Rational -> b forall a b. (RealFrac a, Integral b) => a -> b floor (Int -> Rational forall a b. (Integral a, Num b) => a -> b fromIntegral Int size Rational -> Rational -> Rational forall a. Num a => a -> a -> a * Rational baseFee)) String -> Expectation -> SpecWith (Arg Expectation) forall a. (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) it String "tierRefScriptFee" (Expectation -> SpecWith (Arg Expectation)) -> Expectation -> SpecWith (Arg Expectation) forall a b. (a -> b) -> a -> b $ do let step :: Int step = Int 25600 (Int -> Coin) -> [Int] -> [Coin] forall a b. (a -> b) -> [a] -> [b] map (HasCallStack => Rational -> Int -> Rational -> Int -> Coin Rational -> Int -> Rational -> Int -> Coin tierRefScriptFee Rational 1.5 Int step Rational 15) [Int 0, Int step .. Int 204800] [Coin] -> [Coin] -> Expectation forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation `shouldBe` (Integer -> Coin) -> [Integer] -> [Coin] forall a b. (a -> b) -> [a] -> [b] map Integer -> Coin Coin [Integer 0, Integer 384000, Integer 960000, Integer 1824000, Integer 3120000, Integer 5064000, Integer 7980000, Integer 12354000, Integer 18915000]