Skip to content

Commit 2f12961

Browse files
Soupstrawlehins
andcommitted
Reapply review suggestions
Co-authored-by: Alexey Kuleshevich <[email protected]>
1 parent 684c606 commit 2f12961

File tree

7 files changed

+45
-56
lines changed

7 files changed

+45
-56
lines changed

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/ImpTest.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ fixupDatums tx = impAnn "fixupDatums" $ do
287287
getData txOut =
288288
let sh = txOutScriptHash txOut
289289
in case txOut ^. datumTxOutF of
290-
DatumHash _dh -> case Map.lookup sh (scriptTestContexts @era) of
291-
Just x -> pure . Just $ spendDatum x
292-
Nothing -> do
290+
DatumHash dh -> case Map.lookup sh (scriptTestContexts @era) of
291+
Just x | hashData @era (spendDatum x) == dh -> pure . Just $ spendDatum x
292+
_ -> do
293293
logText $
294294
"Script not found in `scriptTestContexts`:\n"
295295
<> T.pack (show sh)

eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ disjointRefInputs ::
232232
Test (BabbageUtxoPredFailure era)
233233
disjointRefInputs pp inputs refInputs =
234234
when
235-
(pvMajor (pp ^. ppProtocolVersionL) == natVersion @10)
235+
( pvMajor (pp ^. ppProtocolVersionL) > eraProtVerHigh @BabbageEra
236+
&& pvMajor (pp ^. ppProtocolVersionL) < natVersion @11
237+
)
236238
(failureOnNonEmpty common BabbageNonDisjointRefInputs)
237239
where
238240
common = inputs `Set.intersection` refInputs

eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/Imp/UtxoSpec.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import Cardano.Ledger.Babbage.Core (
1313
EraTx (..),
1414
EraTxBody (..),
1515
EraTxOut (..),
16-
KeyRole (..),
1716
)
1817
import Cardano.Ledger.BaseTypes (Inject (..))
1918
import Cardano.Ledger.Coin (Coin (..))
20-
import Cardano.Ledger.Credential (Credential (..), StakeReference (..))
19+
import Cardano.Ledger.Credential (StakeReference (..))
2120
import Cardano.Ledger.Plutus (
2221
Data (..),
2322
Datum (..),
@@ -49,11 +48,11 @@ spec = describe "UTXO" $ do
4948
txOut =
5049
mkBasicTxOut
5150
( mkAddr
52-
(ScriptHashObj @'Payment $ hashPlutusScript (inputsOverlapsWithRefInputs SPlutusV2))
51+
(hashPlutusScript (inputsOverlapsWithRefInputs SPlutusV2))
5352
StakeRefNull
5453
)
5554
(inject $ Coin 1_000_000)
56-
& datumTxOutL .~ (Datum . dataToBinaryData . Data . PV1.I $ 0)
55+
& datumTxOutL .~ Datum (dataToBinaryData . Data $ PV1.I 0)
5756
tx <-
5857
submitTx $
5958
mkBasicTx mkBasicTxBody

eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import Control.DeepSeq (NFData)
118118
import Control.Monad (unless, when, zipWithM)
119119
import Data.Aeson (ToJSON (..), (.=))
120120
import Data.Foldable as F (Foldable (..))
121+
import Data.List.NonEmpty (NonEmpty (..))
121122
import qualified Data.Map.Strict as Map
122123
import qualified Data.OSet.Strict as OSet
123124
import qualified Data.Set as Set
@@ -166,7 +167,7 @@ data ConwayContextError era
166167
| VotingProceduresFieldNotSupported !(VotingProcedures era)
167168
| ProposalProceduresFieldNotSupported !(OSet.OSet (ProposalProcedure era))
168169
| TreasuryDonationFieldNotSupported !Coin
169-
| ReferenceInputsNotDisjointFromInputs !(Set.Set TxIn)
170+
| ReferenceInputsNotDisjointFromInputs !(NonEmpty TxIn)
170171
deriving (Generic)
171172

172173
deriving instance
@@ -472,8 +473,9 @@ instance EraPlutusTxInfo 'PlutusV3 ConwayEra where
472473
refInputsInfo <- mapM (transTxInInfoV3 ltiUTxO) (Set.toList refInputs)
473474
let
474475
commonInputs = txInputs `Set.intersection` refInputs
475-
unless (pvMajor ltiProtVer < natVersion @11 || Set.null commonInputs) . Left $
476-
ReferenceInputsNotDisjointFromInputs commonInputs
476+
unless (pvMajor ltiProtVer < natVersion @11) $ case toList commonInputs of
477+
(x : xs) -> Left $ ReferenceInputsNotDisjointFromInputs $ x :| xs
478+
_ -> Right ()
477479
outputs <-
478480
zipWithM
479481
(Babbage.transTxOutV2 . TxOutFromOutput)

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ spec ::
9090
, ToExpr (Event (EraRule "ENACT" era))
9191
, Eq (Event (EraRule "ENACT" era))
9292
, Typeable (Event (EraRule "ENACT" era))
93-
, ContextError era ~ ConwayContextError era
9493
) =>
9594
Spec
9695
spec = do
@@ -126,7 +125,6 @@ conwaySpec ::
126125
, ToExpr (Event (EraRule "ENACT" era))
127126
, Eq (Event (EraRule "ENACT" era))
128127
, Typeable (Event (EraRule "ENACT" era))
129-
, ContextError era ~ ConwayContextError era
130128
) =>
131129
SpecWith (ImpInit (LedgerSpec era))
132130
conwaySpec = do

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/UtxoSpec.hs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
{-# LANGUAGE ScopedTypeVariables #-}
99
{-# LANGUAGE TypeApplications #-}
1010
{-# LANGUAGE TypeFamilies #-}
11-
{-# LANGUAGE TypeOperators #-}
1211

1312
module Test.Cardano.Ledger.Conway.Imp.UtxoSpec (spec) where
1413

@@ -42,7 +41,6 @@ import Cardano.Ledger.TxIn (TxIn (..))
4241
import Cardano.Ledger.Val
4342
import qualified Data.ByteString.Short as SBS (length)
4443
import Data.Functor ((<&>))
45-
import qualified Data.List.NonEmpty as NE
4644
import qualified Data.Map.Strict as Map
4745
import qualified Data.Sequence.Strict as SSeq
4846
import qualified Data.Set as Set
@@ -58,7 +56,7 @@ spec ::
5856
( ConwayEraImp era
5957
, InjectRuleFailure "LEDGER" BabbageUtxoPredFailure era
6058
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
61-
, ContextError era ~ ConwayContextError era
59+
, Inject (ConwayContextError era) (ContextError era)
6260
) =>
6361
SpecWith (ImpInit (LedgerSpec era))
6462
spec =
@@ -83,39 +81,31 @@ spec =
8381
describe "disjoint inputs and reference inputs" $ do
8482
let
8583
scriptHash lang = hashPlutusScript $ inputsOverlapsWithRefInputs lang
86-
tx :: TxIn -> Tx era
87-
tx txIn =
84+
mkTestTx :: TxIn -> Tx era
85+
mkTestTx txIn =
8886
mkBasicTx mkBasicTxBody
8987
& bodyTxL . inputsTxBodyL .~ Set.singleton txIn
9088
& bodyTxL . referenceInputsTxBodyL .~ Set.singleton txIn
9189

92-
it "Can run scripts that expect inputs and refInputs to overlap (PV 9)" . whenMajorVersion @9 $ do
90+
it "Cannot run scripts that expect inputs and refInputs to overlap (PV 9)" $ whenMajorVersion @9 $ do
9391
txIn <- produceScript $ scriptHash SPlutusV3
94-
submitTx_ @era $ tx txIn
95-
it "Same script cannot appear in regular and reference inputs in PlutusV3 (PV 10)"
96-
. whenMajorVersion @10
97-
$ do
98-
txIn <- produceScript $ scriptHash SPlutusV3
99-
submitFailingTx @era
100-
(tx txIn)
101-
[ injectFailure $
102-
BabbageNonDisjointRefInputs
103-
(txIn NE.:| [])
104-
]
105-
it "Same script cannot appear in regular and reference inputs in PlutusV3 (PV 11)"
106-
. whenMajorVersionAtLeast @11
107-
$ do
108-
txIn <- produceScript $ scriptHash SPlutusV3
109-
submitFailingTx @era
110-
(tx txIn)
111-
[ injectFailure $
112-
CollectErrors
113-
[ BadTranslation
114-
( ReferenceInputsNotDisjointFromInputs
115-
(Set.singleton txIn)
116-
)
117-
]
118-
]
92+
submitFailingTx @era
93+
(mkTestTx txIn)
94+
[ injectFailure $ BabbageNonDisjointRefInputs [txIn]
95+
]
96+
it "Same script cannot appear in regular and reference inputs in PlutusV3 (PV 10)" $ whenMajorVersion @10 $ do
97+
txIn <- produceScript $ scriptHash SPlutusV3
98+
submitFailingTx @era
99+
(mkTestTx txIn)
100+
[ injectFailure $ BabbageNonDisjointRefInputs [txIn]
101+
]
102+
it "Same script cannot appear in regular and reference inputs in PlutusV3 (PV 11)" $ whenMajorVersionAtLeast @11 $ do
103+
txIn <- produceScript $ scriptHash SPlutusV3
104+
submitFailingTx @era
105+
(mkTestTx txIn)
106+
[ injectFailure $
107+
CollectErrors [BadTranslation . inject $ ReferenceInputsNotDisjointFromInputs @era [txIn]]
108+
]
119109
where
120110
checkMinFee :: HasCallStack => NativeScript era -> [Script era] -> ImpTestM era ()
121111
checkMinFee scriptToSpend refScripts = do

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/UtxosSpec.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import Cardano.Ledger.Shelley.LedgerState
3232
import Cardano.Ledger.Shelley.Rules (ShelleyUtxowPredFailure (..))
3333
import Cardano.Ledger.TxIn (TxId (..), mkTxInPartial)
3434
import Data.Default (def)
35-
import Data.Either (isLeft, isRight)
3635
import Data.List.NonEmpty (NonEmpty (..))
3736
import qualified Data.Map.Strict as Map
3837
import qualified Data.OSet.Strict as OSet
@@ -121,17 +120,16 @@ datumAndReferenceInputsSpec = do
121120
, mkTxInPartial producingTx 1
122121
]
123122
& bodyTxL . referenceInputsTxBodyL .~ Set.singleton (mkTxInPartial producingTx 0)
124-
pv <- getProtVer
125-
res <- trySubmitTx consumingTx
126-
if pv == ProtVer (natVersion @10) 0
127-
then case res of
128-
Left (err, _) ->
129-
err
130-
`shouldBeExpr` ( pure . injectFailure . BabbageNonDisjointRefInputs $
131-
mkTxInPartial producingTx 0 :| []
132-
)
133-
x -> x `shouldSatisfyExpr` isLeft
134-
else res `shouldSatisfyExpr` isRight
123+
let badTxIns = mkTxInPartial producingTx 0 :| []
124+
125+
whenMajorVersionAtMost @10 $
126+
submitFailingTx
127+
consumingTx
128+
(pure . injectFailure $ BabbageNonDisjointRefInputs badTxIns)
129+
130+
-- consumingTx uses PlutusV1 script, so it should be a success
131+
whenMajorVersionAtLeast @11 $
132+
submitTx_ consumingTx
135133
it "fails when using inline datums for PlutusV1" $ do
136134
let shSpending = hashPlutusScript (redeemerSameAsDatum SPlutusV1)
137135
refTxOut <- mkRefTxOut shSpending

0 commit comments

Comments
 (0)