{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.CanonicalState.Arbitrary () where

import Cardano.Ledger.CanonicalState.BasicTypes (
  CanonicalCoin (..),
 )
import Cardano.Ledger.CanonicalState.Conway ()
import qualified Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 as Blocks.V0
import qualified Cardano.Ledger.CanonicalState.Namespace.GovCommittee.V0 as Committee.V0
import qualified Cardano.Ledger.CanonicalState.Namespace.UTxO.V0 as UtxoOut.V0
import Cardano.Ledger.Coin (CompactForm (CompactCoin))
import Cardano.Ledger.Core (Era, EraTxOut, TxOut)
import Generic.Random (genericArbitraryU)
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.QuickCheck (Arbitrary (..), Positive (..))

instance Arbitrary Blocks.V0.BlockOut where
  -- starting form the QuickCheck-2.17 there is an arbirary instance for
  -- Natural, so it's possible to use genericArbitraryU directly.
  arbitrary :: Gen BlockOut
arbitrary = Natural -> BlockOut
Blocks.V0.BlockOut (Natural -> BlockOut)
-> (Positive Integer -> Natural) -> Positive Integer -> BlockOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Natural)
-> (Positive Integer -> Integer) -> Positive Integer -> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Positive a -> a
getPositive @Integer (Positive Integer -> BlockOut)
-> Gen (Positive Integer) -> Gen BlockOut
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Positive Integer)
forall a. Arbitrary a => Gen a
arbitrary

instance (EraTxOut era, Arbitrary (TxOut era), Era era) => Arbitrary (UtxoOut.V0.UtxoOut era) where
  arbitrary :: Gen (UtxoOut era)
arbitrary = TxOut era -> UtxoOut era
forall era. EraTxOut era => TxOut era -> UtxoOut era
UtxoOut.V0.mkUtxo (TxOut era -> UtxoOut era) -> Gen (TxOut era) -> Gen (UtxoOut era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (TxOut era)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CanonicalCoin where
  arbitrary :: Gen CanonicalCoin
arbitrary = CompactForm Coin -> CanonicalCoin
CanonicalCoin (CompactForm Coin -> CanonicalCoin)
-> (Word64 -> CompactForm Coin) -> Word64 -> CanonicalCoin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> CompactForm Coin
CompactCoin (Word64 -> CanonicalCoin) -> Gen Word64 -> Gen CanonicalCoin
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Committee.V0.GovCommitteeOut where
  arbitrary :: Gen GovCommitteeOut
arbitrary = Gen GovCommitteeOut
forall a. (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
genericArbitraryU

instance Arbitrary Committee.V0.CanonicalCommitteeAuthorization where
  arbitrary :: Gen CanonicalCommitteeAuthorization
arbitrary = (CommitteeAuthorization -> CanonicalCommitteeAuthorization)
-> Gen CommitteeAuthorization
-> Gen CanonicalCommitteeAuthorization
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CommitteeAuthorization -> CanonicalCommitteeAuthorization
Committee.V0.mkCanonicalCommitteeAuthorization Gen CommitteeAuthorization
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Committee.V0.CanonicalCommitteeState where arbitrary :: Gen CanonicalCommitteeState
arbitrary = Gen CanonicalCommitteeState
forall a. (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
genericArbitraryU