Skip to content

Export and reuse extractWitnessable* functions in tests#1125

Merged
Jimbo4350 merged 2 commits intomasterfrom
worktree-1083-replace-inline-witness-conversions
Mar 11, 2026
Merged

Export and reuse extractWitnessable* functions in tests#1125
Jimbo4350 merged 2 commits intomasterfrom
worktree-1083-replace-inline-witness-conversions

Conversation

@Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Mar 10, 2026

Changelog

- description: |
    Export `extractWitnessableTxIns`, `extractWitnessableMints`,
    `extractWitnessableCertificates`, `extractWitnessableWithdrawals`,
    `extractWitnessableVotes`, and `extractWitnessableProposals` from
    `Cardano.Api.Experimental.Tx.Internal.BodyContent.New` and
    `Cardano.Api.Experimental.Tx`, and reuse them in tests to eliminate
    duplicated inline conversion logic.
  type:
  - feature
  projects:
  - cardano-api

Context

Closes #1083

How to trust this PR

  • The exported functions are the same logic that was previously inlined as list
    comprehensions in prop_extractAllIndexedPlutusScriptWitnesses
  • Run cabal test cardano-api-test and confirm the property test still passes

Checklist

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

Replace six inline list comprehensions in prop_extractAllIndexedPlutusScriptWitnesses
with calls to the existing extractWitnessable* production helpers, which are now
exported from New.hs and re-exported from Tx.hs.
@Jimbo4350 Jimbo4350 force-pushed the worktree-1083-replace-inline-witness-conversions branch from c2aba71 to 17264b1 Compare March 10, 2026 13:40
@Jimbo4350 Jimbo4350 changed the base branch from main to master March 10, 2026 13:40
@Jimbo4350 Jimbo4350 marked this pull request as ready for review March 10, 2026 13:41
Copilot AI review requested due to automatic review settings March 10, 2026 13:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the prop_extractAllIndexedPlutusScriptWitnesses test by replacing inline list comprehensions with calls to the already-existing production extractWitnessable* functions, eliminating duplicated conversion logic between tests and production code.

Changes:

  • Exports 6 extractWitnessable* functions (TxIns, Mints, Certificates, Withdrawals, Votes, Proposals) from Cardano.Api.Experimental.Tx.Internal.BodyContent.New and Cardano.Api.Experimental.Tx
  • Replaces inline list comprehensions in the test with calls to the newly-exported production functions, removing the now-unused Data.Map.Ordered import

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs Adds 6 extractWitnessable* functions to the module's export list under "Internal conversions"
cardano-api/src/Cardano/Api/Experimental/Tx.hs Re-exports the 6 extractWitnessable* functions under "Internal functions"
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Body/Plutus/Scripts.hs Replaces 6 inline list comprehensions with calls to the production extractWitnessable* functions and removes the unused OMap import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

| let Exp.TxProposalProcedures pMap = generatedTxProposalProcedures
, (p, wit) <- OMap.toAscList pMap
]
map (\(w, sw) -> (w, anyScriptWitnessToAnyWitness sw)) $

Check notice

Code scanning / HLint

Use second Note test

cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Body/Plutus/Scripts.hs:180:22-69: Suggestion: Use second
  
Found:
  \ (w, sw) -> (w, anyScriptWitnessToAnyWitness sw)
  
Perhaps:
  Data.Bifunctor.second anyScriptWitnessToAnyWitness
  
Note: increases laziness
Copy link
Contributor

@carbolymer carbolymer Mar 11, 2026

Choose a reason for hiding this comment

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

@copilot how come it did not show up in the hlint github action?

- Apply fourmolu formatting to Scripts.hs (break long lines)
- Remove ordered-containers from cardano-api-test build-depends
  (unused after replacing inline list comprehensions with direct calls
  to the exported extractWitnessable* functions)
@Jimbo4350 Jimbo4350 force-pushed the worktree-1083-replace-inline-witness-conversions branch from 18c3814 to ee7d59f Compare March 10, 2026 15:41
Copy link
Contributor

Copilot AI commented Mar 11, 2026

@carbolymer I've opened a new pull request, #1127, to work on those changes. Once the pull request is ready, I'll request review from you.

@Jimbo4350 Jimbo4350 added this pull request to the merge queue Mar 11, 2026
Merged via the queue into master with commit 897236c Mar 11, 2026
32 checks passed
@Jimbo4350 Jimbo4350 deleted the worktree-1083-replace-inline-witness-conversions branch March 11, 2026 13:22
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.

Refactor allGeneratedPlutusScriptWitnesses

4 participants