Skip to content

Add golden tests for the rest of the query result types#5794

Merged
lehins merged 25 commits into
masterfrom
aniketd/stable-types-for-queries
May 7, 2026
Merged

Add golden tests for the rest of the query result types#5794
lehins merged 25 commits into
masterfrom
aniketd/stable-types-for-queries

Conversation

@aniketd
Copy link
Copy Markdown
Contributor

@aniketd aniketd commented May 4, 2026

Description

There is no separate issue for this one. Consider this a follow up of #5659 where we add golden examples for all query results.

Note

Some ToJSON instances were found to be orphans in downstream packages because ledger didn't have those instances. These have been added here. Also an instance that could not be found, has been invented.

  1. DefaultVote: from cardano-cli/src/Cardano/CLI/Orphan.hs
  2. StakeSnapshot, StakeSnapshots: from cardano-api/src/Cardano/Api/Internal/Orphans/Serialisation.hs
  3. QueryPoolStateResult: written fresh — no prior ToJSON found across cardano-api, cardano-cli, ouroboros-consensus, or cardano-db-sync, including via intermediate wrapper types. Implemented here via KeyValuePairs to match other query result types.

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.

Comment thread libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/QuerySpec.hs Outdated
Comment thread libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/QuerySpec.hs Outdated
Comment thread libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/QuerySpec.hs Outdated
@aniketd aniketd force-pushed the aniketd/stable-types-for-queries branch from 29462f1 to 46169ab Compare May 5, 2026 13:43
@aniketd aniketd marked this pull request as ready for review May 5, 2026 13:44
@aniketd aniketd requested a review from a team as a code owner May 5, 2026 13:44
@aniketd aniketd requested a review from lehins May 5, 2026 13:44
@Soupstraw
Copy link
Copy Markdown
Contributor

Soupstraw commented May 5, 2026

The golden test files are in binary, which makes them hard to check, I suggest using prettyHexEnc before outputting the result to the file. That way the diffs can be checked visually.

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.

Great job on adding those examples.

Could I please ask you to confirm for each JSON instances that you added in this PR (as a comment on the PR itself, namely in Github, not in code) whether it was moved over from some place in cardano-api/consensus or did you add them yourself? This will be important for integration work and ensuring that we didn't break the interface

Comment thread eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs Outdated
Comment thread eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Comment thread eras/shelley/impl/CHANGELOG.md
Comment thread libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
Comment thread libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
Comment thread libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
@aniketd
Copy link
Copy Markdown
Contributor Author

aniketd commented May 6, 2026

Could I please ask you to confirm for each JSON instances that you added in this PR (as a comment on the PR itself, namely in Github, not in code) whether it was moved over from some place in cardano-api/consensus or did you add them yourself? This will be important for integration work and ensuring that we didn't break the interface

@lehins I have added the details to the PR description, as that it can be found quickly. 👍 Thanks! 🙌

@aniketd
Copy link
Copy Markdown
Contributor Author

aniketd commented May 6, 2026

The golden test files are in binary, which makes them hard to check, I suggest using prettyHexEnc before outputting the result to the file. That way the diffs can be checked visually.

@Soupstraw this would be a change to the test harnesses we are using, and could be a separate PR 👍 Thanks! 🙌

@aniketd aniketd force-pushed the aniketd/stable-types-for-queries branch from dd5ecf3 to 6803880 Compare May 6, 2026 13:03
@lehins
Copy link
Copy Markdown
Collaborator

lehins commented May 6, 2026

The golden test files are in binary, which makes them hard to check, I suggest using prettyHexEnc before outputting the result to the file. That way the diffs can be checked visually.

I do very much appose storing binary golden files in hex form in the repo. Not only they double the size of files and add unnecessary overhead to all golden tests, but they also make PRs enormous in size (since github will start to treat them as text). I am not sure who in their right mind would manually inspect hex diff of golden files in a PR review? IMHO, it would result in a ridiculous and useless diff on Github. @Soupstraw, maybe you by now developed a superpower of reading CBOR in hex form, after so much work on cuddle, but I don't think anyone else wants to read hex in PRs 😅.
We have very nice facilities for inspecting diffs on golden test failures, which is more than enough. Anyone interested in seeing the relevant diff can take a look at a CI failure or run tests locally instead.

aniketd added 11 commits May 7, 2026 09:24
Also export exampleVrfVerKeyHash from Shelley.Examples.
JSON goldens should only need to test encoding, and moreover we have to
ensure that all ledger state query result types are able to be encoded:
and so the test harnesses collapse back to a single one.

Some ToJSON instances were found to be orphans in downstream packages
because ledger didn't have those instances.

* DefaultVote: from cardano-cli/src/Cardano/CLI/Orphan.hs
* StakeSnapshot, StakeSnapshots: from
cardano-api/src/Cardano/Api/Internal/Orphans/Serialisation.hs
* QueryPoolStateResult: written fresh — no prior ToJSON found across
cardano-api, cardano-cli, ouroboros-consensus, or cardano-db-sync,
including via intermediate wrapper types. Implemented here via
KeyValuePairs to match other query result types.

We run the tests to add JSON goldens for queryPoolState,
queryStakePoolDefaultVote, and queryStakeSnapshots, which the new
instances unblock.

Note: this bundles three logical changes (instance absorption, harness
collapse, 3 new goldens).
* Add missing changelog entries.
* Revert missing cddl section in shelley changelog.
* Convert positional args to record syntax in Examples.

Also,
* Needed some examples re-exported from conway, they seemed to have been
updated, and led to updates to the goldens.
@lehins lehins force-pushed the aniketd/stable-types-for-queries branch from 6803880 to 20bfe48 Compare May 7, 2026 06:24
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.

Awesome work!
Thank you!

@lehins lehins enabled auto-merge May 7, 2026 08:11
@lehins lehins merged commit fa039c7 into master May 7, 2026
89 of 95 checks passed
@lehins lehins deleted the aniketd/stable-types-for-queries branch May 7, 2026 09:47
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.

3 participants