{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.ToolsSpec (spec) where

import Cardano.Ledger.Tools
import qualified Data.ByteString as BS
import Test.Cardano.Ledger.Common
import Test.QuickCheck.Instances.ByteString ()

spec :: Spec
spec :: Spec
spec = String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Tools" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  String -> Gen Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"`integralToByteStringN . byteStringToNum` roundtrips" (Gen Property -> Spec) -> Gen Property -> Spec
forall a b. (a -> b) -> a -> b
$ do
    bs <- Gen ByteString
forall a. Arbitrary a => Gen a
arbitrary
    pure $ integralToByteStringN (BS.length bs) (byteStringToNum @Integer bs) === bs
  String -> Gen Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"`byteStringToNum . integralToByteStringN` roundtrips" (Gen Property -> Spec) -> Gen Property -> Spec
forall a b. (a -> b) -> a -> b
$ do
    Positive (n :: Integer) <- Gen (Positive Integer)
forall a. Arbitrary a => Gen a
arbitrary
    pure $ byteStringToNum (integralToByteStringN 64 n) === n