Skip to content

Commit b7f6382

Browse files
authored
Merge pull request #5088 from IntersectMBO/td/move-upgrade-to-testlib
Move upgrade functions for tx, body, auxData and wits to `testlib`
2 parents f64c730 + fd3999b commit b7f6382

File tree

51 files changed

+963
-814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+963
-814
lines changed

eras/allegra/impl/cardano-ledger-allegra.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,4 @@ test-suite tests
175175
cardano-ledger-binary:testlib,
176176
cardano-ledger-core:{cardano-ledger-core, testlib},
177177
cardano-ledger-shelley:testlib,
178-
data-default,
179178
testlib,

eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import Cardano.Ledger.Allegra.TxBody (AllegraEraTxBody (..))
1919
import Cardano.Ledger.Allegra.TxWits ()
2020
import Cardano.Ledger.Core (
2121
EraTx (..),
22-
EraTxAuxData (upgradeTxAuxData),
2322
EraTxWits (..),
2423
NativeScript,
25-
upgradeTxBody,
2624
)
2725
import Cardano.Ledger.Keys.WitVKey (witVKeyHash)
2826
import Cardano.Ledger.Shelley.Tx (
@@ -61,12 +59,6 @@ instance EraTx AllegraEra where
6159

6260
getMinFeeTx pp tx _ = shelleyMinFeeTx pp tx
6361

64-
upgradeTx (ShelleyTx txb txwits txAux) =
65-
ShelleyTx
66-
<$> upgradeTxBody txb
67-
<*> pure (upgradeTxWits txwits)
68-
<*> pure (fmap upgradeTxAuxData txAux)
69-
7062
-- =======================================================
7163
-- Validating timelock scripts
7264
-- We extract ValidityInterval from TxBody with vldtTxBodyL getter

eras/allegra/impl/src/Cardano/Ledger/Allegra/TxAuxData.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Cardano.Ledger.MemoBytes (
4848
mkMemoizedEra,
4949
)
5050
import Cardano.Ledger.Shelley.Core
51-
import Cardano.Ledger.Shelley.TxAuxData (Metadatum, ShelleyTxAuxData (..), validMetadatum)
51+
import Cardano.Ledger.Shelley.TxAuxData (Metadatum, validMetadatum)
5252
import Codec.CBOR.Decoding (
5353
TokenType (
5454
TypeListLen,
@@ -92,8 +92,6 @@ instance EraTxAuxData AllegraEra where
9292

9393
metadataTxAuxDataL = metadataAllegraTxAuxDataL
9494

95-
upgradeTxAuxData (ShelleyTxAuxData md) = AllegraTxAuxData md mempty
96-
9795
validateTxAuxData _ (AllegraTxAuxData md as) = as `deepseq` all validMetadatum md
9896

9997
metadataAllegraTxAuxDataL ::

eras/allegra/impl/src/Cardano/Ledger/Allegra/TxBody.hs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Cardano.Ledger.Allegra.Era (AllegraEra)
4141
import Cardano.Ledger.Allegra.Scripts (ValidityInterval (..))
4242
import Cardano.Ledger.Allegra.TxCert ()
4343
import Cardano.Ledger.Allegra.TxOut ()
44-
import Cardano.Ledger.BaseTypes (SlotNo, StrictMaybe (SJust, SNothing))
44+
import Cardano.Ledger.BaseTypes (StrictMaybe (SJust, SNothing))
4545
import Cardano.Ledger.Binary (Annotator, DecCBOR (..), EncCBOR (..), ToCBOR)
4646
import Cardano.Ledger.Binary.Coders (
4747
Decode (..),
@@ -69,7 +69,7 @@ import Cardano.Ledger.MemoBytes (
6969
mkMemoizedEra,
7070
)
7171
import Cardano.Ledger.Shelley.Core
72-
import Cardano.Ledger.Shelley.PParams (Update (..), upgradeUpdate)
72+
import Cardano.Ledger.Shelley.PParams (Update (..))
7373
import Cardano.Ledger.Shelley.TxBody (getShelleyGenesisKeyHashCountTxBody)
7474
import Cardano.Ledger.TxIn (TxIn (..))
7575
import Control.DeepSeq (NFData (..))
@@ -328,23 +328,6 @@ instance EraTxBody AllegraEra where
328328

329329
getGenesisKeyHashCountTxBody = getShelleyGenesisKeyHashCountTxBody
330330

331-
upgradeTxBody txBody = do
332-
certs <- traverse upgradeTxCert (txBody ^. certsTxBodyL)
333-
pure $
334-
AllegraTxBody
335-
{ atbInputs = txBody ^. inputsTxBodyL
336-
, atbOutputs = upgradeTxOut <$> (txBody ^. outputsTxBodyL)
337-
, atbCerts = certs
338-
, atbWithdrawals = txBody ^. withdrawalsTxBodyL
339-
, atbTxFee = txBody ^. feeTxBodyL
340-
, atbValidityInterval = ttlToValidityInterval (txBody ^. ttlTxBodyL)
341-
, atbUpdate = upgradeUpdate () <$> (txBody ^. updateTxBodyL)
342-
, atbAuxDataHash = txBody ^. auxDataHashTxBodyL
343-
}
344-
where
345-
ttlToValidityInterval :: SlotNo -> ValidityInterval
346-
ttlToValidityInterval ttl = ValidityInterval SNothing (SJust ttl)
347-
348331
instance ShelleyEraTxBody AllegraEra where
349332
ttlTxBodyL = notSupportedInThisEraL
350333
{-# INLINEABLE ttlTxBodyL #-}

eras/allegra/impl/src/Cardano/Ledger/Allegra/TxWits.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Cardano.Ledger.Allegra.TxWits () where
1111

1212
import Cardano.Ledger.Allegra.Era (AllegraEra)
1313
import Cardano.Ledger.Allegra.TxAuxData ()
14-
import Cardano.Ledger.Core (EraScript (upgradeScript), EraTxWits (..))
14+
import Cardano.Ledger.Core (EraTxWits (..))
1515
import Cardano.Ledger.Shelley.TxWits (
1616
ShelleyTxWits (..),
1717
addrShelleyTxWitsL,
@@ -32,9 +32,3 @@ instance EraTxWits AllegraEra where
3232

3333
scriptTxWitsL = scriptShelleyTxWitsL
3434
{-# INLINE scriptTxWitsL #-}
35-
36-
upgradeTxWits stw =
37-
ShelleyTxWits
38-
(addrWits stw)
39-
(upgradeScript <$> scriptWits stw)
40-
(bootWits stw)

eras/allegra/impl/test/Test/Cardano/Ledger/Allegra/BinarySpec.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
module Test.Cardano.Ledger.Allegra.BinarySpec (spec) where
77

88
import Cardano.Ledger.Allegra
9-
import Data.Default (def)
109
import Test.Cardano.Ledger.Allegra.Arbitrary ()
1110
import Test.Cardano.Ledger.Allegra.Binary.Annotator ()
1211
import Test.Cardano.Ledger.Allegra.TreeDiff ()
1312
import Test.Cardano.Ledger.Common
14-
import Test.Cardano.Ledger.Core.Binary (specUpgrade)
1513
import Test.Cardano.Ledger.Core.Binary as Binary (decoderEquivalenceCoreEraTypesSpec, txSizeSpec)
1614
import Test.Cardano.Ledger.Core.Binary.RoundTrip (RuleListEra (..))
1715
import Test.Cardano.Ledger.Shelley.Binary.RoundTrip (roundTripShelleyCommonSpec)
1816

1917
spec :: Spec
2018
spec = do
21-
specUpgrade @AllegraEra def
2219
describe "RoundTrip" $ do
2320
roundTripShelleyCommonSpec @AllegraEra
2421
describe "DecCBOR instances equivalence" $ do

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import Cardano.Ledger.Alonzo.Scripts (
8181
)
8282
import Cardano.Ledger.Alonzo.TxBody (
8383
AlonzoEraTxBody (..),
84-
AlonzoTxBodyUpgradeError,
8584
ScriptIntegrityHash,
8685
TxBody (AlonzoTxBody),
8786
)
@@ -112,10 +111,9 @@ import Cardano.Ledger.Core
112111
import Cardano.Ledger.MemoBytes (EqRaw (..))
113112
import Cardano.Ledger.Plutus.Data (Data, hashData)
114113
import Cardano.Ledger.Plutus.Language (nonNativeLanguages)
115-
import Cardano.Ledger.Shelley.Tx (ShelleyTx (ShelleyTx), shelleyEqTxRaw)
114+
import Cardano.Ledger.Shelley.Tx (shelleyEqTxRaw)
116115
import qualified Cardano.Ledger.State as Shelley
117116
import Cardano.Ledger.Val (Val ((<+>), (<×>)))
118-
import Control.Arrow (left)
119117
import Control.DeepSeq (NFData (..))
120118
import Data.Aeson (ToJSON (..))
121119
import qualified Data.ByteString.Lazy as LBS
@@ -146,12 +144,8 @@ data AlonzoTx era = AlonzoTx
146144
}
147145
deriving (Generic)
148146

149-
newtype AlonzoTxUpgradeError = ATUEBodyUpgradeError AlonzoTxBodyUpgradeError
150-
deriving (Show)
151-
152147
instance EraTx AlonzoEra where
153148
type Tx AlonzoEra = AlonzoTx AlonzoEra
154-
type TxUpgradeError AlonzoEra = AlonzoTxUpgradeError
155149

156150
mkBasicTx = mkBasicAlonzoTx
157151

@@ -173,13 +167,6 @@ instance EraTx AlonzoEra where
173167
getMinFeeTx pp tx _ = alonzoMinFeeTx pp tx
174168
{-# INLINE getMinFeeTx #-}
175169

176-
upgradeTx (ShelleyTx body wits aux) =
177-
AlonzoTx
178-
<$> left ATUEBodyUpgradeError (upgradeTxBody body)
179-
<*> pure (upgradeTxWits wits)
180-
<*> pure (IsValid True)
181-
<*> pure (fmap upgradeTxAuxData aux)
182-
183170
instance (Tx era ~ AlonzoTx era, AlonzoEraTx era) => EqRaw (AlonzoTx era) where
184171
eqRaw = alonzoEqTxRaw
185172

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ module Cardano.Ledger.Alonzo.TxAuxData (
3838
hashAlonzoTxAuxData,
3939
validateAlonzoTxAuxData,
4040
getAlonzoTxAuxDataScripts,
41-
translateAlonzoTxAuxData,
4241
metadataAlonzoTxAuxDataL,
4342
timelockScriptsAlonzoTxAuxDataL,
4443
plutusScriptsAllegraTxAuxDataL,
@@ -47,8 +46,8 @@ module Cardano.Ledger.Alonzo.TxAuxData (
4746
emptyAlonzoTxAuxDataRaw,
4847
) where
4948

50-
import Cardano.Ledger.Allegra.Scripts (Timelock, translateTimelock)
51-
import Cardano.Ledger.Allegra.TxAuxData (AllegraEraTxAuxData (..), AllegraTxAuxData (..))
49+
import Cardano.Ledger.Allegra.Scripts (Timelock)
50+
import Cardano.Ledger.Allegra.TxAuxData (AllegraEraTxAuxData (..))
5251
import Cardano.Ledger.Alonzo.Era
5352
import Cardano.Ledger.Alonzo.Scripts (
5453
AlonzoEraScript (..),
@@ -271,14 +270,6 @@ instance EraTxAuxData AlonzoEra where
271270

272271
metadataTxAuxDataL = metadataAlonzoTxAuxDataL
273272

274-
upgradeTxAuxData (AllegraTxAuxData md scripts) =
275-
mkMemoizedEra @AlonzoEra $
276-
AlonzoTxAuxDataRaw
277-
{ atadrMetadata = md
278-
, atadrTimelock = translateTimelock <$> scripts
279-
, atadrPlutus = mempty
280-
}
281-
282273
validateTxAuxData = validateAlonzoTxAuxData
283274

284275
metadataAlonzoTxAuxDataL ::
@@ -371,14 +362,3 @@ pattern AlonzoTxAuxData' ::
371362
AlonzoTxAuxData era
372363
pattern AlonzoTxAuxData' {atadMetadata', atadTimelock', atadPlutus'} <-
373364
(getMemoRawType -> AlonzoTxAuxDataRaw atadMetadata' atadTimelock' atadPlutus')
374-
375-
translateAlonzoTxAuxData ::
376-
(AlonzoEraScript era1, AlonzoEraScript era2) =>
377-
AlonzoTxAuxData era1 ->
378-
AlonzoTxAuxData era2
379-
translateAlonzoTxAuxData AlonzoTxAuxData {atadMetadata, atadTimelock, atadPlutus} =
380-
AlonzoTxAuxData
381-
{ atadMetadata = atadMetadata
382-
, atadTimelock = translateTimelock <$> atadTimelock
383-
, atadPlutus = atadPlutus
384-
}

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

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ module Cardano.Ledger.Alonzo.TxBody (
4545
atbTxNetworkId
4646
),
4747
AlonzoTxBodyRaw (..),
48-
AlonzoTxBodyUpgradeError (..),
4948
AlonzoEraTxBody (..),
5049
ShelleyEraTxBody (..),
5150
AllegraEraTxBody (..),
@@ -103,11 +102,7 @@ import Cardano.Ledger.Binary (
103102
)
104103
import Cardano.Ledger.Binary.Coders
105104
import Cardano.Ledger.Coin (Coin (..))
106-
import Cardano.Ledger.Mary (MaryEra)
107105
import Cardano.Ledger.Mary.Core
108-
import Cardano.Ledger.Mary.TxBody (
109-
TxBody (..),
110-
)
111106
import Cardano.Ledger.Mary.Value (
112107
MultiAsset (..),
113108
PolicyID (..),
@@ -124,22 +119,17 @@ import Cardano.Ledger.MemoBytes (
124119
lensMemoRawType,
125120
mkMemoizedEra,
126121
)
127-
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..), Update (..))
122+
import Cardano.Ledger.Shelley.PParams (Update (..))
128123
import Cardano.Ledger.Shelley.TxBody (getShelleyGenesisKeyHashCountTxBody)
129124
import Cardano.Ledger.TxIn (TxIn (..))
130-
import Control.Arrow (left)
131125
import Control.DeepSeq (NFData (..))
132-
import Control.Monad (when)
133-
import Data.Default (def)
134126
import qualified Data.Map.Strict as Map
135-
import Data.Maybe.Strict (isSJust)
136127
import Data.OSet.Strict (OSet)
137128
import qualified Data.OSet.Strict as OSet
138129
import Data.Sequence.Strict (StrictSeq)
139130
import qualified Data.Sequence.Strict as StrictSeq
140131
import Data.Set (Set)
141132
import qualified Data.Set as Set
142-
import Data.Void (absurd)
143133
import Data.Word (Word32)
144134
import GHC.Generics (Generic)
145135
import Lens.Micro
@@ -200,18 +190,10 @@ deriving instance Show AlonzoTxBodyRaw
200190
instance Memoized (TxBody AlonzoEra) where
201191
type RawType (TxBody AlonzoEra) = AlonzoTxBodyRaw
202192

203-
data AlonzoTxBodyUpgradeError
204-
= -- | The TxBody contains a protocol parameter update that attempts to update
205-
-- the min UTxO. Since this doesn't exist in Alonzo, we fail if an attempt is
206-
-- made to update it.
207-
ATBUEMinUTxOUpdated
208-
deriving (Show)
209-
210193
instance EraTxBody AlonzoEra where
211194
newtype TxBody AlonzoEra = MkAlonzoTxBody (MemoBytes AlonzoTxBodyRaw)
212195
deriving (ToCBOR, Generic)
213196
deriving newtype (SafeToHash)
214-
type TxBodyUpgradeError AlonzoEra = AlonzoTxBodyUpgradeError
215197

216198
mkBasicTxBody = mkMemoizedEra @AlonzoEra emptyAlonzoTxBodyRaw
217199

@@ -254,60 +236,6 @@ instance EraTxBody AlonzoEra where
254236

255237
getGenesisKeyHashCountTxBody = getShelleyGenesisKeyHashCountTxBody
256238

257-
upgradeTxBody
258-
MaryTxBody
259-
{ mtbInputs
260-
, mtbOutputs
261-
, mtbCerts
262-
, mtbWithdrawals
263-
, mtbTxFee
264-
, mtbValidityInterval
265-
, mtbUpdate
266-
, mtbAuxDataHash
267-
, mtbMint
268-
} = do
269-
certs <-
270-
traverse
271-
(left absurd . upgradeTxCert)
272-
mtbCerts
273-
274-
updates <- traverse upgradeUpdate mtbUpdate
275-
pure $
276-
AlonzoTxBody
277-
{ atbInputs = mtbInputs
278-
, atbOutputs = upgradeTxOut <$> mtbOutputs
279-
, atbCerts = certs
280-
, atbWithdrawals = mtbWithdrawals
281-
, atbTxFee = mtbTxFee
282-
, atbValidityInterval = mtbValidityInterval
283-
, atbUpdate = updates
284-
, atbAuxDataHash = mtbAuxDataHash
285-
, atbMint = mtbMint
286-
, atbCollateral = mempty
287-
, atbReqSignerHashes = mempty
288-
, atbScriptIntegrityHash = SNothing
289-
, atbTxNetworkId = SNothing
290-
}
291-
where
292-
upgradeUpdate ::
293-
Update MaryEra ->
294-
Either AlonzoTxBodyUpgradeError (Update AlonzoEra)
295-
upgradeUpdate (Update pp epoch) =
296-
Update <$> upgradeProposedPPUpdates pp <*> pure epoch
297-
298-
upgradeProposedPPUpdates ::
299-
ProposedPPUpdates MaryEra ->
300-
Either AlonzoTxBodyUpgradeError (ProposedPPUpdates AlonzoEra)
301-
upgradeProposedPPUpdates (ProposedPPUpdates m) =
302-
ProposedPPUpdates
303-
<$> traverse
304-
( \ppu -> do
305-
when (isSJust $ ppu ^. ppuMinUTxOValueL) $
306-
Left ATBUEMinUTxOUpdated
307-
pure $ upgradePParamsUpdate def ppu
308-
)
309-
m
310-
311239
instance ShelleyEraTxBody AlonzoEra where
312240
ttlTxBodyL = notSupportedInThisEraL
313241

0 commit comments

Comments
 (0)