Skip to content
Permalink
Browse files

rework integration Launch helper for Jormungandr, reducing duplication

  • Loading branch information...
KtorZ committed Sep 11, 2019
1 parent 867d9b8 commit 4e9d7ab307b9aa8a27ef9b08da5c910ad4a3d182
Showing with 7 additions and 32 deletions.
  1. +7 −32 lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs
@@ -23,10 +23,6 @@ import Control.Concurrent.Async
( Async, async )
import Control.Monad
( void )
import Data.Aeson
( ToJSON (..), Value (..), object, (.=) )
import Data.Yaml
( encodeFile )
import System.Directory
( createDirectory )
import System.FilePath
@@ -36,6 +32,10 @@ import System.IO.Temp
import Test.Utils.Ports
( randomUnusedTCPPorts )

import qualified Cardano.Wallet.Jormungandr.Compatibility as Jormungandr
import qualified Data.ByteString.Char8 as B8
import qualified Data.Yaml as Yaml

-- | Starts jormungandr on a random port using the integration tests config.
-- The data directory will be stored in a unique location under the system
-- temporary directory.
@@ -53,40 +53,15 @@ launchJormungandr output = do
]
pure (handle, baseUrl, port)

-- | Config for the test jormungandr.
data JormConfig = JormConfig
{ jmStorageDir :: FilePath
, jmRestApiPort :: Int
, jmNodeApiPort :: Int
} deriving (Show, Eq)

instance ToJSON JormConfig where
toJSON cfg = object
[ "storage" .= jmStorageDir cfg
, "rest" .= object
[ "listen" .= ("127.0.0.1:" ++ show (jmRestApiPort cfg))
, "prefix" .= String "api"
]
, "p2p" .= object
[ "trusted_peers" .= ([] :: [Value])
, "topics_of_interest" .= object
[ "messages" .= String "low"
, "blocks" .= String "normal"
]
, "public_address" .=
("/ip4/127.0.0.1/tcp/" ++ show (jmNodeApiPort cfg))
]
]

setupConfig :: IO (BaseUrl, Port "node", FilePath)
setupConfig = do
[apiPort, nodePort] <- randomUnusedTCPPorts 2
tmp <- getCanonicalTemporaryDirectory
configDir <- createTempDirectory tmp "cardano-wallet-jormungandr"
let storageDir = configDir </> "storage"
configYaml = configDir </> "config.yaml"
jormConfig = JormConfig storageDir apiPort nodePort
url = BaseUrl Http "localhost" apiPort "/api"
encodeFile configYaml jormConfig
url = BaseUrl Http "127.0.0.1" apiPort "/api"
jormConfig = Jormungandr.genConfigFile storageDir nodePort url
B8.writeFile configYaml (Yaml.encode jormConfig)
createDirectory storageDir
pure (url, Port apiPort, configYaml)

0 comments on commit 4e9d7ab

Please sign in to comment.
You can’t perform that action at this time.