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

Resolving TxId in Mockchain #226

Open
koslambrou opened this issue Oct 22, 2024 · 0 comments
Open

Resolving TxId in Mockchain #226

koslambrou opened this issue Oct 22, 2024 · 0 comments

Comments

@koslambrou
Copy link
Collaborator

Issue

As a user of the Mockchain in testing, I want to be able to easily retrieve the Tx given some TxId.

Currently, we can do this by writing the following function:

resolveTxIdsMockchain ::
  ( MonadError (TestError e) m
  , MonadMockchain m
  )
  => [C.TxId]
  -> m [C.Tx C.ConwayEra]
resolveTxIdsMockchain txIds = do
  txs <- getTxs
  let indexedTxs = Map.fromList $ fmap (\tx -> (C.getTxId $ C.getTxBody tx, tx)) txs
  traverse (\txId -> failOnNothing "Could not find TxId in Mockchain transactions" $ Map.lookup txId indexedTxs) txIds

However, that function is inefficient as we need to query all transactions, then manually index them by TxId.

Possible solution

Add in the MockchainState datatype the field Map TxId Tx, and provide a function to query that (similar to what we do with mcsDatums).

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

No branches or pull requests

1 participant