{-# 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.Conway ()
import qualified Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 as Blocks.V0
import qualified Cardano.Ledger.CanonicalState.Namespace.UTxO.V0 as UtxoOut.V0
import Cardano.Ledger.Core (Era, EraTxOut, TxOut)
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