Skip to content

Commit 3ce10be

Browse files
committed
Expand missing transaction content in examples in Test.Cardano.Ledger.<era>.Examples and refactor transaction examples to reduce duplication
1 parent 14994ef commit 3ce10be

20 files changed

Lines changed: 655 additions & 563 deletions

File tree

eras/allegra/impl/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
* Change `ipv4` and `ipv6` to use exact byte sizes (4 and 16 respectively), no longer allowing leftover bytes
1313

14+
### `testlib`
15+
16+
* In `Test.Cardano.Ledger.Allegra.Examples`:
17+
- Remove `mkAllegraBasedExampleTx`, `exampleAllegraBasedTxBody`, `exampleAllegraBasedShelleyTxBody`
18+
- Add `exampleAllegraBasedTx`
19+
1420
## 1.9.0.0
1521

1622
* Add `Generic` instance for `ApplyTxError`

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ library testlib
169169
QuickCheck,
170170
base,
171171
bytestring,
172+
cardano-data,
172173
cardano-ledger-allegra,
173174
cardano-ledger-binary,
174175
cardano-ledger-core:{cardano-ledger-core, testlib},

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Examples.hs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
{-# LANGUAGE TypeApplications #-}
55
{-# LANGUAGE TypeFamilies #-}
66

7+
-- | The example transactions in this module are not valid transactions. We
8+
-- don't care, we are only interested in serialisation, not validation.
79
module Test.Cardano.Ledger.Allegra.Examples (
810
ledgerExamples,
9-
mkAllegraBasedExampleTx,
10-
exampleAllegraBasedTxBody,
11-
exampleAllegraBasedShelleyTxBody,
11+
exampleAllegraBasedTx,
1212
) where
1313

1414
import Cardano.Ledger.Allegra
@@ -24,16 +24,19 @@ import Cardano.Ledger.Shelley.Rules (
2424
)
2525
import Cardano.Ledger.Shelley.Scripts
2626
import Cardano.Slotting.Slot
27-
import qualified Data.Map.Strict as Map
27+
import qualified Data.MapExtras as Map
2828
import qualified Data.Sequence.Strict as StrictSeq
29+
import Data.Typeable (Typeable)
2930
import Lens.Micro
3031
import Test.Cardano.Ledger.Shelley.Examples (
3132
LedgerExamples,
33+
addShelleyBasedTopTxExampleFee,
34+
addShelleyToBabbageExampleProposedPUpdates,
35+
addShelleyToBabbageTxCerts,
36+
addShelleyToConwayTxCerts,
3237
exampleCoin,
33-
exampleShelleyBasedShelleyTxBody,
34-
exampleShelleyBasedTxBody,
38+
exampleShelleyBasedTx,
3539
mkKeyHash,
36-
mkShelleyBasedExampleTx,
3740
mkShelleyBasedLedgerExamples,
3841
)
3942

@@ -44,53 +47,45 @@ ledgerExamples =
4447
DelegateeNotRegisteredDELEG @AllegraEra (mkKeyHash 1)
4548
)
4649
exampleCoin
47-
(mkAllegraBasedExampleTx $ exampleAllegraBasedShelleyTxBody exampleCoin)
50+
exampleAllegraTx
4851
NoGenesis
4952

50-
mkAllegraBasedExampleTx ::
53+
-- Complete Allegra transaction that is compatible until Babbage era
54+
-- ('ConwayEra' is not an instance of 'ShelleyEraTxBody').
55+
exampleAllegraTx ::
5156
forall era.
5257
( EraTx era
5358
, AllegraEraTxAuxData era
5459
, AllegraEraScript era
60+
, AllegraEraTxBody era
61+
, ShelleyEraTxBody era
5562
) =>
56-
TxBody TopTx era ->
5763
Tx TopTx era
58-
mkAllegraBasedExampleTx txBody =
59-
mkShelleyBasedExampleTx @era txBody
60-
& witsTxL . scriptTxWitsL <>~ Map.singleton (hashScript script) script
61-
& auxDataTxL
62-
%~ fmap
63-
( \auxData ->
64-
auxData & nativeScriptsTxAuxDataL <>~ StrictSeq.singleton exampleTimelock
65-
)
66-
where
67-
script = fromNativeScript exampleTimelock
64+
exampleAllegraTx =
65+
exampleAllegraBasedTx
66+
& addShelleyBasedTopTxExampleFee
67+
& addShelleyToBabbageExampleProposedPUpdates
68+
& addShelleyToBabbageTxCerts
69+
& addShelleyToConwayTxCerts
6870

69-
exampleAllegraBasedShelleyTxBody ::
70-
forall era.
71-
( AllegraEraTxBody era
72-
, ShelleyEraTxBody era
71+
-- Complete transaction which is compatible with any era starting with Allegra.
72+
-- This transaction forms the basis on which future era transactions will be
73+
-- at the very least based on.
74+
exampleAllegraBasedTx ::
75+
forall era l.
76+
( EraTx era
77+
, AllegraEraTxAuxData era
78+
, AllegraEraScript era
79+
, AllegraEraTxBody era
80+
, Typeable l
7381
) =>
74-
Value era ->
75-
TxBody TopTx era
76-
exampleAllegraBasedShelleyTxBody value =
77-
mkAllegraBasedExampleTxBody (exampleShelleyBasedShelleyTxBody value)
78-
79-
exampleAllegraBasedTxBody ::
80-
forall era.
81-
AllegraEraTxBody era =>
82-
Value era ->
83-
TxBody TopTx era
84-
exampleAllegraBasedTxBody value =
85-
mkAllegraBasedExampleTxBody (exampleShelleyBasedTxBody value)
86-
87-
mkAllegraBasedExampleTxBody ::
88-
forall era.
89-
AllegraEraTxBody era =>
90-
TxBody TopTx era ->
91-
TxBody TopTx era
92-
mkAllegraBasedExampleTxBody txBody =
93-
txBody & vldtTxBodyL .~ ValidityInterval (SJust (SlotNo 2)) (SJust (SlotNo 4))
82+
Tx l era
83+
exampleAllegraBasedTx =
84+
exampleShelleyBasedTx
85+
& witsTxL . scriptTxWitsL <>~ Map.fromElems hashScript [fromNativeScript exampleTimelock]
86+
& modifyTxAuxData
87+
(nativeScriptsTxAuxDataL <>~ StrictSeq.singleton exampleTimelock)
88+
& bodyTxL . vldtTxBodyL .~ ValidityInterval (SJust (SlotNo 2)) (SJust (SlotNo 4))
9489

9590
exampleTimelock :: AllegraEraScript era => NativeScript era
9691
exampleTimelock =

eras/alonzo/impl/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
* Add `genDatumPresent`
4444
* Added `Proxy era` argument to `exUnitsRule`
4545
* `TranslationInstance` has a new field `tiPlutusPurpose`
46+
* In `Test.Cardano.Ledger.Alonzo.Examples`:
47+
- Remove `mkAlonzoBasedExampleTx`, `exampleAlonzoBasedShelleyTxBody`, `exampleAlonzoBasedTxBody`, `exampleRedeemer`
48+
- Add `exampleAlonzoBasedTopTx`, `exampleAlonzoBasedTopTx`, `addAlonzoToConwayExampleReqSigners`
4649

4750
## 1.15.0.0
4851

0 commit comments

Comments
 (0)