-
Notifications
You must be signed in to change notification settings - Fork 26
refactor(api): migrate JSON instances to Exp.IsEra constraints with comprehensive golden tests #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…tion Implements a complete golden test suite for TxOut, TxOutValue, AddressInEra, and ReferenceScript types to ensure JSON format stability after migrating from IsShelleyBasedEra/IsCardanoEra constraints to Exp.IsEra constraints. Test Coverage: - TxOut variations: simple, with datum hash, inline datum, reference script, and full - TxOutValue: lovelace-only and multi-asset configurations - AddressInEra: payment address serialization - ReferenceScript: simple script reference handling - UTxO: complete UTxO map serialization with multiple outputs Golden Test Infrastructure: - Helper functions for constructing test addresses, values, and scripts - Pretty JSON encoding for readable golden files - Comprehensive test data builders with realistic hash values - Support for ConwayEra and future eras (Dijkstra) This test suite ensures backwards compatibility of the JSON format is maintained during the constraint migration, preventing breaking changes in API consumers that depend on JSON serialization.
4c21458 to
12c860a
Compare
Refactors JSON serialization instances for core types to use the experimental Exp.IsEra constraint system instead of IsShelleyBasedEra/IsCardanoEra. This unifies the constraint approach across the codebase and simplifies era-based type class instances. Key Changes: - AddressInEra: Migrate ToJSON/FromJSON instances to Exp.IsEra - ReferenceScript: Update JSON instances using Exp.convert for era witnesses - TxOut (CtxTx/CtxUTxO): Consolidate era-specific parsing into unified handlers - TxOutValue: Simplify FromJSON with direct era conversion Implementation Details: - Use Exp.useEra for obtaining era witnesses at the type level - Convert era witnesses to required eon types (AlonzoEraOnwards, BabbageEraOnwards, etc.) - Consolidate duplicate reconciliation logic into single reconcileDatums function - Remove redundant era-specific pattern matching in favor of generic handlers This refactoring maintains full backwards compatibility with existing JSON formats while reducing code duplication and improving maintainability. The changes prepare the codebase for easier extension to future eras by centralizing era-handling logic.
12c860a to
c668629
Compare
Jimbo4350
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this PR in cardano-cli?
Yep, tested locally by referencing |
carbolymer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure about the change in the light of: https://github.com/IntersectMBO/cardano-api/pull/1048/files
@Jimbo4350 would have to double check this.
Changelog
Context
This PR completes the migration of JSON instances to the experimental era infrastructure (
Exp.IsEra), removing the dependency on legacy constraint systems. The refactoring eliminates significant code duplication while preserving the exact JSON serialization format, which is critical for backwards compatibility with existing tools and integrations.The changes are part of upgrading the instance implementations to use the more maintainable and unified era conversion system, making the codebase easier to extend for future eras.
How to trust this PR
The PR includes comprehensive golden tests that verify JSON serialization remains unchanged:
Run the golden tests to verify backwards compatibility:
Key verification points:
cardano-api/test/cardano-api-golden/files/TxOut/demonstrate identical JSON outputChecklist
Changes Made
Refactoring (Commit: 12c860a)
Core API Migrations:
AddressInEraJSON instances fromIsCardanoEra/IsShelleyBasedEratoExp.IsEraReferenceScriptserialization to use new constraints with simplified era handlingTxOut(bothCtxTxandCtxUTxO) JSON parsing to useExp.convertfor era witnessesTxOutValueJSON handling with unified era conversionCode Quality Improvements:
convertfunction callsTesting (Commit: f710b2b)
Golden Test Infrastructure:
Test Coverage:
TxOutValuetests for both lovelace-only and multi-asset valuesAddressInEraserialization testsReferenceScriptgolden testsUTxOserialization with multiple outputsGolden Files Generated:
cardano-api/test/cardano-api-golden/files/TxOut/conway/Technical Details
The refactoring leverages the
Exp.convertfunction to obtain appropriate era witnesses dynamically, eliminating the need for explicit pattern matching on each era. This approach:Impact Analysis