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

module Test.Cardano.Ledger.Core.Tools (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 = forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Tools" forall a b. (a -> b) -> a -> b
$ do
  forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"`integralToByteStringN . byteStringToNum` roundtrips" forall a b. (a -> b) -> a -> b
$ do
    ByteString
bs <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall i. (Integral i, Bits i) => Int -> i -> ByteString
integralToByteStringN (ByteString -> Int
BS.length ByteString
bs) (forall i. (Bits i, Num i) => ByteString -> i
byteStringToNum @Integer ByteString
bs) forall a. (Eq a, Show a) => a -> a -> Property
=== ByteString
bs
  forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"`byteStringToNum . integralToByteStringN` roundtrips" forall a b. (a -> b) -> a -> b
$ do
    Positive (Integer
n :: Integer) <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall i. (Bits i, Num i) => ByteString -> i
byteStringToNum (forall i. (Integral i, Bits i) => Int -> i -> ByteString
integralToByteStringN Int
64 Integer
n) forall a. (Eq a, Show a) => a -> a -> Property
=== Integer
n