{-# 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
    nm <- Gen NetworkMagic -> PropertyT IO NetworkMagic
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen NetworkMagic
genNetworkMagic
    addr <- forAll (genAddressWithNM nm)
    nm === addrNetworkMagic 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
    addr <- Gen Address -> PropertyT IO Address
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen Address
genAddress
    cover 30 "Redeem Address" $ isRedeemAddress addr
    cover 30 "Pubkey Address" $ not (isRedeemAddress addr)

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