1

I'm writing emulator trace tests for the spacebudz contracts. Here is a minimum example:

{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude     #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE TypeApplications      #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ExtendedDefaultRules  #-}

module Test.EmulatorTrace where

import           Control.Monad           hiding ( fmap )
import           Control.Monad.Freer.Extras    as Extras
import           Data.Default                   ( Default(..) )
import qualified Data.Map                      as Map
import           Ledger
import           Ledger.Ada                    as Ada
import           Ledger.TimeSlot
import           Ledger.Value
import           Plutus.Contract.Trace
import           Plutus.Trace.Emulator         as Emulator
import           PlutusTx.Prelude
import           Prelude                        ( IO
                                                , Show(..)
                                                )
import           Wallet.Emulator.Wallet

import           Contract


test :: IO ()
test = do
  test'

test' :: IO ()
test' = runEmulatorTraceIO' def def myTrace

myTrace :: EmulatorTrace ()
myTrace = do

  h1 <- activateContractWallet (Wallet 1) endpoints
  callEndpoint @"init" h1 ()

  void $ Emulator.waitNSlots 10

However, when trying to activate the wallets for the emulator, I get this error:

src/Test/EmulatorTrace.hs:45:43: error:
    • Ambiguous type variable ‘e0’ arising from a use of ‘endpoints’
      prevents the constraint ‘(Wallet.Types.AsContractError
                                  e0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘e0’ should be.
      These potential instances exist:
        two instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the second argument of ‘activateContractWallet’, namely
        ‘endpoints’
      In a stmt of a 'do' block:
        h1 <- activateContractWallet (Wallet 1) endpoints
      In the expression:
        do h1 <- activateContractWallet (Wallet 1) endpoints
           callEndpoint @"init" h1 ()
           void $ waitNSlots 10
   |
45 |   h1 <- activateContractWallet (Wallet 1) endpoints

How is it possible, when every contract example has the same code?

3 Answers 3

0

Well, it's because you're not specifying where the endpoints variable comes from. So, basically the error is saying: You've various instances of endpoints variable, which of those is it?

Try to specify it on your imports, something like this:

import OffChainCode (endpoints)

And if your offchain code is in the Contract file, try to change the name of the module Contract, as it's a Plutus type.

0

This is changed in newer versions so you need to change:

h1 <- activateContractWallet (Wallet 1) endpoints

to

h1 <- activateContractWallet w1 (endpoints @ContractError)

For w1 you need to import Plutus.Contract.Test and for ContractError Wallet.Types

0

I think your endpoint looks something like this

endpoints :: forall  e. AsContractError e => Contract () yourSchema e ()

now in TraceMonad its confused what type should we put for variable e.

if you change your endpoint definition to

endpoints :: Contract () yourSchema Text ()

This worked fine for me as now we are passing concrete types for endpoint.

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.