IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
305 stars 213 forks source link

Emulator's ChainState produces an EmulatorState with empty WalletState Map #696

Open catch-21 opened 2 years ago

catch-21 commented 2 years ago

Summary

Using the Emulator's ChainState to produce an EmulatorState results in an empty WalletState Map. This is probably minor because there is agentState for this purpose, but still good to investigate.

Steps to reproduce the behavior

There is a commented out test to recreate this bug, see here. Please re-enable once fixed.

Actual Result

let trace :: Trace.EmulatorTrace () = do
        thisChainState <- Trace.chainState
        let traceBlockchain = thisChainState ^. chainNewestFirst
            traceEmulatorState = emulatorState traceBlockchain
            walletStateMap = traceEmulatorState ^. walletStates
            w1State = fromJust $ M.lookup w1 walletStateMap -- Fails here: Maybe.fromJust: Nothing

Expected Result

It is possible to get all TxOutRef for any wallet from Trace's ChainState.

Describe the approach you would take to fix this

No response

System info

https://github.com/input-output-hk/plutus-apps/commit/a8540dbc92ecf5e6883eb30e3c47efab3f35b446

berewt commented 1 year ago

Indeed emulatorState only recreates the chainState of an EmulatorState. Its main purpose is to perform a partial initialisation of the EmulatorState when we start the emulator, not to provide access to the whole emulatorState. Its behaviour is aligned with the behaviour of the other initializer: create the chain index and update the wallets through the EmulatorEvents. In this particular case, as we don't replay the events on the newly (re)created state, the wallet list is empty.

We have already discussed the need to clean up and clarify the API, especially to clarify which parts of it are public. I think it's a pretty good example of it. I suggest that we remove the test, close the bug and that we initiate an action item (epic or story (?)) about cleaning and clarifying the API.