module Hydra.Node.RunSpec where

import Hydra.Prelude
import Test.Hydra.Prelude

import Hydra.Node.Run (ConfigurationException, run)
import Hydra.Options (
  ChainConfig (..),
  DirectChainConfig (..),
  RunOptions (..),
  defaultDirectChainConfig,
  defaultRunOptions,
  genFilePath,
 )
import Test.QuickCheck (generate)

spec :: Spec
spec :: Spec
spec =
  String -> IO () -> SpecWith (Arg (IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"throws exception given options are invalid" (IO () -> SpecWith (Arg (IO ())))
-> IO () -> SpecWith (Arg (IO ()))
forall a b. (a -> b) -> a -> b
$ do
    [String]
cardanoKeys <- Gen [String] -> IO [String]
forall a. Gen a -> IO a
generate (Gen [String] -> IO [String]) -> Gen [String] -> IO [String]
forall a b. (a -> b) -> a -> b
$ Int -> Gen String -> Gen [String]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
1 (String -> Gen String
genFilePath String
"vk")
    [String]
hydraVerificationKeys <- Gen [String] -> IO [String]
forall a. Gen a -> IO a
generate (Gen [String] -> IO [String]) -> Gen [String] -> IO [String]
forall a b. (a -> b) -> a -> b
$ Int -> Gen String -> Gen [String]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
2 (String -> Gen String
genFilePath String
"vk")
    RunOptions -> IO ()
run
      RunOptions
defaultRunOptions
        { chainConfig = Direct defaultDirectChainConfig{cardanoVerificationKeys = cardanoKeys}
        , hydraVerificationKeys
        }
      IO () -> Selector ConfigurationException -> IO ()
forall e a.
(HasCallStack, Exception e) =>
IO a -> Selector e -> IO ()
`shouldThrow` Selector ConfigurationException
aConfigurationException

aConfigurationException :: Selector ConfigurationException
aConfigurationException :: Selector ConfigurationException
aConfigurationException = Bool -> Selector ConfigurationException
forall a b. a -> b -> a
const Bool
True