{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Chain.Common.Address (
  tests,
) where

import Cardano.Chain.Common (addrNetworkMagic, isRedeemAddress)
import Cardano.Prelude
import Hedgehog (cover, forAll, property, (===))
import Test.Cardano.Chain.Common.Gen (genAddress, genAddressWithNM, genNetworkMagic)
import Test.Cardano.Prelude
import Test.Options (TSGroup, TSProperty, withTestsTS)

ts_prop_addressNetworkMagicIdentity :: TSProperty
ts_prop_addressNetworkMagicIdentity :: TSProperty
ts_prop_addressNetworkMagicIdentity =
  TestLimit -> Property -> TSProperty
withTestsTS TestLimit
1000 (Property -> TSProperty)
-> (PropertyT IO () -> Property) -> PropertyT IO () -> TSProperty
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
property (PropertyT IO () -> TSProperty) -> PropertyT IO () -> TSProperty
forall a b. (a -> b) -> a -> b
$ do
    NetworkMagic
nm <- Gen NetworkMagic -> PropertyT IO NetworkMagic
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen NetworkMagic
genNetworkMagic
    Address
addr <- Gen Address -> PropertyT IO Address
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll (NetworkMagic -> Gen Address
genAddressWithNM NetworkMagic
nm)
    NetworkMagic
nm NetworkMagic -> NetworkMagic -> PropertyT IO ()
forall (m :: * -> *) a.
(MonadTest m, Eq a, Show a, HasCallStack) =>
a -> a -> m ()
=== Address -> NetworkMagic
addrNetworkMagic Address
addr

ts_prop_isRedeemAddress :: TSProperty
ts_prop_isRedeemAddress :: TSProperty
ts_prop_isRedeemAddress =
  TestLimit -> Property -> TSProperty
withTestsTS TestLimit
1000 (Property -> TSProperty)
-> (PropertyT IO () -> Property) -> PropertyT IO () -> TSProperty
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
property (PropertyT IO () -> TSProperty) -> PropertyT IO () -> TSProperty
forall a b. (a -> b) -> a -> b
$ do
    Address
addr <- Gen Address -> PropertyT IO Address
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen Address
genAddress
    CoverPercentage -> LabelName -> Bool -> PropertyT IO ()
forall (m :: * -> *).
(MonadTest m, HasCallStack) =>
CoverPercentage -> LabelName -> Bool -> m ()
cover CoverPercentage
30 LabelName
"Redeem Address" (Bool -> PropertyT IO ()) -> Bool -> PropertyT IO ()
forall a b. (a -> b) -> a -> b
$ Address -> Bool
isRedeemAddress Address
addr
    CoverPercentage -> LabelName -> Bool -> PropertyT IO ()
forall (m :: * -> *).
(MonadTest m, HasCallStack) =>
CoverPercentage -> LabelName -> Bool -> m ()
cover CoverPercentage
30 LabelName
"Pubkey Address" (Bool -> PropertyT IO ()) -> Bool -> PropertyT IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Address -> Bool
isRedeemAddress Address
addr)

tests :: TSGroup
tests :: TSGroup
tests = $$discoverPropArg