/
EndToEndSpec.hs
90 lines (82 loc) · 3.32 KB
/
EndToEndSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module Test.EndToEndSpec where
import Cardano.Prelude
import qualified Data.ByteString as BS
import Data.String (String)
import HydraNode (
failAfter,
getMetrics,
hydraNodeProcess,
readCreateProcess,
sendRequest,
waitForResponse,
withHydraNode,
withMockChain,
)
import Test.Hspec (
Spec,
describe,
it,
shouldSatisfy,
)
import Text.Regex.TDFA
import Text.Regex.TDFA.Text ()
spec :: Spec
spec = describe "End-to-end test using a mocked chain though" $ do
describe "three hydra nodes scenario" $ do
it "inits and closes a head with a single mock transaction" $ do
failAfter 30 $
withMockChain $
withHydraNode 1 $ \n1 ->
withHydraNode 2 $ \n2 ->
withHydraNode 3 $ \n3 -> do
waitForResponse 10 [n1, n2, n3] "NodeConnectedToNetwork"
let contestationPeriod = 3 -- TODO: Should be part of init
sendRequest n1 "Init [1, 2, 3]"
waitForResponse 3 [n1, n2, n3] "ReadyToCommit"
sendRequest n1 "Commit 10"
sendRequest n2 "Commit 20"
sendRequest n3 "Commit 5"
-- NOTE(SN): uses MockTx and its UTxO type [MockTx]
waitForResponse 3 [n1, n2, n3] "HeadIsOpen []"
sendRequest n1 "NewTx (ValidTx 42)"
waitForResponse 10 [n1, n2, n3] "TxConfirmed (ValidTx 42)"
sendRequest n1 "Close"
waitForResponse 3 [n1] "HeadIsClosed 3 [ValidTx 42]"
waitForResponse (contestationPeriod + 3) [n1] "HeadIsFinalized [ValidTx 42]"
-- NOTE(SN): This is likely too detailed and should move to a lower-level
-- integration test
it "init a head and reject too expensive tx" $ do
failAfter 30 $
withMockChain $
withHydraNode 1 $ \n1 ->
withHydraNode 2 $ \n2 ->
withHydraNode 3 $ \n3 -> do
waitForResponse 10 [n1, n2, n3] "NodeConnectedToNetwork"
sendRequest n1 "Init [1, 2, 3]"
waitForResponse 3 [n1, n2, n3] "ReadyToCommit"
sendRequest n1 "Commit 10"
sendRequest n2 "Commit 20"
sendRequest n3 "Commit 5"
waitForResponse 3 [n1, n2, n3] "HeadIsOpen []"
-- NOTE(SN): Everything above this boilerplate
sendRequest n1 "NewTx InvalidTx"
waitForResponse 3 [n1] "TxInvalid InvalidTx"
describe "Monitoring" $ do
it "Node exposes Prometheus metrics on port 6001" $ do
failAfter 20 $
withMockChain $
withHydraNode 1 $ \n1 -> do
withHydraNode 2 $ \_ ->
withHydraNode 3 $ \_ -> do
waitForResponse 10 [n1] "NodeConnectedToNetwork"
sendRequest n1 "Init [1, 2, 3]"
waitForResponse 3 [n1] "ReadyToCommit"
metrics <- getMetrics n1
metrics `shouldSatisfy` ("hydra_head_events 3" `BS.isInfixOf`)
describe "hydra-node executable" $ do
it "display proper semantic version given it is passed --version argument" $ do
failAfter 5 $ do
version <- readCreateProcess (hydraNodeProcess ["--version"]) ""
version `shouldSatisfy` (=~ ("[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9]+)?" :: String))