Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Jun 8, 2021
1 parent 31d1e96 commit bf9cdf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 4 additions & 7 deletions plutus-pab/src/Plutus/PAB/Core.hs
Expand Up @@ -122,8 +122,7 @@ import Plutus.PAB.Events.Contract (ContractPABRequest)
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse, fromResp)
import Plutus.PAB.Monitoring.PABLogMsg (PABMultiAgentMsg (..))
import Plutus.PAB.Timeout (Timeout)
-- import qualified Plutus.PAB.Timeout as Timeout
import qualified Debug.Trace as Trace
import qualified Plutus.PAB.Timeout as Timeout
import Plutus.PAB.Types (PABError (ContractInstanceNotFound, InstanceAlreadyStopped))
import Plutus.PAB.Webserver.Types (ContractActivationArgs (..))
import Wallet.API (PubKey, Slot)
Expand Down Expand Up @@ -225,12 +224,10 @@ callEndpointOnInstance ::
-> PABAction t env (Maybe NotificationError)
callEndpointOnInstance instanceID ep value = do
state <- asks @(PABEnvironment t env) instancesState
-- timeoutVar <- asks @(PABEnvironment t env) endpointTimeout >>= liftIO . Timeout.startTimeout
result <- liftIO
timeoutVar <- asks @(PABEnvironment t env) endpointTimeout >>= liftIO . Timeout.startTimeout
liftIO
$ STM.atomically
$ Instances.callEndpointOnInstance state (EndpointDescription ep) (JSON.toJSON value) instanceID
Trace.traceM (show result)
pure result
$ Instances.callEndpointOnInstanceTimeout timeoutVar state (EndpointDescription ep) (JSON.toJSON value) instanceID

-- | The 'InstanceState' for the instance. Throws a 'ContractInstanceNotFound' error if the instance does not exist.
instanceStateInternal :: forall t env. ContractInstanceId -> PABAction t env Instances.InstanceState
Expand Down
6 changes: 4 additions & 2 deletions plutus-pab/test/full/Plutus/PAB/Events/ContractSpec.hs
Expand Up @@ -65,15 +65,17 @@ jsonTests =
req = ContractRequest{oldState = State.newState oldState, event = Response{rspRqID = 0, rspItID = 0, rspResponse = JSON.toJSON (ContractHandlersResponse $ AwaitSlotResponse 1)}}
input = BSL.toStrict (JSON.encodePretty req)
v = first (foldMap BS8.unpack) $ runPromptPure (runCliCommand (Proxy @BlockchainActions) (first (T.pack . show) contract) Update) input
result = v >>= JSON.eitherDecode @(PartiallyDecodedResponse ContractHandlerRequest) . BSL.fromStrict
result = v >>= JSON.eitherDecode @ResponseType . BSL.fromStrict

void (assertRight result)
]

assertRight :: Either String a -> IO a
assertRight = either assertFailure pure

initialResponse :: Either String (State.ContractResponse Value Value Value ContractHandlerRequest)
type ResponseType = State.ContractResponse Value Value Value ContractHandlerRequest

initialResponse :: Either String ResponseType
initialResponse =
let v = first (foldMap BS8.unpack) $ runPromptPure (runCliCommand (Proxy @BlockchainActions) (first (T.pack . show) contract) Initialise) mempty
in v >>= JSON.eitherDecode @(State.ContractResponse Value Value Value ContractHandlerRequest) . BSL.fromStrict

0 comments on commit bf9cdf8

Please sign in to comment.