{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

module Test.Cardano.Ledger.Dijkstra.TxInfoSpec (spec) where

import Cardano.Ledger.Allegra.Scripts (invalidBeforeL, invalidHereAfterL)
import Cardano.Ledger.Alonzo.Plutus.Context (
  ContextError,
  EraPlutusTxInfo (..),
  LedgerLevelTxInfo (..),
  LedgerTxInfo (..),
  PlutusTxInfoResult (..),
  SupportedLanguage (..),
  mkTxInfoResult,
  toPlutusTxInfoForPurpose,
 )
import Cardano.Ledger.Alonzo.Plutus.TxInfo (AlonzoContextError (..), transDatums)
import Cardano.Ledger.Alonzo.Scripts (AsPurpose (..), toAsIx, toAsPurpose)
import Cardano.Ledger.Alonzo.TxWits (unRedeemersL, unTxDats)
import Cardano.Ledger.Alonzo.UTxO (AlonzoScriptsNeeded (..))
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError (..))
import Cardano.Ledger.BaseTypes (
  Globals (..),
  Inject (..),
  Network (..),
  ProtVer (..),
  SlotNo (..),
  StrictMaybe (..),
  TxIx (..),
  strictMaybeToMaybe,
 )
import Cardano.Ledger.Conway.Governance (
  GovActionId,
  Vote,
  Voter,
  VotingProcedure (vProcVote),
  foldlVotingProcedures,
 )
import Cardano.Ledger.Conway.TxInfo (
  ConwayEraPlutusTxInfo,
  transMintValue,
  transTxBodyId,
  transTxId,
 )
import Cardano.Ledger.Credential (Credential (..), StakeReference (..))
import Cardano.Ledger.Dijkstra (DijkstraEra)
import Cardano.Ledger.Dijkstra.Core
import Cardano.Ledger.Dijkstra.Scripts (
  AccountBalanceIntervals (..),
 )
import Cardano.Ledger.Dijkstra.State (
  EraUTxO,
  ScriptsNeeded,
  UTxO (..),
  getScriptsNeeded,
  getScriptsProvided,
 )
import Cardano.Ledger.Dijkstra.TxInfo (
  DijkstraContextError (..),
  transDirectDeposits,
  transGuardingTopTxInfo,
  transProposal,
  transTxInInfoV4,
  transTxOutV4,
  transValidityInterval,
  transVotingProcedures,
  transWithdrawals,
 )
import qualified Cardano.Ledger.Dijkstra.TxInfo as Dijkstra
import Cardano.Ledger.Mary.Value (AssetName, MaryValue, PolicyID, flattenMultiAsset)
import Cardano.Ledger.Plutus (
  Language (..),
  SLanguage (..),
  TxOutSource (..),
  getPlutusData,
  hashPlutusScript,
  plutusLanguage,
  transCoinToLovelace,
  transCoinToValue,
  transCred,
  transDatum,
  transSafeHash,
  transScriptHash,
  transTxIx,
 )
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import qualified Cardano.Ledger.Val as Val
import Control.Monad (zipWithM)
import Control.Monad.Trans.Fail.String (errorFail)
import Data.Either (isRight)
import Data.Foldable (toList)
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.Map.NonEmpty as NEM
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (isSJust, isSNothing)
import Data.Monoid (First (..), Sum (..))
import qualified Data.OMap.Strict as OMap
import qualified Data.OSet.Strict as OSet
import Data.Proxy (Proxy (..))
import Data.Semigroup (Max (..), Min (..))
import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro ((&), (.~), (^.))
import qualified PlutusLedgerApi.V3.MintValue as MintValue
import PlutusLedgerApi.V4 (TopTxInfoSimplified (..))
import qualified PlutusLedgerApi.V4 as PV4
import qualified PlutusTx.AssocMap as AssocMap
import qualified PlutusTx.Eq as PlutusTx
import qualified PlutusTx.Functor as PlutusTx
import Test.Cardano.Ledger.Alonzo.Era (mkTestLedgerTxInfoWithScripts)
import Test.Cardano.Ledger.Alonzo.TxInfoSpec (
  testEpochInfo,
  testSystemStart,
  validBetweenEpochInfo,
 )
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary (genOrderedPair)
import Test.Cardano.Ledger.Core.Utils (testGlobals)
import Test.Cardano.Ledger.Dijkstra.Arbitrary ()
import Test.Cardano.Ledger.Dijkstra.ImpTest (
  DijkstraEraImp,
  ShelleyEraImp (..),
  genBadValidityInterval,
  genGoodValidityInterval,
 )
import Test.Cardano.Ledger.Dijkstra.Translation.TranslatableGen (genTranslatableTxWithNestedTxs)
import qualified Test.Cardano.Ledger.Plutus.Examples as Plutus

spec :: forall era. (DijkstraEraImp era, ConwayEraPlutusTxInfo PlutusV4 era) => Spec
spec :: forall era.
(DijkstraEraImp era, ConwayEraPlutusTxInfo 'PlutusV4 era) =>
Spec
spec = String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"TxInfo" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  let mkLocalLedgerTxInfo :: UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
utxo Tx level era
tx =
        let ei :: EpochInfo (Either Text)
ei = Globals -> EpochInfo (Either Text)
epochInfo Globals
testGlobals
            ss :: SystemStart
ss = Globals -> SystemStart
systemStart Globals
testGlobals
         in ProtVer
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO era
-> ScriptsProvided era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
forall era (level :: TxLevel).
(EraUTxO era, EraPlutusContext era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
ProtVer
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO era
-> ScriptsProvided era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkTestLedgerTxInfoWithScripts
              (Version -> Word32 -> ProtVer
ProtVer (forall era. Era era => Version
eraProtVerLow @era) Word32
0)
              EpochInfo (Either Text)
ei
              SystemStart
ss
              UTxO era
utxo
              (UTxO era -> Tx level era -> ScriptsProvided era
forall era (l :: TxLevel).
ShelleyEraImp era =>
UTxO era -> Tx l era -> ScriptsProvided era
forall (l :: TxLevel). UTxO era -> Tx l era -> ScriptsProvided era
impScriptsProvided UTxO era
utxo Tx level era
tx)
              Tx level era
tx
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Translation" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"transValidityInterval" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"validity interval's upper bound is open" Expectation
transVITimeUpperBoundIsOpen
      String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"translates successfully if bounds are valid" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
        (hi, lo) <- Gen (SlotNo, SlotNo)
forall a. (Arbitrary a, Ord a) => Gen (a, a)
genOrderedPair
        validityInterval <- genGoodValidityInterval lo hi
        pure $
          Dijkstra.transValidityInterval
            (Proxy @era)
            (validBetweenEpochInfo lo hi)
            testSystemStart
            validityInterval
            `shouldSatisfy` isRight
      String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"fails to translate if the bounds are invalid" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
        (hi, lo) <- Gen (SlotNo, SlotNo)
forall a. (Arbitrary a, Ord a) => Gen (a, a)
genOrderedPair
        validityInterval <- genBadValidityInterval lo hi
        pure $
          Dijkstra.transValidityInterval
            (Proxy @era)
            (validBetweenEpochInfo lo hi)
            testSystemStart
            validityInterval
            `shouldBeLeft` inject (TimeTranslationPastHorizon @era "out of valid range")
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"PlutusV4" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (TxIx -> Expectation) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Threads the sub-transaction index into txInfoSubTxIx" ((TxIx -> Expectation) -> Spec) -> (TxIx -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$ \(TxIx
txIx :: TxIx) -> do
      let
        tx :: Tx SubTx era
tx = forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @SubTx TxBody SubTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody
        ledgerTxInfo :: LedgerTxInfo SubTx era
ledgerTxInfo = UTxO era
-> Tx SubTx era
-> LedgerLevelTxInfo SubTx era
-> LedgerTxInfo SubTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx SubTx era
tx (LedgerLevelTxInfo SubTx era -> LedgerTxInfo SubTx era)
-> LedgerLevelTxInfo SubTx era -> LedgerTxInfo SubTx era
forall a b. (a -> b) -> a -> b
$ TxIx -> LedgerLevelTxInfo SubTx era
forall era. TxIx -> LedgerLevelTxInfo SubTx era
LedgerSubTxInfo TxIx
txIx
      case PlutusTxInfoResult 'PlutusV4 era
-> Either (ContextError era) (PlutusTxInfo 'PlutusV4)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage 'PlutusV4
-> LedgerTxInfo SubTx era -> PlutusTxInfoResult 'PlutusV4 era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy 'PlutusV4
-> LedgerTxInfo level era -> PlutusTxInfoResult 'PlutusV4 era
toPlutusTxInfo SLanguage 'PlutusV4
SPlutusV4 LedgerTxInfo SubTx era
ledgerTxInfo) of
        Right PlutusTxInfo 'PlutusV4
txInfo ->
          TxInfo -> Maybe Integer
PV4.txInfoSubTxIx PlutusTxInfo 'PlutusV4
TxInfo
txInfo Maybe Integer -> Maybe Integer -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Integer -> Maybe Integer
forall a. a -> Maybe a
Just (TxIx -> Integer
transTxIx TxIx
txIx)
        Left ContextError era
failure ->
          HasCallStack => String -> Expectation
String -> Expectation
expectationFailure (String -> Expectation) -> String -> Expectation
forall a b. (a -> b) -> a -> b
$ String
"Failed to translate sub-transaction TxInfo: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ContextError era -> String
forall a. Show a => a -> String
show ContextError era
failure
    String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Fails translation when Ptr present in outputs" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
      paymentCred <- Gen (Credential Payment)
forall a. Arbitrary a => Gen a
arbitrary
      ptr <- arbitrary
      val <- arbitrary
      let
        txOut = Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
paymentCred (Ptr -> StakeReference
StakeRefPtr Ptr
ptr)) Value era
MaryValue
val
      txIn <- arbitrary
      paymentCred2 <- arbitrary
      stakeRef <- oneof [StakeRefBase <$> arbitrary, pure StakeRefNull]
      let
        utxo =
          Map TxIn (TxOut era) -> UTxO era
