module Test.Cardano.Ledger.Shelley.WitVKeys (tests) where

import Cardano.Ledger.Core
import Data.List (nub, sort)
import Data.Set as Set (fromList, singleton)
import Test.Cardano.Ledger.Core.KeyPair (mkWitnessVKey)
import Test.Cardano.Ledger.Shelley.Serialisation.EraIndepGenerators ()
import Test.Cardano.Ledger.Shelley.Utils (RawSeed, mkKeyPair')
import Test.QuickCheck (conjoin, (===), (==>))
import Test.Tasty (TestTree)
import Test.Tasty.QuickCheck (testProperty)
import qualified Test.Tasty.QuickCheck as TQC

tests :: TestTree
tests :: TestTree
tests = forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"WitVKey does not brake containers due to invalid Ord" RawSeed
-> SafeHash EraIndependentTxBody
-> SafeHash EraIndependentTxBody
-> Property
witVKeysProp

witVKeysProp ::
  RawSeed ->
  SafeHash EraIndependentTxBody ->
  SafeHash EraIndependentTxBody ->
  TQC.Property
witVKeysProp :: RawSeed
-> SafeHash EraIndependentTxBody
-> SafeHash EraIndependentTxBody
-> Property
witVKeysProp RawSeed
seed SafeHash EraIndependentTxBody
h1 SafeHash EraIndependentTxBody
h2 =
  let kp :: KeyPair kd
kp = forall (kd :: KeyRole). RawSeed -> KeyPair kd
mkKeyPair' RawSeed
seed
      w1 :: WitVKey 'Witness
w1 = forall (kr :: KeyRole).
SafeHash EraIndependentTxBody -> KeyPair kr -> WitVKey 'Witness
mkWitnessVKey SafeHash EraIndependentTxBody
h1 forall {kd :: KeyRole}. KeyPair kd
kp
      w2 :: WitVKey 'Witness
w2 = forall (kr :: KeyRole).
SafeHash EraIndependentTxBody -> KeyPair kr -> WitVKey 'Witness
mkWitnessVKey SafeHash EraIndependentTxBody
h2 forall {kd :: KeyRole}. KeyPair kd
kp
   in forall prop. Testable prop => [prop] -> Property
conjoin
        [ forall a. Ord a => [a] -> [a]
sort [WitVKey 'Witness
w1, WitVKey 'Witness
w2] forall a. (Eq a, Show a) => a -> a -> Property
=== forall a. Ord a => [a] -> [a]
sort [WitVKey 'Witness
w2, WitVKey 'Witness
w1]
        , forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Eq a => [a] -> [a]
nub [WitVKey 'Witness
w1, WitVKey 'Witness
w2]) forall a. (Eq a, Show a) => a -> a -> Property
=== forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Ord a => [a] -> Set a
Set.fromList [WitVKey 'Witness
w1, WitVKey 'Witness
w2])
        , WitVKey 'Witness
w1 forall a. Eq a => a -> a -> Bool
/= WitVKey 'Witness
w2 forall prop. Testable prop => Bool -> prop -> Property
==> forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. a -> Set a
Set.singleton WitVKey 'Witness
w1 forall a. Semigroup a => a -> a -> a
<> forall a. a -> Set a
Set.singleton WitVKey 'Witness
w2) forall a. (Eq a, Show a) => a -> a -> Property
=== Int
2
        ]