Source file test_chain_status.ml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
type t =
| Not_running
| Forking of {
protocol : Tezos_crypto.Hashed.Protocol_hash.t;
expiration : Time.Protocol.t;
}
| Running of {
chain_id : Tezos_crypto.Hashed.Chain_id.t;
genesis : Tezos_crypto.Hashed.Block_hash.t;
protocol : Tezos_crypto.Hashed.Protocol_hash.t;
expiration : Time.Protocol.t;
}
let equal s1 s2 =
match (s1, s2) with
| Not_running, Not_running -> true
| ( Forking {protocol = p1; expiration = e1},
Forking {protocol = p2; expiration = e2} ) ->
Tezos_crypto.Hashed.Protocol_hash.equal p1 p2 && Time.Protocol.equal e1 e2
| ( Running {chain_id = c1; genesis = g1; protocol = p1; expiration = e1},
Running {chain_id = c2; genesis = g2; protocol = p2; expiration = e2} ) ->
Tezos_crypto.Hashed.Chain_id.equal c1 c2
&& Tezos_crypto.Hashed.Block_hash.equal g1 g2
&& Tezos_crypto.Hashed.Protocol_hash.equal p1 p2
&& Time.Protocol.equal e1 e2
| Not_running, (Forking _ | Running _)
| (Forking _ | Running _), Not_running
| Forking _, Running _
| Running _, Forking _ ->
false
let encoding =
let open Data_encoding in
def
"test_chain_status"
~description:
"The status of the test chain: not_running (there is no test chain at \
the moment), forking (the test chain is being setup), running (the test \
chain is running)."
@@ union
[
case
(Tag 0)
~title:"Not_running"
(obj1 (req "status" (constant "not_running")))
(function Not_running -> Some () | _ -> None)
(fun () -> Not_running);
case
(Tag 1)
~title:"Forking"
(obj3
(req "status" (constant "forking"))
(req "protocol" Tezos_crypto.Hashed.Protocol_hash.encoding)
(req "expiration" Time.Protocol.encoding))
(function
| Forking {protocol; expiration} -> Some ((), protocol, expiration)
| _ -> None)
(fun ((), protocol, expiration) -> Forking {protocol; expiration});
case
(Tag 2)
~title:"Running"
(obj5
(req "status" (constant "running"))
(req "chain_id" Tezos_crypto.Hashed.Chain_id.encoding)
(req "genesis" Tezos_crypto.Hashed.Block_hash.encoding)
(req "protocol" Tezos_crypto.Hashed.Protocol_hash.encoding)
(req "expiration" Time.Protocol.encoding))
(function
| Running {chain_id; genesis; protocol; expiration} ->
Some ((), chain_id, genesis, protocol, expiration)
| _ -> None)
(fun ((), chain_id, genesis, protocol, expiration) ->
Running {chain_id; genesis; protocol; expiration});
]
let pp ppf = function
| Not_running -> Format.fprintf ppf "@[<v 2>Not running@]"
| Forking {protocol; expiration} ->
Format.fprintf
ppf
"@[<v 2>Forking %a (expires %a)@]"
Tezos_crypto.Hashed.Protocol_hash.pp
protocol
Time.System.pp_hum
(Time.System.of_protocol_exn expiration)
| Running {chain_id; genesis; protocol; expiration} ->
Format.fprintf
ppf
"@[<v 2>Running %a@ Genesis: %a@ Net id: %a@ Expiration: %a@]"
Tezos_crypto.Hashed.Protocol_hash.pp
protocol
Tezos_crypto.Hashed.Block_hash.pp
genesis
Tezos_crypto.Hashed.Chain_id.pp
chain_id
Time.System.pp_hum
(Time.System.of_protocol_exn expiration)
let () = Data_encoding.Registration.register ~pp encoding