Skip to content

Introduce new AnyShelleyBasedEra type and simplify CDDL tests. #5072

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

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Apr 7, 2023

Introduce new AnyShelleyBasedEra type and simplify CDDL tests.

We inline roundtrip functions that are rarely used and convert test groups to property tests for consistency.

@newhoggy newhoggy marked this pull request as ready for review April 7, 2023 06:31
@newhoggy newhoggy requested a review from carbolymer April 8, 2023 05:05
]
prop_roundtrip_TxWitness_Cddl :: Property
prop_roundtrip_TxWitness_Cddl = H.property $ do
AnyShelleyBasedEra era <- H.forAll $ Gen.element [AnyShelleyBasedEra ShelleyBasedEraShelley .. AnyShelleyBasedEra ShelleyBasedEraAlonzo]
Copy link
Contributor

Choose a reason for hiding this comment

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

minBound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now using both minBound and maxBound.

"Alonzo" -> pure $ AnyShelleyBasedEra ShelleyBasedEraAlonzo
"Babbage" -> pure $ AnyShelleyBasedEra ShelleyBasedEraBabbage
"Conway" -> pure $ AnyShelleyBasedEra ShelleyBasedEraConway
wrong -> fail $ "Failed to parse unknown era: " <> Text.unpack wrong
Copy link
Contributor

Choose a reason for hiding this comment

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

This overlaps with:

instance FromJSON AnyCardanoEra where
   parseJSON = withText "AnyCardanoEra"
     $ \case
        "Byron" -> pure $ AnyCardanoEra ByronEra
        "Shelley" -> pure $ AnyCardanoEra ShelleyEra
        "Allegra" -> pure $ AnyCardanoEra AllegraEra
        "Mary" -> pure $ AnyCardanoEra MaryEra
        "Alonzo" -> pure $ AnyCardanoEra AlonzoEra
        "Babbage" -> pure $ AnyCardanoEra BabbageEra
        "Conway" -> pure $ AnyCardanoEra ConwayEra
        wrong -> fail $ "Failed to parse unknown era: " <> Text.unpack wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's overlap, but this instance can't accept Byron.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added property tests to ensure the cardano and shelley based eras always match except for Byron.

@@ -365,6 +383,62 @@ instance IsShelleyBasedEra BabbageEra where
instance IsShelleyBasedEra ConwayEra where
shelleyBasedEra = ShelleyBasedEraConway

data AnyShelleyBasedEra where
AnyShelleyBasedEra
Copy link
Contributor

Choose a reason for hiding this comment

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

What problem is the introduction of this GADT solving?

Copy link
Contributor Author

@newhoggy newhoggy Apr 11, 2023

Choose a reason for hiding this comment

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

@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch 4 times, most recently from e70d2f2 to e374b40 Compare April 11, 2023 23:34
@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch from e374b40 to 8e5c3bf Compare April 11, 2023 23:44
@newhoggy newhoggy requested a review from Jimbo4350 April 11, 2023 23:49
@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch 2 times, most recently from f7252d4 to 5b2c997 Compare April 12, 2023 00:13
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.

two minor comments, happy to approve after

@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch 2 times, most recently from af398c6 to 0b151b3 Compare April 12, 2023 12:39
@@ -0,0 +1,52 @@
{-# LANGUAGE TypeApplications #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Space between pragma and module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch from 0b151b3 to 1150fb9 Compare April 12, 2023 12:40
@newhoggy newhoggy force-pushed the newhoggy/simplify-cddl-tests branch from 1150fb9 to 09a6d21 Compare April 12, 2023 12:40
@newhoggy newhoggy added this pull request to the merge queue Apr 12, 2023
Merged via the queue into master with commit e7d85bb Apr 12, 2023
@iohk-bors iohk-bors bot deleted the newhoggy/simplify-cddl-tests branch April 12, 2023 13:55
@newhoggy newhoggy changed the title Simplify cddl tests Introduce new AnyShelleyBasedEra type and simplify CDDL tests. Apr 21, 2023
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