Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete code for testing generation of jormungandr-config.yaml #956

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/test/unit/Cardano/Pool/MetricsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ prop_combineDefaults
prop_combineDefaults mStake = do
combineMetrics mStake Map.empty Map.empty
===
(Right $ Map.map (, Quantity 0, 0) mStake)
Right (Map.map (, Quantity 0, 0) mStake)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Why not 😅 ...


-- | it fails if a block-producer or performance is not in the stake distr
prop_combineIsLeftBiased
Expand Down
5 changes: 0 additions & 5 deletions lib/jormungandr/test/data/jormungandr/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
storage: "/tmp/cardano-wallet-jormungandr/storage"

rest:
listen: "127.0.0.1:8080"

p2p:
trusted_peers: []
topics_of_interest:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}

-- |
-- Copyright: © 2018-2019 IOHK
Expand All @@ -12,7 +11,6 @@ module Cardano.Wallet.Jormungandr.Launch
( withConfig
, withBackendOnly
, testDataDir
, spec
) where

import Prelude
Expand All @@ -23,32 +21,17 @@ import Cardano.Launcher
( StdStream (..) )
import Cardano.Wallet.Jormungandr.Network
( JormungandrConfig (..), JormungandrConnParams, withJormungandr )
import Cardano.Wallet.Network.Ports
( PortNumber, getRandomPort )
import Control.Exception
( bracket, throwIO )
import Data.Aeson
( Value (..), object, (.=) )
import Data.Aeson.QQ
( aesonQQ )
import Data.Function
( (&) )
import System.Directory
( doesDirectoryExist, removeDirectoryRecursive )
import System.Environment
( lookupEnv )
import System.FilePath
( FilePath, (</>) )
( (</>) )
import System.IO
( IOMode (..), hClose, openFile )
import System.IO.Temp
( createTempDirectory, getCanonicalTemporaryDirectory )
import Test.Hspec
( Spec, describe, it, shouldBe )

import qualified Data.Aeson as Aeson
import qualified Data.Text as T
import qualified Data.Yaml as Yaml

testDataDir :: FilePath
testDataDir = "test" </> "data" </> "jormungandr"
Expand All @@ -69,8 +52,9 @@ setupConfig = do
(Right $ testDataDir </> "block0.bin")
Nothing
(UseHandle logFile)
["--secret", testDataDir </> "secret.yaml"]
genConfigYaml cfg
[ "--secret", testDataDir </> "secret.yaml"
, "--config" , testDataDir </> "config.yaml"
]
pure cfg

teardownConfig :: JormungandrConfig -> IO ()
Expand All @@ -89,50 +73,3 @@ teardownConfig (JormungandrConfig d _ _ output _) = do
withBackendOnly :: (JormungandrConnParams -> IO a) -> IO a
withBackendOnly cb = withConfig $ \jmConfig -> do
withJormungandr nullTracer jmConfig cb >>= either throwIO pure

{-------------------------------------------------------------------------------
Generate YAML config file
-------------------------------------------------------------------------------}

spec :: Spec
spec = describe "genConfigFile integration tests helper" $ do
it "example configuration" $ do
let stateDir = "/state-dir"
genConfigFile stateDir 8081 `shouldBe` [aesonQQ|{
"storage": "/state-dir/chain",
"p2p": {
"trusted_peers": [],
"topics_of_interest": {
"messages": "low",
"blocks": "normal"
},
"public_address" : "/ip4/127.0.0.1/tcp/8081"
}
}|]

genConfigYaml :: JormungandrConfig -> IO ()
genConfigYaml (JormungandrConfig stateDir _ _ _ _) = do
p2pPort <- getRandomPort
genConfigFile stateDir p2pPort
& Yaml.encodeFile nodeConfigFile
where
nodeConfigFile = stateDir </> "jormungandr-config.yaml"

-- | Generate a configuration file for Jö[email protected]
genConfigFile
:: FilePath
-> PortNumber
-> Aeson.Value
genConfigFile stateDir addressPort = object
[ "storage" .= (stateDir </> "chain")
, "p2p" .= object
[ "trusted_peers" .= ([] :: [()])
, "topics_of_interest" .= object
[ "messages" .= String "low"
, "blocks" .= String "normal"
]
, "public_address" .= String publicAddress
]
]
where
publicAddress = T.pack $ mconcat ["/ip4/127.0.0.1/tcp/", show addressPort]