@@ -55,6 +55,7 @@ import Ouroboros.Consensus.Protocol.TPraos
5555 ( TPraos
5656 , TPraosState (TPraosState )
5757 )
58+ import Ouroboros.Consensus.Shelley.Eras (isBeforeDijkstra )
5859import Ouroboros.Consensus.Shelley.HFEras
5960import Ouroboros.Consensus.Shelley.Ledger
6061import Ouroboros.Consensus.Shelley.Ledger.Query.Types
@@ -79,8 +80,9 @@ import Test.Cardano.Protocol.TPraos.Examples
7980import Test.Util.Orphans.Arbitrary ()
8081import Test.Util.Serialisation.Examples
8182 ( Examples (.. )
83+ , addLabelSuffix
8284 , labelled
83- , unlabelled
85+ , maybeLabelled
8486 )
8587import Test.Util.Serialisation.SomeResult (SomeResult (.. ))
8688
@@ -120,35 +122,46 @@ mkLedgerTables tx =
120122 xs -> xs
121123
122124fromShelleyLedgerExamples ::
125+ forall era .
123126 ShelleyCompatible (TPraos StandardCrypto ) era =>
124127 ProtocolLedgerExamples (SL. BHeader StandardCrypto ) era ->
125128 Examples (ShelleyBlock (TPraos StandardCrypto ) era )
126129fromShelleyLedgerExamples
127130 ProtocolLedgerExamples
128131 { pleLedgerExamples = Shelley. LedgerExamples {.. }
129132 , ..
130- } =
131- Examples
132- { exampleBlock = unlabelled blk
133- , exampleSerialisedBlock = unlabelled serialisedBlock
134- , exampleHeader = unlabelled $ getHeader blk
135- , exampleSerialisedHeader = unlabelled serialisedHeader
136- , exampleHeaderHash = unlabelled hash
137- , exampleGenTx = unlabelled tx
138- , exampleGenTxId = unlabelled $ txId tx
139- , exampleApplyTxErr = unlabelled leApplyTxError
140- , exampleQuery = queries
141- , exampleResult = results
142- , exampleAnnTip = unlabelled annTip
143- , exampleLedgerState = unlabelled ledgerState
144- , exampleChainDepState = unlabelled chainDepState
145- , exampleExtLedgerState = unlabelled extLedgerState
146- , exampleSlotNo = unlabelled slotNo
147- , exampleLedgerConfig = unlabelled ledgerConfig
148- , exampleLedgerTables = unlabelled $ mkLedgerTables leTx
149- }
133+ }
134+ | isBeforeDijkstra (Proxy @ era ) =
135+ mkExample Nothing blkWithoutCert
136+ | otherwise =
137+ mkExample (Just " WithoutPerasCert" ) blkWithoutCert
138+ <> mkExample (Just " WithPerasCert" ) blkWithCert
150139 where
151- blk = toShelleyBlock pleBlock
140+ mkExample lbl blk =
141+ Examples
142+ { exampleBlock = maybeLabelled lbl blk
143+ , exampleSerialisedBlock = maybeLabelled lbl serialisedBlock
144+ , exampleHeader = maybeLabelled lbl (getHeader blk)
145+ , exampleSerialisedHeader = maybeLabelled lbl serialisedHeader
146+ , exampleHeaderHash = maybeLabelled lbl hash
147+ , exampleGenTx = maybeLabelled lbl tx
148+ , exampleGenTxId = maybeLabelled lbl (txId tx)
149+ , exampleApplyTxErr = maybeLabelled lbl leApplyTxError
150+ , exampleQuery = maybe queries (flip addLabelSuffix queries) lbl
151+ , exampleResult = maybe results (flip addLabelSuffix results) lbl
152+ , exampleAnnTip = maybeLabelled lbl annTip
153+ , exampleLedgerState = maybeLabelled lbl ledgerState
154+ , exampleChainDepState = maybeLabelled lbl chainDepState
155+ , exampleExtLedgerState = maybeLabelled lbl extLedgerState
156+ , exampleSlotNo = maybeLabelled lbl slotNo
157+ , exampleLedgerConfig = maybeLabelled lbl ledgerConfig
158+ , exampleLedgerTables = maybeLabelled lbl (mkLedgerTables leTx)
159+ }
160+
161+ SL. Block header body = pleBlock
162+ blkWithoutCert = mkShelleyBlock header body
163+ blkWithCert = mkShelleyBlockWithPerasCert perasCert header body
164+
152165 hash = ShelleyHash $ SL. unHashHeader pleHashHeader
153166 serialisedBlock = Serialised " <BLOCK>"
154167 tx = mkShelleyTx leTx
@@ -169,7 +182,7 @@ fromShelleyLedgerExamples
169182 ]
170183 results =
171184 labelled
172- [ (" LedgerTip" , SomeResult GetLedgerTip (blockPoint blk ))
185+ [ (" LedgerTip" , SomeResult GetLedgerTip (blockPoint blkWithoutCert ))
173186 , (" EpochNo" , SomeResult GetEpochNo (EpochNo 10 ))
174187 , (" EmptyPParams" , SomeResult GetCurrentPParams lePParams)
175188 , (" StakeDistribution" , SomeResult GetStakeDistribution $ fromLedgerPoolDistr lePoolDistr)
@@ -228,6 +241,11 @@ fromShelleyLedgerExamples
228241 ExtLedgerState
229242 ledgerState
230243 (genesisHeaderState chainDepState)
244+ perasCert =
245+ PerasCert
246+ { pcCertRound = PerasRoundNo 10
247+ , pcCertBoostedBlock = blockPoint blkWithoutCert
248+ }
231249
232250 ledgerConfig = exampleShelleyLedgerConfig leTranslationContext
233251
@@ -241,31 +259,39 @@ fromShelleyLedgerExamplesPraos
241259 ProtocolLedgerExamples
242260 { pleLedgerExamples = Shelley. LedgerExamples {.. }
243261 , ..
244- } =
245- Examples
246- { exampleBlock = unlabelled blk
247- , exampleSerialisedBlock = unlabelled serialisedBlock
248- , exampleHeader = unlabelled $ getHeader blk
249- , exampleSerialisedHeader = unlabelled serialisedHeader
250- , exampleHeaderHash = unlabelled hash
251- , exampleGenTx = unlabelled tx
252- , exampleGenTxId = unlabelled $ txId tx
253- , exampleApplyTxErr = unlabelled leApplyTxError
254- , exampleQuery = queries
255- , exampleResult = results
256- , exampleAnnTip = unlabelled annTip
257- , exampleLedgerState = unlabelled ledgerState
258- , exampleLedgerTables = unlabelled $ mkLedgerTables leTx
259- , exampleChainDepState = unlabelled chainDepState
260- , exampleExtLedgerState = unlabelled extLedgerState
261- , exampleSlotNo = unlabelled slotNo
262- , exampleLedgerConfig = unlabelled ledgerConfig
263- }
262+ }
263+ | isBeforeDijkstra (Proxy @ era ) =
264+ mkExample Nothing blkWithoutCert
265+ | otherwise =
266+ mkExample (Just " WithoutPerasCert" ) blkWithoutCert
267+ <> mkExample (Just " WithPerasCert" ) blkWithCert
264268 where
265- blk =
266- toShelleyBlock $
267- let SL. Block hdr1 bdy = pleBlock
268- in SL. Block (translateHeader hdr1) bdy
269+ mkExample lbl blk =
270+ Examples
271+ { exampleBlock = maybeLabelled lbl blk
272+ , exampleSerialisedBlock = maybeLabelled lbl serialisedBlock
273+ , exampleHeader = maybeLabelled lbl $ getHeader blk
274+ , exampleSerialisedHeader = maybeLabelled lbl serialisedHeader
275+ , exampleHeaderHash = maybeLabelled lbl hash
276+ , exampleGenTx = maybeLabelled lbl tx
277+ , exampleGenTxId = maybeLabelled lbl $ txId tx
278+ , exampleApplyTxErr = maybeLabelled lbl leApplyTxError
279+ , exampleQuery = maybe queries (flip addLabelSuffix queries) lbl
280+ , exampleResult = maybe results (flip addLabelSuffix results) lbl
281+ , exampleAnnTip = maybeLabelled lbl annTip
282+ , exampleLedgerState = maybeLabelled lbl ledgerState
283+ , exampleLedgerTables = maybeLabelled lbl $ mkLedgerTables leTx
284+ , exampleChainDepState = maybeLabelled lbl chainDepState
285+ , exampleExtLedgerState = maybeLabelled lbl extLedgerState
286+ , exampleSlotNo = maybeLabelled lbl slotNo
287+ , exampleLedgerConfig = maybeLabelled lbl ledgerConfig
288+ }
289+
290+ SL. Block header' body = pleBlock
291+ header = translateHeader header'
292+
293+ blkWithoutCert = mkShelleyBlock header body
294+ blkWithCert = mkShelleyBlockWithPerasCert perasCert header body
269295
270296 translateHeader :: SL. BHeader StandardCrypto -> Praos. Header StandardCrypto
271297 translateHeader (SL. BHeader bhBody bhSig) =
@@ -305,7 +331,7 @@ fromShelleyLedgerExamplesPraos
305331 ]
306332 results =
307333 labelled
308- [ (" LedgerTip" , SomeResult GetLedgerTip (blockPoint blk ))
334+ [ (" LedgerTip" , SomeResult GetLedgerTip (blockPoint blkWithoutCert ))
309335 , (" EpochNo" , SomeResult GetEpochNo (EpochNo 10 ))
310336 , (" EmptyPParams" , SomeResult GetCurrentPParams lePParams)
311337 , (" StakeDistribution" , SomeResult GetStakeDistribution $ fromLedgerPoolDistr lePoolDistr)
@@ -366,6 +392,11 @@ fromShelleyLedgerExamplesPraos
366392 ExtLedgerState
367393 ledgerState
368394 (genesisHeaderState chainDepState)
395+ perasCert =
396+ PerasCert
397+ { pcCertRound = PerasRoundNo 10
398+ , pcCertBoostedBlock = blockPoint blkWithoutCert
399+ }
369400
370401 ledgerConfig = exampleShelleyLedgerConfig leTranslationContext
371402
0 commit comments