refactor(api): migrate JSON instances to Exp.IsEra constraints with comprehensive golden tests #1042
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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