Skip to content

Commit

Permalink
add flag to run indexing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
euonymos committed Nov 28, 2024
1 parent 3af9d69 commit baee6d0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
9 changes: 6 additions & 3 deletions docs/catalyst_milestone_reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
## Summary

* L1 indexing:
* [pr]()
* [source]()
* [tests]()
* [Basic indexing support PR #98](https://github.com/mlabs-haskell/cem-script/pull/98)
* [Oura config generation PR #100](https://github.com/mlabs-haskell/cem-script/pull/100)
* [Source](https://github.com/mlabs-haskell/cem-script/blob/master/src/Cardano/CEM/Indexing.hs)
* [Tests for Auction example](https://github.com/mlabs-haskell/cem-script/blob/master/test/OuraFilter/Auction.hs)
* Final code clean-up
* Final tutorial and docs

# Milestone 4

Expand Down
4 changes: 3 additions & 1 deletion src/Cardano/CEM/Indexing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import Cardano.Ledger.BaseTypes qualified as Ledger
import Data.Data (Proxy)
import Data.String (IsString)
import Data.Text qualified as T
import Toml (Table)
import Toml qualified
import Toml.Pretty qualified
import Toml.Schema ((.=))
import Toml.Schema.ToValue qualified as Toml.ToValue
import Prelude
Expand Down Expand Up @@ -62,7 +64,7 @@ ouraMonitoringScript p network sourcePath sinkPath =
. pure
. selectByAddress
. Address.cardanoAddressBech32
<$> Address.scriptC2ardanoAddress p network
<$> Address.scriptCardanoAddress p network

cursor :: Toml.Table
cursor =
Expand Down
22 changes: 15 additions & 7 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ import Prelude
import Test.Hspec (hspec, runIO)

import Auction (auctionSpec)
import Data.Maybe (isJust)
import Dynamic (dynamicSpec)
import OffChain (offChainSpec)
import OuraFilters (ouraFiltersSpec)
import System.Environment (lookupEnv)
import Utils (clearLogs)
import Voting (votingSpec)

main :: IO ()
main = hspec do
auctionSpec
votingSpec
offChainSpec
dynamicSpec
runIO clearLogs
ouraFiltersSpec
main = do
runIndexing <- isJust <$> lookupEnv "INDEXING_TEST"
hspec do
auctionSpec
votingSpec
offChainSpec
dynamicSpec
if runIndexing
then do
-- These tests are not currently supported on CI
runIO clearLogs
ouraFiltersSpec
else pure mempty
16 changes: 8 additions & 8 deletions test/Oura.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Oura (

import Prelude

import Cardano.CEM.Indexing qualified as Config
import Cardano.CEM.Indexing qualified as Indexing
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (Async)
import Control.Concurrent.Async qualified as Async
Expand Down Expand Up @@ -45,7 +45,7 @@ newtype WorkDir = MkWorkDir {unWorkDir :: T.Text}
withOura ::
WorkDir ->
Utils.SpotGarbage IO Process.ProcessHandle ->
(Config.SourcePath -> Config.SinkPath -> Table) ->
(Indexing.SourcePath -> Indexing.SinkPath -> Table) ->
(Oura IO -> IO r) ->
IO r
withOura spotHandle workdir makeConfig =
Expand All @@ -54,25 +54,25 @@ withOura spotHandle workdir makeConfig =
runOura ::
WorkDir ->
Utils.SpotGarbage IO Process.ProcessHandle ->
(Config.SourcePath -> Config.SinkPath -> Table) ->
(Indexing.SourcePath -> Indexing.SinkPath -> Table) ->
Maybe Communication.Interval ->
ContT r IO (Oura IO)
runOura (MkWorkDir (T.unpack -> workdir)) spotHandle makeConfig outputCheckingInterval = do
writerPath <-
ContT $
withNewFile "writer.socket" workdir
sinkPath :: Config.SinkPath <-
sinkPath :: Indexing.SinkPath <-
fmap fromString $
ContT $
withNewFile "sink.socket" workdir
sourcePath :: Config.SourcePath <-
sourcePath :: Indexing.SourcePath <-
fmap fromString $
ContT $
withNewFile "source.socket" workdir
lift $ removeFile $ T.unpack $ Config.unSourcePath sourcePath
lift $ removeFile $ T.unpack $ Indexing.unSourcePath sourcePath
let
config = configToText $ makeConfig sourcePath sinkPath
configPath <- ContT $ withNewFile "config.toml" workdir
config = Indexing.configToText $ makeConfig sourcePath sinkPath
configPath <- ContT $ withNewFile "Indexing.toml" workdir
lift $ T.IO.writeFile configPath config
(ouraHandle, waitingForClose) <- launchOura configPath spotHandle
lift $ Async.link waitingForClose
Expand Down

0 comments on commit baee6d0

Please sign in to comment.