Skip to content

[#404] Improve expectContractEntrypoints (Cleveland)

Description

Didn't yet add tests, want some feedback as to the general approach here. Note the design notes below highlighted in bold

Disclaimer: some ideas are shamelessly stolen from !682 (closed), but I didn't end up reusing much of the code from there (if at all).


Problem: this function has several usability issues:

  • Uses 'show'
  • Doesn't check for extraneous entrypoints
  • Error messages are pretty non-descriptive
  • Can't pass the expected entrypoint signature unless it's known on the type level (which isn't particularly great for, e.g. "golden tests")

Solution: Most "backstage" changes have to happen in "Test.Cleveland.Michelson.Unit":

  • 'matchContractEntrypoints' is removed (behaviour change with a similar signature, hopefully helps avoid confusion)
  • Introduce a type hierarchy for matching two 'Map EpName Ty' representing expected and actual entrypoints. Define 'Buildable' instances for that.
  • Compare actual contract entrypoints and spec via mkEntrypointsMap (this is somewhat questionanble, needs discussion; In particular, how should we handle duplicate entrypoint names?)
  • Introduce "business end" functions 'contractCoversEntrypoints' (roughly equivalent to the removed 'matchContractEntrypoints'), 'contractMatchesEntrypoints' (exact match), assertion 'assertEPComparisonSuccessful' which can be applied to the result of one of the comparison functions.
  • The new comparison functions DO NOT implicitly round-trip the contract through text. To do that, two new helper functions are introduced: 'withMichelsonOutput' and 'withMichelineOutput' (perhaps more descriptive names would be 'with*Roundtrip', needs discussion)
  • High-level testing functions testContractCoversEntrypoints , testContractMatchesEntrypoints are introduced which make test trees given a contract and an entrypoint spec. These functions do test for Michelson and Micheline roundtrips.

Pretty much the same approach is used with "Test.Cleveland.Lorentz.Unit":

  • 'expectContractEntrypoints' removed (behaviour change)
  • Four new functions introduced, 'testContractCoversEntrypointsT', which accepts type-level spec, and 'testContractCoversEntrypoints', which accepts value-level spec (as 'Map EpName Ty'), and corresponding testContractMatchesEntrypoints[T] variants.

Related issue(s)

Resolves #404 (closed)

Checklist for your Merge Request

Related changes (conditional)

  • Tests (see short guidelines)

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Changelog N/A.

Stylistic guide (mandatory)

Edited by Nikolay Yakimov

Merge request reports