Skip to content

Conversation

@newhoggy
Copy link
Collaborator

@newhoggy newhoggy commented Nov 26, 2025

Summary

This PR adds comprehensive test coverage for the TxOut JSON instances and documents the deprecation of era case* functions.

Changes

1. Deprecation Notice for Era Case Functions

Adds documentation to Cardano.Api.Era.Internal.Case noting that case* functions are deprecated and will be removed in a future release. New code should use direct pattern matching on era witnesses instead.

2. Comprehensive TxOut JSON Tests

Implements extensive test coverage for the ToJSON and FromJSON instances of TxOut, adapted for the Exp.IsEra constraint on ToJSON.

New test modules:

  • Test.Gen.Cardano.Api.TxOut: Specialized generators for TxOut with specific datum types (no datum, datum hash, supplemental, inline) and invalid JSON scenarios
  • 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 Conway era (CtxTx and CtxUTxO)
  • Test.Cardano.Api.TxOut.JsonEdgeCases: Edge case tests for supplemental datum behavior, null field handling, ToJSON output validation
  • Test.Cardano.Api.TxOut.JsonErrorCases: Error case tests for conflicting datums, mismatched hashes, partial fields, invalid data

Note: Tests are limited to Conway era because:

  • ToJSON now uses Exp.IsEra constraint (Conway/Dijkstra only)
  • Dijkstra era is not yet fully supported by shelleyBasedEraConstraints

Test Coverage

  • Roundtrip tests: CtxTx and CtxUTxO contexts
  • Datum-specific tests: No datum, datum hash, supplemental datum, inline datum
  • Error handling: Conflicting datums, mismatched hashes, partial fields, invalid data, missing required fields
  • Edge cases: Supplemental datum field behavior, null field handling, ToJSON output validation

Changelog

- description: |
    Add comprehensive JSON roundtrip and error tests for TxOut instances.
    Document deprecation of case* functions in Era.Internal.Case.
  type:
    - test
    - documentation
  projects:
    - cardano-api
    - cardano-api-gen

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff

@newhoggy newhoggy force-pushed the newhoggy/tests-for-TxOut-2 branch from 55e5a9d to 1eafdd8 Compare November 26, 2025 13:47
@newhoggy newhoggy changed the title Newhoggy/tests for tx out 2 feat: newhoggy tests for TxOut 2 Nov 26, 2025
@newhoggy newhoggy changed the title feat: newhoggy tests for TxOut 2 test(api): add TxOut JSON tests and document case* deprecation Nov 26, 2025
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking until I have time to review. Hopefully be EOD today.

]

-- | Generate a TxOut for a specific era (using appropriate datum types)
genTxOutForEra
Copy link
Contributor

@Jimbo4350 Jimbo4350 Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this being consumed? This function is promoting the propagation of the eon based types we are trying to get rid of e.g AlonzoEraOnwardsAlonzo etc.

Copy link
Collaborator Author

@newhoggy newhoggy Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used. Missed this one when simplifying tests. I have removed it.

@newhoggy newhoggy force-pushed the newhoggy/tests-for-TxOut-2 branch from f90e9af to bbdeb99 Compare November 28, 2025 12:36
@newhoggy newhoggy requested a review from Jimbo4350 November 28, 2025 13:01
Implements extensive test coverage for the ToJSON and FromJSON instances
of TxOut, adapted for the new Exp.IsEra constraint on ToJSON.

Test modules added:
- Test.Gen.Cardano.Api.TxOut: 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 Conway
  era 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

Note: Tests are limited to Conway era because:
- ToJSON now uses Exp.IsEra constraint (Conway/Dijkstra only)
- Dijkstra era is not yet fully supported by shelleyBasedEraConstraints
@newhoggy newhoggy force-pushed the newhoggy/tests-for-TxOut-2 branch from bbdeb99 to db7c007 Compare November 28, 2025 13:03
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