@@ -14,17 +14,26 @@ import Cardano.Ledger.Alonzo.Plutus.TxInfo (
1414 )
1515import Cardano.Ledger.Alonzo.Rules (AlonzoUtxosPredFailure (CollectErrors ))
1616import Cardano.Ledger.Babbage (BabbageEra )
17- import Cardano.Ledger.Babbage.Core (referenceInputsTxBodyL )
17+ import Cardano.Ledger.Babbage.Core (
18+ collateralInputsTxBodyL ,
19+ collateralReturnTxBodyL ,
20+ datumTxOutL ,
21+ referenceInputsTxBodyL ,
22+ totalCollateralTxBodyL ,
23+ )
24+ import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure (.. ))
1825import Cardano.Ledger.Babbage.TxInfo (
1926 BabbageContextError (
2027 ReferenceInputsNotSupported ,
2128 ReferenceScriptsNotSupported
2229 ),
2330 )
2431import Cardano.Ledger.Babbage.TxOut (referenceScriptTxOutL )
25- import Cardano.Ledger.BaseTypes (StrictMaybe (.. ), TxIx (.. ), inject )
26- import Cardano.Ledger.Coin (Coin (.. ))
32+ import Cardano.Ledger.BaseTypes (ProtVer (.. ), TxIx (.. ), inject , natVersion )
33+ import Cardano.Ledger.Coin (Coin (.. ), DeltaCoin ( .. ) )
2734import Cardano.Ledger.Core (
35+ ProtVerHigh ,
36+ bodyTxL ,
2837 eraProtVerHigh ,
2938 eraProtVerLow ,
3039 fromNativeScript ,
@@ -33,20 +42,24 @@ import Cardano.Ledger.Core (
3342 inputsTxBodyL ,
3443 mkBasicTx ,
3544 mkBasicTxBody ,
45+ mkBasicTxOut ,
3646 mkCoinTxOut ,
3747 outputsTxBodyL ,
3848 )
39- import Cardano.Ledger.Plutus (Language (.. ), hashPlutusScript , withSLanguage )
49+ import Cardano.Ledger.Credential (StakeReference (.. ))
50+ import Cardano.Ledger.Plutus (Language (.. ), hashPlutusScript , mkInlineDatum , withSLanguage )
4051import Cardano.Ledger.Shelley.Scripts (pattern RequireAllOf )
4152import Lens.Micro
53+ import qualified PlutusLedgerApi.V1 as PV1
4254import Test.Cardano.Ledger.Alonzo.ImpTest
4355import Test.Cardano.Ledger.Babbage.ImpTest (BabbageEraImp )
56+ import Test.Cardano.Ledger.Core.Utils (txInAt )
4457import Test.Cardano.Ledger.Imp.Common
4558import Test.Cardano.Ledger.Plutus.Examples
4659
4760spec :: forall era . BabbageEraImp era => SpecWith (ImpInit (LedgerSpec era ))
4861spec = describe " UTXOS" $ do
49- describe " Plutus V1 with references" $ do
62+ describe " PlutusV1 with references" $ do
5063 let inBabbage = eraProtVerLow @ era <= eraProtVerHigh @ BabbageEra
5164 behavior = if inBabbage then " fails" else " succeeds"
5265 submitBabbageFailingTx tx failures =
@@ -59,7 +72,7 @@ spec = describe "UTXOS" $ do
5972 addr <- freshKeyAddr_
6073 let txOut =
6174 mkCoinTxOut addr (inject $ Coin 5_000_000 )
62- & referenceScriptTxOutL .~ SJust nativeScript
75+ & referenceScriptTxOutL .~ pure nativeScript
6376 tx =
6477 mkBasicTx $
6578 mkBasicTxBody
@@ -92,3 +105,48 @@ spec = describe "UTXOS" $ do
92105 ReferenceInputsNotSupported @ era [refIn]
93106 ]
94107 ]
108+
109+ describe " PlutusV2 with references" $ do
110+ it " succeeds with same txIn in regular inputs and reference inputs" $ do
111+ let
112+ scriptHash = withSLanguage PlutusV2 $ hashPlutusScript . inputsOverlapsWithRefInputs
113+ txOut =
114+ mkBasicTxOut (mkAddr scriptHash StakeRefNull ) mempty
115+ & datumTxOutL .~ mkInlineDatum (PV1. I 0 )
116+ tx <-
117+ submitTx $
118+ mkBasicTx $
119+ mkBasicTxBody & outputsTxBodyL .~ [txOut]
120+ let txIn = txInAt 0 tx
121+ majorVer <- pvMajor <$> getProtVer
122+ when (majorVer <= natVersion @ (ProtVerHigh BabbageEra ) || majorVer >= natVersion @ 11 ) $
123+ submitTx_ $
124+ mkBasicTx mkBasicTxBody
125+ & bodyTxL . inputsTxBodyL .~ [txIn]
126+ & bodyTxL . referenceInputsTxBodyL .~ [txIn]
127+
128+ it " Incorrect collateral total" $ do
129+ let
130+ scriptHash = withSLanguage PlutusV2 (hashPlutusScript . alwaysSucceedsWithDatum)
131+ txOut =
132+ mkBasicTxOut (mkAddr scriptHash StakeRefNull ) mempty
133+ & datumTxOutL .~ mkInlineDatum (PV1. I 1 )
134+ tx <-
135+ submitTx $
136+ mkBasicTx $
137+ mkBasicTxBody & outputsTxBodyL .~ [txOut]
138+ let txIn = txInAt 0 tx
139+ addr <- freshKeyAddr_
140+ coll <- sendCoinTo addr $ Coin 5_000_000
141+ let
142+ collReturn = mkBasicTxOut addr . inject $ Coin 2_000_000
143+ tx2 =
144+ mkBasicTx $
145+ mkBasicTxBody
146+ & inputsTxBodyL .~ [txIn]
147+ & collateralInputsTxBodyL .~ [coll]
148+ & collateralReturnTxBodyL .~ pure collReturn
149+ & totalCollateralTxBodyL .~ pure (Coin 1_000_000 )
150+ submitFailingTx
151+ tx2
152+ [injectFailure (IncorrectTotalCollateralField (DeltaCoin 3_000_000 ) (Coin 1_000_000 ))]
0 commit comments