Skip to content

Commit 81637a1

Browse files
authored
Merge pull request #4918 from IntersectMBO/nm/mapRdmrsL
Add `unRedeemersL` and `unTxDatsL` lenses
2 parents 0e04cf4 + a34ae3b commit 81637a1

File tree

20 files changed

+85
-78
lines changed

20 files changed

+85
-78
lines changed

eras/alonzo/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Stop re-exporting deprecated `AuxiliaryDataHash` from `Cardano.Ledger.Alonzo.TxAuxData`
2525
* Deprecate `Alonzo` type synonym
2626
* Remove crypto parametrization from `AlonzoEra`
27+
* Add `unRedeemersL`, `unTxDatsL`
28+
* Deprecate `lookupRedeemer`, `nullRedeemers`, `nullDats`
2729

2830
### `testlib`
2931

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/Evaluate.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
import Cardano.Ledger.Alonzo.Core
3636
import Cardano.Ledger.Alonzo.Plutus.Context (ContextError, EraPlutusContext (..), LedgerTxInfo (..))
3737
import Cardano.Ledger.Alonzo.Scripts (lookupPlutusScript, plutusScriptLanguage, toAsItem, toAsIx)
38-
import Cardano.Ledger.Alonzo.TxWits (lookupRedeemer, unRedeemers)
38+
import Cardano.Ledger.Alonzo.TxWits (unRedeemersL)
3939
import Cardano.Ledger.Alonzo.UTxO (AlonzoEraUTxO, AlonzoScriptsNeeded (..))
4040
import Cardano.Ledger.BaseTypes (kindObject)
4141
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
@@ -178,7 +178,7 @@ collectPlutusScriptsWithContext epochInfo systemStart pp tx utxo =
178178

