Skip to content
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

Draft: Use era type class constraints in generators #709

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

locallycompact
Copy link
Contributor

@locallycompact locallycompact commented Dec 13, 2024

Draft. I tried to change some generator to use type classes rather than witnesses, which works - but I struggled to update the tests that use generators in any era. I managed to make it compile, but what I had to do is very unsatisfying, so I'm wondering if anyone can see how to do that part better - or explain why it isn't possible.

Thanks.

Changelog

- description: |
    Change hedgehog generators to use type classes.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

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

)
(genTxBodyContent sbe)
(genTxBodyContent)

Check warning

Code scanning / HLint

Redundant bracket Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs:817:5-22: Warning: Redundant bracket
  
Found:
  (genTxBodyContent)
  
Perhaps:
  genTxBodyContent
:: IsShelleyBasedEra era
=> Gen [KeyWitness era]
genWitnesses = do
bsWits <- Gen.list (Range.constant 0 10) (genShelleyBootstrapWitness)

Check warning

Code scanning / HLint

Redundant bracket Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs:873:44-71: Warning: Redundant bracket
  
Found:
  (genShelleyBootstrapWitness)
  
Perhaps:
  genShelleyBootstrapWitness
=> Gen [KeyWitness era]
genWitnesses = do
bsWits <- Gen.list (Range.constant 0 10) (genShelleyBootstrapWitness)
keyWits <- Gen.list (Range.constant 0 10) (genShelleyKeyWitness)

Check warning

Code scanning / HLint

Redundant bracket Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs:874:45-66: Warning: Redundant bracket
  
Found:
  (genShelleyKeyWitness)
  
Perhaps:
  genShelleyKeyWitness
@@ -33,7 +34,7 @@
prop_roundtrip_txbodycontent_txouts :: forall era. ShelleyBasedEra era -> Property
prop_roundtrip_txbodycontent_txouts era = H.property $ do
(body, content :: TxBodyContent BuildTx era) <-
shelleyBasedEraConstraints era $ H.forAll $ genValidTxBody era
shelleyBasedEraConstraints era $ H.forAll $ genValidTxBody

Check notice

Code scanning / HLint

Redundant $ Note test

cardano-api/test/cardano-api-test/Test/Cardano/Api/TxBody.hs:37:47: Suggestion: Redundant $
  
Found:
  H.forAll $ genValidTxBody
  
Perhaps:
  H.forAll genValidTxBody
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.

1 participant