Use `NetworkEnv` in a cleveland test

Clarification and motivation

Consider a Cleveland test where you need to run an arbitrary tezos-client command.

You'd need to access Cleveland's NetworkEnv (and its inner MorleyClientEnv).

At first glance, using whenNetworkEnabled might seem like what you need for this. However, trying to run withEnv inside a testScenario/testScenarioOnNetwork will cause a deadlock.

test_demo :: TestTree
test_demo =
  whenNetworkEnabled $ \withEnv ->
    testScenarioOnNetwork "Demo" $ scenario do
      runIO $ withEnv \env -> do
        -- run tezos-client commands here
        pass

This is because the NetworkEnv can only be accessed inside a lock. This is done to ensure we never have network tests running in parallel and corrupting tezos-client's data directory.

In the test above, testScenarioOnNetwork grabbed access to the lock, and will not let go of it until the test is done running. withEnv then tried to grab the lock as well, thus leading to a deadlock.

We should think of a way of accommodating this (very real) use case.

Perhaps add a new Cleveland capability that grants the user the ability to call getNetworkEnv, and can only be called in network-only tests? Similar to EmulatedImpl & MonadEmulated, we could have NetworkImpl and MonadNetwork.

Acceptance criteria

  • We can use NetworkEnv / MorleyClientEnv in a Cleveland network test.
Edited by Diogo Castro