Skip to content

Commit 9734171

Browse files
authored
Merge pull request #4968 from IntersectMBO/lehins/move-annotator-to-testlib
Move annotator to testlib
2 parents 35a5bb0 + 605c458 commit 9734171

File tree

117 files changed

+1278
-1133
lines changed

Some content is hidden

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

117 files changed

+1278
-1133
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## 1.8.0.0
44

5-
* Expose access to `AllegraTxBodyRaw` and `TimelockRaw`
6-
* Expose constructor `MkAllegraTxBody` and `MkTimelock`
5+
* Move `Annotator` instances to `testlib`
6+
* Expose access to `AllegraTxBodyRaw`, `AllegraTxAuxData` and `TimelockRaw`
7+
* Expose constructor `MkAllegraTxBody`, `MkTxAuxData` and `MkTimelock`
78
* Deprecate `TimelockConstr`
89
* Rename `atbrTxFee` to `atbrFee` for consistency
910

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ library
8787
library testlib
8888
exposed-modules:
8989
Test.Cardano.Ledger.Allegra.Arbitrary
90+
Test.Cardano.Ledger.Allegra.Binary.Annotator
9091
Test.Cardano.Ledger.Allegra.Binary.Cddl
9192
Test.Cardano.Ledger.Allegra.CDDL
9293
Test.Cardano.Ledger.Allegra.Imp
@@ -112,6 +113,7 @@ library testlib
112113
base,
113114
bytestring,
114115
cardano-ledger-allegra,
116+
cardano-ledger-binary,
115117
cardano-ledger-core:{cardano-ledger-core, testlib},
116118
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
117119
cardano-strict-containers,

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ where
5252
import Cardano.Ledger.Allegra.Era (AllegraEra)
5353
import Cardano.Ledger.BaseTypes (StrictMaybe (SJust, SNothing))
5454
import Cardano.Ledger.Binary (
55-
Annotator (..),
5655
DecCBOR (decCBOR),
5756
EncCBOR (encCBOR),
5857
ToCBOR (..),
@@ -66,7 +65,6 @@ import Cardano.Ledger.Binary.Coders (
6665
encode,
6766
(!>),
6867
(<!),
69-
(<*!),
7068
)
7169
import Cardano.Ledger.Core
7270
import Cardano.Ledger.MemoBytes (
@@ -189,20 +187,6 @@ instance Era era => EncCBOR (TimelockRaw era) where
189187
TimelockTimeStart m -> Sum TimelockTimeStart 4 !> To m
190188
TimelockTimeExpire m -> Sum TimelockTimeExpire 5 !> To m
191189

192-
-- This instance allows us to derive instance DecCBOR (Annotator (Timelock era)).
193-
-- Since Timelock is a newtype around (Memo (Timelock era)).
194-
instance Era era => DecCBOR (Annotator (TimelockRaw era)) where
195-
decCBOR = decode (Summands "TimelockRaw" decRaw)
196-
where
197-
decRaw :: Word -> Decode 'Open (Annotator (TimelockRaw era))
198-
decRaw 0 = Ann (SumD TimelockSignature <! From)
199-
decRaw 1 = Ann (SumD TimelockAllOf) <*! D (sequence <$> decCBOR)
200-
decRaw 2 = Ann (SumD TimelockAnyOf) <*! D (sequence <$> decCBOR)
201-
decRaw 3 = Ann (SumD TimelockMOf) <*! Ann From <*! D (sequence <$> decCBOR)
202-
decRaw 4 = Ann (SumD TimelockTimeStart <! From)
203-
decRaw 5 = Ann (SumD TimelockTimeExpire <! From)
204-
decRaw n = Invalid n
205-
206190
instance Era era => DecCBOR (TimelockRaw era) where
207191
decCBOR = decode $ Summands "TimelockRaw" $ \case
208192
0 -> SumD TimelockSignature <! From
@@ -247,9 +231,6 @@ deriving instance Show (Timelock era)
247231
instance EqRaw (Timelock era) where
248232
eqRaw = eqTimelockRaw
249233

250-
instance Era era => DecCBOR (Annotator (Timelock era)) where
251-
decCBOR = fmap MkTimelock <$> decCBOR
252-
253234
-- | Since Timelock scripts are a strictly backwards compatible extension of
254235
-- MultiSig scripts, we can use the same 'scriptPrefixTag' tag here as we did
255236
-- for the ValidateScript instance in MultiSig

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ instance TranslateEra AllegraEra NewEpochState where
7474

7575
instance TranslateEra AllegraEra ShelleyTx where
7676
type TranslationError AllegraEra ShelleyTx = DecoderError
77-
translateEra _ctx = translateEraThroughCBOR "ShelleyTx"
77+
translateEra _ctx = translateEraThroughCBOR
7878

7979
--------------------------------------------------------------------------------
8080
-- Auxiliary instances and functions
@@ -164,7 +164,7 @@ instance TranslateEra AllegraEra EpochState where
164164

165165
instance TranslateEra AllegraEra ShelleyTxWits where
166166
type TranslationError AllegraEra ShelleyTxWits = DecoderError
167-
translateEra _ctx = translateEraThroughCBOR "ShelleyTxWits"
167+
translateEra _ctx = translateEraThroughCBOR
168168

169169
instance TranslateEra AllegraEra Update where
170170
translateEra _ (Update pp en) = pure $ Update (coerce pp) en

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

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
{-# LANGUAGE StandaloneDeriving #-}
1414
{-# LANGUAGE TypeApplications #-}
1515
{-# LANGUAGE TypeFamilies #-}
16-
{-# LANGUAGE TypeOperators #-}
1716
{-# LANGUAGE UndecidableInstances #-}
1817
{-# LANGUAGE UndecidableSuperClasses #-}
1918
{-# LANGUAGE ViewPatterns #-}
2019
{-# OPTIONS_GHC -Wno-orphans #-}
2120

2221
module Cardano.Ledger.Allegra.TxAuxData (
23-
AllegraTxAuxData (AllegraTxAuxData),
24-
AllegraTxAuxDataRaw,
22+
AllegraTxAuxData (AllegraTxAuxData, MkAlegraTxAuxData),
23+
AllegraTxAuxDataRaw (..),
2524
metadataAllegraTxAuxDataL,
2625
AllegraEraTxAuxData (..),
2726
timelockScriptsAllegraTxAuxDataL,
@@ -31,7 +30,6 @@ where
3130
import Cardano.Ledger.Allegra.Era (AllegraEra)
3231
import Cardano.Ledger.Allegra.Scripts (Timelock)
3332
import Cardano.Ledger.Binary (
34-
Annotator (..),
3533
DecCBOR (..),
3634
EncCBOR (..),
3735
ToCBOR,
@@ -40,7 +38,6 @@ import Cardano.Ledger.Binary (
4038
import Cardano.Ledger.Binary.Coders
4139
import Cardano.Ledger.MemoBytes (
4240
EqRaw,
43-
Mem,
4441
MemoBytes,
4542
MemoHashIndex,
4643
Memoized (RawType),
@@ -109,7 +106,8 @@ instance AllegraEraTxAuxData AllegraEra where
109106

110107
timelockScriptsAllegraTxAuxDataL ::
111108
forall era.
112-
Era era => Lens' (AllegraTxAuxData era) (StrictSeq (Timelock era))
109+
Era era =>
110+
Lens' (AllegraTxAuxData era) (StrictSeq (Timelock era))
113111
timelockScriptsAllegraTxAuxDataL =
114112
lensMemoRawType @era atadrTimelock $
115113
\txAuxDataRaw ts -> txAuxDataRaw {atadrTimelock = ts}
@@ -120,7 +118,7 @@ deriving instance Era era => NoThunks (AllegraTxAuxDataRaw era)
120118

121119
instance NFData (AllegraTxAuxDataRaw era)
122120

123-
newtype AllegraTxAuxData era = AuxiliaryDataWithBytes (MemoBytes (AllegraTxAuxDataRaw era))
121+
newtype AllegraTxAuxData era = MkAlegraTxAuxData (MemoBytes (AllegraTxAuxDataRaw era))
124122
deriving (Generic)
125123
deriving newtype (Eq, ToCBOR, SafeToHash, DecCBOR)
126124

@@ -163,30 +161,6 @@ instance Era era => EncCBOR (AllegraTxAuxDataRaw era) where
163161
-- | Encodes memoized bytes created upon construction.
164162
instance Era era => EncCBOR (AllegraTxAuxData era)
165163

166-
instance Era era => DecCBOR (Annotator (AllegraTxAuxDataRaw era)) where
167-
decCBOR =
168-
peekTokenType >>= \case
169-
TypeMapLen -> decodeFromMap
170-
TypeMapLen64 -> decodeFromMap
171-
TypeMapLenIndef -> decodeFromMap
172-
TypeListLen -> decodeFromList
173-
TypeListLen64 -> decodeFromList
174-
TypeListLenIndef -> decodeFromList
175-
_ -> fail "Failed to decode AuxiliaryDataRaw"
176-
where
177-
decodeFromMap =
178-
decode
179-
( Ann (Emit AllegraTxAuxDataRaw)
180-
<*! Ann From
181-
<*! Ann (Emit StrictSeq.empty)
182-
)
183-
decodeFromList =
184-
decode
185-
( Ann (RecD AllegraTxAuxDataRaw)
186-
<*! Ann From
187-
<*! D (sequence <$> decCBOR)
188-
)
189-
190164
instance Era era => DecCBOR (AllegraTxAuxDataRaw era) where
191165
decCBOR =
192166
peekTokenType >>= \case
@@ -210,8 +184,3 @@ instance Era era => DecCBOR (AllegraTxAuxDataRaw era) where
210184
<! From
211185
<! From
212186
)
213-
214-
deriving via
215-
(Mem (AllegraTxAuxDataRaw era))
216-
instance
217-
Era era => DecCBOR (Annotator (AllegraTxAuxData era))

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Cardano.Ledger.Allegra.Scripts (ValidityInterval (..))
5252
import Cardano.Ledger.Allegra.TxCert ()
5353
import Cardano.Ledger.Allegra.TxOut ()
5454
import Cardano.Ledger.BaseTypes (SlotNo, StrictMaybe (SJust, SNothing))
55-
import Cardano.Ledger.Binary (Annotator, DecCBOR (..), EncCBOR (..), ToCBOR)
55+
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), ToCBOR)
5656
import Cardano.Ledger.Binary.Coders (
5757
Decode (..),
5858
Encode (..),
@@ -70,7 +70,6 @@ import Cardano.Ledger.Compactible (Compactible (..))
7070
import Cardano.Ledger.Core
7171
import Cardano.Ledger.MemoBytes (
7272
EqRaw,
73-
Mem,
7473
MemoBytes,
7574
MemoHashIndex,
7675
Memoized (RawType),
@@ -136,12 +135,6 @@ instance (DecCBOR ma, Monoid ma, AllegraEraTxBody era) => DecCBOR (AllegraTxBody
136135
[(0, "atbrInputs"), (1, "atbrOutputs"), (2, "atbrFee")]
137136
)
138137

139-
instance
140-
(DecCBOR m, Monoid m, AllegraEraTxBody era) =>
141-
DecCBOR (Annotator (AllegraTxBodyRaw m era))
142-
where
143-
decCBOR = pure <$> decCBOR
144-
145138
-- Sparse encodings of AllegraTxBodyRaw, the key values are fixed by backward compatibility
146139
-- concerns as we want the ShelleyTxBody to deserialise as AllegraTxBody.
147140
-- txXparse and bodyFields should be Duals, visual inspection helps ensure this.
@@ -242,11 +235,6 @@ deriving newtype instance
242235
-- | Encodes memoized bytes created upon construction.
243236
instance Era era => EncCBOR (AllegraTxBody era)
244237

245-
deriving via
246-
Mem (AllegraTxBodyRaw () era)
247-
instance
248-
AllegraEraTxBody era => DecCBOR (Annotator (AllegraTxBody era))
249-
250238
type instance MemoHashIndex (AllegraTxBodyRaw c era) = EraIndependentTxBody
251239

252240
instance Era era => HashAnnotated (AllegraTxBody era) EraIndependentTxBody where

eras/allegra/impl/test/Test/Cardano/Ledger/Allegra/Binary/CddlSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Test.Cardano.Ledger.Allegra.Binary.CddlSpec (spec) where
55

66
import Cardano.Ledger.Allegra (AllegraEra)
77
import Cardano.Ledger.Core
8+
import Test.Cardano.Ledger.Allegra.Binary.Annotator ()
89
import Test.Cardano.Ledger.Allegra.Binary.Cddl (readAllegraCddlFiles)
910
import Test.Cardano.Ledger.Allegra.CDDL (allegraCDDL)
1011
import Test.Cardano.Ledger.Binary.Cddl (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Test.Cardano.Ledger.Allegra.BinarySpec (spec) where
88
import Cardano.Ledger.Allegra
99
import Data.Default (def)
1010
import Test.Cardano.Ledger.Allegra.Arbitrary ()
11+
import Test.Cardano.Ledger.Allegra.Binary.Annotator ()
1112
import Test.Cardano.Ledger.Allegra.TreeDiff ()
1213
import Test.Cardano.Ledger.Common
1314
import Test.Cardano.Ledger.Core.Binary (specUpgrade)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingVia #-}
3+
{-# LANGUAGE FlexibleContexts #-}
4+
{-# LANGUAGE FlexibleInstances #-}
5+
{-# LANGUAGE LambdaCase #-}
6+
{-# LANGUAGE OverloadedStrings #-}
7+
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE StandaloneDeriving #-}
9+
{-# LANGUAGE TypeFamilies #-}
10+
{-# LANGUAGE UndecidableInstances #-}
11+
{-# OPTIONS_GHC -Wno-orphans #-}
12+
13+
module Test.Cardano.Ledger.Allegra.Binary.Annotator (
14+
module Test.Cardano.Ledger.Shelley.Binary.Annotator,
15+
) where
16+
17+
import Cardano.Ledger.Allegra.Scripts
18+
import Cardano.Ledger.Allegra.TxAuxData
19+
import Cardano.Ledger.Allegra.TxBody.Internal
20+
import Cardano.Ledger.Binary
21+
import Cardano.Ledger.Binary.Coders
22+
import Cardano.Ledger.Core
23+
import qualified Data.Sequence.Strict as StrictSeq
24+
import Test.Cardano.Ledger.Allegra.Arbitrary ()
25+
import Test.Cardano.Ledger.Core.Binary.Annotator
26+
import Test.Cardano.Ledger.Shelley.Binary.Annotator
27+
28+
instance Era era => DecCBOR (Annotator (AllegraTxAuxDataRaw era)) where
29+
decCBOR =
30+
peekTokenType >>= \case
31+
TypeMapLen -> decodeFromMap
32+
TypeMapLen64 -> decodeFromMap
33+
TypeMapLenIndef -> decodeFromMap
34+
TypeListLen -> decodeFromList
35+
TypeListLen64 -> decodeFromList
36+
TypeListLenIndef -> decodeFromList
37+
_ -> fail "Failed to decode AuxiliaryDataRaw"
38+
where
39+
decodeFromMap =
40+
decode
41+
( Ann (Emit AllegraTxAuxDataRaw)
42+
<*! Ann From
43+
<*! Ann (Emit StrictSeq.empty)
44+
)
45+
decodeFromList =
46+
decode
47+
( Ann (RecD AllegraTxAuxDataRaw)
48+
<*! Ann From
49+
<*! D (sequence <$> decCBOR)
50+
)
51+
52+
deriving via
53+
(Mem (AllegraTxAuxDataRaw era))
54+
instance
55+
Era era => DecCBOR (Annotator (AllegraTxAuxData era))
56+
57+
instance Era era => DecCBOR (Annotator (TimelockRaw era)) where
58+
decCBOR = decode (Summands "TimelockRaw" decRaw)
59+
where
60+
decRaw :: Word -> Decode 'Open (Annotator (TimelockRaw era))
61+
decRaw 0 = Ann (SumD TimelockSignature <! From)
62+
decRaw 1 = Ann (SumD TimelockAllOf) <*! D (sequence <$> decCBOR)
63+
decRaw 2 = Ann (SumD TimelockAnyOf) <*! D (sequence <$> decCBOR)
64+
decRaw 3 = Ann (SumD TimelockMOf) <*! Ann From <*! D (sequence <$> decCBOR)
65+
decRaw 4 = Ann (SumD TimelockTimeStart <! From)
66+
decRaw 5 = Ann (SumD TimelockTimeExpire <! From)
67+
decRaw n = Invalid n
68+
69+
instance Era era => DecCBOR (Annotator (Timelock era)) where
70+
decCBOR = fmap MkTimelock <$> decCBOR
71+
72+
instance
73+
(DecCBOR m, Monoid m, AllegraEraTxBody era) =>
74+
DecCBOR (Annotator (AllegraTxBodyRaw m era))
75+
where
76+
decCBOR = pure <$> decCBOR
77+
78+
deriving via
79+
Mem (AllegraTxBodyRaw () era)
80+
instance
81+
AllegraEraTxBody era => DecCBOR (Annotator (AllegraTxBody era))

eras/alonzo/impl/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Version history for `cardano-ledger-alonzo`
22

3-
## 1.13.1.0
3+
## 1.14.0.0
44

5+
* Move `Annotator` instances and `alonzoSegwitTx` to `testlib`
6+
* Expose `addScriptsTxWitsRaw`, `decodeAlonzoPlutusScript` and `asHashedScriptPair`
7+
* Expose `emptyAlonzoTxAuxDataRaw`, `decodeTxAuxDataByTokenType` and `addPlutusScripts`
58
* Expose `alonzoEqTxWitsRaw` and `emptyTxWitsRaw`
69
* Expose access to `AlonzoTxAuxDataRaw`, `AlonzoTxBodyRaw`, `AlonzoTxWitsRaw`, `RedeemersRaw` and `TxDatsRaw`
710
* Expose constructors `MkAlonzoTxAuxData`, `MkAlonzoTxBody`, `MkAlonzoTxWits`, `MkRedeemers` and `MkTxDats`

0 commit comments

Comments
 (0)