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

Ts newstyle specs #4314

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

Ts newstyle specs #4314

wants to merge 1 commit into from

Conversation

TimSheard
Copy link
Contributor

@TimSheard TimSheard commented May 1, 2024

Use the new style constrained generators to build Specifications of well formed type used in the Cardano Ledger.
Well formed means that constraints that should hold in the NewEpochState on the chain will hold on the randomly generated
values. The (WellFormed t) class has a has a member function with type ( wff :: Gen t )

These Specifications will probably have to be refined over time. But they are complete in that the machinery exists for every
type in the Ledger. Currently they mimic the constraints in the oldstyle constrained generators. They are significantly simpler and much more composeable.

The PR also has a few fixes that were necessary to handle the constraints we wrote. This PR exercised the constrained generators library quite a bit, and it needed some additions. These include

  • Filled in missing cases in computation of cardinality, methods cardinalTypeSpec and cardinalTrueSpec
  • Better use of constraints like (x ==. mempty) to get accurate size information
  • Added typeSpecOpt to a few HasSpec instances
  • Added the function rngSet_ :: Term fn (Map a b) -> Term (Set b)

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

@TimSheard TimSheard force-pushed the ts-newstyle-specs branch 4 times, most recently from bc6ff1d to 87d7cd0 Compare May 3, 2024 23:49
@MaximilianAlgehed
Copy link
Collaborator

@TimSheard may I suggest - to make the rngSet_ thing easier to implement - that you rebase this on #4325 and add a TestableFn for rngSetFn? That way you'd get a lot more certainty about the implementation.

Another thing I've been thinking about is it it wouldn't be better to just bite the bullet and implement toSet_ :: Term fn [a] -> Term fn (Set a) instead of special casing it for the range of maps?

@TimSheard TimSheard force-pushed the ts-newstyle-specs branch 2 times, most recently from e132b2d to 191a9e6 Compare May 16, 2024 14:33
@TimSheard
Copy link
Contributor Author

So my experience with maps suggests a solution for List. We can add that later.

@TimSheard TimSheard force-pushed the ts-newstyle-specs branch 3 times, most recently from 0b11983 to 08a72c4 Compare May 30, 2024 23:33
@TimSheard TimSheard force-pushed the ts-newstyle-specs branch 2 times, most recently from 276731a to 6de375e Compare June 2, 2024 11:13
@TimSheard TimSheard marked this pull request as ready for review June 2, 2024 22:36
Added ToDelta as operation on Coin, RngSetFn as operation on Map
Added a tractible type PParamSubset as a SimpleRep type for PParam specs
Added PPUdates, canFollow abstraction
Added CertState, UTxOState, LedgerState, EpochState
Use reify to propagate invariants
Added class WellFormed
Made a few changes to Base.hs, replacing (MemberSpec []) with ErrorSpec
Added HSpec tests
Work on canFollow and dependencies, added (>=.)
Added MinValSize to track size when using rngSet_
Fix omissions and problems with cardinality
Improved SizeSpec's in Sets, List, and Maps. Also add typeSpecOpt to Map and Set
go n cont = do
a <- g
if p a then pure a else scaleT (+ 1) $ go (n - 1) cont
Loose -> (100 :: Int, genError) -- TODO: Maybe 1 is not the right number here!
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems outdated


-- | When a test on a Map spec fails, this function traces the steps, to help
-- discover what went wrong.
manualMapTest ::
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be turned into a test instead?

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.

None yet

3 participants