Skip to content

[#687] Fix `getRunMode` and `whenEmulated`

Nikolay Yakimov requested to merge lierdakil/#687-fix-run-mode into master

Description

Problem: getRunMode and whenEmulated behave is counter-intuitively, and haddock comments are fairly misleading:

Check at runtime whether are we executed against network or in emulation.

In practice, the result depends solely on the type of the scenario: if it's ClevelandT, getRunMode returns NetworkMode, and for EmulatedT, respectively EmulationMode.

We would like the result to depend on the base monad (i.e. PureM or ClientM) instead.

Solution: Fixing getRunMode turns out to be a little tricky, especially after !1027 (merged), since we don't have late binding, and it makes it impossible to inject the emulated capability mid-scenario.

Hence, getRunMode is replaced by ifEmulation helper. PureM can provide an EmulatedImpl on demand, so we add cmiEmulatedImpl, which is Nothing in ClientM, and implement ifEmulation in terms of that. whenEmulation and a new helper whenNetwork are implemented via ifEmulation.

One quirk is that we need a way to get ClevelandCaps polymorphically, for that clevelandCapsL is introduced. senderL, moneybagL, getMiscCap, getOpsCap can then be defined in terms of clevelandCapsL.

Related issue(s)

Resolves #687 (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.

Stylistic guide (mandatory)

Edited by Nikolay Yakimov

Merge request reports