Skip to content

Add example transaction golden test for each era#5799

Open
koslambrou wants to merge 2 commits intomasterfrom
koslambrou/golden-example-tx-each-era
Open

Add example transaction golden test for each era#5799
koslambrou wants to merge 2 commits intomasterfrom
koslambrou/golden-example-tx-each-era

Conversation

@koslambrou
Copy link
Copy Markdown
Contributor

@koslambrou koslambrou commented May 5, 2026

Description

Add Test.Cardano.Ledger.Core.Binary.Golden.goldenExampleEraTxCborSpec in cardano-ledger-core:testlib and generate the golden example transactions for each era.

goldenExampleEraTxCborSpec allows us to generate a Spec for
generating a golden/tx.cbor golden file out of some Tx provided as a
parameter.

Then, for each era's test-suite, we call this function to generate the
golden file using the example transaction we have defined for each era.

We also extended EraTest so that we don't need to manually call
getDataFileName in order to get the fullpath for each era's cabal
project.

We also create new Binary.Golden modules for Mary and Babbage (previously
they reused Allegra's and Alonzo's respectively).

Additionally, fix exampleDijkstraBasedTopTx to not add PlutusV4 scripts
to scriptTxWitsL: PlutusV4 is not included in Dijkstra's
transaction_witness_set CDDL, so those scripts were
silently dropped during serialization, causing a roundtrip failure.

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

decoderEquivalenceEraSpec @AlonzoEra @(TxDats AlonzoEra)
decoderEquivalenceEraSpec @AlonzoEra @(Redeemers AlonzoEra)
Binary.txSizeSpec @AlonzoEra
Golden.spec @AlonzoEra
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate execution.

"golden/block.cbor"
(eraProtVerLow @AlonzoEra)
(pleBlock ledgerExamplesAlonzo)
cborAnnGoldenSpec
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate. Now covered by new golden tests.


exampleBabbageNewEpochState ::
( BabbageEraTest era
( BabbageEraPParams era
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took out BabbageEraTest because it now causes a circular dependency because we would need to import import Test.Cardano.Ledger.Babbage.Era.

A solution for this would be to split the Example.hs module into 2: Example.NewEpochState and Example.Tx. Thoughts?

@koslambrou
Copy link
Copy Markdown
Contributor Author

koslambrou commented May 5, 2026

I wasn't 100% sure where to call goldenExampleEraTxCborSpec for each era. The test module structure is not consistent across eras.

A future PR would be required to organize the test modules so that each era follows the same pattern.

@koslambrou koslambrou force-pushed the koslambrou/golden-example-tx-each-era branch 3 times, most recently from 8b6ba69 to 145dd64 Compare May 5, 2026 17:36
koslambrou added 2 commits May 5, 2026 13:47
…c` in cardano-ledger-core:testlib and generate the golden example transactions for each era.

`goldenExampleEraTxCborSpec` allows us to generate a `Spec` for
generating a `golden/tx.cbor` golden file out of some `Tx` provided as a
parameter.

Then, for each era's test-suite, we call this function to generate the
golden file using the example transaction we have defined for each era.

We also extended `EraTest` so that we don't need to manually call
`getDataFileName` in order to get the fullpath for each era's cabal
project.

We also create new `Binary.Golden` modules for Mary and Babbage (previously
they reused Allegra's and Alonzo's respectively, which used the wrong era's
example transactions).

Additionally, fix `exampleDijkstraBasedTopTx` to not add PlutusV4 scripts
to `scriptTxWitsL`: PlutusV4 is not included in Dijkstra's
`transaction_witness_set` CDDL, so those scripts were
silently dropped during serialization, causing a roundtrip failure.
@koslambrou koslambrou force-pushed the koslambrou/golden-example-tx-each-era branch from 145dd64 to 1515f46 Compare May 5, 2026 17:47
@koslambrou koslambrou marked this pull request as ready for review May 6, 2026 11:40
@koslambrou koslambrou requested a review from a team as a code owner May 6, 2026 11:40
Copy link
Copy Markdown
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase it on top of #5803 and use the new hierarchy for example golden tests


mkEraFullPath = getDataFileName

exampleTx = leTx ledgerExamples
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes back to my in a previous PR: #5761 (comment)

For now, I don't think it is needed on its own, but at some point later it will likely be useful. So, we have a choice either start exporting it later, or export the exact same thing example[Era]Tx from every era. It's up to you.

That is exactly where we need this explicit export, because after this PR is merged we will remove leTx from LedgerExamples

Suggested change
exampleTx = leTx ledgerExamples
exampleTx = exampleShelleyTx

Please apply the same suggestion for all eras

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants