test(api): add comprehensive JSON tests for TxOut instances#1005
Open
test(api): add comprehensive JSON tests for TxOut instances#1005
Conversation
Jimbo4350
previously requested changes
Nov 11, 2025
Contributor
Jimbo4350
left a comment
There was a problem hiding this comment.
Do we need JSON serialization across all eras? Where is this used? If we do, I want to do away with all of the intermediate eons and parameterize on ShelleyBasedEra era. Soon all of the intermediate eons will be removed.
cardano-api/cardano-api.cabal
Outdated
| Test.Cardano.Api.Transaction.Autobalance | ||
| Test.Cardano.Api.Transaction.Body.Plutus.Scripts | ||
| Test.Cardano.Api.TxBody | ||
| Test.Cardano.Api.TxOut.Gen |
Contributor
There was a problem hiding this comment.
Shouldn't this be in the gen library?
cardano-api/src/Cardano/Api/Era.hs
Outdated
| , caseShelleyToBabbageOrConwayEraOnwards | ||
|
|
||
| -- ** Case on BabbageEraOnwards | ||
| , caseBabbageOnlyOrConwayEraOnwards |
Contributor
There was a problem hiding this comment.
I'm actively looking to remove these functions.
7ee9c53 to
9782105
Compare
5a2b00b to
44ac1d8
Compare
Implements extensive test coverage for the ToJSON and FromJSON instances of TxOut across all eras and contexts, ensuring robust JSON serialization and deserialization behavior. Test modules added: - Test.Cardano.Api.TxOut.Gen: Specialized generators for TxOut with specific datum types (no datum, datum hash, supplemental, inline) and invalid JSON scenarios for error testing - Test.Cardano.Api.TxOut.Helpers: Test utilities including JSON field assertions, parse failure validators, and datum equality checks - Test.Cardano.Api.TxOut.Json: Main test module organizing all test suites - Test.Cardano.Api.TxOut.JsonRoundtrip: Roundtrip property tests for all eras (Shelley through Conway) in both CtxTx and CtxUTxO contexts - Test.Cardano.Api.TxOut.JsonEdgeCases: Edge case tests for supplemental datum behavior, null field handling, and ToJSON output validation - Test.Cardano.Api.TxOut.JsonErrorCases: Error case tests for conflicting datums, mismatched hashes, partial fields, and invalid data Coverage highlights: - All eras from Byron through Dijkstra (where supported) - Both transaction contexts (CtxTx and CtxUTxO) - All datum types including edge cases like supplemental datums - Comprehensive error handling validation - JSON field presence and null handling verification This test suite ensures the TxOut JSON instances maintain backward compatibility while properly handling the complex datum type variations across different Cardano eras.
…operty testing Consolidates individual era-specific test properties into unified era-agnostic implementations that test all Shelley-based eras dynamically. This reduces code duplication and ensures new eras are automatically tested when added to the framework. Replaces 12 individual era test properties with 2 unified implementations
44ac1d8 to
38dcfaa
Compare
Jimbo4350
requested changes
Nov 27, 2025
| ShelleyBasedEraBabbage -> | ||
| Gen.choice | ||
| [ genTxOutWithNoDatum ShelleyBasedEraBabbage | ||
| , genTxOutWithDatumHash AlonzoEraOnwardsBabbage |
|
This PR is stale because it has been open 45 days with no activity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 introduces an extensive test suite to validate the JSON instances for
TxOutacross all Cardano eras and transaction contexts. The tests ensure that JSON serialization and deserialization behave correctly for all datum type variations, including edge cases and error scenarios. Additionally, a helper function for era-specific branching has been exposed in the public API to support cleaner conditional logic when dealing with Babbage vs Conway+ era differences.Preparation for work on #926
How to trust this PR
The test suite provides comprehensive coverage of TxOut JSON behavior:
Test Coverage Added:
Test Infrastructure:
Test.Cardano.Api.TxOut.Gen: Specialized generators for TxOut with specific datum types and invalid JSON scenariosTest.Cardano.Api.TxOut.Helpers: Utilities for JSON field assertions, parse failure validation, and datum equality checksTest.Cardano.Api.TxOut.Json: Main test module organizing all test suitesTest.Cardano.Api.TxOut.JsonRoundtrip: Property tests for all era/context combinationsTest.Cardano.Api.TxOut.JsonEdgeCases: Tests for supplemental datum behavior and null field handlingTest.Cardano.Api.TxOut.JsonErrorCases: Validation of error handling for malformed JSONAPI Enhancement:
caseBabbageOnlyOrConwayEraOnwardsfromCardano.Api.Erato enable cleaner branching logic for Babbage vs Conway+ era featuresTo run the new tests:
Checklist