1212
1313module Test.Cardano.Ledger.Conway.Imp.UtxoSpec (spec ) where
1414
15- import Cardano.Crypto.Hash (hashFromTextAsHex )
1615import Cardano.Ledger.Address
1716import Cardano.Ledger.Alonzo.Scripts
18- import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ), unTxDatsL )
1917import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure (.. ))
20- import Cardano.Ledger.Babbage.Tx (hashScriptIntegrity )
2118import Cardano.Ledger.Babbage.TxBody (referenceInputsTxBodyL )
2219import Cardano.Ledger.Babbage.TxOut (referenceScriptTxOutL )
2320import Cardano.Ledger.BaseTypes
2421import Cardano.Ledger.Coin (Coin (.. ))
25- import Cardano.Ledger.Conway.Core (AlonzoEraTxBody (.. ), AlonzoEraTxWits (.. ), ppMaxTxExUnitsL )
26- import Cardano.Ledger.Conway.PParams (getLanguageView , ppMinFeeRefScriptCostPerByteL )
22+ import Cardano.Ledger.Conway.PParams (ppMinFeeRefScriptCostPerByteL )
2723import Cardano.Ledger.Credential (Credential (.. ), StakeReference (.. ))
28- import Cardano.Ledger.Hashes (unsafeMakeSafeHash )
2924import Cardano.Ledger.MemoBytes (getMemoRawBytes )
30- import Cardano.Ledger.Plutus (Data (.. ))
3125import Cardano.Ledger.Plutus.Language (
32- Language (.. ),
3326 Plutus (.. ),
34- PlutusLanguage ,
3527 SLanguage (.. ),
3628 hashPlutusScript ,
3729 )
38- import Cardano.Ledger.Plutus.Preprocessor.Binary.V2 (inputsIsSubsetOfRefInputsBytes )
3930import Cardano.Ledger.Shelley.Core
4031import Cardano.Ledger.Shelley.LedgerState
4132import Cardano.Ledger.Shelley.Scripts (
@@ -44,22 +35,20 @@ import Cardano.Ledger.Shelley.Scripts (
4435 )
4536import Cardano.Ledger.Shelley.UTxO (getShelleyMinFeeTxUtxo )
4637import Cardano.Ledger.State (getMinFeeTxUtxo )
47- import Cardano.Ledger.TxIn (TxId ( .. ), TxIn (.. ))
38+ import Cardano.Ledger.TxIn (TxIn (.. ))
4839import Cardano.Ledger.Val
4940import qualified Data.ByteString.Short as SBS (length )
5041import Data.Functor ((<&>) )
5142import qualified Data.List.NonEmpty as NE
5243import qualified Data.Map.Strict as Map
53- import Data.Maybe (fromJust )
5444import qualified Data.Sequence.Strict as SSeq
5545import qualified Data.Set as Set
5646import Lens.Micro ((&) , (.~) , (^.) )
57- import qualified PlutusLedgerApi.Common as P
5847import Test.Cardano.Ledger.Conway.ImpTest
5948import Test.Cardano.Ledger.Core.Rational ((%!) )
6049import Test.Cardano.Ledger.Core.Utils (txInAt )
6150import Test.Cardano.Ledger.Imp.Common
62- import Test.Cardano.Ledger.Plutus.Examples (alwaysSucceedsNoDatum )
51+ import Test.Cardano.Ledger.Plutus.Examples (alwaysSucceedsNoDatum , inputsIsSubsetOfRefInputs )
6352
6453spec ::
6554 forall era .
@@ -86,62 +75,19 @@ spec =
8675 ++ extraScripts
8776 describe " disjoint inputs and reference inputs" $ do
8877 let
89- plutus = Plutus $ snd inputsIsSubsetOfRefInputsBytes
90- scriptAddr :: forall (pv :: Language ). PlutusLanguage pv => Addr
91- scriptAddr =
92- mkAddr
93- (ScriptHashObj @ 'Payment $ hashPlutusScript @ pv plutus)
94- StakeRefNull
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
98- -- txIn <- sendCoinTo (scriptAddr @'PlutusV2) $ Coin 1_000_000
99- -- submitTx_ $
100- -- mkBasicTx mkBasicTxBody
101- -- & bodyTxL . inputsTxBodyL .~ Set.singleton txIn
102- -- & bodyTxL . referenceInputsTxBodyL .~ Set.singleton txIn
103- -- & witsTxL . scriptTxWitsL .~ Map.singleton (hashPlutusScript @'PlutusV2 plutus) (PlutusScript $ script @'PlutusV2)
78+ scriptHash lang = hashPlutusScript (inputsIsSubsetOfRefInputs lang)
79+ tx :: TxIn -> Tx era
80+ tx txIn =
81+ mkBasicTx mkBasicTxBody
82+ & bodyTxL . inputsTxBodyL .~ Set. singleton txIn
83+ & bodyTxL . referenceInputsTxBodyL .~ Set. singleton txIn
10484 it " Same script cannot appear in regular and reference inputs in PlutusV3" $ do
105- -- maxExUnits <- getsNES $ nesEsL . curPParamsEpochStateL . ppMaxTxExUnitsL
106- txIn <- sendCoinTo (scriptAddr @ 'PlutusV3) $ Coin 1_000_000
107- -- collateralIn <- sendCoinTo (scriptAddr @'PlutusV3) $ Coin 1_000_000_000
108- -- pp <- getsPParams id
109- let
110- tx =
111- mkBasicTx mkBasicTxBody
112- & bodyTxL . inputsTxBodyL .~ Set. singleton txIn
113- & bodyTxL . referenceInputsTxBodyL .~ Set. singleton txIn
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
85+ txIn <- produceScript $ scriptHash SPlutusV3
13086 submitFailingTx @ era
131- tx
87+ (tx txIn)
13288 [ injectFailure $
13389 BabbageNonDisjointRefInputs
134- ( NE. fromList
135- [ TxIn
136- ( TxId
137- ( unsafeMakeSafeHash . fromJust $
138- hashFromTextAsHex
139- " 3b3a57c1fe445f8346b94a64ee39baf3f253e0932f37014c2735bb326d12be81"
140- )
141- )
142- (TxIx 0 )
143- ]
144- )
90+ (txIn NE. :| [] )
14591 ]
14692 where
14793 checkMinFee :: HasCallStack => NativeScript era -> [Script era ] -> ImpTestM era ()
0 commit comments