33{-# LANGUAGE FlexibleContexts #-}
44{-# LANGUAGE LambdaCase #-}
55{-# LANGUAGE NumericUnderscores #-}
6+ {-# LANGUAGE OverloadedLists #-}
67{-# LANGUAGE OverloadedStrings #-}
78{-# LANGUAGE PatternSynonyms #-}
89{-# LANGUAGE ScopedTypeVariables #-}
1112
1213module Test.Cardano.Ledger.Conway.Imp.UtxoSpec (spec ) where
1314
15+ import Cardano.Crypto.Hash (hashFromTextAsHex )
1416import Cardano.Ledger.Address
1517import Cardano.Ledger.Alonzo.Scripts
18+ import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ), unTxDatsL )
19+ import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure (.. ))
20+ import Cardano.Ledger.Babbage.Tx (hashScriptIntegrity )
1621import Cardano.Ledger.Babbage.TxBody (referenceInputsTxBodyL )
1722import Cardano.Ledger.Babbage.TxOut (referenceScriptTxOutL )
1823import Cardano.Ledger.BaseTypes
1924import Cardano.Ledger.Coin (Coin (.. ))
20- import Cardano.Ledger.Conway.PParams (ppMinFeeRefScriptCostPerByteL )
25+ import Cardano.Ledger.Conway.Core (AlonzoEraTxBody (.. ), AlonzoEraTxWits (.. ), ppMaxTxExUnitsL )
26+ import Cardano.Ledger.Conway.PParams (getLanguageView , ppMinFeeRefScriptCostPerByteL )
2127import Cardano.Ledger.Credential (Credential (.. ), StakeReference (.. ))
28+ import Cardano.Ledger.Hashes (unsafeMakeSafeHash )
2229import Cardano.Ledger.MemoBytes (getMemoRawBytes )
23- import Cardano.Ledger.Plutus.Language (Language (.. ), Plutus (.. ), PlutusLanguage , SLanguage (.. ), hashPlutusScript )
30+ import Cardano.Ledger.Plutus (Data (.. ))
31+ import Cardano.Ledger.Plutus.Language (
32+ Language (.. ),
33+ Plutus (.. ),
34+ PlutusLanguage ,
35+ SLanguage (.. ),
36+ hashPlutusScript ,
37+ )
2438import Cardano.Ledger.Plutus.Preprocessor.Binary.V2 (inputsIsSubsetOfRefInputsBytes )
2539import Cardano.Ledger.Shelley.Core
2640import Cardano.Ledger.Shelley.LedgerState
@@ -30,28 +44,26 @@ import Cardano.Ledger.Shelley.Scripts (
3044 )
3145import Cardano.Ledger.Shelley.UTxO (getShelleyMinFeeTxUtxo )
3246import Cardano.Ledger.State (getMinFeeTxUtxo )
33- import Cardano.Ledger.TxIn (TxIn (.. ))
47+ import Cardano.Ledger.TxIn (TxId ( .. ), TxIn (.. ))
3448import Cardano.Ledger.Val
3549import qualified Data.ByteString.Short as SBS (length )
3650import Data.Functor ((<&>) )
51+ import qualified Data.List.NonEmpty as NE
3752import qualified Data.Map.Strict as Map
53+ import Data.Maybe (fromJust )
3854import qualified Data.Sequence.Strict as SSeq
3955import qualified Data.Set as Set
4056import Lens.Micro ((&) , (.~) , (^.) )
57+ import qualified PlutusLedgerApi.Common as P
4158import Test.Cardano.Ledger.Conway.ImpTest
4259import Test.Cardano.Ledger.Core.Rational ((%!) )
4360import Test.Cardano.Ledger.Core.Utils (txInAt )
4461import Test.Cardano.Ledger.Imp.Common
4562import Test.Cardano.Ledger.Plutus.Examples (alwaysSucceedsNoDatum )
46- import Data.Maybe (fromJust )
47- import Cardano.Ledger.Conway.Core (AlonzoEraTxWits (.. ), ppMaxTxExUnitsL , AlonzoEraTxBody (.. ))
48- import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ))
49- import Cardano.Ledger.Plutus (Data (.. ))
50- import qualified PlutusLedgerApi.Common as P
5163
5264spec ::
5365 forall era .
54- ConwayEraImp era =>
66+ ( ConwayEraImp era , InjectRuleFailure " LEDGER " BabbageUtxoPredFailure era ) =>
5567 SpecWith (ImpInit (LedgerSpec era ))
5668spec =
5769 describe " Reference scripts" $ do
@@ -80,29 +92,57 @@ spec =
8092 mkAddr
8193 (ScriptHashObj @ 'Payment $ hashPlutusScript @ pv plutus)
8294 StakeRefNull
83- script :: forall (pv :: Language ). PlutusLanguage pv => PlutusScript era
84- script = fromJust $ mkPlutusScript @ era @ pv plutus
85- -- it "Same script can appear in regular and reference inputs in PlutusV2" $ do
95+ -- script :: forall (pv :: Language). PlutusLanguage pv => PlutusScript era
96+ -- script = fromJust $ mkPlutusScript @era @pv plutus
97+ -- it "Same script can appear in regular and reference inputs in PlutusV2" $ do
8698 -- txIn <- sendCoinTo (scriptAddr @'PlutusV2) $ Coin 1_000_000
8799 -- submitTx_ $
88100 -- mkBasicTx mkBasicTxBody
89101 -- & bodyTxL . inputsTxBodyL .~ Set.singleton txIn
90102 -- & bodyTxL . referenceInputsTxBodyL .~ Set.singleton txIn
91103 -- & witsTxL . scriptTxWitsL .~ Map.singleton (hashPlutusScript @'PlutusV2 plutus) (PlutusScript $ script @'PlutusV2)
92104 it " Same script cannot appear in regular and reference inputs in PlutusV3" $ do
93- maxExUnits <- getsNES $ nesEsL . curPParamsEpochStateL . ppMaxTxExUnitsL
105+ -- maxExUnits <- getsNES $ nesEsL . curPParamsEpochStateL . ppMaxTxExUnitsL
94106 txIn <- sendCoinTo (scriptAddr @ 'PlutusV3) $ Coin 1_000_000
95- collateralIn <- sendCoinTo (scriptAddr @ 'PlutusV3) $ Coin 1_000_000_000
107+ -- collateralIn <- sendCoinTo (scriptAddr @'PlutusV3) $ Coin 1_000_000_000
108+ -- pp <- getsPParams id
96109 let
97- tx =
110+ tx =
98111 mkBasicTx mkBasicTxBody
99112 & bodyTxL . inputsTxBodyL .~ Set. singleton txIn
100113 & bodyTxL . referenceInputsTxBodyL .~ Set. singleton txIn
101- & bodyTxL . collateralInputsTxBodyL .~ Set. singleton collateralIn
102- & bodyTxL . feeTxBodyL .~ Coin 100_000_000
103- & witsTxL . scriptTxWitsL .~ Map. singleton (hashPlutusScript @ 'PlutusV3 plutus) (PlutusScript $ script @ 'PlutusV3)
104- & witsTxL . rdmrsTxWitsL .~ Redeemers (Map. singleton (SpendingPurpose (AsIx 0 )) (Data $ P. I 0 , maxExUnits))
105- submitTx_ @ era tx
114+ -- langViews = Set.map (getLanguageView pp) (Set.singleton PlutusV2)
115+ -- txWits =
116+ -- mkBasicTxWits
117+ -- & scriptTxWitsL
118+ -- .~ Map.singleton (hashPlutusScript @'PlutusV3 plutus) (PlutusScript $ script @'PlutusV3)
119+ -- & rdmrsTxWitsL .~ Redeemers (Map.singleton (SpendingPurpose (AsIx 0)) (Data $ P.I 0, maxExUnits))
120+ -- & datsTxWitsL . unTxDatsL .~ mempty
121+ -- tx =
122+ -- mkBasicTx mkBasicTxBody
123+ -- & bodyTxL . inputsTxBodyL .~ Set.singleton txIn
124+ -- & bodyTxL . referenceInputsTxBodyL .~ Set.singleton txIn
125+ -- & bodyTxL . collateralInputsTxBodyL .~ Set.singleton collateralIn
126+ -- & bodyTxL . feeTxBodyL .~ Coin 100_000_000
127+ -- & bodyTxL . scriptIntegrityHashTxBodyL
128+ -- .~ hashScriptIntegrity @era langViews (txWits ^. rdmrsTxWitsL) (txWits ^. datsTxWitsL)
129+ -- & witsTxL .~ txWits
130+ submitFailingTx @ era
131+ tx
132+ [ injectFailure $
133+ BabbageNonDisjointRefInputs
134+ ( NE. fromList
135+ [ TxIn
136+ ( TxId
137+ ( unsafeMakeSafeHash . fromJust $
138+ hashFromTextAsHex
139+ " 3b3a57c1fe445f8346b94a64ee39baf3f253e0932f37014c2735bb326d12be81"
140+ )
141+ )
142+ (TxIx 0 )
143+ ]
144+ )
145+ ]
106146 where
107147 checkMinFee :: HasCallStack => NativeScript era -> [Script era ] -> ImpTestM era ()
108148 checkMinFee scriptToSpend refScripts = do
0 commit comments