179179
getScriptWithRedeemer ((plutusScriptHash, plutusPurpose), plutusScript) =
180180
let redeemerIndex = hoistPlutusPurpose toAsIx plutusPurpose
181-
in case lookupRedeemer redeemerIndex $ tx ^. witsTxL . rdmrsTxWitsL of
181+
in case Map.lookup redeemerIndex $ tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL of
182182
Just (d, exUnits) -> Right (plutusScript, plutusPurpose, d, exUnits, plutusScriptHash)
183183
Nothing -> Left (NoRedeemer (hoistPlutusPurpose toAsItem plutusPurpose))
184184
apply (plutusScript, plutusPurpose, redeemerData, exUnits, plutusScriptHash) = do
@@ -372,7 +372,7 @@ evalTxExUnitsWithLogs pp tx utxo epochInfo systemStart = Map.mapWithKey findAndC
372372
maxBudget = pp ^. ppMaxTxExUnitsL
373373
txBody = tx ^. bodyTxL
374374
wits = tx ^. witsTxL
375-
rdmrs = unRedeemers $ wits ^. rdmrsTxWitsL
375+
rdmrs = wits ^. rdmrsTxWitsL . unRedeemersL
376376
protVer = pp ^. ppProtocolVersionL
377377
costModels = costModelsValid $ pp ^. ppCostModelsL
378378
ScriptsProvided scriptsProvided = getScriptsProvided utxo tx

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Cardano.Ledger.Alonzo.Core
5050
import Cardano.Ledger.Alonzo.Era (AlonzoEra)
5151
import Cardano.Ledger.Alonzo.Plutus.Context
5252
import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose (..), PlutusScript (..), toAsItem)
53-
import Cardano.Ledger.Alonzo.TxWits (unTxDats)
53+
import Cardano.Ledger.Alonzo.TxWits (unTxDatsL)
5454
import Cardano.Ledger.BaseTypes (ProtVer, StrictMaybe (..), strictMaybeToMaybe)
5555
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
5656
import Cardano.Ledger.Binary.Coders (
@@ -288,7 +288,7 @@ transTxBodyReqSignerHashes txBody = transKeyHash <$> Set.toList (txBody ^. reqSi
288288

289289
-- | Translate all `TxDats`s from within `TxWits`
290290
transTxWitsDatums :: AlonzoEraTxWits era => TxWits era -> [(PV1.DatumHash, PV1.Datum)]
291-
transTxWitsDatums txWits = transDataPair <$> Map.toList (unTxDats $ txWits ^. datsTxWitsL)
291+
transTxWitsDatums txWits = transDataPair <$> Map.toList (txWits ^. datsTxWitsL . unTxDatsL)
292292

293293
-- ==================================
294294
-- translate Values

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxo.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import Cardano.Ledger.Alonzo.TxBody (
5454
AlonzoEraTxOut (..),
5555
MaryEraTxBody (..),
5656
)
57-
import Cardano.Ledger.Alonzo.TxWits (AlonzoEraTxWits (..), nullRedeemers)
57+
import Cardano.Ledger.Alonzo.TxWits (AlonzoEraTxWits (..), unRedeemersL)
5858
import Cardano.Ledger.BaseTypes (
5959
Mismatch (..),
6060
Network,
@@ -285,7 +285,7 @@ feesOK pp tx u@(UTxO utxo) =
285285
(minFee <= theFee)
286286
(FeeTooSmallUTxO Mismatch {mismatchSupplied = theFee, mismatchExpected = minFee})
287287
, -- Part 2: (txrdmrs tx ≠ ∅ ⇒ validateCollateral)
288-
unless (nullRedeemers (tx ^. witsTxL . rdmrsTxWitsL)) $
288+
unless (null $ tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL) $
289289
validateCollateral pp txBody utxoCollateral
290290
]
291291

@@ -367,7 +367,7 @@ validateOutsideForecast ei slotNo sysSt tx =
367367
{- (_,i_f) := txvldt tx -}
368368
case tx ^. bodyTxL . vldtTxBodyL of
369369
ValidityInterval _ (SJust ifj)
370-
| not (nullRedeemers (tx ^. witsTxL . rdmrsTxWitsL)) ->
370+
| not . null $ tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL ->
371371
let ei' = unsafeLinearExtendEpochInfo slotNo ei
372372
in -- ◇ ∉ { txrdmrs tx, i_f } ⇒
373373
failureUnless (isRight (epochInfoSlotToUTCTime ei' sysSt ifj)) $ OutsideForecast ifj

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import Cardano.Ledger.Alonzo.Rules.Utxos (AlonzoUtxosPredFailure)
3939
import Cardano.Ledger.Alonzo.Scripts (plutusScriptLanguage, toAsItem, toAsIx)
4040
import Cardano.Ledger.Alonzo.Tx (hashScriptIntegrity)
4141
import Cardano.Ledger.Alonzo.TxWits (
42-
unRedeemers,
43-
unTxDats,
42+
unRedeemersL,
43+
unTxDatsL,
4444
)
4545
import Cardano.Ledger.Alonzo.UTxO (
4646
AlonzoEraUTxO (..),
@@ -237,7 +237,7 @@ missingRequiredDatums utxo tx = do
237237
let txBody = tx ^. bodyTxL
238238
scriptsProvided = getScriptsProvided utxo tx
239239
(inputHashes, txInsNoDataHash) = getInputDataHashesTxBody utxo txBody scriptsProvided
240-
txHashes = domain (unTxDats $ tx ^. witsTxL . datsTxWitsL)
240+
txHashes = domain (tx ^. witsTxL . datsTxWitsL . unTxDatsL)
241241
unmatchedDatumHashes = eval (inputHashes txHashes)
242242
allowedSupplementalDataHashes = getSupplementalDataHashes utxo txBody
243243
supplimentalDatumHashes = eval (txHashes inputHashes)
@@ -274,7 +274,7 @@ hasExactSetOfRedeemers tx (ScriptsProvided scriptsProvided) (AlonzoScriptsNeeded
274274
]
275275
(extraRdmrs, missingRdmrs) =
276276
extSymmetricDifference
277-
(Map.keys $ unRedeemers $ tx ^. witsTxL . rdmrsTxWitsL)
277+
(Map.keys $ tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL)
278278
id
279279
redeemersNeeded
280280
fst

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ import Cardano.Ledger.Alonzo.TxWits (
9393
AlonzoTxWits (..),
9494
Redeemers (..),
9595
TxDats (..),
96-
nullDats,
97-
nullRedeemers,
9896
txrdmrs,
99-
unRedeemers,
97+
unRedeemersL,
98+
unTxDatsL,
10099
)
101100
import Cardano.Ledger.Binary (
102101
Annotator (..),
@@ -124,14 +123,12 @@ import Control.Arrow (left)
124123
import Control.DeepSeq (NFData (..))
125124
import Data.Aeson (ToJSON (..))
126125
import qualified Data.ByteString.Lazy as LBS
127-
import qualified Data.Map.Strict as Map
128126
import Data.Maybe.Strict (
129127
StrictMaybe (..),
130128
maybeToStrictMaybe,
131129
strictMaybeToMaybe,
132130
)
133131
import Data.Set (Set)
134-
import qualified Data.Set as Set
135132
import Data.Typeable (Typeable)
136133
import Data.Word (Word32)
137134
import GHC.Generics (Generic)
@@ -292,7 +289,7 @@ deriving instance AlonzoEraScript era => NoThunks (ScriptIntegrity era)
292289
-- Instead, we must use a reproducable serialization
293290
instance Era era => SafeToHash (ScriptIntegrity era) where
294291
originalBytes (ScriptIntegrity m d l) =
295-
let dBytes = if nullDats d then mempty else originalBytes d
292+
let dBytes = if null (d ^. unTxDatsL) then mempty else originalBytes d
296293
lBytes = serialize' (eraProtVerLow @era) (encodeLangViews l)
297294
in originalBytes m <> dBytes <> lBytes
298295

@@ -308,7 +305,7 @@ hashScriptIntegrity ::
308305
TxDats era ->
309306
StrictMaybe ScriptIntegrityHash
310307
hashScriptIntegrity langViews rdmrs dats =
311-
if nullRedeemers rdmrs && Set.null langViews && nullDats dats
308+
if null (rdmrs ^. unRedeemersL) && null langViews && null (dats ^. unTxDatsL)
312309
then SNothing
313310
else SJust (hashAnnotated (ScriptIntegrity rdmrs dats langViews))
314311

@@ -351,8 +348,7 @@ totExUnits ::
351348
(EraTx era, AlonzoEraTxWits era) =>
352349
Tx era ->
353350
ExUnits
354-
totExUnits tx =
355-
foldMap snd . Map.elems . unRedeemers $ tx ^. witsTxL . rdmrsTxWitsL
351+
totExUnits tx = foldMap snd $ tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL
356352

357353
--------------------------------------------------------------------------------
358354
-- Serialisation

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
module Cardano.Ledger.Alonzo.TxWits (
2626
Redeemers (Redeemers),
2727
RedeemersRaw,
28+
unRedeemersL,
2829
unRedeemers,
2930
nullRedeemers,
3031
lookupRedeemer,
@@ -55,6 +56,7 @@ module Cardano.Ledger.Alonzo.TxWits (
5556
AlonzoEraTxWits (..),
5657
hashDataTxWitsL,
5758
unTxDats,
59+
unTxDatsL,
5860
nullDats,
5961
alonzoEqTxWitsRaw,
6062
)
@@ -202,8 +204,16 @@ pattern Redeemers rs <-
202204
unRedeemers :: Redeemers era -> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
203205
unRedeemers = unRedeemersRaw . getMemoRawType
204206

207+
-- Conceptually, this is an Iso' but vanilla microlens doesn't have Iso's
208+
unRedeemersL ::
209+
forall era.
210+
AlonzoEraScript era => Lens' (Redeemers era) (Map.Map (PlutusPurpose AsIx era) (Data era, ExUnits))
211+
unRedeemersL f = fmap Redeemers . f . unRedeemers
212+
{-# INLINE unRedeemersL #-}
213+
205214
nullRedeemers :: Redeemers era -> Bool
206215
nullRedeemers = Map.null . unRedeemers
216+
{-# DEPRECATED nullRedeemers "In favor of `unRedeemersL`" #-}
207217

208218
emptyTxWitness :: AlonzoEraScript era => AlonzoTxWitsRaw era
209219
emptyTxWitness = AlonzoTxWitsRaw mempty mempty mempty mempty emptyRedeemers
@@ -217,6 +227,7 @@ lookupRedeemer ::
217227
Redeemers era ->
218228
Maybe (Data era, ExUnits)
219229
lookupRedeemer key = Map.lookup key . unRedeemers
230+
{-# DEPRECATED lookupRedeemer "In favor of `unRedeemersL`" #-}
220231

221232
-- | Upgrade redeemers from one era to another. The underlying data structure
222233
-- will remain identical, but the memoised serialisation may change to reflect
@@ -294,7 +305,7 @@ deriving instance
294305

295306
isEmptyTxWitness :: AlonzoEraScript era => AlonzoTxWits era -> Bool
296307
isEmptyTxWitness (getMemoRawType -> AlonzoTxWitsRaw a b c d (Redeemers e)) =
297-
Set.null a && Set.null b && Map.null c && nullDats d && Map.null e
308+
Set.null a && Set.null b && Map.null c && Map.null (d ^. unTxDatsL) && Map.null e
298309

299310
-- =====================================================
300311
newtype TxDatsRaw era = TxDatsRaw {unTxDatsRaw :: Map DataHash (Data era)}
@@ -321,8 +332,14 @@ pattern TxDats m <- (getMemoRawType -> TxDatsRaw m)
321332
unTxDats :: TxDats era -> Map DataHash (Data era)
322333
unTxDats (TxDats' m) = m
323334

335+
-- Conceptually, this is an Iso' but vanilla microlens doesn't have Iso's
336+
unTxDatsL :: forall era. Era era => Lens' (TxDats era) (Map DataHash (Data era))
337+
unTxDatsL f = fmap TxDats . f . unTxDats
338+
{-# INLINE unTxDatsL #-}
339+
324340
nullDats :: TxDats era -> Bool
325341
nullDats (TxDats' d) = Map.null d
342+
{-# DEPRECATED nullDats "In favor of `unTxDatsL`" #-}
326343

327344
instance Era era => DecCBOR (Annotator (TxDatsRaw era)) where
328345
decCBOR =
@@ -547,8 +564,8 @@ instance AlonzoEraScript era => EncCBOR (AlonzoTxWitsRaw era) where
547564
!> Omit null (Key 3 $ encodePlutus SPlutusV1)
548565
!> Omit null (Key 6 $ encodePlutus SPlutusV2)
549566
!> Omit null (Key 7 $ encodePlutus SPlutusV3)
550-
!> Omit nullDats (Key 4 $ To dats)
551-
!> Omit nullRedeemers (Key 5 $ To rdmrs)
567+
!> Omit (null . unTxDats) (Key 4 $ To dats)
568+
!> Omit (null . unRedeemers) (Key 5 $ To rdmrs)
552569
where
553570
encodePlutus ::
554571
PlutusLanguage l =>

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/UTxO.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Cardano.Ledger.Alonzo.CertState ()
3737
import Cardano.Ledger.Alonzo.Core
3838
import Cardano.Ledger.Alonzo.Era (AlonzoEra)
3939
import Cardano.Ledger.Alonzo.Scripts (lookupPlutusScript, plutusScriptLanguage)
40-
import Cardano.Ledger.Alonzo.TxWits (unTxDats)
40+
import Cardano.Ledger.Alonzo.TxWits (unTxDatsL)
4141
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
4242
import Cardano.Ledger.CertState (EraCertState (..))
4343
import Cardano.Ledger.Credential (credScriptHash)
@@ -144,7 +144,7 @@ getAlonzoSpendingDatum (UTxO m) tx sp = do
144144
AsItem txIn <- toSpendingPurpose sp
145145
txOut <- Map.lookup txIn m
146146
SJust hash <- Just $ txOut ^. dataHashTxOutL
147-
Map.lookup hash (unTxDats $ tx ^. witsTxL . datsTxWitsL)
147+
Map.lookup hash $ tx ^. witsTxL . datsTxWitsL . unTxDatsL
148148

149149
getAlonzoScriptsHashesNeeded :: AlonzoScriptsNeeded era -> Set.Set ScriptHash
150150
getAlonzoScriptsHashesNeeded (AlonzoScriptsNeeded sn) = Set.fromList (map snd sn)

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxoSpec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Cardano.Ledger.Alonzo.Core
1111
import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoPredFailure (..))
1212
import Cardano.Ledger.Alonzo.Scripts (eraLanguages)
1313
import Cardano.Ledger.Alonzo.TxAuxData (mkAlonzoTxAuxData)
14-
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..))
14+
import Cardano.Ledger.Alonzo.TxWits (unRedeemersL)
1515
import Cardano.Ledger.BaseTypes (Mismatch (..), Network (..), StrictMaybe (..))
1616
import Cardano.Ledger.Coin (Coin (..), toDeltaCoin)
1717
import qualified Cardano.Ledger.Metadata as M
@@ -20,7 +20,7 @@ import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL, nesEsL)
2020
import Control.Monad (forM)
2121
import qualified Data.Map.Strict as Map
2222
import Data.Ratio ((%))
23-
import Lens.Micro (to, (&), (.~), (<>~), (^.))
23+
import Lens.Micro (to, (%~), (&), (.~), (<>~), (^.))
2424
import qualified PlutusLedgerApi.Common as P
2525
import Test.Cardano.Ledger.Alonzo.ImpTest
2626
import Test.Cardano.Ledger.Imp.Common
@@ -53,7 +53,7 @@ spec = describe "UTXO" $ do
5353
tx =
5454
mkBasicTx mkBasicTxBody
5555
& bodyTxL . inputsTxBodyL .~ [txIn]
56-
& witsTxL . rdmrsTxWitsL <>~ Redeemers (Map.singleton prp (dat, txExUnits))
56+
& witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert prp (dat, txExUnits)
5757
submitFailingTx
5858
tx
5959
[ injectFailure $

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Cardano.Ledger.Alonzo.Rules (
1818
)
1919
import Cardano.Ledger.Alonzo.Scripts (eraLanguages)
2020
import Cardano.Ledger.Alonzo.Tx (IsValid (..))
21-
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..))
21+
import Cardano.Ledger.Alonzo.TxWits (unRedeemersL)
2222
import Cardano.Ledger.Plutus.Data (Data (..))
2323
import Cardano.Ledger.Plutus.Language (hashPlutusScript, withSLanguage)
2424
import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL, nesEsL)
@@ -83,12 +83,8 @@ spec = describe "UTXOS" $
8383
mkBasicTx mkBasicTxBody
8484
& bodyTxL . inputsTxBodyL .~ Set.singleton txIn0
8585
& isValidTxL .~ IsValid False
86-
& witsTxL . rdmrsTxWitsL
87-
.~ Redeemers
88-
( Map.singleton
89-
(mkSpendingPurpose $ AsIx 0)
90-
(Data $ P.I 32, exUnits)
91-
)
86+
& witsTxL . rdmrsTxWitsL . unRedeemersL
87+
.~ Map.singleton (mkSpendingPurpose $ AsIx 0) (Data $ P.I 32, exUnits)
9288

9389
describe "Scripts pass in phase 2" $ do
9490
let scripts' = drop 1 scripts

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxowSpec/Invalid.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Cardano.Ledger.Alonzo.Rules (
1818
AlonzoUtxowPredFailure (..),
1919
)
2020
import Cardano.Ledger.Alonzo.Scripts (eraLanguages)
21-
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..), TxDats (..), unRedeemers)
21+
import Cardano.Ledger.Alonzo.TxWits (TxDats (..), unRedeemersL)
2222
import Cardano.Ledger.BaseTypes (Mismatch (..), StrictMaybe (..), natVersion)
2323
import Cardano.Ledger.Coin (Coin (..))
2424
import Cardano.Ledger.Credential (Credential (..), StakeReference (..))
@@ -37,7 +37,7 @@ import qualified Data.Map.Strict as Map
3737
import Data.Maybe (isJust)
3838
import Data.Sequence.Strict (StrictSeq ((:<|)))
3939
import qualified Data.Set as Set
40-
import Lens.Micro (Lens', lens, (%~), (&), (.~), (<>~), (^.))
40+
import Lens.Micro ((%~), (&), (.~), (<>~), (^.))
4141
import qualified PlutusLedgerApi.Common as P
4242
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
4343
import Test.Cardano.Ledger.Alonzo.ImpTest
@@ -67,8 +67,6 @@ spec = describe "Invalid transactions" $ do
6767

6868
let resetAddrWits tx = updateAddrTxWits $ tx & witsTxL . addrTxWitsL .~ []
6969
fixupResetAddrWits = fixupPPHash >=> resetAddrWits
70-
redeemersL :: Lens' (Redeemers era) (Map.Map (PlutusPurpose AsIx era) (Data era, ExUnits))
71-
redeemersL = lens unRedeemers (const $ Redeemers @era)
7270
-- PlutusPurpose serialization wasn't fixed until Conway
7371
withPlutusPurposeRoundTripFailures =
7472
if eraProtVerLow @era < natVersion @9
@@ -176,7 +174,7 @@ spec = describe "Invalid transactions" $ do
176174
, mkUnRegTxCert cred
177175
]
178176
tx <- submitTx $ mkBasicTx (mkBasicTxBody & certsTxBodyL .~ certs)
179-
let redeemers = tx ^. witsTxL . rdmrsTxWitsL . redeemersL
177+
let redeemers = tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL
180178
Map.keys redeemers
181179
`shouldBe` [ mkCertifyingPurpose $ AsIx 1
182180
, mkCertifyingPurpose $ AsIx 2
@@ -201,11 +199,11 @@ spec = describe "Invalid transactions" $ do
201199
let tx =
202200
mkBasicTx mkBasicTxBody
203201
& bodyTxL . inputsTxBodyL .~ [txIn]
204-
& witsTxL . rdmrsTxWitsL . redeemersL .~ mintingRedeemers
202+
& witsTxL . rdmrsTxWitsL . unRedeemersL .~ mintingRedeemers
205203
mintingRedeemers = Map.singleton (mkMintingPurpose $ AsIx 0) (Data $ P.I 32, ExUnits 0 0)
206204
isSpender = isJust . toSpendingPurpose @era @AsIx
207205
removeSpenders = Map.filterWithKey (const . not . isSpender)
208-
dropSpendingRedeemers = pure . (witsTxL . rdmrsTxWitsL . redeemersL %~ removeSpenders)
206+
dropSpendingRedeemers = pure . (witsTxL . rdmrsTxWitsL . unRedeemersL %~ removeSpenders)
209207
withPostFixup (dropSpendingRedeemers >=> fixupPPHash >=> resetAddrWits) $
210208
withPlutusPurposeRoundTripFailures $
211209
submitFailingTx
@@ -245,10 +243,10 @@ spec = describe "Invalid transactions" $ do
245243
tx =
246244
mkBasicTx mkBasicTxBody
247245
& bodyTxL . inputsTxBodyL <>~ [txIn]
248-
& witsTxL . rdmrsTxWitsL . redeemersL <>~ Map.singleton purpose redeemer
246+
& witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert purpose redeemer
249247
txFixed <- fixupTx tx
250248
-- The `Ix` of the redeemer may have been changed by `fixupRedeemerIndices`
251-
let fixedRedeemers = txFixed ^. witsTxL . rdmrsTxWitsL . redeemersL
249+
let fixedRedeemers = txFixed ^. witsTxL . rdmrsTxWitsL . unRedeemersL
252250
extraRedeemers = Map.keys $ Map.filter (== redeemer) fixedRedeemers
253251
withNoFixup $
254252
withPlutusPurposeRoundTripFailures $
@@ -278,7 +276,7 @@ spec = describe "Invalid transactions" $ do
278276
tx =
279277
mkBasicTx mkBasicTxBody
280278
& bodyTxL . certsTxBodyL <>~ certs
281-
& witsTxL . rdmrsTxWitsL . redeemersL <>~ redeemers
279+
& witsTxL . rdmrsTxWitsL . unRedeemersL <>~ redeemers
282280
withPlutusPurposeRoundTripFailures $
283281
submitFailingTx
284282
tx

0 commit comments

Comments
 (0)