{-# LANGUAGE TemplateHaskell #-}

module Test.Cardano.Crypto.Signing.Redeem.Compact (
  tests,
)
where

import Cardano.Crypto.Signing.Redeem (
  fromCompactRedeemVerificationKey,
  toCompactRedeemVerificationKey,
 )
import Cardano.Prelude
import Hedgehog (MonadTest, Property, checkParallel, tripping)
import Test.Cardano.Crypto.Gen (genRedeemVerificationKey)
import Test.Cardano.Prelude

--------------------------------------------------------------------------------
-- Compact RedeemVerificationKey
--------------------------------------------------------------------------------

roundTripCompactRedeemVerificationKey :: Property
roundTripCompactRedeemVerificationKey :: Property
roundTripCompactRedeemVerificationKey =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
1000
    Gen RedeemVerificationKey
genRedeemVerificationKey
    (forall (m :: * -> *) a b.
(HasCallStack, MonadTest m, Show a, Show b, Eq a) =>
(a -> b) -> (b -> a) -> a -> m ()
trippingCompact RedeemVerificationKey -> CompactRedeemVerificationKey
toCompactRedeemVerificationKey CompactRedeemVerificationKey -> RedeemVerificationKey
fromCompactRedeemVerificationKey)

-------------------------------------------------------------------------------
-- Tripping util
-------------------------------------------------------------------------------

trippingCompact ::
  (HasCallStack, MonadTest m, Show a, Show b, Eq a) =>
  (a -> b) ->
  (b -> a) ->
  a ->
  m ()
trippingCompact :: forall (m :: * -> *) a b.
(HasCallStack, MonadTest m, Show a, Show b, Eq a) =>
(a -> b) -> (b -> a) -> a -> m ()
trippingCompact a -> b
toCompact b -> a
fromCompact a
x =
  forall (m :: * -> *) (f :: * -> *) b a.
(MonadTest m, Applicative f, Show b, Show (f a), Eq (f a),
 HasCallStack) =>
a -> (a -> b) -> (b -> f a) -> m ()
tripping a
x a -> b
toCompact (forall a. a -> Identity a
Identity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. b -> a
fromCompact)

-------------------------------------------------------------------------------
-- Main test export
-------------------------------------------------------------------------------

tests :: IO Bool
tests :: IO Bool
tests = forall (m :: * -> *). MonadIO m => Group -> m Bool
checkParallel $$String
[(PropertyName, Property)]
Property
String -> PropertyName
String -> GroupName
GroupName -> [(PropertyName, Property)] -> Group
discoverRoundTrip