forall era. Map TxIn (TxOut era) -> UTxO era
UTxO
            [ (TxIn
txIn, Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
paymentCred2 StakeReference
stakeRef) Value era
MaryValue
val)
            ]
        tx =
          forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$
            TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody
              TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL ((StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> StrictSeq (TxOut era) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ [Item (StrictSeq (TxOut era))
TxOut era
txOut]
              TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (Set TxIn -> Identity (Set TxIn))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
inputsTxBodyL ((Set TxIn -> Identity (Set TxIn))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> Set TxIn -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ [Item (Set TxIn)
TxIn
txIn]
        ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
utxo Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
      pure $
        toPlutusTxInfoForPurpose SPlutusV4 ledgerTxInfo (SpendingPurpose AsPurpose)
          `shouldBeLeft` inject (PointerPresentInOutput @era (TxOutFromOutput $ TxIx 0))
    String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Fails translation when Byron addresses present in outputs" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
      ba0 <- Gen BootstrapAddress
forall a. Arbitrary a => Gen a
arbitrary
      ba2 <- arbitrary
      paymentCred <- arbitrary
      val0 <- arbitrary
      val1 <- arbitrary
      val2 <- arbitrary
      let
        txOuts =
          [ Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (BootstrapAddress -> Addr
AddrBootstrap BootstrapAddress
ba0) Value era
val0
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
paymentCred StakeReference
StakeRefNull) Value era
val1
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (BootstrapAddress -> Addr
AddrBootstrap BootstrapAddress
ba2) Value era
val2
          ]
        tx = forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$ TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL ((StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> StrictSeq (TxOut era) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictSeq (TxOut era)
txOuts
        ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
      pure $
        toPlutusTxInfoForPurpose SPlutusV4 ledgerTxInfo (SpendingPurpose AsPurpose)
          `shouldBeLeft` inject (ByronTxOutInContext @era (TxOutFromOutput $ TxIx 0))
    String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Reports the first error kind when Ptr and Byron outputs are mixed" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
      pc0 <- Gen (Credential Payment)
forall a. Arbitrary a => Gen a
arbitrary
      pc2 <- arbitrary
      ptr0 <- arbitrary
      ptr2 <- arbitrary
      bootstrapAddr <- arbitrary
      val0 <- arbitrary
      val1 <- arbitrary
      val2 <- arbitrary
      let
        txOuts =
          [ Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
pc0 (Ptr -> StakeReference
StakeRefPtr Ptr
ptr0)) Value era
MaryValue
val0
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (BootstrapAddress -> Addr
AddrBootstrap BootstrapAddress
bootstrapAddr) Value era
MaryValue
val1
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
pc2 (Ptr -> StakeReference
StakeRefPtr Ptr
ptr2)) Value era
MaryValue
val2
          ]
        tx = forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$ TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL ((StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> StrictSeq (TxOut era) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictSeq (TxOut era)
txOuts
        ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
      pure $
        toPlutusTxInfoForPurpose SPlutusV4 ledgerTxInfo (SpendingPurpose AsPurpose)
          `shouldBeLeft` inject (PointerPresentInOutput @era (TxOutFromOutput $ TxIx 0))
    String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Translates outputs in the order they appear in the TxBody" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
      pc0 <- Gen (Credential Payment)
forall a. Arbitrary a => Gen a
arbitrary
      pc1 <- arbitrary
      pc2 <- arbitrary
      val0 <- arbitrary
      val1 <- arbitrary
      val2 <- arbitrary
      let
        txOuts =
          [ Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
pc0 StakeReference
StakeRefNull) Value era
val0
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
pc1 StakeReference
StakeRefNull) Value era
val1
          , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
pc2 StakeReference
StakeRefNull) Value era
val2
          ]
        tx = forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$ TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL ((StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> StrictSeq (TxOut era) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictSeq (TxOut era)
txOuts
        ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
      pure $
        case toPlutusTxInfoForPurpose SPlutusV4 ledgerTxInfo (SpendingPurpose AsPurpose) of
          Right PlutusTxInfo 'PlutusV4
txInfo ->
            (TxOut -> Address) -> [TxOut] -> [Address]
forall a b. (a -> b) -> [a] -> [b]
map TxOut -> Address
PV4.txOutAddress (TxInfo -> [TxOut]
PV4.txInfoOutputs PlutusTxInfo 'PlutusV4
TxInfo
txInfo)
              [Address] -> [Address] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Credential -> Maybe AccountId -> Address
PV4.Address (Credential Payment -> Credential
forall (kr :: KeyRole). Credential kr -> Credential
transCred Credential Payment
pc) Maybe AccountId
forall a. Maybe a
Nothing | Credential Payment
pc <- [Item [Credential Payment]
Credential Payment
pc0, Item [Credential Payment]
Credential Payment
pc1, Item [Credential Payment]
Credential Payment
pc2]]
          Either (ContextError era) (PlutusTxInfo 'PlutusV4)
err -> HasCallStack => String -> Expectation
String -> Expectation
expectationFailure (String -> Expectation) -> String -> Expectation
forall a b. (a -> b) -> a -> b
$ String
"Failed to translate TxInfo: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Either (ContextError era) TxInfo -> String
forall a. Show a => a -> String
show Either (ContextError era) (PlutusTxInfo 'PlutusV4)
Either (ContextError era) TxInfo
err
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"toPlutusTxInfo" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"succeeds when purpose points at a script hash" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
        paymentCred1 <- Gen (Credential Payment)
forall a. Arbitrary a => Gen a
arbitrary
        stakeRef1 <- oneof [StakeRefBase <$> arbitrary, pure StakeRefNull]
        stakeRef2 <- oneof [StakeRefBase <$> arbitrary, pure StakeRefNull]
        coin1 <- arbitrary
        coin2 <- arbitrary
        txIn <- arbitrary
        redeemer <- arbitrary
        exUnits <- arbitrary
        let plutusScript = SLanguage 'PlutusV4 -> Plutus 'PlutusV4
forall (l :: Language). SLanguage l -> Plutus l
Plutus.alwaysSucceedsNoDatum SLanguage 'PlutusV4
SPlutusV4
            script = Fail (PlutusScript era) -> PlutusScript era
forall a. HasCallStack => Fail a -> a
errorFail (Fail (PlutusScript era) -> PlutusScript era)
-> Fail (PlutusScript era) -> PlutusScript era
forall a b. (a -> b) -> a -> b
$ Plutus 'PlutusV4 -> Fail (PlutusScript era)
forall era (l :: Language) (m :: * -> *).
(AlonzoEraScript era, PlutusLanguage l, MonadFail m) =>
Plutus l -> m (PlutusScript era)
forall (l :: Language) (m :: * -> *).
(PlutusLanguage l, MonadFail m) =>
Plutus l -> m (PlutusScript era)
mkPlutusScript Plutus 'PlutusV4
plutusScript
        let
          proxy = forall {k} (t :: k). Proxy t
forall (t :: Language). Proxy t
Proxy @PlutusV4
          scriptHash = Plutus 'PlutusV4 -> ScriptHash
forall (l :: Language). PlutusLanguage l => Plutus l -> ScriptHash
hashPlutusScript Plutus 'PlutusV4
plutusScript
          paymentCred2 = ScriptHash -> Credential kr
forall (kr :: KeyRole). ScriptHash -> Credential kr
ScriptHashObj ScriptHash
scriptHash
          txOut = Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
paymentCred1 StakeReference
stakeRef1) (Coin -> Value era
forall t s. Inject t s => t -> s
Val.inject Coin
coin1)
          utxo =
            Map TxIn (TxOut era) -> UTxO era
forall era. Map TxIn (TxOut era) -> UTxO era
UTxO
              [
                ( TxIn
txIn
                , Addr -> Value era -> TxOut era
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
mkBasicTxOut (Network -> Credential Payment -> StakeReference -> Addr
Addr Network
Testnet Credential Payment
forall {kr :: KeyRole}. Credential kr
paymentCred2 StakeReference
stakeRef2) (Coin -> Value era
forall t s. Inject t s => t -> s
Val.inject Coin
coin2)
                )
              ]
          tx =
            forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx
              ( TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody
                  TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL ((StrictSeq (TxOut era) -> Identity (StrictSeq (TxOut era)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> StrictSeq (TxOut era) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ [Item (StrictSeq (TxOut era))
TxOut era
txOut]
                  TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (Set TxIn -> Identity (Set TxIn))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
inputsTxBodyL ((Set TxIn -> Identity (Set TxIn))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> Set TxIn -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ [Item (Set TxIn)
TxIn
txIn]
              )
              Tx TopTx era -> (Tx TopTx era -> Tx TopTx era) -> Tx TopTx era
forall a b. a -> (a -> b) -> b
& (TxWits era -> Identity (TxWits era))
-> Tx TopTx era -> Identity (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era -> Identity (TxWits era))
 -> Tx TopTx era -> Identity (Tx TopTx era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> TxWits era -> Identity (TxWits era))
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
    -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> Tx TopTx era
-> Identity (Tx TopTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Redeemers era -> Identity (Redeemers era))
-> TxWits era -> Identity (TxWits era)
forall era.
AlonzoEraTxWits era =>
Lens' (TxWits era) (Redeemers era)
Lens' (TxWits era) (Redeemers era)
rdmrsTxWitsL ((Redeemers era -> Identity (Redeemers era))
 -> TxWits era -> Identity (TxWits era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> Redeemers era -> Identity (Redeemers era))
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
    -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> TxWits era
-> Identity (TxWits era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
 -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> Redeemers era -> Identity (Redeemers era)
forall era.
AlonzoEraScript era =>
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
unRedeemersL
                ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
  -> Identity (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
 -> Tx TopTx era -> Identity (Tx TopTx era))
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
-> Tx TopTx era
-> Tx TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PlutusPurpose AsIx era
-> (Data era, ExUnits)
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
forall k a. k -> a -> Map k a
Map.singleton (AsIx Word32 TxIn -> PlutusPurpose AsIx era
forall era (f :: * -> * -> *).
AlonzoEraScript era =>
f Word32 TxIn -> PlutusPurpose f era
SpendingPurpose (AsIx Word32 TxIn -> PlutusPurpose AsIx era)
-> AsIx Word32 TxIn -> PlutusPurpose AsIx era
forall a b. (a -> b) -> a -> b
$ Word32 -> AsIx Word32 TxIn
forall ix it. ix -> AsIx ix it
AsIx Word32
0) (Data era
redeemer, ExUnits
exUnits)
              Tx TopTx era -> (Tx TopTx era -> Tx TopTx era) -> Tx TopTx era
forall a b. a -> (a -> b) -> b
& (TxWits era -> Identity (TxWits era))
-> Tx TopTx era -> Identity (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era -> Identity (TxWits era))
 -> Tx TopTx era -> Identity (Tx TopTx era))
-> ((Map ScriptHash (Script era)
     -> Identity (Map ScriptHash (Script era)))
    -> TxWits era -> Identity (TxWits era))
-> (Map ScriptHash (Script era)
    -> Identity (Map ScriptHash (Script era)))
-> Tx TopTx era
-> Identity (Tx TopTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map ScriptHash (Script era)
 -> Identity (Map ScriptHash (Script era)))
-> TxWits era -> Identity (TxWits era)
forall era.
EraTxWits era =>
Lens' (TxWits era) (Map ScriptHash (Script era))
Lens' (TxWits era) (Map ScriptHash (Script era))
scriptTxWitsL ((Map ScriptHash (Script era)
  -> Identity (Map ScriptHash (Script era)))
 -> Tx TopTx era -> Identity (Tx TopTx era))
-> Map ScriptHash (Script era) -> Tx TopTx era -> Tx TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ScriptHash -> Script era -> Map ScriptHash (Script era)
forall k a. k -> a -> Map k a
Map.singleton ScriptHash
scriptHash (PlutusScript era -> Script era
forall era. AlonzoEraScript era => PlutusScript era -> Script era
fromPlutusScript PlutusScript era
script)
          ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
utxo Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
          purpose = forall era (f :: * -> * -> *).
AlonzoEraScript era =>
f Word32 TxIn -> PlutusPurpose f era
SpendingPurpose @era (AsIxItem Word32 TxIn -> PlutusPurpose AsIxItem era)
-> AsIxItem Word32 TxIn -> PlutusPurpose AsIxItem era
forall a b. (a -> b) -> a -> b
$ Word32 -> TxIn -> AsIxItem Word32 TxIn
forall ix it. ix -> it -> AsIxItem ix it
AsIxItem Word32
0 TxIn
txIn
          TxIn (TxId txIdHash) (TxIx txIx) = txIn
          TxId txBodyHash = txIdTx tx
          txInRef = TxId -> Integer -> TxOutRef
PV4.TxOutRef (BuiltinByteString -> TxId
PV4.TxId (BuiltinByteString -> TxId) -> BuiltinByteString -> TxId
forall a b. (a -> b) -> a -> b
$ SafeHash EraIndependentTxBody -> BuiltinByteString
forall i. SafeHash i -> BuiltinByteString
transSafeHash SafeHash EraIndependentTxBody
txIdHash) (Word16 -> Integer
forall a. Integral a => a -> Integer
toInteger Word16
txIx)
          transStakeRef (StakeRefBase Credential Staking
cred) = AccountId -> Maybe AccountId
forall a. a -> Maybe a
Just (AccountId -> Maybe AccountId)
-> (Credential -> AccountId) -> Credential -> Maybe AccountId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Credential -> AccountId
PV4.AccountId (Credential -> Maybe AccountId) -> Credential -> Maybe AccountId
forall a b. (a -> b) -> a -> b
$ Credential Staking -> Credential
forall (kr :: KeyRole). Credential kr -> Credential
transCred Credential Staking
cred
          transStakeRef StakeReference
_ = Maybe AccountId
forall a. Maybe a
Nothing
          addr1 = Credential -> Maybe AccountId -> Address
PV4.Address (Credential Payment -> Credential
forall (kr :: KeyRole). Credential kr -> Credential
transCred Credential Payment
paymentCred1) (StakeReference -> Maybe AccountId
transStakeRef StakeReference
stakeRef1)
          addr2 = Credential -> Maybe AccountId -> Address
PV4.Address (Credential (ZonkAny MinVersion) -> Credential
forall (kr :: KeyRole). Credential kr -> Credential
transCred Credential (ZonkAny MinVersion)
forall {kr :: KeyRole}. Credential kr
paymentCred2) (StakeReference -> Maybe AccountId
transStakeRef StakeReference
stakeRef2)
        pure $ case toPlutusTxInfoForPurpose proxy ledgerTxInfo (hoistPlutusPurpose toAsPurpose purpose) of
          Right PlutusTxInfo 'PlutusV4
txInfo ->
            PlutusTxInfo 'PlutusV4
TxInfo
txInfo
              TxInfo -> TxInfo -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` PV4.TxInfo
                { txInfoWithdrawals :: Map Credential Lovelace
PV4.txInfoWithdrawals = [(Credential, Lovelace)] -> Map Credential Lovelace
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                , txInfoVotes :: Map Voter (Map GovernanceActionId Vote)
PV4.txInfoVotes = [(Voter, Map GovernanceActionId Vote)]
-> Map Voter (Map GovernanceActionId Vote)
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                , txInfoValidRange :: POSIXTimeRange
PV4.txInfoValidRange = Maybe POSIXTime -> Maybe POSIXTime -> POSIXTimeRange
PV4.POSIXTimeRange Maybe POSIXTime
forall a. Maybe a
Nothing Maybe POSIXTime
forall a. Maybe a
Nothing
                , txInfoTxCerts :: [TxCert]
PV4.txInfoTxCerts = []
                , txInfoTreasuryDonation :: Lovelace
PV4.txInfoTreasuryDonation = Integer -> Lovelace
PV4.Lovelace Integer
0
                , txInfoSubTxIx :: Maybe Integer
PV4.txInfoSubTxIx = Maybe Integer
forall a. Maybe a
Nothing
                , txInfoRequiredTopLevelGuards :: Map Credential (Maybe Datum)
PV4.txInfoRequiredTopLevelGuards = [(Credential, Maybe Datum)] -> Map Credential (Maybe Datum)
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                , txInfoReferenceInputs :: [TxInInfo]
PV4.txInfoReferenceInputs = []
                , txInfoRedeemers :: Map ScriptPurpose Redeemer
PV4.txInfoRedeemers =
                    [(ScriptPurpose, Redeemer)] -> Map ScriptPurpose Redeemer
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList
                      [
                        ( ScriptHash -> TxOutRef -> ScriptPurpose
PV4.Spending (ScriptHash -> ScriptHash
transScriptHash ScriptHash
scriptHash) TxOutRef
txInRef
                        , BuiltinData -> Redeemer
PV4.Redeemer (BuiltinData -> Redeemer)
-> (Data -> BuiltinData) -> Data -> Redeemer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Data -> BuiltinData
PV4.dataToBuiltinData (Data -> Redeemer) -> Data -> Redeemer
forall a b. (a -> b) -> a -> b
$ Data era -> Data
forall era. Data era -> Data
getPlutusData Data era
redeemer
                        )
                      ]
                , txInfoProposalProcedures :: [ProposalProcedure]
PV4.txInfoProposalProcedures = []
                , txInfoOutputs :: [TxOut]
PV4.txInfoOutputs =
                    [ Address -> Value -> OutputDatum -> Maybe ScriptHash -> TxOut
PV4.TxOut
                        Address
addr1
                        (Coin -> Value
transCoinToValue Coin
coin1)
                        OutputDatum
PV4.NoOutputDatum
                        Maybe ScriptHash
forall a. Maybe a
Nothing
                    ]
                , txInfoMint :: MintValue
PV4.txInfoMint = MintValue
PV4.emptyMintValue
                , txInfoInputs :: [TxInInfo]
PV4.txInfoInputs =
                    [ TxOutRef -> TxOut -> TxInInfo
PV4.TxInInfo
                        TxOutRef
txInRef
                        ( Address -> Value -> OutputDatum -> Maybe ScriptHash -> TxOut
PV4.TxOut
                            Address
addr2
                            (Coin -> Value
transCoinToValue Coin
coin2)
                            OutputDatum
PV4.NoOutputDatum
                            Maybe ScriptHash
forall a. Maybe a
Nothing
                        )
                    ]
                , txInfoId :: TxId
PV4.txInfoId = BuiltinByteString -> TxId
PV4.TxId (BuiltinByteString -> TxId) -> BuiltinByteString -> TxId
forall a b. (a -> b) -> a -> b
$ SafeHash EraIndependentTxBody -> BuiltinByteString
forall i. SafeHash i -> BuiltinByteString
transSafeHash SafeHash EraIndependentTxBody
txBodyHash
                , txInfoGuards :: [Credential]
PV4.txInfoGuards = []
                , txInfoDirectDeposits :: Map Credential Lovelace
PV4.txInfoDirectDeposits = [(Credential, Lovelace)] -> Map Credential Lovelace
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                , txInfoData :: Map DatumHash Datum
PV4.txInfoData = [(DatumHash, Datum)] -> Map DatumHash Datum
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                , txInfoCurrentTreasuryAmount :: Maybe Lovelace
PV4.txInfoCurrentTreasuryAmount = Maybe Lovelace
forall a. Maybe a
Nothing
                , txInfoAccountBalanceIntervals :: AccountBalanceIntervals
PV4.txInfoAccountBalanceIntervals =
                    Map AccountId AccountBalanceInterval -> AccountBalanceIntervals
PV4.AccountBalanceIntervals (Map AccountId AccountBalanceInterval -> AccountBalanceIntervals)
-> Map AccountId AccountBalanceInterval -> AccountBalanceIntervals
forall a b. (a -> b) -> a -> b
$ [(AccountId, AccountBalanceInterval)]
-> Map AccountId AccountBalanceInterval
forall k v. [(k, v)] -> Map k v
PV4.unsafeFromList []
                }
          Left ContextError era
failure -> HasCallStack => String -> Expectation
String -> Expectation
expectationFailure (String -> Expectation) -> String -> Expectation
forall a b. (a -> b) -> a -> b
$ String
"Failed to translate TxInfo: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ContextError era -> String
forall a. Show a => a -> String
show ContextError era
failure
      String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"transGuardingTopTxInfo" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
        String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
          String
"TopTxInfo construction matches a reference construction built from the ledger values"
          (forall era.
(DijkstraEraTxBody era, EraUTxO era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era, AlonzoEraTxWits era,
 Value era ~ MaryValue, ConwayEraPlutusTxInfo 'PlutusV4 era,
 Inject (AlonzoContextError era) (ContextError era),
 Inject (BabbageContextError era) (ContextError era),
 Inject (DijkstraContextError era) (ContextError era),
 Arbitrary (Tx TopTx era), Arbitrary (Value era),
 Arbitrary (Script era)) =>
Property
propTopTxInfoMatchesReference @era)

  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"PlutusV1-V3" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    let plutusV1toV3 :: [SupportedLanguage era]
        plutusV1toV3 :: [SupportedLanguage era]
plutusV1toV3 =
          [ SLanguage 'PlutusV1 -> SupportedLanguage era
forall (l :: Language) era.
EraPlutusTxInfo l era =>
SLanguage l -> SupportedLanguage era
SupportedLanguage SLanguage 'PlutusV1
SPlutusV1
          , SLanguage 'PlutusV2 -> SupportedLanguage era
forall (l :: Language) era.
EraPlutusTxInfo l era =>
SLanguage l -> SupportedLanguage era
SupportedLanguage SLanguage 'PlutusV2
SPlutusV2
          , SLanguage 'PlutusV3 -> SupportedLanguage era
forall (l :: Language) era.
EraPlutusTxInfo l era =>
SLanguage l -> SupportedLanguage era
SupportedLanguage SLanguage 'PlutusV3
SPlutusV3
          ]
    [SupportedLanguage era] -> (SupportedLanguage era -> Spec) -> Spec
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SupportedLanguage era]
plutusV1toV3 ((SupportedLanguage era -> Spec) -> Spec)
-> (SupportedLanguage era -> Spec) -> Spec
forall a b. (a -> b) -> a -> b
$ \(SupportedLanguage SLanguage l
slang) -> do
      String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"UnsupportedScriptInSubTx" (Expectation -> SpecWith (Arg Expectation))
-> Expectation -> SpecWith (Arg Expectation)
forall a b. (a -> b) -> a -> b
$ do
        let
          tx :: Tx SubTx era
tx = forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @SubTx TxBody SubTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody
          ledgerTxInfo :: LedgerTxInfo SubTx era
ledgerTxInfo = UTxO era
-> Tx SubTx era
-> LedgerLevelTxInfo SubTx era
-> LedgerTxInfo SubTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx SubTx era
tx (LedgerLevelTxInfo SubTx era -> LedgerTxInfo SubTx era)
-> LedgerLevelTxInfo SubTx era -> LedgerTxInfo SubTx era
forall a b. (a -> b) -> a -> b
$ TxIx -> LedgerLevelTxInfo SubTx era
forall era. TxIx -> LedgerLevelTxInfo SubTx era
LedgerSubTxInfo (Word16 -> TxIx
TxIx Word16
0)
          txInfoResult :: Either (ContextError era) (PlutusTxInfo l)
txInfoResult = PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage l -> LedgerTxInfo SubTx era -> PlutusTxInfoResult l era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
toPlutusTxInfo SLanguage l
slang LedgerTxInfo SubTx era
ledgerTxInfo)
        Either (ContextError era) (PlutusTxInfo l)
txInfoResult
          Either (ContextError era) (PlutusTxInfo l)
-> ContextError era -> Expectation
forall a b.
(HasCallStack, Show a, Eq a, Show b) =>
Either a b -> a -> Expectation
`shouldBeLeft` DijkstraContextError era -> ContextError era
forall t s. Inject t s => t -> s
inject (forall era. Language -> TxId -> DijkstraContextError era
UnsupportedScriptInSubTx @era (SLanguage l -> Language
forall (l :: Language) (proxy :: Language -> *).
PlutusLanguage l =>
proxy l -> Language
plutusLanguage SLanguage l
slang) (Tx SubTx era -> TxId
forall era (l :: TxLevel). EraTx era => Tx l era -> TxId
txIdTx Tx SubTx era
tx))
      String -> Gen Expectation -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"DirectDepositsNotSupported" (Gen Expectation -> Spec) -> Gen Expectation -> Spec
forall a b. (a -> b) -> a -> b
$ do
        accountAddr <- Gen AccountAddress
forall a. Arbitrary a => Gen a
arbitrary
        coin <- arbitrary
        let
          dd = Map AccountAddress Coin -> DirectDeposits
DirectDeposits (AccountAddress -> Coin -> Map AccountAddress Coin
forall k a. k -> a -> Map k a
Map.singleton AccountAddress
accountAddr Coin
coin)
          tx =
            forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$
              TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (DirectDeposits -> Identity DirectDeposits)
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) DirectDeposits
forall (l :: TxLevel). Lens' (TxBody l era) DirectDeposits
directDepositsTxBodyL ((DirectDeposits -> Identity DirectDeposits)
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> DirectDeposits -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DirectDeposits
dd
          ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
          txInfoResult = PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage l -> LedgerTxInfo TopTx era -> PlutusTxInfoResult l era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
toPlutusTxInfo SLanguage l
slang LedgerTxInfo TopTx era
ledgerTxInfo)
        pure $
          txInfoResult `shouldBeLeft` inject (DirectDepositsNotSupported @era dd)
      String
-> (NonEmptyMap AccountAddress (AccountBalanceInterval era)
    -> Expectation)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"AccountBalanceIntervalsNotSupported" ((NonEmptyMap AccountAddress (AccountBalanceInterval era)
  -> Expectation)
 -> Spec)
-> (NonEmptyMap AccountAddress (AccountBalanceInterval era)
    -> Expectation)
-> Spec
forall a b. (a -> b) -> a -> b
$ \NonEmptyMap AccountAddress (AccountBalanceInterval era)
neAccountBalanceIntervals ->
        let
          abi :: AccountBalanceIntervals era
abi = Map AccountAddress (AccountBalanceInterval era)
-> AccountBalanceIntervals era
forall era.
Map AccountAddress (AccountBalanceInterval era)
-> AccountBalanceIntervals era
AccountBalanceIntervals (Map AccountAddress (AccountBalanceInterval era)
 -> AccountBalanceIntervals era)
-> Map AccountAddress (AccountBalanceInterval era)
-> AccountBalanceIntervals era
forall a b. (a -> b) -> a -> b
$ NonEmptyMap AccountAddress (AccountBalanceInterval era)
-> Map AccountAddress (AccountBalanceInterval era)
forall k v. NonEmptyMap k v -> Map k v
NEM.toMap NonEmptyMap AccountAddress (AccountBalanceInterval era)
neAccountBalanceIntervals
          tx :: Tx TopTx era
tx =
            forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$
              TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (AccountBalanceIntervals era
 -> Identity (AccountBalanceIntervals era))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) (AccountBalanceIntervals era)
forall (l :: TxLevel).
Lens' (TxBody l era) (AccountBalanceIntervals era)
accountBalanceIntervalsTxBodyL ((AccountBalanceIntervals era
  -> Identity (AccountBalanceIntervals era))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> AccountBalanceIntervals era
-> TxBody TopTx era
-> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ AccountBalanceIntervals era
abi
          ledgerTxInfo :: LedgerTxInfo TopTx era
ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
          txInfoResult :: Either (ContextError era) (PlutusTxInfo l)
txInfoResult = PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage l -> LedgerTxInfo TopTx era -> PlutusTxInfoResult l era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
toPlutusTxInfo SLanguage l
slang LedgerTxInfo TopTx era
ledgerTxInfo)
         in
          Either (ContextError era) (PlutusTxInfo l)
txInfoResult Either (ContextError era) (PlutusTxInfo l)
-> ContextError era -> Expectation
forall a b.
(HasCallStack, Show a, Eq a, Show b) =>
Either a b -> a -> Expectation
`shouldBeLeft` DijkstraContextError era -> ContextError era
forall t s. Inject t s => t -> s
inject (forall era. AccountBalanceIntervals era -> DijkstraContextError era
AccountBalanceIntervalsNotSupported @era AccountBalanceIntervals era
abi)
      String -> (ScriptHash -> Expectation) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"GuardScriptHashesNotSupported" ((ScriptHash -> Expectation) -> Spec)
-> (ScriptHash -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$ \(ScriptHash
scriptHash :: ScriptHash) ->
        let
          neScriptHashes :: NonEmpty ScriptHash
neScriptHashes = ScriptHash
scriptHash ScriptHash -> [ScriptHash] -> NonEmpty ScriptHash
forall a. a -> [a] -> NonEmpty a
:| []
          guards :: OSet (Credential kr)
guards = [Credential kr] -> OSet (Credential kr)
forall a. Ord a => [a] -> OSet a
OSet.fromList [ScriptHash -> Credential kr
forall (kr :: KeyRole). ScriptHash -> Credential kr
ScriptHashObj ScriptHash
scriptHash]
          tx :: Tx TopTx era
tx =
            forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$
              TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (OSet (Credential Guard) -> Identity (OSet (Credential Guard)))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) (OSet (Credential Guard))
forall (l :: TxLevel).
Lens' (TxBody l era) (OSet (Credential Guard))
guardsTxBodyL ((OSet (Credential Guard) -> Identity (OSet (Credential Guard)))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> OSet (Credential Guard) -> TxBody TopTx era -> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ OSet (Credential Guard)
forall {kr :: KeyRole}. OSet (Credential kr)
guards
          ledgerTxInfo :: LedgerTxInfo TopTx era
ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
          txInfoResult :: Either (ContextError era) (PlutusTxInfo l)
txInfoResult = PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage l -> LedgerTxInfo TopTx era -> PlutusTxInfoResult l era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
toPlutusTxInfo SLanguage l
slang LedgerTxInfo TopTx era
ledgerTxInfo)
         in
          Either (ContextError era) (PlutusTxInfo l)
txInfoResult Either (ContextError era) (PlutusTxInfo l)
-> ContextError era -> Expectation
forall a b.
(HasCallStack, Show a, Eq a, Show b) =>
Either a b -> a -> Expectation
`shouldBeLeft` DijkstraContextError era -> ContextError era
forall t s. Inject t s => t -> s
inject (forall era. NonEmpty ScriptHash -> DijkstraContextError era
GuardScriptHashesNotSupported @era NonEmpty ScriptHash
neScriptHashes)
      String
-> (NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
    -> Expectation)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"RequiredTopLevelGuardsNotSupported" ((NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
  -> Expectation)
 -> Spec)
-> (NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
    -> Expectation)
-> Spec
forall a b. (a -> b) -> a -> b
$ \NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
neRequiredTopLevelGuards ->
        let
          tx :: Tx TopTx era
tx =
            forall era (l :: TxLevel). EraTx era => TxBody l era -> Tx l era
mkBasicTx @era @TopTx (TxBody TopTx era -> Tx TopTx era)
-> TxBody TopTx era -> Tx TopTx era
forall a b. (a -> b) -> a -> b
$
              TxBody TopTx era
forall era (l :: TxLevel).
(EraTxBody era, Typeable l) =>
TxBody l era
forall (l :: TxLevel). Typeable l => TxBody l era
mkBasicTxBody TxBody TopTx era
-> (TxBody TopTx era -> TxBody TopTx era) -> TxBody TopTx era
forall a b. a -> (a -> b) -> b
& (Map (Credential Guard) (StrictMaybe (Data era))
 -> Identity (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody TopTx era -> Identity (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL ((Map (Credential Guard) (StrictMaybe (Data era))
  -> Identity (Map (Credential Guard) (StrictMaybe (Data era))))
 -> TxBody TopTx era -> Identity (TxBody TopTx era))
-> Map (Credential Guard) (StrictMaybe (Data era))
-> TxBody TopTx era
-> TxBody TopTx era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall k v. NonEmptyMap k v -> Map k v
NEM.toMap NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
neRequiredTopLevelGuards
          ledgerTxInfo :: LedgerTxInfo TopTx era
ledgerTxInfo = UTxO era
-> Tx TopTx era
-> LedgerLevelTxInfo TopTx era
-> LedgerTxInfo TopTx era
forall {era} {level :: TxLevel}.
(ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 Event (EraRule "LEDGER" era) ~ EraRuleEvent "LEDGER" era,
 Event (EraRule "TICK" era) ~ EraRuleEvent "TICK" era,
 PredicateFailure (EraRule "BBODY" era)
 ~ EraRuleFailure "BBODY" era,
 PredicateFailure (EraRule "LEDGER" era)
 ~ EraRuleFailure "LEDGER" era,
 Assert
   (OrdCond
      (CmpNat (ProtVerLow era) (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerLow era)) 'True 'True 'False)
   (TypeError ...),
 Assert
   (OrdCond (CmpNat MinVersion (ProtVerHigh era)) 'True 'True 'False)
   (TypeError ...),
 EraPlutusContext era, ShelleyEraImp era,
 ToExpr (PlutusPurpose AsIxItem era),
 ToExpr (EraRuleFailure "BBODY" era),
 ToExpr (EraRuleFailure "LEDGER" era),
 EncCBOR (EraRuleFailure "BBODY" era),
 EncCBOR (EraRuleFailure "LEDGER" era),
 DecCBOR (EraRuleFailure "BBODY" era),
 DecCBOR (EraRuleFailure "LEDGER" era),
 Ord (EraRuleFailure "BBODY" era),
 Ord (EraRuleFailure "LEDGER" era),
 Show (EraRuleFailure "BBODY" era),
 Show (EraRuleFailure "LEDGER" era),
 NFData (EraRuleFailure "BBODY" era),
 NFData (EraRuleFailure "LEDGER" era)) =>
UTxO era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkLocalLedgerTxInfo UTxO era
forall a. Monoid a => a
mempty Tx TopTx era
tx (LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era)
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall a b. (a -> b) -> a -> b
$ Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
forall a. Monoid a => a
mempty
          txInfoResult :: Either (ContextError era) (PlutusTxInfo l)
txInfoResult = PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage l -> LedgerTxInfo TopTx era -> PlutusTxInfoResult l era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
toPlutusTxInfo SLanguage l
slang LedgerTxInfo TopTx era
ledgerTxInfo)
         in
          Either (ContextError era) (PlutusTxInfo l)
txInfoResult
            Either (ContextError era) (PlutusTxInfo l)
-> ContextError era -> Expectation
forall a b.
(HasCallStack, Show a, Eq a, Show b) =>
Either a b -> a -> Expectation
`shouldBeLeft` DijkstraContextError era -> ContextError era
forall t s. Inject t s => t -> s
inject
              (forall era.
NonEmptySet (Credential Guard) -> DijkstraContextError era
RequiredTopLevelGuardsNotSupported @era (NonEmptySet (Credential Guard) -> DijkstraContextError era)
-> NonEmptySet (Credential Guard) -> DijkstraContextError era
forall a b. (a -> b) -> a -> b
$ NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
-> NonEmptySet (Credential Guard)
forall k v. NonEmptyMap k v -> NonEmptySet k
NEM.keysSet NonEmptyMap (Credential Guard) (StrictMaybe (Data era))
neRequiredTopLevelGuards)

-- | The test checks that since protocol version 9 'transVITime' works correctly,
-- by returning open upper bound of the validaty interval.
transVITimeUpperBoundIsOpen :: Expectation
transVITimeUpperBoundIsOpen :: Expectation
transVITimeUpperBoundIsOpen = do
  let interval :: ValidityInterval
interval = StrictMaybe SlotNo -> StrictMaybe SlotNo -> ValidityInterval
ValidityInterval StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing (SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust (Word64 -> SlotNo
SlotNo Word64
40))
  Proxy DijkstraEra
-> EpochInfo (Either Text)
-> SystemStart
-> ValidityInterval
-> Either (ContextError DijkstraEra) POSIXTimeRange
forall era (proxy :: * -> *).
Inject (AlonzoContextError era) (ContextError era) =>
proxy era
-> EpochInfo (Either Text)
-> SystemStart
-> ValidityInterval
-> Either (ContextError era) POSIXTimeRange
Dijkstra.transValidityInterval (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @DijkstraEra) EpochInfo (Either Text)
forall a. EpochInfo (Either a)
testEpochInfo SystemStart
testSystemStart ValidityInterval
interval
    Either (DijkstraContextError DijkstraEra) POSIXTimeRange
-> POSIXTimeRange -> Expectation
forall a b.
(HasCallStack, Show a, Show b, Eq b) =>
Either a b -> b -> Expectation
`shouldBeRight` Maybe POSIXTime -> Maybe POSIXTime -> POSIXTimeRange
PV4.POSIXTimeRange Maybe POSIXTime
forall a. Maybe a
Nothing (POSIXTime -> Maybe POSIXTime
forall a. a -> Maybe a
Just (POSIXTime -> Maybe POSIXTime) -> POSIXTime -> Maybe POSIXTime
forall a b. (a -> b) -> a -> b
$ Integer -> POSIXTime
PV4.POSIXTime Integer
40000)

-- | Compare the 'PV4.TopTxInfo' built by 'transGuardingTopTxInfo' against a
-- reference implementation built from the ledger values of the batch.
--
-- 'PV4.topTxInfoStartingAccountBalanceIntervals' is not checked: it is not
-- aggregated across the batch of transactions, but it is the translation of a
-- field that only exists on the top-level transaction. Therefore, the
-- translation test will be left to the unit tests of
-- 'PV4.txInfoAccountBalanceIntervals'.
propTopTxInfoMatchesReference ::
  forall era.
  ( DijkstraEraTxBody era
  , EraUTxO era
  , ScriptsNeeded era ~ AlonzoScriptsNeeded era
  , AlonzoEraTxWits era
  , Value era ~ MaryValue
  , ConwayEraPlutusTxInfo PlutusV4 era
  , Inject (AlonzoContextError era) (ContextError era)
  , Inject (BabbageContextError era) (ContextError era)
  , Inject (DijkstraContextError era) (ContextError era)
  , Arbitrary (Tx TopTx era)
  , Arbitrary (Value era)
  , Arbitrary (Script era)
  ) =>
  Property
propTopTxInfoMatchesReference :: forall era.
(DijkstraEraTxBody era, EraUTxO era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era, AlonzoEraTxWits era,
 Value era ~ MaryValue, ConwayEraPlutusTxInfo 'PlutusV4 era,
 Inject (AlonzoContextError era) (ContextError era),
 Inject (BabbageContextError era) (ContextError era),
 Inject (DijkstraContextError era) (ContextError era),
 Arbitrary (Tx TopTx era), Arbitrary (Value era),
 Arbitrary (Script era)) =>
Property
propTopTxInfoMatchesReference =
  Property -> Property
forall prop. Testable prop => prop -> Property
checkCoverage (Property -> Property)
-> (((Tx TopTx era, UTxO era, ScriptHash) -> Property) -> Property)
-> ((Tx TopTx era, UTxO era, ScriptHash) -> Property)
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (Tx TopTx era, UTxO era, ScriptHash)
-> ((Tx TopTx era, UTxO era, ScriptHash) -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (Tx TopTx era, UTxO era, ScriptHash)
genBatchWithGuardingScriptHash (((Tx TopTx era, UTxO era, ScriptHash) -> Property) -> Property)
-> ((Tx TopTx era, UTxO era, ScriptHash) -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \(Tx TopTx era
topTx, UTxO era
utxo, ScriptHash
guardingScriptHash) ->
    Tx TopTx era -> UTxO era -> Property -> Property
forall prop.
Testable prop =>
Tx TopTx era -> UTxO era -> prop -> Property
checkNestedTxsCoverage Tx TopTx era
topTx UTxO era
utxo
      (Property -> Property)
-> (Expectation -> Property) -> Expectation -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> ScriptHash -> Expectation -> Property
forall prop.
Testable prop =>
Tx TopTx era -> ScriptHash -> prop -> Property
checkGuardDatumsCoverage Tx TopTx era
topTx ScriptHash
guardingScriptHash
      (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$ do
        let mkLedgerTxInfo :: Tx l era -> LedgerLevelTxInfo l era -> LedgerTxInfo l era
            mkLedgerTxInfo :: forall (l :: TxLevel).
Tx l era -> LedgerLevelTxInfo l era -> LedgerTxInfo l era
mkLedgerTxInfo =
              -- Like the ledger, every transaction of the batch can use the scripts of the batch
              ProtVer
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO era
-> ScriptsProvided era
-> Tx l era
-> LedgerLevelTxInfo l era
-> LedgerTxInfo l era
forall era (level :: TxLevel).
(EraUTxO era, EraPlutusContext era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
ProtVer
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO era
-> ScriptsProvided era
-> Tx level era
-> LedgerLevelTxInfo level era
-> LedgerTxInfo level era
mkTestLedgerTxInfoWithScripts
                (Version -> Word32 -> ProtVer
ProtVer (forall era. Era era => Version
eraProtVerLow @era) Word32
0)
                EpochInfo (Either Text)
forall a. EpochInfo (Either a)
testEpochInfo
                SystemStart
testSystemStart
                UTxO era
utxo
                (UTxO era -> Tx TopTx era -> ScriptsProvided era
forall era.
EraUTxO era =>
UTxO era -> Tx TopTx era -> ScriptsProvided era
getScriptsProvided UTxO era
utxo Tx TopTx era
topTx)
            mkSubLedgerTxInfo :: TxIx -> Tx SubTx era -> LedgerTxInfo SubTx era
mkSubLedgerTxInfo TxIx
txIx Tx SubTx era
subTx = Tx SubTx era
-> LedgerLevelTxInfo SubTx era -> LedgerTxInfo SubTx era
forall (l :: TxLevel).
Tx l era -> LedgerLevelTxInfo l era -> LedgerTxInfo l era
mkLedgerTxInfo Tx SubTx era
subTx (TxIx -> LedgerLevelTxInfo SubTx era
forall era. TxIx -> LedgerLevelTxInfo SubTx era
LedgerSubTxInfo TxIx
txIx)
            subTxsWithIx :: [(TxIx, Tx SubTx era)]
subTxsWithIx = [TxIx] -> [Tx SubTx era] -> [(TxIx, Tx SubTx era)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word16 -> TxIx
TxIx Word16
0 ..] (OMap TxId (Tx SubTx era) -> [Tx SubTx era]
forall k v. Ord k => OMap k v -> [v]
OMap.elems (Tx TopTx era
topTx Tx TopTx era
-> Getting
     (OMap TxId (Tx SubTx era))
     (Tx TopTx era)
     (OMap TxId (Tx SubTx era))
-> OMap TxId (Tx SubTx era)
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era
 -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
-> Tx TopTx era -> Const (OMap TxId (Tx SubTx era)) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
 -> Tx TopTx era -> Const (OMap TxId (Tx SubTx era)) (Tx TopTx era))
-> ((OMap TxId (Tx SubTx era)
     -> Const (OMap TxId (Tx SubTx era)) (OMap TxId (Tx SubTx era)))
    -> TxBody TopTx era
    -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
-> Getting
     (OMap TxId (Tx SubTx era))
     (Tx TopTx era)
     (OMap TxId (Tx SubTx era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OMap TxId (Tx SubTx era)
 -> Const (OMap TxId (Tx SubTx era)) (OMap TxId (Tx SubTx era)))
-> TxBody TopTx era
-> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era)
forall era.
DijkstraEraTxBody era =>
Lens' (TxBody TopTx era) (OMap TxId (Tx SubTx era))
Lens' (TxBody TopTx era) (OMap TxId (Tx SubTx era))
subTransactionsTxBodyL))
            subTxInfoResults :: Map TxId (TxInfoResult era)
subTxInfoResults =
              [(TxId, TxInfoResult era)] -> Map TxId (TxInfoResult era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
                [ (Tx SubTx era -> TxId
forall era (l :: TxLevel). EraTx era => Tx l era -> TxId
txIdTx Tx SubTx era
subTx, LedgerTxInfo SubTx era -> TxInfoResult era
forall era (level :: TxLevel).
EraPlutusContext era =>
LedgerTxInfo level era -> TxInfoResult era
forall (level :: TxLevel).
LedgerTxInfo level era -> TxInfoResult era
mkTxInfoResult (TxIx -> Tx SubTx era -> LedgerTxInfo SubTx era
mkSubLedgerTxInfo TxIx
txIx Tx SubTx era
subTx))
                | (TxIx
txIx, Tx SubTx era
subTx) <- [(TxIx, Tx SubTx era)]
subTxsWithIx
                ]
            ledgerTxInfo :: LedgerTxInfo TopTx era
ledgerTxInfo = Tx TopTx era
-> LedgerLevelTxInfo TopTx era -> LedgerTxInfo TopTx era
forall (l :: TxLevel).
Tx l era -> LedgerLevelTxInfo l era -> LedgerTxInfo l era
mkLedgerTxInfo Tx TopTx era
topTx (Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
forall era.
Map TxId (TxInfoResult era) -> LedgerLevelTxInfo TopTx era
LedgerTopTxInfo Map TxId (TxInfoResult era)
subTxInfoResults)
        txInfo <- Either (ContextError era) TxInfo -> IO TxInfo
forall a b. (HasCallStack, Show a) => Either a b -> IO b
expectRight (Either (ContextError era) TxInfo -> IO TxInfo)
-> Either (ContextError era) TxInfo -> IO TxInfo
forall a b. (a -> b) -> a -> b
$ PlutusTxInfoResult 'PlutusV4 era
-> Either (ContextError era) (PlutusTxInfo 'PlutusV4)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage 'PlutusV4
-> LedgerTxInfo TopTx era -> PlutusTxInfoResult 'PlutusV4 era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy 'PlutusV4
-> LedgerTxInfo level era -> PlutusTxInfoResult 'PlutusV4 era
toPlutusTxInfo SLanguage 'PlutusV4
SPlutusV4 LedgerTxInfo TopTx era
ledgerTxInfo)
        topTxInfo <- expectRight $ transGuardingTopTxInfo SPlutusV4 txInfo guardingScriptHash ledgerTxInfo
        expectedTopTxInfoSimplified <- expectRight $ mkReferenceTopTxInfoSimplified ledgerTxInfo
        PV4.topTxInfoSimplified topTxInfo `shouldMatchTopTxInfoSimplified` expectedTopTxInfoSimplified
        -- The sub-transactions are translated directly rather than looked up by 'TxId' in
        -- 'subTxInfoResults', so this checks the lookup and that the 'OMap' order is kept.
        expectedSubTxInfos <-
          expectRight $
            traverse
              (\(TxIx
txIx, Tx SubTx era
subTx) -> PlutusTxInfoResult 'PlutusV4 era
-> Either (ContextError era) (PlutusTxInfo 'PlutusV4)
forall (l :: Language) era.
PlutusTxInfoResult l era
-> Either (ContextError era) (PlutusTxInfo l)
unPlutusTxInfoResult (SLanguage 'PlutusV4
-> LedgerTxInfo SubTx era -> PlutusTxInfoResult 'PlutusV4 era
forall (l :: Language) era (proxy :: Language -> *)
       (level :: TxLevel).
EraPlutusTxInfo l era =>
proxy l -> LedgerTxInfo level era -> PlutusTxInfoResult l era
forall (proxy :: Language -> *) (level :: TxLevel).
proxy 'PlutusV4
-> LedgerTxInfo level era -> PlutusTxInfoResult 'PlutusV4 era
toPlutusTxInfo SLanguage 'PlutusV4
SPlutusV4 (TxIx -> Tx SubTx era -> LedgerTxInfo SubTx era
mkSubLedgerTxInfo TxIx
txIx Tx SubTx era
subTx)))
              subTxsWithIx
        PV4.topTxInfoSubTransactions topTxInfo `shouldBe` expectedSubTxInfos
        shouldHaveUniqueAssocMapKeys (PV4.topTxInfoDatums topTxInfo)
        assocMapToMap (PV4.topTxInfoDatums topTxInfo)
          `shouldBe` mkReferenceGuardDatums guardingScriptHash topTx
  where
    -- A batch together with the guarding script hash whose 'PV4.TopTxInfo' is built. The hash
    -- is usually one of the script hashes in the required top-level guards of the batch, so
    -- that 'PV4.topTxInfoDatums' is not empty, and otherwise arbitrary.
    genBatchWithGuardingScriptHash :: Gen (Tx TopTx era, UTxO era, ScriptHash)
    genBatchWithGuardingScriptHash :: Gen (Tx TopTx era, UTxO era, ScriptHash)
genBatchWithGuardingScriptHash = do
      (topTx, utxo) <- forall era.
(DijkstraEraTxBody era, AlonzoEraTxWits era, EraUTxO era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era,
 EraPlutusTxInfo 'PlutusV4 era, Arbitrary (Tx TopTx era),
 Arbitrary (Value era), Arbitrary (Script era)) =>
Gen (Tx TopTx era, UTxO era)
genTranslatableTxWithNestedTxs @era
      let requiredGuardScriptHashes =
            [ ScriptHash
sh
            | ScriptHashObj ScriptHash
sh <-
                Set (Credential Guard) -> [Credential Guard]
forall a. Set a -> [a]
Set.toList (Set (Credential Guard) -> [Credential Guard])
-> Set (Credential Guard) -> [Credential Guard]
forall a b. (a -> b) -> a -> b
$
                  Map (Credential Guard) (StrictMaybe (Data era))
-> Set (Credential Guard)
forall k a. Map k a -> Set k
Map.keysSet (Tx TopTx era
topTx Tx TopTx era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx TopTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (TxBody TopTx era))
-> Tx TopTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era)))
       (TxBody TopTx era))
 -> Tx TopTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx TopTx era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody TopTx era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era)))
         (TxBody TopTx era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx TopTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody TopTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)
                    Set (Credential Guard)
-> Set (Credential Guard) -> Set (Credential Guard)
forall a. Semigroup a => a -> a -> a
<> (Tx SubTx era -> Set (Credential Guard))
-> [Tx SubTx era] -> Set (Credential Guard)
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Map (Credential Guard) (StrictMaybe (Data era))
-> Set (Credential Guard)
forall k a. Map k a -> Set k
Map.keysSet (Map (Credential Guard) (StrictMaybe (Data era))
 -> Set (Credential Guard))
-> (Tx SubTx era
    -> Map (Credential Guard) (StrictMaybe (Data era)))
-> Tx SubTx era
-> Set (Credential Guard)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx SubTx era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx SubTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (TxBody SubTx era))
-> Tx SubTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era)))
       (TxBody SubTx era))
 -> Tx SubTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx SubTx era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody SubTx era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era)))
         (TxBody SubTx era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx SubTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody SubTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (TxBody SubTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)) (Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx)
            ]
      guardingScriptHash <-
        case requiredGuardScriptHashes of
          [] -> Gen ScriptHash
forall a. Arbitrary a => Gen a
arbitrary
          [ScriptHash]
_ -> [(Int, Gen ScriptHash)] -> Gen ScriptHash
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency [(Int
9, [ScriptHash] -> Gen ScriptHash
forall a. HasCallStack => [a] -> Gen a
elements [ScriptHash]
requiredGuardScriptHashes), (Int
1, Gen ScriptHash
forall a. Arbitrary a => Gen a
arbitrary)]
      pure (topTx, utxo, guardingScriptHash)

    -- The datum of the guarding script in the required top-level guards of each transaction of
    -- the batch, keyed by the 'TxId' of that transaction.
    mkReferenceGuardDatums :: ScriptHash -> Tx TopTx era -> Map.Map PV4.TxId PV4.Datum
    mkReferenceGuardDatums :: ScriptHash -> Tx TopTx era -> Map TxId Datum
mkReferenceGuardDatums ScriptHash
guardingScriptHash Tx TopTx era
topTx =
      [(TxId, Datum)] -> Map TxId Datum
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
        [ (TxId -> TxId
transTxId TxId
txId, Data era -> Datum
forall era. Data era -> Datum
transDatum Data era
datum)
        | (TxId
txId, Map (Credential Guard) (StrictMaybe (Data era))
guards) <-
            (Tx TopTx era -> TxId
forall era (l :: TxLevel). EraTx era => Tx l era -> TxId
txIdTx Tx TopTx era
topTx, Tx TopTx era
topTx Tx TopTx era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx TopTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (TxBody TopTx era))
-> Tx TopTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era)))
       (TxBody TopTx era))
 -> Tx TopTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx TopTx era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody TopTx era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era)))
         (TxBody TopTx era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx TopTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody TopTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (TxBody TopTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)
              (TxId, Map (Credential Guard) (StrictMaybe (Data era)))
-> [(TxId, Map (Credential Guard) (StrictMaybe (Data era)))]
-> [(TxId, Map (Credential Guard) (StrictMaybe (Data era)))]
forall a. a -> [a] -> [a]
: [ (Tx SubTx era -> TxId
forall era (l :: TxLevel). EraTx era => Tx l era -> TxId
txIdTx Tx SubTx era
subTx, Tx SubTx era
subTx Tx SubTx era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx SubTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (TxBody SubTx era))
-> Tx SubTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era)))
       (TxBody SubTx era))
 -> Tx SubTx era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx SubTx era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody SubTx era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era)))
         (TxBody SubTx era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx SubTx era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody SubTx era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (TxBody SubTx era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL) | Tx SubTx era
subTx <- Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx
                ]
        , SJust Data era
datum <- [StrictMaybe (Data era)
-> Credential Guard
-> Map (Credential Guard) (StrictMaybe (Data era))
-> StrictMaybe (Data era)
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault StrictMaybe (Data era)
forall a. StrictMaybe a
SNothing (ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
ScriptHashObj ScriptHash
guardingScriptHash) Map (Credential Guard) (StrictMaybe (Data era))
guards]
        ]

    -- Require enough batches where the guarding script has a datum in the
    -- top-level transaction, and in a sub-transaction, since production looks
    -- these up separately, so that 'PV4.topTxInfoDatums' is tested by including
    -- datums from more than one transaction. Also require generated batch to
    -- sometimes have no transaction with a datum for the provided guarding script.
    checkGuardDatumsCoverage :: Testable prop => Tx TopTx era -> ScriptHash -> prop -> Property
    checkGuardDatumsCoverage :: forall prop.
Testable prop =>
Tx TopTx era -> ScriptHash -> prop -> Property
checkGuardDatumsCoverage Tx TopTx era
topTx ScriptHash
guardingScriptHash =
      let hasGuardDatum :: Tx l era -> Bool
          hasGuardDatum :: forall (l :: TxLevel). Tx l era -> Bool
hasGuardDatum Tx l era
tx =
            StrictMaybe (Data era) -> Bool
forall a. StrictMaybe a -> Bool
isSJust (StrictMaybe (Data era) -> Bool) -> StrictMaybe (Data era) -> Bool
forall a b. (a -> b) -> a -> b
$
              StrictMaybe (Data era)
-> Credential Guard
-> Map (Credential Guard) (StrictMaybe (Data era))
-> StrictMaybe (Data era)
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault
                StrictMaybe (Data era)
forall a. StrictMaybe a
SNothing
                (ScriptHash -> Credential Guard
forall (kr :: KeyRole). ScriptHash -> Credential kr
ScriptHashObj ScriptHash
guardingScriptHash)
                (Tx l era
tx Tx l era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Tx l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
 -> Tx l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody l era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)
          datumCount :: Int
datumCount = Map TxId Datum -> Int
forall k a. Map k a -> Int
Map.size (ScriptHash -> Tx TopTx era -> Map TxId Datum
mkReferenceGuardDatums ScriptHash
guardingScriptHash Tx TopTx era
topTx)
       in Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
5 (Int
datumCount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0) String
"Guarding script has no datum in any transaction"
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
10 (Tx TopTx era -> Bool
forall (l :: TxLevel). Tx l era -> Bool
hasGuardDatum Tx TopTx era
topTx) String
"Guarding script has a datum in the top-level transaction"
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
              Double
10
              ((Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Tx SubTx era -> Bool
forall (l :: TxLevel). Tx l era -> Bool
hasGuardDatum (Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx))
              String
"Guarding script has a datum in a sub-transaction"
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> prop -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
2 (Int
datumCount Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) String
"Guarding script has a datum in two or more transactions"

    -- Reports how many sub-transactions are generated, and require enough
    -- batches where the fields aggregated across the batch are set in more than
    -- one transaction, since that is where the aggregation strategies of
    -- 'transGuardingTopTxInfo' can disagree.
    checkNestedTxsCoverage :: Testable prop => Tx TopTx era -> UTxO era -> prop -> Property
    checkNestedTxsCoverage :: forall prop.
Testable prop =>
Tx TopTx era -> UTxO era -> prop -> Property
checkNestedTxsCoverage Tx TopTx era
topTx UTxO era
utxo =
      let subTxs :: [Tx SubTx era]
subTxs = Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx
       in String -> [String] -> Property -> Property
forall prop.
Testable prop =>
String -> [String] -> prop -> Property
tabulate String
"Number of sub-transactions" [Int -> String
forall a. Show a => a -> String
show ([Tx SubTx era] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tx SubTx era]
subTxs)]
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
5 ([Tx SubTx era] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Tx SubTx era]
subTxs) String
"Has no sub-transactions"
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
15 ([Tx SubTx era] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tx SubTx era]
subTxs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) String
"Has at least two sub-transactions"
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverConcatenatedFields Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverMints Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverAccounts Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverValidityIntervals Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverGuards Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverDatums Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> UTxO era -> Property -> Property
forall prop.
Testable prop =>
Tx TopTx era -> UTxO era -> prop -> Property
coverRedeemers Tx TopTx era
topTx UTxO era
utxo
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> Property -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverVotes Tx TopTx era
topTx
            (Property -> Property) -> (prop -> Property) -> prop -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era -> prop -> Property
forall p. Testable p => Tx TopTx era -> p -> Property
coverTreasury Tx TopTx era
topTx

    -- Fields concatenated across the batch
    coverConcatenatedFields :: Testable p => Tx TopTx era -> p -> Property
    coverConcatenatedFields :: forall p. Testable p => Tx TopTx era -> p -> Property
coverConcatenatedFields Tx TopTx era
topTx =
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set TxIn)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"inputs" (Tx l era -> Getting (Set TxIn) (Tx l era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Tx l era -> Const (Set TxIn) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (Set TxIn) (TxBody l era))
 -> Tx l era -> Const (Set TxIn) (Tx l era))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Getting (Set TxIn) (Tx l era) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody l era -> Const (Set TxIn) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
inputsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set TxIn)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"reference inputs" (Tx l era -> Getting (Set TxIn) (Tx l era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Tx l era -> Const (Set TxIn) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (Set TxIn) (TxBody l era))
 -> Tx l era -> Const (Set TxIn) (Tx l era))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Getting (Set TxIn) (Tx l era) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody l era -> Const (Set TxIn) (TxBody l era)
forall era (l :: TxLevel).
BabbageEraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
referenceInputsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set TxIn)
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
25 String
"reference inputs" (Tx l era -> Getting (Set TxIn) (Tx l era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Tx l era -> Const (Set TxIn) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (Set TxIn) (TxBody l era))
 -> Tx l era -> Const (Set TxIn) (Tx l era))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Getting (Set TxIn) (Tx l era) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody l era -> Const (Set TxIn) (TxBody l era)
forall era (l :: TxLevel).
BabbageEraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
referenceInputsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> StrictSeq (TxOut era))
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"outputs" (Tx l era
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
-> StrictSeq (TxOut era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
 -> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era))
-> ((StrictSeq (TxOut era)
     -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
    -> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxOut era)
 -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
-> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> StrictSeq (TxCert era))
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"certs" (Tx l era
-> Getting
     (StrictSeq (TxCert era)) (Tx l era) (StrictSeq (TxCert era))
-> StrictSeq (TxCert era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
-> Tx l era -> Const (StrictSeq (TxCert era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
 -> Tx l era -> Const (StrictSeq (TxCert era)) (Tx l era))
-> ((StrictSeq (TxCert era)
     -> Const (StrictSeq (TxCert era)) (StrictSeq (TxCert era)))
    -> TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
-> Getting
     (StrictSeq (TxCert era)) (Tx l era) (StrictSeq (TxCert era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxCert era)
 -> Const (StrictSeq (TxCert era)) (StrictSeq (TxCert era)))
-> TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxCert era))
forall (l :: TxLevel).
Lens' (TxBody l era) (StrictSeq (TxCert era))
certsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel).
    Tx l era -> OSet (ProposalProcedure era))
-> p
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"proposals" (Tx l era
-> Getting
     (OSet (ProposalProcedure era))
     (Tx l era)
     (OSet (ProposalProcedure era))
-> OSet (ProposalProcedure era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era
 -> Const (OSet (ProposalProcedure era)) (TxBody l era))
-> Tx l era -> Const (OSet (ProposalProcedure era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era
  -> Const (OSet (ProposalProcedure era)) (TxBody l era))
 -> Tx l era -> Const (OSet (ProposalProcedure era)) (Tx l era))
-> ((OSet (ProposalProcedure era)
     -> Const
          (OSet (ProposalProcedure era)) (OSet (ProposalProcedure era)))
    -> TxBody l era
    -> Const (OSet (ProposalProcedure era)) (TxBody l era))
-> Getting
     (OSet (ProposalProcedure era))
     (Tx l era)
     (OSet (ProposalProcedure era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OSet (ProposalProcedure era)
 -> Const
      (OSet (ProposalProcedure era)) (OSet (ProposalProcedure era)))
-> TxBody l era
-> Const (OSet (ProposalProcedure era)) (TxBody l era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (OSet (ProposalProcedure era))
forall (l :: TxLevel).
Lens' (TxBody l era) (OSet (ProposalProcedure era))
proposalProceduresTxBodyL)

    coverMints :: Testable p => Tx TopTx era -> p -> Property
    coverMints :: forall p. Testable p => Tx TopTx era -> p -> Property
coverMints Tx TopTx era
topTx = do
      let
        mintedAssetIdsWith :: (Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
        mintedAssetIdsWith :: forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith Integer -> Bool
p Tx l era
tx =
          [(PolicyID, AssetName)] -> Set (PolicyID, AssetName)
forall a. Ord a => [a] -> Set a
Set.fromList
            [ (PolicyID
pid, AssetName
an)
            | (PolicyID
pid, AssetName
an, Integer
q) <- MultiAsset -> [(PolicyID, AssetName, Integer)]
flattenMultiAsset (Tx l era
tx Tx l era -> Getting MultiAsset (Tx l era) MultiAsset -> MultiAsset
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const MultiAsset (TxBody l era))
-> Tx l era -> Const MultiAsset (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const MultiAsset (TxBody l era))
 -> Tx l era -> Const MultiAsset (Tx l era))
-> ((MultiAsset -> Const MultiAsset MultiAsset)
    -> TxBody l era -> Const MultiAsset (TxBody l era))
-> Getting MultiAsset (Tx l era) MultiAsset
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MultiAsset -> Const MultiAsset MultiAsset)
-> TxBody l era -> Const MultiAsset (TxBody l era)
forall era (l :: TxLevel).
MaryEraTxBody era =>
Lens' (TxBody l era) MultiAsset
forall (l :: TxLevel). Lens' (TxBody l era) MultiAsset
mintTxBodyL)
            , Integer -> Bool
p Integer
q
            ]
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
25 String
"minted asset ids" ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0))
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
25 String
"burned asset ids" ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0))
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
10
          ( let mintedAssetIds :: Set (PolicyID, AssetName)
mintedAssetIds = [Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName)
forall a. Monoid a => [a] -> a
mconcat ([Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName)
forall a b. (a -> b) -> a -> b
$ Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0))
                burnedAssetIds :: Set (PolicyID, AssetName)
burnedAssetIds = [Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName)
forall a. Monoid a => [a] -> a
mconcat ([Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)] -> Set (PolicyID, AssetName)
forall a b. (a -> b) -> a -> b
$ Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0))
             in Bool -> Bool
not (Set (PolicyID, AssetName) -> Set (PolicyID, AssetName) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
Set.disjoint Set (PolicyID, AssetName)
mintedAssetIds Set (PolicyID, AssetName)
burnedAssetIds)
          )
          String
"Same asset id minted in one tx and burned in another"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
10
          ( let mintedAssetIdsPerTx :: [Set (PolicyID, AssetName)]
mintedAssetIdsPerTx = Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0))
                burnedAssetIdsPerTx :: [Set (PolicyID, AssetName)]
burnedAssetIdsPerTx = Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Set (PolicyID, AssetName))
-> [Set (PolicyID, AssetName)]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx ((Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
forall (l :: TxLevel).
(Integer -> Bool) -> Tx l era -> Set (PolicyID, AssetName)
mintedAssetIdsWith (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0))
             in [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or
                  [ PolicyID
mintedPolicyId PolicyID -> PolicyID -> Bool
forall a. Eq a => a -> a -> Bool
== PolicyID
burnedPolicyId Bool -> Bool -> Bool
&& AssetName
mintedAssetName AssetName -> AssetName -> Bool
forall a. Eq a => a -> a -> Bool
/= AssetName
burnedAssetName
                  | (Int
i, Set (PolicyID, AssetName)
minted) <- [Int]
-> [Set (PolicyID, AssetName)]
-> [(Int, Set (PolicyID, AssetName))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 :: Int ..] [Set (PolicyID, AssetName)]
mintedAssetIdsPerTx
                  , (Int
j, Set (PolicyID, AssetName)
burned) <- [Int]
-> [Set (PolicyID, AssetName)]
-> [(Int, Set (PolicyID, AssetName))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
Item [Int]
0 ..] [Set (PolicyID, AssetName)]
burnedAssetIdsPerTx
                  , Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
j
                  , (PolicyID
mintedPolicyId, AssetName
mintedAssetName) <- Set (PolicyID, AssetName) -> [(PolicyID, AssetName)]
forall a. Set a -> [a]
Set.toList Set (PolicyID, AssetName)
minted
                  , (PolicyID
burnedPolicyId, AssetName
burnedAssetName) <- Set (PolicyID, AssetName) -> [(PolicyID, AssetName)]
forall a. Set a -> [a]
Set.toList Set (PolicyID, AssetName)
burned
                  ]
          )
          String
"Same policy id, different asset names, minted in one tx and burned in another"

    -- Withdrawals and direct deposits
    coverAccounts :: Testable p => Tx TopTx era -> p -> Property
    coverAccounts :: forall p. Testable p => Tx TopTx era -> p -> Property
coverAccounts Tx TopTx era
topTx =
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Withdrawals)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"withdrawals" (Tx l era
-> Getting Withdrawals (Tx l era) Withdrawals -> Withdrawals
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const Withdrawals (TxBody l era))
-> Tx l era -> Const Withdrawals (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const Withdrawals (TxBody l era))
 -> Tx l era -> Const Withdrawals (Tx l era))
-> ((Withdrawals -> Const Withdrawals Withdrawals)
    -> TxBody l era -> Const Withdrawals (TxBody l era))
-> Getting Withdrawals (Tx l era) Withdrawals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Withdrawals -> Const Withdrawals Withdrawals)
-> TxBody l era -> Const Withdrawals (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) Withdrawals
forall (l :: TxLevel). Lens' (TxBody l era) Withdrawals
withdrawalsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set AccountAddress)
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs
          Tx TopTx era
topTx
          Double
25
          String
"withdrawals"
          (Map AccountAddress Coin -> Set AccountAddress
forall k a. Map k a -> Set k
Map.keysSet (Map AccountAddress Coin -> Set AccountAddress)
-> (Tx l era -> Map AccountAddress Coin)
-> Tx l era
-> Set AccountAddress
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Withdrawals -> Map AccountAddress Coin
unWithdrawals (Withdrawals -> Map AccountAddress Coin)
-> (Tx l era -> Withdrawals) -> Tx l era -> Map AccountAddress Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx l era
-> Getting Withdrawals (Tx l era) Withdrawals -> Withdrawals
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const Withdrawals (TxBody l era))
-> Tx l era -> Const Withdrawals (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const Withdrawals (TxBody l era))
 -> Tx l era -> Const Withdrawals (Tx l era))
-> ((Withdrawals -> Const Withdrawals Withdrawals)
    -> TxBody l era -> Const Withdrawals (TxBody l era))
-> Getting Withdrawals (Tx l era) Withdrawals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Withdrawals -> Const Withdrawals Withdrawals)
-> TxBody l era -> Const Withdrawals (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) Withdrawals
forall (l :: TxLevel). Lens' (TxBody l era) Withdrawals
withdrawalsTxBodyL))
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> DirectDeposits)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"direct deposits" (Tx l era
-> Getting DirectDeposits (Tx l era) DirectDeposits
-> DirectDeposits
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const DirectDeposits (TxBody l era))
-> Tx l era -> Const DirectDeposits (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const DirectDeposits (TxBody l era))
 -> Tx l era -> Const DirectDeposits (Tx l era))
-> ((DirectDeposits -> Const DirectDeposits DirectDeposits)
    -> TxBody l era -> Const DirectDeposits (TxBody l era))
-> Getting DirectDeposits (Tx l era) DirectDeposits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DirectDeposits -> Const DirectDeposits DirectDeposits)
-> TxBody l era -> Const DirectDeposits (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) DirectDeposits
forall (l :: TxLevel). Lens' (TxBody l era) DirectDeposits
directDepositsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set AccountAddress)
-> p
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs
          Tx TopTx era
topTx
          Double
25
          String
"direct deposits"
          (Map AccountAddress Coin -> Set AccountAddress
forall k a. Map k a -> Set k
Map.keysSet (Map AccountAddress Coin -> Set AccountAddress)
-> (Tx l era -> Map AccountAddress Coin)
-> Tx l era
-> Set AccountAddress
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectDeposits -> Map AccountAddress Coin
unDirectDeposits (DirectDeposits -> Map AccountAddress Coin)
-> (Tx l era -> DirectDeposits)
-> Tx l era
-> Map AccountAddress Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx l era
-> Getting DirectDeposits (Tx l era) DirectDeposits
-> DirectDeposits
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const DirectDeposits (TxBody l era))
-> Tx l era -> Const DirectDeposits (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const DirectDeposits (TxBody l era))
 -> Tx l era -> Const DirectDeposits (Tx l era))
-> ((DirectDeposits -> Const DirectDeposits DirectDeposits)
    -> TxBody l era -> Const DirectDeposits (TxBody l era))
-> Getting DirectDeposits (Tx l era) DirectDeposits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DirectDeposits -> Const DirectDeposits DirectDeposits)
-> TxBody l era -> Const DirectDeposits (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) DirectDeposits
forall (l :: TxLevel). Lens' (TxBody l era) DirectDeposits
directDepositsTxBodyL))

    coverValidityIntervals :: Testable p => Tx TopTx era -> p -> Property
    coverValidityIntervals :: forall p. Testable p => Tx TopTx era -> p -> Property
coverValidityIntervals Tx TopTx era
topTx = do
      let subTxs :: [Tx SubTx era]
subTxs = Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx
          allTxVldtIntervals :: [ValidityInterval]
allTxVldtIntervals = Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> ValidityInterval)
-> [ValidityInterval]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx (Tx l era
-> Getting ValidityInterval (Tx l era) ValidityInterval
-> ValidityInterval
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const ValidityInterval (TxBody l era))
-> Tx l era -> Const ValidityInterval (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const ValidityInterval (TxBody l era))
 -> Tx l era -> Const ValidityInterval (Tx l era))
-> ((ValidityInterval -> Const ValidityInterval ValidityInterval)
    -> TxBody l era -> Const ValidityInterval (TxBody l era))
-> Getting ValidityInterval (Tx l era) ValidityInterval
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const ValidityInterval ValidityInterval)
-> TxBody l era -> Const ValidityInterval (TxBody l era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL)
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> ValidityInterval)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"validity intervals" (Tx l era
-> Getting ValidityInterval (Tx l era) ValidityInterval
-> ValidityInterval
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const ValidityInterval (TxBody l era))
-> Tx l era -> Const ValidityInterval (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const ValidityInterval (TxBody l era))
 -> Tx l era -> Const ValidityInterval (Tx l era))
-> ((ValidityInterval -> Const ValidityInterval ValidityInterval)
    -> TxBody l era -> Const ValidityInterval (TxBody l era))
-> Getting ValidityInterval (Tx l era) ValidityInterval
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const ValidityInterval ValidityInterval)
-> TxBody l era -> Const ValidityInterval (TxBody l era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
3
          ( (ValidityInterval -> Bool) -> [ValidityInterval] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (StrictMaybe SlotNo -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (StrictMaybe SlotNo -> Bool)
-> (ValidityInterval -> StrictMaybe SlotNo)
-> ValidityInterval
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidityInterval -> StrictMaybe SlotNo
invalidHereafter) [ValidityInterval]
allTxVldtIntervals
              Bool -> Bool -> Bool
&& (ValidityInterval -> Bool) -> [ValidityInterval] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (StrictMaybe SlotNo -> Bool
forall a. StrictMaybe a -> Bool
isSJust (StrictMaybe SlotNo -> Bool)
-> (ValidityInterval -> StrictMaybe SlotNo)
-> ValidityInterval
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidityInterval -> StrictMaybe SlotNo
invalidBefore) [ValidityInterval]
allTxVldtIntervals
          )
          String
"Validity interval with no upper bounds in tx batch, but at least one top or sub tx with a lower bound"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
3
          ( (ValidityInterval -> Bool) -> [ValidityInterval] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (StrictMaybe SlotNo -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (StrictMaybe SlotNo -> Bool)
-> (ValidityInterval -> StrictMaybe SlotNo)
-> ValidityInterval
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidityInterval -> StrictMaybe SlotNo
invalidBefore) [ValidityInterval]
allTxVldtIntervals
              Bool -> Bool -> Bool
&& (ValidityInterval -> Bool) -> [ValidityInterval] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (StrictMaybe SlotNo -> Bool
forall a. StrictMaybe a -> Bool
isSJust (StrictMaybe SlotNo -> Bool)
-> (ValidityInterval -> StrictMaybe SlotNo)
-> ValidityInterval
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidityInterval -> StrictMaybe SlotNo
invalidHereafter) [ValidityInterval]
allTxVldtIntervals
          )
          String
"Validity interval with no lower bounds in tx batch, but at least one top or sub txs with an upper bound"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
5
          ( (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
              ( \Tx SubTx era
subTx ->
                  Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe SlotNo) (Tx SubTx era) (StrictMaybe SlotNo)
-> StrictMaybe SlotNo
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe SlotNo) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era
  -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe SlotNo) (Tx SubTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> TxBody SubTx era
    -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> Getting (StrictMaybe SlotNo) (Tx SubTx era) (StrictMaybe SlotNo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> TxBody SubTx era
-> Const (StrictMaybe SlotNo) (TxBody SubTx era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL ((ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
 -> TxBody SubTx era
 -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> (StrictMaybe SlotNo
    -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> TxBody SubTx era
-> Const (StrictMaybe SlotNo) (TxBody SubTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe SlotNo
 -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval
Lens' ValidityInterval (StrictMaybe SlotNo)
invalidBeforeL StrictMaybe SlotNo -> StrictMaybe SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
> Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe SlotNo) (Tx TopTx era) (StrictMaybe SlotNo)
-> StrictMaybe SlotNo
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe SlotNo) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe SlotNo) (Tx TopTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> TxBody TopTx era
    -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> Getting (StrictMaybe SlotNo) (Tx TopTx era) (StrictMaybe SlotNo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> TxBody TopTx era
-> Const (StrictMaybe SlotNo) (TxBody TopTx era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL ((ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
 -> TxBody TopTx era
 -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> (StrictMaybe SlotNo
    -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> TxBody TopTx era
-> Const (StrictMaybe SlotNo) (TxBody TopTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe SlotNo
 -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval
Lens' ValidityInterval (StrictMaybe SlotNo)
invalidBeforeL
              )
              [Tx SubTx era]
subTxs
          )
          String
"Strictly greatest lower bound comes from a sub tx"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
5
          (Set SlotNo -> Int
forall a. Set a -> Int
Set.size ([SlotNo] -> Set SlotNo
forall a. Ord a => [a] -> Set a
Set.fromList [SlotNo
slot | SJust SlotNo
slot <- (ValidityInterval -> StrictMaybe SlotNo)
-> [ValidityInterval] -> [StrictMaybe SlotNo]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValidityInterval -> StrictMaybe SlotNo
invalidBefore [ValidityInterval]
allTxVldtIntervals]) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2)
          String
"Lower bound set in two or more transactions, with different slots"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
5
          (Set SlotNo -> Int
forall a. Set a -> Int
Set.size ([SlotNo] -> Set SlotNo
forall a. Ord a => [a] -> Set a
Set.fromList [SlotNo
slot | SJust SlotNo
slot <- (ValidityInterval -> StrictMaybe SlotNo)
-> [ValidityInterval] -> [StrictMaybe SlotNo]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValidityInterval -> StrictMaybe SlotNo
invalidHereafter [ValidityInterval]
allTxVldtIntervals]) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2)
          String
"Upper bound set in two or more transactions, with different slots"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
5
          ( (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
              ( \Tx SubTx era
subTx ->
                  (Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe SlotNo) (Tx SubTx era) (StrictMaybe SlotNo)
-> StrictMaybe SlotNo
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe SlotNo) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era
  -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe SlotNo) (Tx SubTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> TxBody SubTx era
    -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> Getting (StrictMaybe SlotNo) (Tx SubTx era) (StrictMaybe SlotNo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> TxBody SubTx era
-> Const (StrictMaybe SlotNo) (TxBody SubTx era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL ((ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
 -> TxBody SubTx era
 -> Const (StrictMaybe SlotNo) (TxBody SubTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> (StrictMaybe SlotNo
    -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> TxBody SubTx era
-> Const (StrictMaybe SlotNo) (TxBody SubTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe SlotNo
 -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval
Lens' ValidityInterval (StrictMaybe SlotNo)
invalidHereAfterL)
                    StrictMaybe SlotNo -> StrictMaybe SlotNo -> Bool
`isUpperBoundBelow` (Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe SlotNo) (Tx TopTx era) (StrictMaybe SlotNo)
-> StrictMaybe SlotNo
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe SlotNo) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe SlotNo) (Tx TopTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> TxBody TopTx era
    -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> Getting (StrictMaybe SlotNo) (Tx TopTx era) (StrictMaybe SlotNo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> TxBody TopTx era
-> Const (StrictMaybe SlotNo) (TxBody TopTx era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL ((ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
 -> TxBody TopTx era
 -> Const (StrictMaybe SlotNo) (TxBody TopTx era))
-> ((StrictMaybe SlotNo
     -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
    -> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval)
-> (StrictMaybe SlotNo
    -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> TxBody TopTx era
-> Const (StrictMaybe SlotNo) (TxBody TopTx era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe SlotNo
 -> Const (StrictMaybe SlotNo) (StrictMaybe SlotNo))
-> ValidityInterval -> Const (StrictMaybe SlotNo) ValidityInterval
Lens' ValidityInterval (StrictMaybe SlotNo)
invalidHereAfterL)
              )
              [Tx SubTx era]
subTxs
          )
          String
"Strictly lowest upper bound comes from a sub tx"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
1
          ([ValidityInterval] -> ValidityInterval
forall a. Monoid a => [a] -> a
mconcat [ValidityInterval]
allTxVldtIntervals ValidityInterval -> [ValidityInterval] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [ValidityInterval]
allTxVldtIntervals)
          String
"Greatest lower bound and smallest upper bound come from two different txs"

    -- Guards and required top-level guards
    coverGuards :: Testable p => Tx TopTx era -> p -> Property
    coverGuards :: forall p. Testable p => Tx TopTx era -> p -> Property
coverGuards Tx TopTx era
topTx =
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> OSet (Credential Guard))
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"guards" (Tx l era
-> Getting
     (OSet (Credential Guard)) (Tx l era) (OSet (Credential Guard))
-> OSet (Credential Guard)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
-> Tx l era -> Const (OSet (Credential Guard)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
 -> Tx l era -> Const (OSet (Credential Guard)) (Tx l era))
-> ((OSet (Credential Guard)
     -> Const (OSet (Credential Guard)) (OSet (Credential Guard)))
    -> TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
-> Getting
     (OSet (Credential Guard)) (Tx l era) (OSet (Credential Guard))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OSet (Credential Guard)
 -> Const (OSet (Credential Guard)) (OSet (Credential Guard)))
-> TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) (OSet (Credential Guard))
forall (l :: TxLevel).
Lens' (TxBody l era) (OSet (Credential Guard))
guardsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set (Credential Guard))
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
25 String
"guards" (OSet (Credential Guard) -> Set (Credential Guard)
forall a. OSet a -> Set a
OSet.toSet (OSet (Credential Guard) -> Set (Credential Guard))
-> (Tx l era -> OSet (Credential Guard))
-> Tx l era
-> Set (Credential Guard)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx l era
-> Getting
     (OSet (Credential Guard)) (Tx l era) (OSet (Credential Guard))
-> OSet (Credential Guard)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
-> Tx l era -> Const (OSet (Credential Guard)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
 -> Tx l era -> Const (OSet (Credential Guard)) (Tx l era))
-> ((OSet (Credential Guard)
     -> Const (OSet (Credential Guard)) (OSet (Credential Guard)))
    -> TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era))
-> Getting
     (OSet (Credential Guard)) (Tx l era) (OSet (Credential Guard))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OSet (Credential Guard)
 -> Const (OSet (Credential Guard)) (OSet (Credential Guard)))
-> TxBody l era -> Const (OSet (Credential Guard)) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens' (TxBody l era) (OSet (Credential Guard))
forall (l :: TxLevel).
Lens' (TxBody l era) (OSet (Credential Guard))
guardsTxBodyL))
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel).
    Tx l era -> Map (Credential Guard) (StrictMaybe (Data era)))
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs
          Tx TopTx era
topTx
          Double
25
          String
"required top-level guards"
          (Tx l era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Tx l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
 -> Tx l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody l era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set (Credential Guard))
-> p
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs
          Tx TopTx era
topTx
          Double
25
          String
"required top-level guards"
          (Map (Credential Guard) (StrictMaybe (Data era))
-> Set (Credential Guard)
forall k a. Map k a -> Set k
Map.keysSet (Map (Credential Guard) (StrictMaybe (Data era))
 -> Set (Credential Guard))
-> (Tx l era -> Map (Credential Guard) (StrictMaybe (Data era)))
-> Tx l era
-> Set (Credential Guard)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx l era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Tx l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
 -> Tx l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody l era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL))

    coverDatums :: Testable p => Tx TopTx era -> p -> Property
    coverDatums :: forall p. Testable p => Tx TopTx era -> p -> Property
coverDatums Tx TopTx era
topTx =
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> TxDats era)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"datums" (Tx l era
-> Getting (TxDats era) (Tx l era) (TxDats era) -> TxDats era
forall s a. s -> Getting a s a -> a
^. (TxWits era -> Const (TxDats era) (TxWits era))
-> Tx l era -> Const (TxDats era) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era -> Const (TxDats era) (TxWits era))
 -> Tx l era -> Const (TxDats era) (Tx l era))
-> ((TxDats era -> Const (TxDats era) (TxDats era))
    -> TxWits era -> Const (TxDats era) (TxWits era))
-> Getting (TxDats era) (Tx l era) (TxDats era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxDats era -> Const (TxDats era) (TxDats era))
-> TxWits era -> Const (TxDats era) (TxWits era)
forall era. AlonzoEraTxWits era => Lens' (TxWits era) (TxDats era)
Lens' (TxWits era) (TxDats era)
datsTxWitsL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set DataHash)
-> p
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
25 String
"datums" (Map DataHash (Data era) -> Set DataHash
forall k a. Map k a -> Set k
Map.keysSet (Map DataHash (Data era) -> Set DataHash)
-> (Tx l era -> Map DataHash (Data era))
-> Tx l era
-> Set DataHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxDats era -> Map DataHash (Data era)
forall era. TxDats era -> Map DataHash (Data era)
unTxDats (TxDats era -> Map DataHash (Data era))
-> (Tx l era -> TxDats era) -> Tx l era -> Map DataHash (Data era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tx l era
-> Getting (TxDats era) (Tx l era) (TxDats era) -> TxDats era
forall s a. s -> Getting a s a -> a
^. (TxWits era -> Const (TxDats era) (TxWits era))
-> Tx l era -> Const (TxDats era) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era -> Const (TxDats era) (TxWits era))
 -> Tx l era -> Const (TxDats era) (Tx l era))
-> ((TxDats era -> Const (TxDats era) (TxDats era))
    -> TxWits era -> Const (TxDats era) (TxWits era))
-> Getting (TxDats era) (Tx l era) (TxDats era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxDats era -> Const (TxDats era) (TxDats era))
-> TxWits era -> Const (TxDats era) (TxWits era)
forall era. AlonzoEraTxWits era => Lens' (TxWits era) (TxDats era)
Lens' (TxWits era) (TxDats era)
datsTxWitsL))

    coverRedeemers :: Testable p => Tx TopTx era -> UTxO era -> p -> Property
    coverRedeemers :: forall prop.
Testable prop =>
Tx TopTx era -> UTxO era -> prop -> Property
coverRedeemers Tx TopTx era
topTx UTxO era
utxo =
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Redeemers era)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"redeemers" (Tx l era
-> Getting (Redeemers era) (Tx l era) (Redeemers era)
-> Redeemers era
forall s a. s -> Getting a s a -> a
^. (TxWits era -> Const (Redeemers era) (TxWits era))
-> Tx l era -> Const (Redeemers era) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era -> Const (Redeemers era) (TxWits era))
 -> Tx l era -> Const (Redeemers era) (Tx l era))
-> ((Redeemers era -> Const (Redeemers era) (Redeemers era))
    -> TxWits era -> Const (Redeemers era) (TxWits era))
-> Getting (Redeemers era) (Tx l era) (Redeemers era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Redeemers era -> Const (Redeemers era) (Redeemers era))
-> TxWits era -> Const (Redeemers era) (TxWits era)
forall era.
AlonzoEraTxWits era =>
Lens' (TxWits era) (Redeemers era)
Lens' (TxWits era) (Redeemers era)
rdmrsTxWitsL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set ScriptHash)
-> Property
-> Property
forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs
          Tx TopTx era
topTx
          Double
15
          String
"redeemer script hashes"
          ([ScriptHash] -> Set ScriptHash
forall a. Ord a => [a] -> Set a
Set.fromList ([ScriptHash] -> Set ScriptHash)
-> (Tx l era -> [ScriptHash]) -> Tx l era -> Set ScriptHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTxO era -> Tx l era -> [ScriptHash]
forall era (l :: TxLevel).
(EraUTxO era, AlonzoEraTxWits era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
UTxO era -> Tx l era -> [ScriptHash]
scriptHashesPerRedeemer UTxO era
utxo)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
25
          ( ([ScriptHash] -> Bool) -> [[ScriptHash]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
              (\[ScriptHash]
hs -> [ScriptHash] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ScriptHash]
hs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Set ScriptHash -> Int
forall a. Set a -> Int
Set.size ([ScriptHash] -> Set ScriptHash
forall a. Ord a => [a] -> Set a
Set.fromList [ScriptHash]
hs))
              (Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> [ScriptHash])
-> [[ScriptHash]]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx (UTxO era -> Tx l era -> [ScriptHash]
forall era (l :: TxLevel).
(EraUTxO era, AlonzoEraTxWits era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
UTxO era -> Tx l era -> [ScriptHash]
scriptHashesPerRedeemer UTxO era
utxo))
          )
          String
"Same script executed for two purposes in one transaction"

    coverVotes :: Testable p => Tx TopTx era -> p -> Property
    coverVotes :: forall p. Testable p => Tx TopTx era -> p -> Property
coverVotes Tx TopTx era
topTx = do
      let
        subTxs :: [Tx SubTx era]
subTxs = Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx
        -- The `Vote` cast on each `(Voter, GovActionId)` pair by a transaction
        getTxVotes :: Tx l era -> Map.Map (Voter, GovActionId) Vote
        getTxVotes :: forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes Tx l era
tx =
          (Map (Voter, GovActionId) Vote
 -> Voter
 -> GovActionId
 -> VotingProcedure era
 -> Map (Voter, GovActionId) Vote)
-> Map (Voter, GovActionId) Vote
-> VotingProcedures era
-> Map (Voter, GovActionId) Vote
forall c era.
(c -> Voter -> GovActionId -> VotingProcedure era -> c)
-> c -> VotingProcedures era -> c
foldlVotingProcedures
            (\Map (Voter, GovActionId) Vote
acc Voter
voter GovActionId
gaid VotingProcedure era
vp -> (Voter, GovActionId)
-> Vote
-> Map (Voter, GovActionId) Vote
-> Map (Voter, GovActionId) Vote
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (Voter
voter, GovActionId
gaid) (VotingProcedure era -> Vote
forall era. VotingProcedure era -> Vote
vProcVote VotingProcedure era
vp) Map (Voter, GovActionId) Vote
acc)
            Map (Voter, GovActionId) Vote
forall a. Monoid a => a
mempty
            (Tx l era
tx Tx l era
-> Getting (VotingProcedures era) (Tx l era) (VotingProcedures era)
-> VotingProcedures era
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (VotingProcedures era) (TxBody l era))
-> Tx l era -> Const (VotingProcedures era) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (VotingProcedures era) (TxBody l era))
 -> Tx l era -> Const (VotingProcedures era) (Tx l era))
-> ((VotingProcedures era
     -> Const (VotingProcedures era) (VotingProcedures era))
    -> TxBody l era -> Const (VotingProcedures era) (TxBody l era))
-> Getting (VotingProcedures era) (Tx l era) (VotingProcedures era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VotingProcedures era
 -> Const (VotingProcedures era) (VotingProcedures era))
-> TxBody l era -> Const (VotingProcedures era) (TxBody l era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (VotingProcedures era)
forall (l :: TxLevel). Lens' (TxBody l era) (VotingProcedures era)
votingProceduresTxBodyL)
        votesPerTx :: [Map (Voter, GovActionId) Vote]
votesPerTx = Tx TopTx era
-> (forall (l :: TxLevel).
    Tx l era -> Map (Voter, GovActionId) Vote)
-> [Map (Voter, GovActionId) Vote]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx Tx l era -> Map (Voter, GovActionId) Vote
forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes
      Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> VotingProcedures era)
-> Property
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"votes" (Tx l era
-> Getting (VotingProcedures era) (Tx l era) (VotingProcedures era)
-> VotingProcedures era
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (VotingProcedures era) (TxBody l era))
-> Tx l era -> Const (VotingProcedures era) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (VotingProcedures era) (TxBody l era))
 -> Tx l era -> Const (VotingProcedures era) (Tx l era))
-> ((VotingProcedures era
     -> Const (VotingProcedures era) (VotingProcedures era))
    -> TxBody l era -> Const (VotingProcedures era) (TxBody l era))
-> Getting (VotingProcedures era) (Tx l era) (VotingProcedures era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VotingProcedures era
 -> Const (VotingProcedures era) (VotingProcedures era))
-> TxBody l era -> Const (VotingProcedures era) (TxBody l era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (VotingProcedures era)
forall (l :: TxLevel). Lens' (TxBody l era) (VotingProcedures era)
votingProceduresTxBodyL)
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
15
          ( (Set Vote -> Bool) -> Map (Voter, GovActionId) (Set Vote) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
              ((Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) (Int -> Bool) -> (Set Vote -> Int) -> Set Vote -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Vote -> Int
forall a. Set a -> Int
Set.size)
              ((Set Vote -> Set Vote -> Set Vote)
-> [Map (Voter, GovActionId) (Set Vote)]
-> Map (Voter, GovActionId) (Set Vote)
forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith Set Vote -> Set Vote -> Set Vote
forall a. Semigroup a => a -> a -> a
(<>) ((Map (Voter, GovActionId) Vote
 -> Map (Voter, GovActionId) (Set Vote))
-> [Map (Voter, GovActionId) Vote]
-> [Map (Voter, GovActionId) (Set Vote)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Vote -> Set Vote)
-> Map (Voter, GovActionId) Vote
-> Map (Voter, GovActionId) (Set Vote)
forall a b.
(a -> b)
-> Map (Voter, GovActionId) a -> Map (Voter, GovActionId) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vote -> Set Vote
forall a. a -> Set a
Set.singleton) [Map (Voter, GovActionId) Vote]
votesPerTx))
          )
          String
"Same voter and governance action with different votes in more than one transaction"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
15
          ( [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or
              [ Voter
voter Voter -> Voter -> Bool
forall a. Eq a => a -> a -> Bool
== Voter
voter' Bool -> Bool -> Bool
&& GovActionId
gaid GovActionId -> GovActionId -> Bool
forall a. Eq a => a -> a -> Bool
/= GovActionId
gaid'
              | (Int
i, Map (Voter, GovActionId) Vote
votes) <- [Int]
-> [Map (Voter, GovActionId) Vote]
-> [(Int, Map (Voter, GovActionId) Vote)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 :: Int ..] [Map (Voter, GovActionId) Vote]
votesPerTx
              , (Int
j, Map (Voter, GovActionId) Vote
votes') <- [Int]
-> [Map (Voter, GovActionId) Vote]
-> [(Int, Map (Voter, GovActionId) Vote)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
Item [Int]
0 ..] [Map (Voter, GovActionId) Vote]
votesPerTx
              , Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
j
              , (Voter
voter, GovActionId
gaid) <- Map (Voter, GovActionId) Vote -> [(Voter, GovActionId)]
forall k a. Map k a -> [k]
Map.keys Map (Voter, GovActionId) Vote
votes
              , (Voter
voter', GovActionId
gaid') <- Map (Voter, GovActionId) Vote -> [(Voter, GovActionId)]
forall k a. Map k a -> [k]
Map.keys Map (Voter, GovActionId) Vote
votes'
              ]
          )
          String
"Same voter, different governance actions, across transactions"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
15
          ((Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Map (Voter, GovActionId) Bool -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or (Map (Voter, GovActionId) Bool -> Bool)
-> (Tx SubTx era -> Map (Voter, GovActionId) Bool)
-> Tx SubTx era
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vote -> Vote -> Bool)
-> Map (Voter, GovActionId) Vote
-> Map (Voter, GovActionId) Vote
-> Map (Voter, GovActionId) Bool
forall k a b c.
Ord k =>
(a -> b -> c) -> Map k a -> Map k b -> Map k c
Map.intersectionWith Vote -> Vote -> Bool
forall a. Eq a => a -> a -> Bool
(/=) (Tx TopTx era -> Map (Voter, GovActionId) Vote
forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes Tx TopTx era
topTx) (Map (Voter, GovActionId) Vote -> Map (Voter, GovActionId) Bool)
-> (Tx SubTx era -> Map (Voter, GovActionId) Vote)
-> Tx SubTx era
-> Map (Voter, GovActionId) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx SubTx era -> Map (Voter, GovActionId) Vote
forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes) [Tx SubTx era]
subTxs)
          String
"Same voter and governance action in the top transaction and a sub transaction, with different votes"
        (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
          Double
15
          ( let subTxVoteOccurrences :: Map (Voter, GovActionId) Int
subTxVoteOccurrences =
                  (Int -> Int -> Int)
-> [Map (Voter, GovActionId) Int] -> Map (Voter, GovActionId) Int
forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) [(Vote -> Int)
-> Map (Voter, GovActionId) Vote -> Map (Voter, GovActionId) Int
forall a b.
(a -> b)
-> Map (Voter, GovActionId) a -> Map (Voter, GovActionId) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Vote -> Int
forall a b. a -> b -> a
const (Int
1 :: Int)) (Tx SubTx era -> Map (Voter, GovActionId) Vote
forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes Tx SubTx era
subTx) | Tx SubTx era
subTx <- [Tx SubTx era]
subTxs]
             in (((Voter, GovActionId), Int) -> Bool)
-> [((Voter, GovActionId), Int)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\((Voter, GovActionId)
k, Int
n) -> Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2 Bool -> Bool -> Bool
&& (Voter, GovActionId)
k (Voter, GovActionId) -> Map (Voter, GovActionId) Vote -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`Map.notMember` Tx TopTx era -> Map (Voter, GovActionId) Vote
forall (l :: TxLevel). Tx l era -> Map (Voter, GovActionId) Vote
getTxVotes Tx TopTx era
topTx) ([((Voter, GovActionId), Int)] -> Bool)
-> [((Voter, GovActionId), Int)] -> Bool
forall a b. (a -> b) -> a -> b
$
                  Map (Voter, GovActionId) Int -> [((Voter, GovActionId), Int)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Voter, GovActionId) Int
subTxVoteOccurrences
          )
          String
"Same voter and governance action in two or more sub transactions, but not in the top transaction"

    -- Current treasury amount and treasury donations
    coverTreasury :: Testable p => Tx TopTx era -> p -> Property
    coverTreasury :: forall p. Testable p => Tx TopTx era -> p -> Property
coverTreasury Tx TopTx era
topTx =
      let subTxs :: [Tx SubTx era]
subTxs = Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx
       in Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
            Double
0.5
            ( StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL)
                Bool -> Bool -> Bool
&& (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Tx SubTx era
subTx -> StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (StrictMaybe Coin -> Bool) -> StrictMaybe Coin -> Bool
forall a b. (a -> b) -> a -> b
$ Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL) [Tx SubTx era]
subTxs
            )
            String
"Current treasury amount absent in top tx and sub txs"
            (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
              Double
5
              ( StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSJust (Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL)
                  Bool -> Bool -> Bool
&& (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Tx SubTx era
subTx -> StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (StrictMaybe Coin -> Bool) -> StrictMaybe Coin -> Bool
forall a b. (a -> b) -> a -> b
$ Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL) [Tx SubTx era]
subTxs
              )
              String
"Current treasury amount present in top tx, but not in sub txs"
            (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
              Double
3
              ( StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSNothing (Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL)
                  Bool -> Bool -> Bool
&& (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Tx SubTx era
subTx -> StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSJust (StrictMaybe Coin -> Bool) -> StrictMaybe Coin -> Bool
forall a b. (a -> b) -> a -> b
$ Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL) [Tx SubTx era]
subTxs
              )
              String
"Current treasury amount absent in top tx, but present in at least one sub txs"
            (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
              Double
5
              ( StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSJust (Tx TopTx era
topTx Tx TopTx era
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
 -> Tx TopTx era -> Const (StrictMaybe Coin) (Tx TopTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era))
-> Getting (StrictMaybe Coin) (Tx TopTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody TopTx era -> Const (StrictMaybe Coin) (TxBody TopTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL)
                  Bool -> Bool -> Bool
&& (Tx SubTx era -> Bool) -> [Tx SubTx era] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Tx SubTx era
subTx -> StrictMaybe Coin -> Bool
forall a. StrictMaybe a -> Bool
isSJust (StrictMaybe Coin -> Bool) -> StrictMaybe Coin -> Bool
forall a b. (a -> b) -> a -> b
$ Tx SubTx era
subTx Tx SubTx era
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL) [Tx SubTx era]
subTxs
              )
              String
"Current treasury amount present in top tx, and present in at least one sub txs"
            (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Bool -> String -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover
              Double
10
              ( Set Coin -> Int
forall a. Set a -> Int
Set.size
                  ([Coin] -> Set Coin
forall a. Ord a => [a] -> Set a
Set.fromList [Coin
amount | SJust Coin
amount <- (Tx SubTx era -> StrictMaybe Coin)
-> [Tx SubTx era] -> [StrictMaybe Coin]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Tx SubTx era
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. (TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
 -> Tx SubTx era -> Const (StrictMaybe Coin) (Tx SubTx era))
-> ((StrictMaybe Coin
     -> Const (StrictMaybe Coin) (StrictMaybe Coin))
    -> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era))
-> Getting (StrictMaybe Coin) (Tx SubTx era) (StrictMaybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe Coin -> Const (StrictMaybe Coin) (StrictMaybe Coin))
-> TxBody SubTx era -> Const (StrictMaybe Coin) (TxBody SubTx era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) (StrictMaybe Coin)
forall (l :: TxLevel). Lens' (TxBody l era) (StrictMaybe Coin)
currentTreasuryValueTxBodyL) [Tx SubTx era]
subTxs])
                  Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2
              )
              String
"Current treasury amount present in two or more sub txs, with different values"
            (Property -> Property) -> (p -> Property) -> p -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Coin)
-> p
-> Property
forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
25 String
"treasury donations" (Tx l era -> Getting Coin (Tx l era) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const Coin (TxBody l era))
-> Tx l era -> Const Coin (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const Coin (TxBody l era))
 -> Tx l era -> Const Coin (Tx l era))
-> ((Coin -> Const Coin Coin)
    -> TxBody l era -> Const Coin (TxBody l era))
-> Getting Coin (Tx l era) Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Coin -> Const Coin Coin)
-> TxBody l era -> Const Coin (TxBody l era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) Coin
forall (l :: TxLevel). Lens' (TxBody l era) Coin
treasuryDonationTxBodyL)

    -- Require at least @rate@ percent of the generated batches to have a non-empty
    -- value of the field extracted by @f@ in more than one transaction
    -- (top-level + sub-transactions).
    --
    -- This is particularly useful for tests which test the aggregation of
    -- values across transactions. In such a scenario, a transaction field set
    -- in only one transaction would never be combined with another. If that
    -- happens, then we won't be testing different aggregation strategies when
    -- constructing `TopTxInfoSimplified`.
    coverNonEmptyValueInNestedTxs ::
      (Testable p, Eq a, Monoid a) =>
      Tx TopTx era ->
      Double ->
      String ->
      (forall l. Tx l era -> a) ->
      p ->
      Property
    coverNonEmptyValueInNestedTxs :: forall p a.
(Testable p, Eq a, Monoid a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> a)
-> p
-> Property
coverNonEmptyValueInNestedTxs Tx TopTx era
topTx Double
rate String
name forall (l :: TxLevel). Tx l era -> a
f =
      Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
rate ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ((a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
forall a. Monoid a => a
mempty) (Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx Tx l era -> a
forall (l :: TxLevel). Tx l era -> a
f)) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) (String -> p -> Property) -> String -> p -> Property
forall a b. (a -> b) -> a -> b
$
        String
"Non-empty " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
name String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" in more than one transaction"

    -- Require at least @rate@ percent of the generated batches to have a
    -- key, extracted by @f@, shared by at least two transactions of the
    -- transaction batch (top-level + sub-transactions), while no single
    -- transaction holds every key of the batch.
    coverSharedKeysInNestedTxs ::
      (Testable p, Ord a) =>
      Tx TopTx era ->
      Double ->
      String ->
      (forall l. Tx l era -> Set a) ->
      p ->
      Property
    coverSharedKeysInNestedTxs :: forall p a.
(Testable p, Ord a) =>
Tx TopTx era
-> Double
-> String
-> (forall (l :: TxLevel). Tx l era -> Set a)
-> p
-> Property
coverSharedKeysInNestedTxs Tx TopTx era
topTx Double
rate String
name forall (l :: TxLevel). Tx l era -> Set a
f =
      let keySetPerTx :: [Set a]
keySetPerTx = Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Set a) -> [Set a]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx Tx l era -> Set a
forall (l :: TxLevel). Tx l era -> Set a
f
          allKeys :: Set a
allKeys = [Set a] -> Set a
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [Set a]
keySetPerTx
          hasSharedKey :: Bool
hasSharedKey = [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ((Set a -> Int) -> [Set a] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Set a -> Int
forall a. Set a -> Int
Set.size [Set a]
keySetPerTx) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Set a -> Int
forall a. Set a -> Int
Set.size Set a
allKeys
          noTxHoldsAllKeys :: Bool
noTxHoldsAllKeys = Set a -> [Set a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
notElem Set a
allKeys [Set a]
keySetPerTx
       in Double -> Bool -> String -> p -> Property
forall prop.
Testable prop =>
Double -> Bool -> String -> prop -> Property
cover Double
rate (Bool
hasSharedKey Bool -> Bool -> Bool
&& Bool
noTxHoldsAllKeys) (String -> p -> Property) -> String -> p -> Property
forall a b. (a -> b) -> a -> b
$
            String
"Keys of " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
name String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" are shared in more than one transaction, none holding them all"

    -- Construct a reference 'PV4.TopTxInfoSimplified' out of the 'LedgerTxInfo' of a top-level
    -- transaction. The idea is to compare this with the production code by using a different way of
    -- constructing each 'PV4.TopTxInfoSimplified' field.
    --
    -- The production implementation builds each field in one of two ways:
    --
    --   * "combine-then-translate": it combines the ledger values of every transaction of the
    --     batch monoidally, and then translates the result to the Plutus type (e.g. mints,
    --     withdrawals, validity range, votes, datums);
    --   * it reuses the already translated 'PV4.TxInfo' of every transaction of the batch, and
    --     concatenates the relevant field (e.g. ids, inputs, outputs, certificates, guards).
    --
    -- This reference implementation instead uses a "translate-then-combine"
    -- approach for every field: it translates the ledger values of each
    -- transaction directly to Plutus types, without reading any per-transaction
    -- 'PV4.TxInfo', and then combines the translated values. For the first kind
    -- of fields, this checks that combining before translating doesn't lose
    -- data or reorder the elements. For the second kind, this checks that the
    -- per-transaction 'PV4.TxInfo's are looked up and concatenated in batch
    -- order (sub-transactions in order, top-level transaction last).
    --
    -- Both approaches should yield the same result.
    mkReferenceTopTxInfoSimplified ::
      LedgerTxInfo TopTx era ->
      Either (ContextError era) PV4.TopTxInfoSimplified
    mkReferenceTopTxInfoSimplified :: LedgerTxInfo TopTx era
-> Either (ContextError era) TopTxInfoSimplified
mkReferenceTopTxInfoSimplified LedgerTxInfo TopTx era
ledgerTxInfo = do
      let proxyEra :: Proxy era
proxyEra = forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @era
          proxyLang :: Proxy 'PlutusV4
proxyLang = forall {k} (t :: k). Proxy t
forall (t :: Language). Proxy t
Proxy @PlutusV4
          utxo :: UTxO era
utxo = LedgerTxInfo TopTx era -> UTxO era
forall era (level :: TxLevel). LedgerTxInfo level era -> UTxO era
ltiUTxO LedgerTxInfo TopTx era
ledgerTxInfo
          topTx :: Tx TopTx era
topTx = LedgerTxInfo TopTx era -> Tx TopTx era
forall era (level :: TxLevel).
LedgerTxInfo level era -> Tx level era
ltiTx LedgerTxInfo TopTx era
ledgerTxInfo
      inputs <-
        Tx TopTx era
-> (forall (l :: TxLevel).
    Tx l era -> Either (ContextError era) [TxInInfo])
-> Either (ContextError era) [TxInInfo]
forall era m e.
(EraTx era, DijkstraEraTxBody era, Monoid m) =>
Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Either e m) -> Either e m
foldMapBatchM
          Tx TopTx era
topTx
          (\Tx l era
tx -> (TxIn -> Either (ContextError era) TxInInfo)
-> [TxIn] -> Either (ContextError era) [TxInInfo]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (UTxO era -> TxIn -> Either (ContextError era) TxInInfo
forall era.
(BabbageEraTxOut era, Value era ~ MaryValue,
 Inject (AlonzoContextError era) (ContextError era),
 Inject (BabbageContextError era) (ContextError era),
 Inject (DijkstraContextError era) (ContextError era)) =>
UTxO era -> TxIn -> Either (ContextError era) TxInInfo
transTxInInfoV4 UTxO era
utxo) (Set TxIn -> [TxIn]
forall a. Set a -> [a]
Set.toList (Tx l era
tx Tx l era -> Getting (Set TxIn) (Tx l era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Tx l era -> Const (Set TxIn) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (Set TxIn) (TxBody l era))
 -> Tx l era -> Const (Set TxIn) (Tx l era))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Getting (Set TxIn) (Tx l era) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody l era -> Const (Set TxIn) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
inputsTxBodyL)))
      referenceInputs <-
        foldMapBatchM
          topTx
          (\Tx l era
tx -> (TxIn -> Either (ContextError era) TxInInfo)
-> [TxIn] -> Either (ContextError era) [TxInInfo]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (UTxO era -> TxIn -> Either (ContextError era) TxInInfo
forall era.
(BabbageEraTxOut era, Value era ~ MaryValue,
 Inject (AlonzoContextError era) (ContextError era),
 Inject (BabbageContextError era) (ContextError era),
 Inject (DijkstraContextError era) (ContextError era)) =>
UTxO era -> TxIn -> Either (ContextError era) TxInInfo
transTxInInfoV4 UTxO era
utxo) (Set TxIn -> [TxIn]
forall a. Set a -> [a]
Set.toList (Tx l era
tx Tx l era -> Getting (Set TxIn) (Tx l era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Tx l era -> Const (Set TxIn) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (Set TxIn) (TxBody l era))
 -> Tx l era -> Const (Set TxIn) (Tx l era))
-> ((Set TxIn -> Const (Set TxIn) (Set TxIn))
    -> TxBody l era -> Const (Set TxIn) (TxBody l era))
-> Getting (Set TxIn) (Tx l era) (Set TxIn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody l era -> Const (Set TxIn) (TxBody l era)
forall era (l :: TxLevel).
BabbageEraTxBody era =>
Lens' (TxBody l era) (Set TxIn)
forall (l :: TxLevel). Lens' (TxBody l era) (Set TxIn)
referenceInputsTxBodyL)))
      outputs <-
        foldMapBatchM
          topTx
          ( \Tx l era
tx ->
              (TxIx -> TxOut era -> Either (ContextError era) TxOut)
-> [TxIx] -> [TxOut era] -> Either (ContextError era) [TxOut]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM
                (TxOutSource -> TxOut era -> Either (ContextError era) TxOut
forall era.
(BabbageEraTxOut era, Value era ~ MaryValue,
 Inject (BabbageContextError era) (ContextError era),
 Inject (DijkstraContextError era) (ContextError era)) =>
TxOutSource -> TxOut era -> Either (ContextError era) TxOut
transTxOutV4 (TxOutSource -> TxOut era -> Either (ContextError era) TxOut)
-> (TxIx -> TxOutSource)
-> TxIx
-> TxOut era
-> Either (ContextError era) TxOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxIx -> TxOutSource
TxOutFromOutput)
                [Item [TxIx]
TxIx
forall a. Bounded a => a
minBound ..]
                (StrictSeq (TxOut era) -> [TxOut era]
forall a. StrictSeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Tx l era
tx Tx l era
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
-> StrictSeq (TxOut era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
 -> Tx l era -> Const (StrictSeq (TxOut era)) (Tx l era))
-> ((StrictSeq (TxOut era)
     -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
    -> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era))
-> Getting
     (StrictSeq (TxOut era)) (Tx l era) (StrictSeq (TxOut era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxOut era)
 -> Const (StrictSeq (TxOut era)) (StrictSeq (TxOut era)))
-> TxBody l era -> Const (StrictSeq (TxOut era)) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxOut era))
forall (l :: TxLevel). Lens' (TxBody l era) (StrictSeq (TxOut era))
outputsTxBodyL))
          )
      txCerts <-
        foldMapBatchM
          topTx
          ( \Tx l era
tx ->
              (TxCert era -> Either (ContextError era) TxCert)
-> [TxCert era] -> Either (ContextError era) [TxCert]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Proxy 'PlutusV4
-> ProtVer
-> TxCert era
-> Either (ContextError era) (PlutusTxCert 'PlutusV4)
forall (l :: Language) era (proxy :: Language -> *).
EraPlutusTxInfo l era =>
proxy l
-> ProtVer
-> TxCert era
-> Either (ContextError era) (PlutusTxCert l)
forall (proxy :: Language -> *).
proxy 'PlutusV4
-> ProtVer
-> TxCert era
-> Either (ContextError era) (PlutusTxCert 'PlutusV4)
toPlutusTxCert Proxy 'PlutusV4
proxyLang (LedgerTxInfo TopTx era -> ProtVer
forall era (level :: TxLevel). LedgerTxInfo level era -> ProtVer
ltiProtVer LedgerTxInfo TopTx era
ledgerTxInfo)) (StrictSeq (TxCert era) -> [TxCert era]
forall a. StrictSeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Tx l era
tx Tx l era
-> Getting
     (StrictSeq (TxCert era)) (Tx l era) (StrictSeq (TxCert era))
-> StrictSeq (TxCert era)
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
-> Tx l era -> Const (StrictSeq (TxCert era)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
 -> Tx l era -> Const (StrictSeq (TxCert era)) (Tx l era))
-> ((StrictSeq (TxCert era)
     -> Const (StrictSeq (TxCert era)) (StrictSeq (TxCert era)))
    -> TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era))
-> Getting
     (StrictSeq (TxCert era)) (Tx l era) (StrictSeq (TxCert era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictSeq (TxCert era)
 -> Const (StrictSeq (TxCert era)) (StrictSeq (TxCert era)))
-> TxBody l era -> Const (StrictSeq (TxCert era)) (TxBody l era)
forall era (l :: TxLevel).
EraTxBody era =>
Lens' (TxBody l era) (StrictSeq (TxCert era))
forall (l :: TxLevel).
Lens' (TxBody l era) (StrictSeq (TxCert era))
certsTxBodyL))
          )
      validRangePerTx <-
        foldMapBatchM
          topTx
          ( \Tx l era
tx ->
              (POSIXTimeRange -> [POSIXTimeRange] -> [POSIXTimeRange]
forall a. a -> [a] -> [a]
: [])
                (POSIXTimeRange -> [POSIXTimeRange])
-> Either (ContextError era) POSIXTimeRange
-> Either (ContextError era) [POSIXTimeRange]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy era
-> EpochInfo (Either Text)
-> SystemStart
-> ValidityInterval
-> Either (ContextError era) POSIXTimeRange
forall era (proxy :: * -> *).
Inject (AlonzoContextError era) (ContextError era) =>
proxy era
-> EpochInfo (Either Text)
-> SystemStart
-> ValidityInterval
-> Either (ContextError era) POSIXTimeRange
transValidityInterval
                  Proxy era
proxyEra
                  (LedgerTxInfo TopTx era -> EpochInfo (Either Text)
forall era (level :: TxLevel).
LedgerTxInfo level era -> EpochInfo (Either Text)
ltiEpochInfo LedgerTxInfo TopTx era
ledgerTxInfo)
                  (LedgerTxInfo TopTx era -> SystemStart
forall era (level :: TxLevel).
LedgerTxInfo level era -> SystemStart
ltiSystemStart LedgerTxInfo TopTx era
ledgerTxInfo)
                  (Tx l era
tx Tx l era
-> Getting ValidityInterval (Tx l era) ValidityInterval
-> ValidityInterval
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const ValidityInterval (TxBody l era))
-> Tx l era -> Const ValidityInterval (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const ValidityInterval (TxBody l era))
 -> Tx l era -> Const ValidityInterval (Tx l era))
-> ((ValidityInterval -> Const ValidityInterval ValidityInterval)
    -> TxBody l era -> Const ValidityInterval (TxBody l era))
-> Getting ValidityInterval (Tx l era) ValidityInterval
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const ValidityInterval ValidityInterval)
-> TxBody l era -> Const ValidityInterval (TxBody l era)
forall era (l :: TxLevel).
AllegraEraTxBody era =>
Lens' (TxBody l era) ValidityInterval
forall (l :: TxLevel). Lens' (TxBody l era) ValidityInterval
vldtTxBodyL)
          )
      pure
        PV4.TopTxInfoSimplified
          { ttisIds = mapTxBatch topTx (transTxBodyId . (^. bodyTxL))
          , ttisInputs = inputs
          , ttisReferenceInputs = referenceInputs
          , ttisOutputs = outputs
          , ttisMints =
              MintValue.UnsafeMintValue $
                PV4.getValue $
                  foldMapBatch topTx (PV4.mintValueMinted . transMintValue . (^. bodyTxL . mintTxBodyL))
          , ttisBurns =
              MintValue.UnsafeMintValue
                . PlutusTx.fmap (PlutusTx.fmap negate)
                . PV4.getValue
                $ foldMapBatch topTx (PV4.mintValueBurned . transMintValue . (^. bodyTxL . mintTxBodyL))
          , ttisTxCerts = txCerts
          , ttisWithdrawals =
              unionsAssocMapWith (+) $
                mapTxBatch topTx (transWithdrawals . (^. bodyTxL . withdrawalsTxBodyL))
          , ttisDirectDeposits =
              unionsAssocMapWith (+) $
                mapTxBatch topTx (transDirectDeposits . (^. bodyTxL . directDepositsTxBodyL))
          , -- Intersect the translated intervals, i.e. the greatest
            -- lower bound and the smallest upper bound, with `Nothing` meaning unbounded.
            ttisValidRange =
              PV4.POSIXTimeRange
                (getMax <$> foldMap (fmap Max . PV4.fromInclusive) validRangePerTx)
                (getMin <$> foldMap (fmap Min . PV4.untilExclusive) validRangePerTx)
          , ttisGuards = foldMapBatch topTx (fmap transCred . toList . (^. bodyTxL . guardsTxBodyL))
          , ttisRequiredTopLevelGuards =
              Set.toList
                ( foldMapBatch
                    topTx
                    (\Tx l era
tx -> (Credential Guard -> Credential)
-> Set (Credential Guard) -> Set Credential
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map Credential Guard -> Credential
forall (kr :: KeyRole). Credential kr -> Credential
transCred (Set (Credential Guard) -> Set Credential)
-> Set (Credential Guard) -> Set Credential
forall a b. (a -> b) -> a -> b
$ Map (Credential Guard) (StrictMaybe (Data era))
-> Set (Credential Guard)
forall k a. Map k a -> Set k
Map.keysSet (Map (Credential Guard) (StrictMaybe (Data era))
 -> Set (Credential Guard))
-> Map (Credential Guard) (StrictMaybe (Data era))
-> Set (Credential Guard)
forall a b. (a -> b) -> a -> b
$ Tx l era
tx Tx l era
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
-> Map (Credential Guard) (StrictMaybe (Data era))
forall s a. s -> Getting a s a -> a
^. (TxBody l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Tx l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era
  -> Const
       (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
 -> Tx l era
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era))) (Tx l era))
-> ((Map (Credential Guard) (StrictMaybe (Data era))
     -> Const
          (Map (Credential Guard) (StrictMaybe (Data era)))
          (Map (Credential Guard) (StrictMaybe (Data era))))
    -> TxBody l era
    -> Const
         (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era))
-> Getting
     (Map (Credential Guard) (StrictMaybe (Data era)))
     (Tx l era)
     (Map (Credential Guard) (StrictMaybe (Data era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential Guard) (StrictMaybe (Data era))
 -> Const
      (Map (Credential Guard) (StrictMaybe (Data era)))
      (Map (Credential Guard) (StrictMaybe (Data era))))
-> TxBody l era
-> Const
     (Map (Credential Guard) (StrictMaybe (Data era))) (TxBody l era)
forall era (l :: TxLevel).
DijkstraEraTxBody era =>
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
forall (l :: TxLevel).
Lens'
  (TxBody l era) (Map (Credential Guard) (StrictMaybe (Data era)))
requiredTopLevelGuardsTxBodyL)
                )
          , -- The script hash of each redeemer whose purpose the transaction
            -- needs is looked up with 'getScriptsNeeded', instead of reading the
            -- translated `PV4.txInfoRedeemers`. Note that `ltiScriptHashesUsed`,
            -- which production reads, is also built from 'getScriptsNeeded', so
            -- this does not check 'getScriptsNeeded' itself. The generator
            -- provides the script of every redeemer, so the "provided" filter of
            -- production is not repeated here. The hashes are translated, and
            -- then deduplicated across the batch in the Plutus `ScriptHash`
            -- order.
            ttisRedeemerHashes =
              Set.toList $
                foldMapBatch topTx (Set.fromList . fmap transScriptHash . scriptHashesPerRedeemer utxo)
          , -- Union of the translated datums of each transaction.
            ttisData =
              PV4.unsafeFromList $
                Map.toList $
                  foldMapBatch topTx (Map.fromList . transDatums . (^. witsTxL . datsTxWitsL))
          , -- Each transaction's votes are translated, then merged
            -- per voter. For the same voter and governance action, a later
            -- transaction's vote replaces an earlier one, so the top-level
            -- transaction's votes win.
            ttisVotes =
              unionsAssocMapWith (AssocMap.unionWith (\Vote
_ Vote
new -> Vote
new)) $
                mapTxBatch topTx (transVotingProcedures . (^. bodyTxL . votingProceduresTxBodyL))
          , ttisProposalProcedures =
              foldMapBatch
                topTx
                (fmap (transProposal proxyLang) . toList . (^. bodyTxL . proposalProceduresTxBodyL))
          , -- The first transaction of the batch with a current treasury amount wins. Each
            -- amount is translated from the ledger value, instead of read from the per-tx
            -- 'PV4.TxInfo'.
            ttisCurrentTreasuryAmount =
              getFirst $
                foldMapBatch
                  topTx
                  ( First
                      . fmap transCoinToLovelace
                      . strictMaybeToMaybe
                      . (^. bodyTxL . currentTreasuryValueTxBodyL)
                  )
          , ttisTreasuryDonations =
              getSum
                (foldMapBatch topTx (\Tx l era
tx -> Lovelace -> Sum Lovelace
forall a. a -> Sum a
Sum (Lovelace -> Sum Lovelace) -> Lovelace -> Sum Lovelace
forall a b. (a -> b) -> a -> b
$ Coin -> Lovelace
transCoinToLovelace (Tx l era
tx Tx l era -> Getting Coin (Tx l era) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. (TxBody l era -> Const Coin (TxBody l era))
-> Tx l era -> Const Coin (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody l era -> Const Coin (TxBody l era))
 -> Tx l era -> Const Coin (Tx l era))
-> ((Coin -> Const Coin Coin)
    -> TxBody l era -> Const Coin (TxBody l era))
-> Getting Coin (Tx l era) Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Coin -> Const Coin Coin)
-> TxBody l era -> Const Coin (TxBody l era)
forall era (l :: TxLevel).
ConwayEraTxBody era =>
Lens' (TxBody l era) Coin
forall (l :: TxLevel). Lens' (TxBody l era) Coin
treasuryDonationTxBodyL)))
          }

-- | Compare each 'PV4.TopTxInfoSimplified' field separately.
--
-- The `Eq` instances of the `PV4.Map`-based (represented as list of tuples)
-- fields should not be used because the instance converts to 'Data.Map' to do
-- the comparison. In doing so, we won't be able to catch issues with
-- unordered or duplicated keys in 'PV4.Map'. Therefore, we do equality checks
-- directly on each field.
shouldMatchTopTxInfoSimplified :: PV4.TopTxInfoSimplified -> PV4.TopTxInfoSimplified -> Expectation
shouldMatchTopTxInfoSimplified :: TopTxInfoSimplified -> TopTxInfoSimplified -> Expectation
shouldMatchTopTxInfoSimplified TopTxInfoSimplified
actual TopTxInfoSimplified
expected = do
  -- We deconstruct the data constructor here in order to get a GHC error if
  -- new fields are added. This also helps as a reminder for the programmer to
  -- add an assertion for the new field.
  let ttis :: TopTxInfoSimplified
ttis@(PV4.TopTxInfoSimplified [TxId]
_ [TxInInfo]
_ [TxInInfo]
_ [TxOut]
_ MintValue
_ MintValue
_ [TxCert]
_ Map Credential Lovelace
_ Map Credential Lovelace
_ POSIXTimeRange
_ [Credential]
_ [Credential]
_ [ScriptHash]
_ Map DatumHash Datum
_ Map Voter (Map GovernanceActionId Vote)
_ [ProposalProcedure]
_ Maybe Lovelace
_ Lovelace
_) = TopTxInfoSimplified
actual
      PV4.TopTxInfoSimplified {[TxId]
[ScriptHash]
[Credential]
[TxOut]
[ProposalProcedure]
[TxCert]
[TxInInfo]
Maybe Lovelace
Map DatumHash Datum
Map Credential Lovelace
Map Voter (Map GovernanceActionId Vote)
POSIXTimeRange
Lovelace
MintValue
ttisIds :: TopTxInfoSimplified -> [TxId]
ttisInputs :: TopTxInfoSimplified -> [TxInInfo]
ttisReferenceInputs :: TopTxInfoSimplified -> [TxInInfo]
ttisOutputs :: TopTxInfoSimplified -> [TxOut]
ttisMints :: TopTxInfoSimplified -> MintValue
ttisBurns :: TopTxInfoSimplified -> MintValue
ttisTxCerts :: TopTxInfoSimplified -> [TxCert]
ttisWithdrawals :: TopTxInfoSimplified -> Map Credential Lovelace
ttisDirectDeposits :: TopTxInfoSimplified -> Map Credential Lovelace
ttisValidRange :: TopTxInfoSimplified -> POSIXTimeRange
ttisGuards :: TopTxInfoSimplified -> [Credential]
ttisRequiredTopLevelGuards :: TopTxInfoSimplified -> [Credential]
ttisRedeemerHashes :: TopTxInfoSimplified -> [ScriptHash]
ttisData :: TopTxInfoSimplified -> Map DatumHash Datum
ttisVotes :: TopTxInfoSimplified -> Map Voter (Map GovernanceActionId Vote)
ttisProposalProcedures :: TopTxInfoSimplified -> [ProposalProcedure]
ttisCurrentTreasuryAmount :: TopTxInfoSimplified -> Maybe Lovelace
ttisTreasuryDonations :: TopTxInfoSimplified -> Lovelace
ttisIds :: [TxId]
ttisInputs :: [TxInInfo]
ttisReferenceInputs :: [TxInInfo]
ttisOutputs :: [TxOut]
ttisMints :: MintValue
ttisBurns :: MintValue
ttisTxCerts :: [TxCert]
ttisWithdrawals :: Map Credential Lovelace
ttisDirectDeposits :: Map Credential Lovelace
ttisValidRange :: POSIXTimeRange
ttisGuards :: [Credential]
ttisRequiredTopLevelGuards :: [Credential]
ttisRedeemerHashes :: [ScriptHash]
ttisData :: Map DatumHash Datum
ttisVotes :: Map Voter (Map GovernanceActionId Vote)
ttisProposalProcedures :: [ProposalProcedure]
ttisCurrentTreasuryAmount :: Maybe Lovelace
ttisTreasuryDonations :: Lovelace
..} = TopTxInfoSimplified
ttis
  [TxId]
ttisIds [TxId] -> [TxId] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [TxId]
PV4.ttisIds TopTxInfoSimplified
expected
  [TxInInfo]
ttisInputs [TxInInfo] -> [TxInInfo] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [TxInInfo]
PV4.ttisInputs TopTxInfoSimplified
expected
  [TxInInfo]
ttisReferenceInputs [TxInInfo] -> [TxInInfo] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [TxInInfo]
PV4.ttisReferenceInputs TopTxInfoSimplified
expected
  [TxOut]
ttisOutputs [TxOut] -> [TxOut] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [TxOut]
PV4.ttisOutputs TopTxInfoSimplified
expected
  HasCallStack => (Integer -> Bool) -> MintValue -> Expectation
(Integer -> Bool) -> MintValue -> Expectation
shouldBeCanonicalMintValue (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0) MintValue
ttisMints
  MintValue -> Map CurrencySymbol (Map TokenName Integer)
mintValueToMap MintValue
ttisMints Map CurrencySymbol (Map TokenName Integer)
-> Map CurrencySymbol (Map TokenName Integer) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` MintValue -> Map CurrencySymbol (Map TokenName Integer)
mintValueToMap (TopTxInfoSimplified -> MintValue
PV4.ttisMints TopTxInfoSimplified
expected)
  HasCallStack => (Integer -> Bool) -> MintValue -> Expectation
(Integer -> Bool) -> MintValue -> Expectation
shouldBeCanonicalMintValue (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
0) MintValue
ttisBurns
  MintValue -> Map CurrencySymbol (Map TokenName Integer)
mintValueToMap MintValue
ttisBurns Map CurrencySymbol (Map TokenName Integer)
-> Map CurrencySymbol (Map TokenName Integer) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` MintValue -> Map CurrencySymbol (Map TokenName Integer)
mintValueToMap (TopTxInfoSimplified -> MintValue
PV4.ttisBurns TopTxInfoSimplified
expected)
  [TxCert]
ttisTxCerts [TxCert] -> [TxCert] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [TxCert]
PV4.ttisTxCerts TopTxInfoSimplified
expected
  Map Credential Lovelace -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveUniqueAssocMapKeys Map Credential Lovelace
ttisWithdrawals
  Map Credential Lovelace -> Map Credential Lovelace
forall k v. Ord k => Map k v -> Map k v
assocMapToMap Map Credential Lovelace
ttisWithdrawals Map Credential Lovelace -> Map Credential Lovelace -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map Credential Lovelace -> Map Credential Lovelace
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (TopTxInfoSimplified -> Map Credential Lovelace
PV4.ttisWithdrawals TopTxInfoSimplified
expected)
  Map Credential Lovelace -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveUniqueAssocMapKeys Map Credential Lovelace
ttisDirectDeposits
  Map Credential Lovelace -> Map Credential Lovelace
forall k v. Ord k => Map k v -> Map k v
assocMapToMap Map Credential Lovelace
ttisDirectDeposits Map Credential Lovelace -> Map Credential Lovelace -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map Credential Lovelace -> Map Credential Lovelace
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (TopTxInfoSimplified -> Map Credential Lovelace
PV4.ttisDirectDeposits TopTxInfoSimplified
expected)
  POSIXTimeRange
ttisValidRange POSIXTimeRange -> POSIXTimeRange -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> POSIXTimeRange
PV4.ttisValidRange TopTxInfoSimplified
expected
  [Credential]
ttisGuards [Credential] -> [Credential] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [Credential]
PV4.ttisGuards TopTxInfoSimplified
expected
  -- Sorting the actual list keeps its duplicates, while the expected list has none.
  -- We sort here manually because Ledger and Plutus codebases differ on the 'Ord'
  -- instance of 'Credential'.
  [Credential] -> [Credential]
forall a. Ord a => [a] -> [a]
List.sort [Credential]
ttisRequiredTopLevelGuards [Credential] -> [Credential] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [Credential]
PV4.ttisRequiredTopLevelGuards TopTxInfoSimplified
expected
  [ScriptHash]
ttisRedeemerHashes [ScriptHash] -> [ScriptHash] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [ScriptHash]
PV4.ttisRedeemerHashes TopTxInfoSimplified
expected
  -- Exact order comparison depends on ledger and Plutus agreeing on hash
  -- order.
  Map DatumHash Datum -> [(DatumHash, Datum)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList Map DatumHash Datum
ttisData [(DatumHash, Datum)] -> [(DatumHash, Datum)] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map DatumHash Datum -> [(DatumHash, Datum)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList (TopTxInfoSimplified -> Map DatumHash Datum
PV4.ttisData TopTxInfoSimplified
expected)
  Map Voter (Map GovernanceActionId Vote) -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveUniqueAssocMapKeys Map Voter (Map GovernanceActionId Vote)
ttisVotes
  (Map GovernanceActionId Vote -> Expectation)
-> [Map GovernanceActionId Vote] -> Expectation
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Map GovernanceActionId Vote -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveUniqueAssocMapKeys (Map Voter (Map GovernanceActionId Vote)
-> [Map GovernanceActionId Vote]
forall k v. Map k v -> [v]
AssocMap.elems Map Voter (Map GovernanceActionId Vote)
ttisVotes)
  (Map GovernanceActionId Vote -> Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
forall a b. (a -> b) -> Map Voter a -> Map Voter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map GovernanceActionId Vote -> Map GovernanceActionId Vote
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (Map Voter (Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
forall k v. Ord k => Map k v -> Map k v
assocMapToMap Map Voter (Map GovernanceActionId Vote)
ttisVotes)
    Map Voter (Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` (Map GovernanceActionId Vote -> Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
forall a b. (a -> b) -> Map Voter a -> Map Voter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map GovernanceActionId Vote -> Map GovernanceActionId Vote
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (Map Voter (Map GovernanceActionId Vote)
-> Map Voter (Map GovernanceActionId Vote)
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (TopTxInfoSimplified -> Map Voter (Map GovernanceActionId Vote)
PV4.ttisVotes TopTxInfoSimplified
expected))
  [ProposalProcedure]
ttisProposalProcedures [ProposalProcedure] -> [ProposalProcedure] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> [ProposalProcedure]
PV4.ttisProposalProcedures TopTxInfoSimplified
expected
  Maybe Lovelace
ttisCurrentTreasuryAmount Maybe Lovelace -> Maybe Lovelace -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> Maybe Lovelace
PV4.ttisCurrentTreasuryAmount TopTxInfoSimplified
expected
  Lovelace
ttisTreasuryDonations Lovelace -> Lovelace -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` TopTxInfoSimplified -> Lovelace
PV4.ttisTreasuryDonations TopTxInfoSimplified
expected

-- | The sub-transactions of a top-level transaction, in 'OMap' order.
getSubTransactions :: (EraTx era, DijkstraEraTxBody era) => Tx TopTx era -> [Tx SubTx era]
getSubTransactions :: forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx = OMap TxId (Tx SubTx era) -> [Tx SubTx era]
forall k v. Ord k => OMap k v -> [v]
OMap.elems (Tx TopTx era
topTx Tx TopTx era
-> Getting
     (OMap TxId (Tx SubTx era))
     (Tx TopTx era)
     (OMap TxId (Tx SubTx era))
-> OMap TxId (Tx SubTx era)
forall s a. s -> Getting a s a -> a
^. (TxBody TopTx era
 -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
-> Tx TopTx era -> Const (OMap TxId (Tx SubTx era)) (Tx TopTx era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL ((TxBody TopTx era
  -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
 -> Tx TopTx era -> Const (OMap TxId (Tx SubTx era)) (Tx TopTx era))
-> ((OMap TxId (Tx SubTx era)
     -> Const (OMap TxId (Tx SubTx era)) (OMap TxId (Tx SubTx era)))
    -> TxBody TopTx era
    -> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era))
-> Getting
     (OMap TxId (Tx SubTx era))
     (Tx TopTx era)
     (OMap TxId (Tx SubTx era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OMap TxId (Tx SubTx era)
 -> Const (OMap TxId (Tx SubTx era)) (OMap TxId (Tx SubTx era)))
-> TxBody TopTx era
-> Const (OMap TxId (Tx SubTx era)) (TxBody TopTx era)
forall era.
DijkstraEraTxBody era =>
Lens' (TxBody TopTx era) (OMap TxId (Tx SubTx era))
Lens' (TxBody TopTx era) (OMap TxId (Tx SubTx era))
subTransactionsTxBodyL)

-- | The value extracted by @f@ from each transaction of the batch, in batch order: the
-- sub-transactions in 'OMap' order, then the top-level transaction last, mirroring
-- `foldMapBatch` in "Cardano.Ledger.Dijkstra.TxInfo". Sub-transactions and the top-level
-- transaction have different types, so @f@ must be polymorphic in the transaction level.
mapTxBatch ::
  (EraTx era, DijkstraEraTxBody era) => Tx TopTx era -> (forall l. Tx l era -> a) -> [a]
mapTxBatch :: forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx forall (l :: TxLevel). Tx l era -> a
f = (Tx SubTx era -> a) -> [Tx SubTx era] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Tx SubTx era -> a
forall (l :: TxLevel). Tx l era -> a
f (Tx TopTx era -> [Tx SubTx era]
forall era.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> [Tx SubTx era]
getSubTransactions Tx TopTx era
topTx) [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> [Tx TopTx era -> a
forall (l :: TxLevel). Tx l era -> a
f Tx TopTx era
topTx]

-- | Combine the values extracted by @f@ from each transaction of the batch, in batch order.
foldMapBatch ::
  (EraTx era, DijkstraEraTxBody era, Monoid m) => Tx TopTx era -> (forall l. Tx l era -> m) -> m
foldMapBatch :: forall era m.
(EraTx era, DijkstraEraTxBody era, Monoid m) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> m) -> m
foldMapBatch Tx TopTx era
topTx forall (l :: TxLevel). Tx l era -> m
f = [m] -> m
forall a. Monoid a => [a] -> a
mconcat (Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> m) -> [m]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx Tx l era -> m
forall (l :: TxLevel). Tx l era -> m
f)

-- | Same as 'foldMapBatch', but for per-transaction translations that can fail.
foldMapBatchM ::
  (EraTx era, DijkstraEraTxBody era, Monoid m) =>
  Tx TopTx era ->
  (forall l. Tx l era -> Either e m) ->
  Either e m
foldMapBatchM :: forall era m e.
(EraTx era, DijkstraEraTxBody era, Monoid m) =>
Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Either e m) -> Either e m
foldMapBatchM Tx TopTx era
topTx forall (l :: TxLevel). Tx l era -> Either e m
f = [m] -> m
forall a. Monoid a => [a] -> a
mconcat ([m] -> m) -> Either e [m] -> Either e m
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Either e m] -> Either e [m]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA (Tx TopTx era
-> (forall (l :: TxLevel). Tx l era -> Either e m) -> [Either e m]
forall era a.
(EraTx era, DijkstraEraTxBody era) =>
Tx TopTx era -> (forall (l :: TxLevel). Tx l era -> a) -> [a]
mapTxBatch Tx TopTx era
topTx Tx l era -> Either e m
forall (l :: TxLevel). Tx l era -> Either e m
f)

-- | The script hash of each redeemer of a transaction whose purpose the transaction needs, so
-- the hash of a script used for two purposes appears twice.
scriptHashesPerRedeemer ::
  (EraUTxO era, AlonzoEraTxWits era, ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
  UTxO era ->
  Tx l era ->
  [ScriptHash]
scriptHashesPerRedeemer :: forall era (l :: TxLevel).
(EraUTxO era, AlonzoEraTxWits era,
 ScriptsNeeded era ~ AlonzoScriptsNeeded era) =>
UTxO era -> Tx l era -> [ScriptHash]
scriptHashesPerRedeemer UTxO era
utxo Tx l era
tx =
  let AlonzoScriptsNeeded [(PlutusPurpose AsIxItem era, ScriptHash)]
needed = UTxO era -> TxBody l era -> ScriptsNeeded era
forall era (t :: TxLevel).
EraUTxO era =>
UTxO era -> TxBody t era -> ScriptsNeeded era
forall (t :: TxLevel).
UTxO era -> TxBody t era -> ScriptsNeeded era
getScriptsNeeded UTxO era
utxo (Tx l era
tx Tx l era
-> Getting (TxBody l era) (Tx l era) (TxBody l era) -> TxBody l era
forall s a. s -> Getting a s a -> a
^. Getting (TxBody l era) (Tx l era) (TxBody l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxBody l era)
forall (l :: TxLevel). Lens' (Tx l era) (TxBody l era)
bodyTxL)
      redeemers :: Map (PlutusPurpose AsIx era) (Data era, ExUnits)
redeemers = Tx l era
tx Tx l era
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx l era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
forall s a. s -> Getting a s a -> a
^. (TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Tx l era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx l era)
forall era (l :: TxLevel).
EraTx era =>
Lens' (Tx l era) (TxWits era)
forall (l :: TxLevel). Lens' (Tx l era) (TxWits era)
witsTxL ((TxWits era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
 -> Tx l era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx l era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> TxWits era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx l era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Redeemers era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall era.
AlonzoEraTxWits era =>
Lens' (TxWits era) (Redeemers era)
Lens' (TxWits era) (Redeemers era)
rdmrsTxWitsL ((Redeemers era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
 -> TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> Redeemers era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> Redeemers era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era)
forall era.
AlonzoEraScript era =>
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
unRedeemersL
   in [ScriptHash
sh | (PlutusPurpose AsIxItem era
purpose, ScriptHash
sh) <- [(PlutusPurpose AsIxItem era, ScriptHash)]
needed, (forall ix it. AsIxItem ix it -> AsIx ix it)
-> PlutusPurpose AsIxItem era -> PlutusPurpose AsIx era
forall era (g :: * -> * -> *) (f :: * -> * -> *).
AlonzoEraScript era =>
(forall ix it. g ix it -> f ix it)
-> PlutusPurpose g era -> PlutusPurpose f era
forall (g :: * -> * -> *) (f :: * -> * -> *).
(forall ix it. g ix it -> f ix it)
-> PlutusPurpose g era -> PlutusPurpose f era
hoistPlutusPurpose AsIxItem ix it -> AsIx ix it
forall ix it. AsIxItem ix it -> AsIx ix it
toAsIx PlutusPurpose AsIxItem era
purpose PlutusPurpose AsIx era
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`Map.member` Map (PlutusPurpose AsIx era) (Data era, ExUnits)
redeemers]

-- | View a 'PV4.Map' as a 'Data.Map', ignoring the original order of its
-- entries and possible duplicates.
assocMapToMap :: Ord k => PV4.Map k v -> Map.Map k v
assocMapToMap :: forall k v. Ord k => Map k v -> Map k v
assocMapToMap = [(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(k, v)] -> Map k v)
-> (Map k v -> [(k, v)]) -> Map k v -> Map k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> [(k, v)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList

-- | Union a list of 'PV4.Map's, combining the values of a key present in more than one of them
-- with @combine@. The fold is from the left, so @combine@ receives the value of the earlier map
-- first.
unionsAssocMapWith :: PlutusTx.Eq k => (v -> v -> v) -> [PV4.Map k v] -> PV4.Map k v
unionsAssocMapWith :: forall k v. Eq k => (v -> v -> v) -> [Map k v] -> Map k v
unionsAssocMapWith v -> v -> v
combine = (Map k v -> Map k v -> Map k v) -> Map k v -> [Map k v] -> Map k v
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((v -> v -> v) -> Map k v -> Map k v -> Map k v
forall k a. Eq k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
AssocMap.unionWith v -> v -> v
combine) Map k v
forall k v. Map k v
AssocMap.empty

-- | Convert 'MintValue.MintValue' to 'Data.Map'.
mintValueToMap :: MintValue.MintValue -> Map.Map PV4.CurrencySymbol (Map.Map PV4.TokenName Integer)
mintValueToMap :: MintValue -> Map CurrencySymbol (Map TokenName Integer)
mintValueToMap = (Map TokenName Integer -> Map TokenName Integer)
-> Map CurrencySymbol (Map TokenName Integer)
-> Map CurrencySymbol (Map TokenName Integer)
forall a b.
(a -> b) -> Map CurrencySymbol a -> Map CurrencySymbol b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map TokenName Integer -> Map TokenName Integer
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (Map CurrencySymbol (Map TokenName Integer)
 -> Map CurrencySymbol (Map TokenName Integer))
-> (MintValue -> Map CurrencySymbol (Map TokenName Integer))
-> MintValue
-> Map CurrencySymbol (Map TokenName Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map CurrencySymbol (Map TokenName Integer)
-> Map CurrencySymbol (Map TokenName Integer)
forall k v. Ord k => Map k v -> Map k v
assocMapToMap (Map CurrencySymbol (Map TokenName Integer)
 -> Map CurrencySymbol (Map TokenName Integer))
-> (MintValue -> Map CurrencySymbol (Map TokenName Integer))
-> MintValue
-> Map CurrencySymbol (Map TokenName Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MintValue -> Map CurrencySymbol (Map TokenName Integer)
MintValue.unMintValue

shouldHaveUniqueAssocMapKeys :: (HasCallStack, Ord k, Show k) => PV4.Map k v -> Expectation
shouldHaveUniqueAssocMapKeys :: forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveUniqueAssocMapKeys Map k v
m =
  let keys :: [k]
keys = Map k v -> [k]
forall k v. Map k v -> [k]
AssocMap.keys Map k v
m
   in [k] -> [k]
forall a. Eq a => [a] -> [a]
List.nub [k]
keys [k] -> [k] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [k]
keys

-- | Checks that both nested 'PV4.Map' of 'MintValue.MintValue' have strictly
-- ascending keys (sorted and without duplicates), and every quantity satisfies
-- the predicate.
shouldBeCanonicalMintValue ::
  HasCallStack => (Integer -> Bool) -> MintValue.MintValue -> Expectation
shouldBeCanonicalMintValue :: HasCallStack => (Integer -> Bool) -> MintValue -> Expectation
shouldBeCanonicalMintValue Integer -> Bool
isValidQuantity (MintValue.UnsafeMintValue Map CurrencySymbol (Map TokenName Integer)
m) = do
  Map CurrencySymbol (Map TokenName Integer) -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveStrictlyAscendingKeys Map CurrencySymbol (Map TokenName Integer)
m
  (Map TokenName Integer -> Expectation)
-> [Map TokenName Integer] -> Expectation
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Map TokenName Integer -> Expectation
forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveStrictlyAscendingKeys (Map CurrencySymbol (Map TokenName Integer)
-> [Map TokenName Integer]
forall k v. Map k v -> [v]
AssocMap.elems Map CurrencySymbol (Map TokenName Integer)
m)
  (Map TokenName Integer -> [Integer])
-> [Map TokenName Integer] -> [Integer]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((Integer -> Bool) -> [Integer] -> [Integer]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Integer -> Bool) -> Integer -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Bool
isValidQuantity) ([Integer] -> [Integer])
-> (Map TokenName Integer -> [Integer])
-> Map TokenName Integer
-> [Integer]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map TokenName Integer -> [Integer]
forall k v. Map k v -> [v]
AssocMap.elems) (Map CurrencySymbol (Map TokenName Integer)
-> [Map TokenName Integer]
forall k v. Map k v -> [v]
AssocMap.elems Map CurrencySymbol (Map TokenName Integer)
m) [Integer] -> [Integer] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` []

-- | Checks that 'PV4.Map' keys are sorted and without duplicates.
shouldHaveStrictlyAscendingKeys :: (HasCallStack, Ord k, Show k) => PV4.Map k v -> Expectation
shouldHaveStrictlyAscendingKeys :: forall k v. (HasCallStack, Ord k, Show k) => Map k v -> Expectation
shouldHaveStrictlyAscendingKeys Map k v
m =
  let keys :: [k]
keys = Map k v -> [k]
forall k v. Map k v -> [k]
AssocMap.keys Map k v
m
   in [k]
keys [k] -> [k] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Set k -> [k]
forall a. Set a -> [a]
Set.toAscList ([k] -> Set k
forall a. Ord a => [a] -> Set a
Set.fromList [k]
keys)

-- Whether the first upper bound of a validity interval is strictly below the second one,
-- where an absent upper bound means unbounded.
isUpperBoundBelow :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> Bool
isUpperBoundBelow :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> Bool
isUpperBoundBelow (SJust SlotNo
slot) (SJust SlotNo
slot') = SlotNo
slot SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< SlotNo
slot'
isUpperBoundBelow (SJust SlotNo
_) StrictMaybe SlotNo
SNothing = Bool
True
isUpperBoundBelow StrictMaybe SlotNo
SNothing StrictMaybe SlotNo
_ = Bool
False