-
Notifications
You must be signed in to change notification settings - Fork 25
test(api): add comprehensive JSON tests for TxOut instances #1005
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
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.
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 |
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.
Shouldn't this be in the gen library?
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.
Moved!
cardano-api/src/Cardano/Api/Era.hs
Outdated
| , caseShelleyToBabbageOrConwayEraOnwards | ||
|
|
||
| -- ** Case on BabbageEraOnwards | ||
| , caseBabbageOnlyOrConwayEraOnwards |
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 actively looking to remove these functions.
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.
Removed!
4f64fb9 to
7ee9c53
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.
7ee9c53 to
9782105
Compare
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