Skip to content

Commit

Permalink
test suite for Aff Interface - utxosAt
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjmhart committed Jan 9, 2022
1 parent 7588e45 commit 38a2781
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Ogmios.purs
Expand Up @@ -99,12 +99,35 @@ mkOgmiosWebSocket url = do
utxoQueryDispatchIdMap <- createMutableDispatch
let md = (messageDispatch utxoQueryDispatchIdMap)
ws <- _mkWebSocket url
_wsWatch ws (removeAllListeners utxoQueryDispatchIdMap)
_onWsConnect ws $ do
_wsWatch ws (removeAllListeners utxoQueryDispatchIdMap)
_onWsMessage ws (defaultMessageListener md)
_onWsError ws defaultErrorListener
pure $ OgmiosWebSocket ws { utxo: mkListenerSet utxoQueryDispatchIdMap }

mkOgmiosWebSocket'
:: Url
-> (Either Error OgmiosWebSocket -> Effect Unit)
-> Effect Canceler
mkOgmiosWebSocket' url cb = do
utxoQueryDispatchIdMap <- createMutableDispatch
let md = (messageDispatch utxoQueryDispatchIdMap)
ws <- _mkWebSocket url
_onWsConnect ws $ do
_wsWatch ws (removeAllListeners utxoQueryDispatchIdMap)
_onWsMessage ws (defaultMessageListener md)
_onWsError ws defaultErrorListener
cb $ Right $ OgmiosWebSocket ws { utxo: mkListenerSet utxoQueryDispatchIdMap }
pure $ Canceler $ \err -> liftEffect $ cb $ Left $ err

-- makeAff
-- :: forall a
-- . ((Either Error a -> Effect Unit) -> Effect Canceler)
-- -> Aff a

mkOgmiosWebSocketAff :: Url -> Aff OgmiosWebSocket
mkOgmiosWebSocketAff url = makeAff (mkOgmiosWebSocket' url)

-- getter
underlyingWebSocket :: OgmiosWebSocket -> WebSocket
underlyingWebSocket (OgmiosWebSocket ws _) = ws
Expand Down
36 changes: 36 additions & 0 deletions test/AffInterface.purs
@@ -0,0 +1,36 @@
module Test.AffInterface where

import Prelude
import Control.Monad.Reader.Trans (runReaderT)
import Data.Argonaut as Json
import Data.Array as Array
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Effect.Exception.Unsafe (unsafeThrowException)
import Test.Spec.Assertions (shouldSatisfy, shouldNotSatisfy)
import TestM (TestPlanM, ValidationM, runValidationM)
import Mote (group, test)
import Ogmios (mkOgmiosWebSocketAff, utxosAt)

testnet_addr :: String
testnet_addr =
"addr_test1qr7g8nrv76fc7k4ueqwecljxx9jfwvsgawhl55hck3n8uwaz26mpcwu58zdkhpdnc6nuq3fa8vylc8ak9qvns7r2dsysp7ll4d"

-- note: currently this suite relies on Ogmios being open and running against the
-- testnet, and does not directly test outputs, as this suite is intended to
-- help verify that the Aff interface for websockets itself works,
-- not that the data represents expected values, as that would depend on chain
-- state, and ogmios itself.
suite :: TestPlanM Unit
suite = do
group "Aff Int" $
test "UtxosAt" $ do
ws <- mkOgmiosWebSocketAff "ws:127.0.0.1:1337"
(runReaderT
(do
utxoqr <- utxosAt testnet_addr
pure unit
))
{ ws }

2 changes: 2 additions & 0 deletions test/Main.purs
Expand Up @@ -9,6 +9,7 @@ import Effect.Aff.Class (liftAff)
import Test.Spec (Spec, describe, it)
import Test.Spec.Runner (runSpec)
import Test.Spec.Reporter (consoleReporter)
import Test.AffInterface as AffInterface
import Test.Parser as ParseTest
import TestM (TestPlanM)
import Mote (Plan, foldPlan, planT)
Expand Down Expand Up @@ -39,3 +40,4 @@ interpret spif = do
testPlan :: TestPlanM Unit
testPlan = do
ParseTest.suite
AffInterface.suite

0 comments on commit 38a2781

Please sign in to comment.