{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Cardano.Ledger.State.StakePoolSpec (spec) where

import Cardano.Ledger.Address (raNetwork)
import Cardano.Ledger.Coin
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.State
import Data.Set (Set)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary ()

spec :: Spec
spec :: Spec
spec = do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"StakePoolState" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String
-> ((StakePoolParams, CompactForm Coin, Set (Credential Staking))
    -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"mkStakePoolState/stakePoolStateToPoolParams round-trip" (((StakePoolParams, CompactForm Coin, Set (Credential Staking))
  -> Property)
 -> Spec)
-> ((StakePoolParams, CompactForm Coin, Set (Credential Staking))
    -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
      \( StakePoolParams
stakePoolParams :: StakePoolParams
         , CompactForm Coin
deposit :: CompactForm Coin
         , Set (Credential Staking)
delegs :: Set (Credential Staking)
         ) ->
          let poolId :: KeyHash StakePool
poolId = StakePoolParams -> KeyHash StakePool
sppId StakePoolParams
stakePoolParams
              network :: Network
network = RewardAccount -> Network
raNetwork (RewardAccount -> Network) -> RewardAccount -> Network
forall a b. (a -> b) -> a -> b
$ StakePoolParams -> RewardAccount
sppRewardAccount StakePoolParams
stakePoolParams
              stakePoolState :: StakePoolState
stakePoolState = CompactForm Coin
-> Set (Credential Staking) -> StakePoolParams -> StakePoolState
mkStakePoolState CompactForm Coin
deposit Set (Credential Staking)
delegs StakePoolParams
stakePoolParams
              stakePoolParams' :: StakePoolParams
stakePoolParams' = KeyHash StakePool -> Network -> StakePoolState -> StakePoolParams
stakePoolStateToStakePoolParams KeyHash StakePool
poolId Network
network StakePoolState
stakePoolState
           in StakePoolParams
stakePoolParams StakePoolParams -> StakePoolParams -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== StakePoolParams
stakePoolParams'