Skip to content

Commit

Permalink
Assert that devnet also holds some UTxO
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jun 3, 2024
1 parent 8bbb264 commit 090a3a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Main where

import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import Pegasus (RunningNode (..), withCardanoNodeDevnet)
import Pegasus (Devnet (..), withCardanoNodeDevnet)
import System.IO (BufferMode (..), hSetBuffering, stdout)
import Text.Pretty.Simple (pPrint)

Expand Down
6 changes: 3 additions & 3 deletions src/Pegasus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import System.IO qualified
import System.Posix (Handler (Catch), installHandler, ownerReadMode, setFileMode, sigTERM)
import System.Process.Typed (setStdout, stopProcess, useHandleClose, waitExitCode, withProcessWait)

data RunningNode = RunningNode
data Devnet = Devnet
{ nodeVersion :: Text
, nodeSocket :: SocketPath
, logFile :: FilePath
Expand All @@ -47,7 +47,7 @@ withCardanoNodeDevnet ::
-- | Directory to persist logs and any state.
FilePath ->
-- | Callback when network started.
(RunningNode -> IO ()) ->
(Devnet -> IO ()) ->
IO ()
withCardanoNodeDevnet dir cont = do
cleanup
Expand All @@ -68,7 +68,7 @@ withCardanoNodeDevnet dir cont = do
let socketPath = File $ dir </> nodeSocket
waitForSocket socketPath
cont
RunningNode
Devnet
{ nodeVersion
, nodeSocket = socketPath
, logFile
Expand Down
14 changes: 11 additions & 3 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Data.ByteString qualified as BS
import Data.ByteString.Char8 qualified as BS8
import Data.Function ((&))
import Data.Time (NominalDiffTime)
import Lens.Micro ((^?))
import Lens.Micro.Aeson (key, _Number)
import Lens.Micro ((^..), (^?))
import Lens.Micro.Aeson (key, members, _Number)
import System.Process.Typed (
ExitCode (..),
byteStringOutput,
Expand All @@ -29,7 +29,7 @@ import System.Process.Typed (
)
import System.Timeout (timeout)
import Test.HUnit (assertFailure)
import Test.Hspec (HasCallStack, Spec, hspec, it, shouldReturn, shouldSatisfy)
import Test.Hspec (HasCallStack, Spec, hspec, it, shouldNotBe, shouldReturn, shouldSatisfy)

main :: IO ()
main = hspec spec
Expand All @@ -44,10 +44,14 @@ testStartsDevnetWithin1Second :: IO ()
testStartsDevnetWithin1Second =
withProcessTerm cmd $ \p -> do
failAfter 1 $ waitUntilReady p
-- Devnet should produce blocks
b1 <- cliQueryBlock
threadDelay 100_000 -- TODO: configurable block time
b2 <- cliQueryBlock
b2 `shouldSatisfy` (> b1)
-- Devnet should contain some UTxO
utxo <- cliQueryUTxOList
utxo `shouldNotBe` []
where
waitUntilReady p = do
t <- BS8.hGetLine (getStdout p)
Expand All @@ -64,6 +68,10 @@ testStartsDevnetWithin1Second =
out <- readProcessStdout_ (shell "./tmp-pegasus/bin/cardano-cli query tip --testnet-magic 42 --socket-path tmp-pegasus/node.socket")
pure $ out ^? key "block" . _Number

cliQueryUTxOList = do
out <- readProcessStdout_ (shell "./tmp-pegasus/bin/cardano-cli query utxo --whole-utxo --output-json --testnet-magic 42 --socket-path tmp-pegasus/node.socket")
pure $ out ^.. members

testCardanoNodeEmbed :: IO ()
testCardanoNodeEmbed = do
withProcessTerm cmd $ \_ -> do
Expand Down

0 comments on commit 090a3a3

Please sign in to comment.