1

I'm doing integration tests with Emulation As far as I understand under emulation wallets have initial funds.

Example:

test :: IO ()
test = runEmulatorTraceIO $ do
    let 
        w1 = knownWallet 1
        walletAddress = mockWalletAddress w1
        # how to get utxos for walletAddress under emulator ????

1 Answer 1

1

This helper function can help you. It returns the list of TxOutRef and TxOut owned by an address.

import Control.Lens
import qualified Data.Map as Map
import Ledger 
import Ledger.Index
import Plutus.Trace.Emulator qualified as Trace

getUtxos :: Address -> Trace.EmulatorTrace [(TxOutRef, TxOut)]
getUtxos addr = do
    state <- Trace.chainState
    let utxoIndex = getIndex $ state ^. Trace.index 
        utxos     =  [(oref, o) | (oref, o) <- Map.toList utxoIndex, txOutAddress o == addr]
    pure utxos    
3
  • Oh. Really many thanks ! I'll check Commented Feb 7, 2022 at 17:18
  • @ViktorYasterbov, does it work?
    – kindofdev
    Commented Feb 7, 2022 at 19:16
  • Yeah. Great. Everything is fine. Thank you for help. you gave me good hint eventually how to process things under Emulator. I did the same for getting values etc Commented Feb 9, 2022 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.